Check-in [670a171020]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Добавлен датчик огня. Добавлены символичекие константы в СУ роботом.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:670a171020245197e7be0a3bbe2db84666bb65ff
User & Date: zhekasakun 2016-11-19 15:14:04
Context
2016-11-19
20:38
Исправлена ошибка с ложными срабатываниями УЗ датчика при питании от сети. При питании от батарей ложные срабатывания остались. check-in: 9fe8e5126e user: zhekasakun tags: trunk
15:14
Добавлен датчик огня. Добавлены символичекие константы в СУ роботом. check-in: 670a171020 user: zhekasakun tags: trunk
2016-11-14
22:16
Повторил то, что было у Димы. check-in: e4b88a2fdf user: zhekasakun tags: trunk
Changes

Changes to src/firebot2/firebot/firebot.atsuo.

cannot compute difference between binary files

Changes to src/firebot2/firebot/src/RobotControl.c.

72
73
74
75
76
77
78





79

80
81
82
83
84
85
86
..
89
90
91
92
93
94
95



96
97
98
99
100
101
102
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329


330
331
332
333
334
335
336
...
454
455
456
457
458
459
460


461
462
463
464
465
466
467
...
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502









503
504
505
506
507
508
509
void scanningCurrent();

char status_robot[10];					
StatesRobot_t state_robot = WAIT;

uint8_t state_autopilot;
float dist_left, dist_right;





uint8_t chose_way, turn_left;

uint8_t tmp1,tmp2;
uint8_t degree_turn = 1;

//Главная функция управления роботом
void mainRobot()
{	
	sei();
................................................................................
	initUltrasonic();
	initDrive(HEAD);						
	initWheelDrive();							
	startADC(0);        // Запуск АЦП для его калибровки
	//sendStrRFM("Ready robot");
	setStateRobot(AUTO);
	



	/*LED(ON,LED_SCAN);
	LED(OFF,LED_RFM);
	//sprintf(status_robot,"Autopilot");
	onCheckCollision(FORWARD);
	state_autopilot = MOVE;
	movement(FORWARD,MIN,0);
	state_robot = AUTO;*/
................................................................................
						offCheckCollision();
						/*LED(ON,IR_ROBOT_3);
						LED(ON,IR_ROBOT_4);*/
						LED(ON,LED_RFM);
						LED(OFF,LED_SCAN);
						measure(ULTRASONIC, HEAD, HEAD_LEFT);
						state_autopilot = OBSTACLE_SPACE;
						chose_way = 0;
						//ctr_tmp = 0;
						state_tmp = 0;
						//sendStrRFM("1");
					}
					else{
						//if(isObstacleSurface()){
						if(0){	
................................................................................
							}
							else{
								LED(ON, IR_ROBOT_3);
								turn_left = 0;
							}
							movement(BACKWARD,MIN,5);	
							state_autopilot = OBSTACLE_SURFACE;
							chose_way = 0;
						}
					}
					break; 
				//Обнаружено припядствие
				case OBSTACLE_SPACE:
					
					switch(chose_way){
						case 0:
						switch (state_tmp)
						{
							case 0:
									if(readyDistance() || completeCtrScan()){
										dist_right = getUltrasonic();
										measure(ULTRASONIC, HEAD, HEAD_RIGHT);
										chose_way = 1;
										//sendStrRFM("2");
									}
									break;
								case 1:
									if (isMeasureUltrasonic()){
										dist_right = getUltrasonic();
										//sendStrRFM("2.1");
										chose_way = 1;
									}
									break;
							}
							//if(getStrMeasure() != NULL){
							/*else{
								if(readyDistance() == -1){
									LED(OFF, IR_ROBOT_4);
................................................................................
									movement(RIGHT, MIN, 25);
									setPositionDrive(HEAD, HEAD_LEFT);
									turn_left = 0;
									chose_way = 2;
								}
							}*/
							break;
						case 1:
							//if(getStrMeasure() != NULL){
							if (readyDistance()){
								//sendStrRFM("3");
								dist_left = getUltrasonic();
								if ((dist_left < 4) && (dist_right < 4)){
									movement(BACKWARD, MIN, 2);
									chose_way = 3;
								}
								else{
									if (dist_left >= dist_right){	
										LED(OFF, IR_ROBOT_4);
										movement(RIGHT, MIN, 30);
										setPositionDrive(HEAD, HEAD_LEFT);
										turn_left = 0;
										chose_way = 2;
									}
									else{
										LED(OFF, IR_ROBOT_3);
										movement(LEFT, MIN, 28);
										setPositionDrive(HEAD,HEAD_RIGHT);
										turn_left = 1;
										chose_way = 2;
									}	
								}
							}
							/*if (ctr_tmp++ > 1000){
								startUltrasonic();
							}*/
							
................................................................................
									movement(LEFT, MIN, 25);
									setPositionDrive(HEAD, HEAD_RIGHT);
									turn_left = 0;
									chose_way = 2;
								}
							}*/
							break;
						case 2:
							if(processMovement()){
								LED(OFF,LED_RFM);
								LED(ON,LED_SCAN);
								onCheckCollision(FORWARD_CHECK);
								movement(FORWARD, MIN, 0);
								state_autopilot = MOVE;
							}
							break;
						case 3:
							if(processMovement()){
								measure(ULTRASONIC, HEAD, HEAD_LEFT);
								chose_way = 0;
							}
							break;	
					}
					break;
				case OBSTACLE_SURFACE:
					switch(chose_way){
						case 0:
							if(processMovement()){
								if(turn_left){
									movement(LEFT, MIN, 222);
									setPositionDrive(HEAD,HEAD_LEFT);
									chose_way = 1;
								}
								else{
									movement(RIGHT, MAX, 222);
									setPositionDrive(HEAD,HEAD_RIGHT);
									chose_way = 1;
								}
							}
							break;
						case 1:
							if (turn_left)
								tmp1 = gettingADC(IR_ROBOT_4);
							else
								tmp1 = gettingADC(IR_ROBOT_3);	
							if((processMovement() == 1) || (tmp1 < 100)){
								LED(OFF,LED_RFM);
								LED(ON,LED_SCAN);
								LED(OFF, IR_ROBOT_3);
								LED(OFF, IR_ROBOT_4);
								onCheckCollision(FORWARD_CHECK);
								movement(FORWARD, MAX, 0);
								state_autopilot = MOVE;
							}


							break;
					}
			}
			break;
	}
}

................................................................................
				measure(INFRARED, CARRIAGE, position);
				return 1;
			} 
		}
	}
	return 0;		
}



//Обработчик запроса передвижения
uint8_t movementQuery(char *query_move)
{
	char cmd[8];
	char direct[8] = {'\0'};
	//int spd = 0;
................................................................................
					onCheckCollision(BACKWARD_CHECK);
					movement(BACKWARD,MIN,0);
					return 1;
			}
			if (strcmp(direct,"left") == 0){
					offCheckCollision();
					onCheckCollision(LEFT_CHECK);
					movement(LEFT,MIN,0);
					return 1;
			}
			if (strcmp(direct,"right") == 0){
					offCheckCollision();
					onCheckCollision(RIGHT_CHECK);
					movement(RIGHT,MIN,0);
					return 1;
			}
			if(strcmp(direct,"stop") == 0){
				setStateRobot(WAIT);
				return 0;
			}	
			if(strcmp(direct,"auto") == 0){	
				setStateRobot(AUTO);
				return 0;
			}









	}
	return 0;		
}
	
void scanningCurrent()
{
			const uint16_t  NUM = 200;







>
>
>
>
>
|
>







 







>
>
>







 







|







 







|







|


|



|







|







 







|






|







|






|







 







|








|


|






|




|




|



|













>
>







 







>
>







 







|





|










>
>
>
>
>
>
>
>
>







72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
..
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
...
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
...
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
...
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
void scanningCurrent();

char status_robot[10];					
StatesRobot_t state_robot = WAIT;

uint8_t state_autopilot;
float dist_left, dist_right;
enum {
	WAIT_LEFT_MEAS,
	WAIT_RIGHT_MEAS,
	WAIT_ROTATION,
	WAIT_REVERSE_MOVE
} chose_way;
uint8_t turn_left;
uint8_t tmp1,tmp2;
uint8_t degree_turn = 1;

//Главная функция управления роботом
void mainRobot()
{	
	sei();
................................................................................
	initUltrasonic();
	initDrive(HEAD);						
	initWheelDrive();							
	startADC(0);        // Запуск АЦП для его калибровки
	//sendStrRFM("Ready robot");
	setStateRobot(AUTO);
	
	//Cooler
	DDRC |= (1<<6);
	
	/*LED(ON,LED_SCAN);
	LED(OFF,LED_RFM);
	//sprintf(status_robot,"Autopilot");
	onCheckCollision(FORWARD);
	state_autopilot = MOVE;
	movement(FORWARD,MIN,0);
	state_robot = AUTO;*/
................................................................................
						offCheckCollision();
						/*LED(ON,IR_ROBOT_3);
						LED(ON,IR_ROBOT_4);*/
						LED(ON,LED_RFM);
						LED(OFF,LED_SCAN);
						measure(ULTRASONIC, HEAD, HEAD_LEFT);
						state_autopilot = OBSTACLE_SPACE;
						chose_way = WAIT_LEFT_MEAS;
						//ctr_tmp = 0;
						state_tmp = 0;
						//sendStrRFM("1");
					}
					else{
						//if(isObstacleSurface()){
						if(0){	
................................................................................
							}
							else{
								LED(ON, IR_ROBOT_3);
								turn_left = 0;
							}
							movement(BACKWARD,MIN,5);	
							state_autopilot = OBSTACLE_SURFACE;
							chose_way = WAIT_LEFT_MEAS;
						}
					}
					break; 
				//Обнаружено припядствие
				case OBSTACLE_SPACE:
					
					switch(chose_way){
						case WAIT_LEFT_MEAS:
						switch (state_tmp)
						{
								case 0:
									if(readyDistance() || completeCtrScan()){
										dist_right = getUltrasonic();
										measure(ULTRASONIC, HEAD, HEAD_RIGHT);
										chose_way = WAIT_RIGHT_MEAS;
										//sendStrRFM("2");
									}
									break;
								case 1:
									if (isMeasureUltrasonic()){
										dist_right = getUltrasonic();
										//sendStrRFM("2.1");
										chose_way = WAIT_RIGHT_MEAS;
									}
									break;
							}
							//if(getStrMeasure() != NULL){
							/*else{
								if(readyDistance() == -1){
									LED(OFF, IR_ROBOT_4);
................................................................................
									movement(RIGHT, MIN, 25);
									setPositionDrive(HEAD, HEAD_LEFT);
									turn_left = 0;
									chose_way = 2;
								}
							}*/
							break;
						case WAIT_RIGHT_MEAS:
							//if(getStrMeasure() != NULL){
							if (readyDistance()){
								//sendStrRFM("3");
								dist_left = getUltrasonic();
								if ((dist_left < 4) && (dist_right < 4)){
									movement(BACKWARD, MIN, 2);
									chose_way = WAIT_REVERSE_MOVE;
								}
								else{
									if (dist_left >= dist_right){	
										LED(OFF, IR_ROBOT_4);
										movement(RIGHT, MIN, 30);
										setPositionDrive(HEAD, HEAD_LEFT);
										turn_left = 0;
										chose_way = WAIT_ROTATION;
									}
									else{
										LED(OFF, IR_ROBOT_3);
										movement(LEFT, MIN, 28);
										setPositionDrive(HEAD,HEAD_RIGHT);
										turn_left = 1;
										chose_way = WAIT_ROTATION;
									}	
								}
							}
							/*if (ctr_tmp++ > 1000){
								startUltrasonic();
							}*/
							
................................................................................
									movement(LEFT, MIN, 25);
									setPositionDrive(HEAD, HEAD_RIGHT);
									turn_left = 0;
									chose_way = 2;
								}
							}*/
							break;
						case WAIT_ROTATION:
							if(processMovement()){
								LED(OFF,LED_RFM);
								LED(ON,LED_SCAN);
								onCheckCollision(FORWARD_CHECK);
								movement(FORWARD, MIN, 0);
								state_autopilot = MOVE;
							}
							break;
						case WAIT_REVERSE_MOVE:
							if(processMovement()){
								measure(ULTRASONIC, HEAD, HEAD_LEFT);
								chose_way = WAIT_LEFT_MEAS;
							}
							break;	
					}
					break;
				case OBSTACLE_SURFACE:
					switch(chose_way){
						case WAIT_LEFT_MEAS:
							if(processMovement()){
								if(turn_left){
									movement(LEFT, MIN, 222);
									setPositionDrive(HEAD,HEAD_LEFT);
									chose_way = WAIT_RIGHT_MEAS;
								}
								else{
									movement(RIGHT, MAX, 222);
									setPositionDrive(HEAD,HEAD_RIGHT);
									chose_way = WAIT_RIGHT_MEAS;
								}
							}
							break;
						case WAIT_RIGHT_MEAS:
							if (turn_left)
								tmp1 = gettingADC(IR_ROBOT_4);
							else
								tmp1 = gettingADC(IR_ROBOT_3);	
							if((processMovement() == 1) || (tmp1 < 100)){
								LED(OFF,LED_RFM);
								LED(ON,LED_SCAN);
								LED(OFF, IR_ROBOT_3);
								LED(OFF, IR_ROBOT_4);
								onCheckCollision(FORWARD_CHECK);
								movement(FORWARD, MAX, 0);
								state_autopilot = MOVE;
							}
							break;
						default:
							break;
					}
			}
			break;
	}
}

................................................................................
				measure(INFRARED, CARRIAGE, position);
				return 1;
			} 
		}
	}
	return 0;		
}

char answer[3];

//Обработчик запроса передвижения
uint8_t movementQuery(char *query_move)
{
	char cmd[8];
	char direct[8] = {'\0'};
	//int spd = 0;
................................................................................
					onCheckCollision(BACKWARD_CHECK);
					movement(BACKWARD,MIN,0);
					return 1;
			}
			if (strcmp(direct,"left") == 0){
					offCheckCollision();
					onCheckCollision(LEFT_CHECK);
					movement(RIGHT,MIN,0);
					return 1;
			}
			if (strcmp(direct,"right") == 0){
					offCheckCollision();
					onCheckCollision(RIGHT_CHECK);
					movement(LEFT,MIN,0);
					return 1;
			}
			if(strcmp(direct,"stop") == 0){
				setStateRobot(WAIT);
				return 0;
			}	
			if(strcmp(direct,"auto") == 0){	
				setStateRobot(AUTO);
				return 0;
			}
			if(strcmp(direct,"fire") == 0){
				setStateRobot(WAIT);
				answer[0] = (char)gettingADC(1);
				answer[1] = 123;
				answer[2] = '\0';
				PORTC ^= (1<<6);
				sendingStrRFM(answer);
				return 0;
			}	
	}
	return 0;		
}
	
void scanningCurrent()
{
			const uint16_t  NUM = 200;

Changes to src/firebot2/firebot/src/Scanning subsystem/ADC.c.

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	//Ожидание конца преобразования
	while (ADCSRA & (1<<ADSC));
	return ADCH;
}

uint8_t gettingADC (uint8_t channel_run)
{
	ADMUX = 1 << ADLAR | channel_run;
	//АЦП без прерываний
	ADCSRA = 1<<ADEN | 1 <<ADSC | 1<<ADPS2 | 1<<ADPS1 | 1<<ADPS0;
	while (ADCSRA & (1<<ADSC));
	return ADCH;
}

uint16_t gettingADC_10bit (uint8_t channel)







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	//Ожидание конца преобразования
	while (ADCSRA & (1<<ADSC));
	return ADCH;
}

uint8_t gettingADC (uint8_t channel_run)
{
	ADMUX = 1<<REFS0 | 1 << ADLAR | channel_run;
	//АЦП без прерываний
	ADCSRA = 1<<ADEN | 1 <<ADSC | 1<<ADPS2 | 1<<ADPS1 | 1<<ADPS0;
	while (ADCSRA & (1<<ADSC));
	return ADCH;
}

uint16_t gettingADC_10bit (uint8_t channel)