Revision 624
robot now abandons seeking if receives a new command
trunk/code/projects/colonet/robot/colonet_dragonfly/colonet_dragonfly.c | ||
---|---|---|
29 | 29 |
|
30 | 30 |
static unsigned robot_x, robot_y; |
31 | 31 |
static volatile int updated_robot_pos_ready; |
32 |
static volatile int new_movement_command_received; |
|
32 | 33 |
#define ERROR_MAG_TO_MOTOR_DIFFENTIAL_CONST (1) |
33 | 34 |
|
34 | 35 |
/* Internal function prototypes */ |
... | ... | |
59 | 60 |
robot_x = 0; |
60 | 61 |
robot_y = 0; |
61 | 62 |
updated_robot_pos_ready = 0; |
63 |
new_movement_command_received = 0; |
|
62 | 64 |
|
63 | 65 |
return 0; |
64 | 66 |
} |
... | ... | |
131 | 133 |
} |
132 | 134 |
|
133 | 135 |
static void move_to_position_routine(unsigned target_x, unsigned target_y) { |
136 |
new_movement_command_received = 0; |
|
137 |
|
|
134 | 138 |
usb_puts("move to absolute position routine!\n"); |
135 |
|
|
139 |
|
|
136 | 140 |
updated_robot_pos_ready = 0; |
137 | 141 |
request_abs_position(); // While we're doing this computation, server can be reporting next position. |
138 | 142 |
|
... | ... | |
149 | 153 |
|
150 | 154 |
unsigned last_x = robot_x, last_y = robot_y; |
151 | 155 |
|
152 |
char buf[40]; |
|
156 |
// char buf[40];
|
|
153 | 157 |
//sprintf(buf, "cur dist is %f\n", dist((float)robot_x, (float)robot_y, (float)target_x, (float)target_y)); |
154 | 158 |
//usb_puts(buf); |
155 | 159 |
//sprintf(buf, "radius squared is %f\n", TARGET_POSITION_STOP_DISTANCE_THRESHOLD); |
156 | 160 |
//usb_puts(buf); |
157 | 161 |
|
158 |
// usb_puts("entering while loop.\n"); |
|
159 |
|
|
160 |
while (dist(robot_x, robot_y, target_x, target_y) > TARGET_POSITION_STOP_DISTANCE_THRESHOLD) { |
|
161 |
|
|
162 |
// usb_puts("inside while loop.\n"); |
|
163 |
|
|
162 |
while (!new_movement_command_received && |
|
163 |
dist(robot_x, robot_y, target_x, target_y) > TARGET_POSITION_STOP_DISTANCE_THRESHOLD) { |
|
164 | 164 |
updated_robot_pos_ready = 0; |
165 | 165 |
request_abs_position(); // While we're doing this computation, server can be reporting next position. |
166 | 166 |
|
... | ... | |
178 | 178 |
int v_x = cur_robot_x - last_x; |
179 | 179 |
int v_y = cur_robot_y - last_y; |
180 | 180 |
|
181 |
|
|
181 |
// sprintf(buf, "vx:%d vy:%d rx:%d ry:%d ex:%d ey:%d\n", v_x, v_y, e_x, e_y, e_x, e_y); |
|
182 |
// usb_puts(buf); |
|
182 | 183 |
|
183 |
sprintf(buf, "vx:%d vy:%d rx:%d ry:%d ex:%d ey:%d\n", v_x, v_y, e_x, e_y, e_x, e_y); |
|
184 |
usb_puts(buf); |
|
185 |
|
|
186 | 184 |
int e_mag = e_x*e_x + e_y*e_y; |
187 | 185 |
|
188 | 186 |
int motor_differential = e_mag >> 7;// / 128; |
... | ... | |
216 | 214 |
// Motor differential proportional to magnitude of directional error. |
217 | 215 |
// int motor_differential = (int)(e_mag * ERROR_MAG_TO_MOTOR_DIFFENTIAL_CONST); |
218 | 216 |
*/ |
219 |
|
|
220 | 217 |
|
218 |
|
|
221 | 219 |
int p_x = v_y; |
222 | 220 |
int p_y = -v_x; |
223 |
|
|
221 |
|
|
224 | 222 |
int e_trans_x = p_x * e_x + p_y * e_y; |
225 | 223 |
|
226 | 224 |
/* |
... | ... | |
246 | 244 |
motor_differential = -motor_differential; |
247 | 245 |
} |
248 | 246 |
|
249 |
sprintf(buf, "motor_diff: %d\n", motor_differential); |
|
250 |
usb_puts(buf); |
|
247 |
// sprintf(buf, "motor_diff: %d\n", motor_differential);
|
|
248 |
// usb_puts(buf);
|
|
251 | 249 |
|
252 | 250 |
last_x = cur_robot_x; |
253 | 251 |
last_y = cur_robot_y; |
... | ... | |
264 | 262 |
} |
265 | 263 |
} |
266 | 264 |
|
267 |
usb_puts("reached destination!\n"); |
|
265 |
// usb_puts("reached destination!\n");
|
|
268 | 266 |
} |
269 | 267 |
|
270 | 268 |
/* Private functions */ |
... | ... | |
279 | 277 |
*/ |
280 | 278 |
static void colonet_handle_receive(char type, int wl_source, unsigned char* packet, int length) { |
281 | 279 |
length = length; |
280 |
wl_source = wl_source; |
|
282 | 281 |
|
283 | 282 |
ColonetRobotServerPacket* pkt = (ColonetRobotServerPacket*)packet; |
284 | 283 |
unsigned char* args; //up to 7 char args |
... | ... | |
294 | 293 |
int i; |
295 | 294 |
for (i = 0; i < length; i++) { |
296 | 295 |
sprintf(buf, "%d: %d ", i, packet[i]); |
297 |
usb_puts(buf);
|
|
296 |
usb_puts(buf); |
|
298 | 297 |
} |
299 | 298 |
usb_puts("\n"); |
300 | 299 |
*/ |
... | ... | |
322 | 321 |
//Sharp |
323 | 322 |
case READ_DISTANCE: |
324 | 323 |
break; |
325 |
case LINEARIZE_DISTANCE: |
|
326 |
break; |
|
327 |
case LOG_DISTANCE: |
|
328 |
break; |
|
329 | 324 |
|
330 | 325 |
//Analog |
331 | 326 |
case CALL_ANALOG8: |
... | ... | |
338 | 333 |
case BATTERY: |
339 | 334 |
sprintf((char*)pkt->data, "%d", (int)battery8()); |
340 | 335 |
|
336 |
usb_puts("battery:"); |
|
337 |
usb_puts((char*)pkt->data); |
|
338 |
usb_puts("\n"); |
|
339 |
|
|
341 | 340 |
// NOTE: wl_send_robot_to_robot_global_packet does not work here! |
342 | 341 |
wl_send_global_packet(COLONET_PACKET_GROUP_ID, 0, (char*)pkt, sizeof(ColonetRobotServerPacket), 0); |
343 |
|
|
344 |
sprintf(buf, "it's a battery request\nsent battery value: %s\n", pkt->data); |
|
345 |
usb_puts(buf); |
|
346 | 342 |
break; |
347 | 343 |
|
348 | 344 |
//BOM |
... | ... | |
353 | 349 |
break; |
354 | 350 |
} |
355 | 351 |
} else if (type == COLONET_COMMAND) { |
356 |
sprintf(buf, "colonet command ... pkt->msg_code=%d\n", pkt->msg_code); |
|
357 |
usb_puts(buf); |
|
352 |
// sprintf(buf, "colonet command ... pkt->msg_code=%d\n", pkt->msg_code);
|
|
353 |
// usb_puts(buf);
|
|
358 | 354 |
|
359 | 355 |
/* TODO uncomment this stuff */ |
360 | 356 |
/* if (pkt.msg_code >= USER_DEFINED_MSG_ID_START && */ |
... | ... | |
383 | 379 |
break; |
384 | 380 |
|
385 | 381 |
case MOVE_TO_ABSOLUTE_POSITION: |
386 |
usb_puts("move to abs position2!\n"); |
|
382 |
new_movement_command_received = 1; |
|
383 |
|
|
384 |
usb_puts("move to abs position!\n"); |
|
387 | 385 |
move_to_position_routine((unsigned)int_args[0], (unsigned)int_args[1]); |
388 | 386 |
break; |
389 | 387 |
|
... | ... | |
403 | 401 |
case BUZZER_OFF: |
404 | 402 |
buzzer_off(); |
405 | 403 |
break; |
404 |
|
|
405 |
//Orb |
|
406 | 406 |
case ORB_INIT: |
407 | 407 |
orb_init(); |
408 | 408 |
break; |
409 |
//Orb |
|
410 | 409 |
case ORB_SET: |
411 | 410 |
orb_set(args[0], args[1], args[2]); |
412 | 411 |
break; |
... | ... | |
419 | 418 |
case ORB_ENABLE: |
420 | 419 |
orb_enable(); |
421 | 420 |
break; |
422 |
case LED_INIT: |
|
423 |
break; |
|
424 |
case LED_USER: |
|
425 |
break; |
|
421 |
|
|
426 | 422 |
//Motors |
427 | 423 |
case MOTORS_INIT: |
428 | 424 |
usb_puts("calling motors_init\n"); |
429 | 425 |
motors_init(); |
430 | 426 |
break; |
431 | 427 |
case MOTOR1_SET: |
428 |
new_movement_command_received = 1; |
|
429 |
|
|
432 | 430 |
sprintf(buf, "calling motor1_set [%i] [%i]\n", args[0], args[1]); |
433 | 431 |
usb_puts(buf); |
434 | 432 |
motor1_set(args[0], args[1]); |
435 | 433 |
break; |
436 | 434 |
case MOTOR2_SET: |
435 |
new_movement_command_received = 1; |
|
436 |
|
|
437 | 437 |
sprintf(buf, "calling motor2_set [%i] [%i]\n", args[0], args[1]); |
438 | 438 |
usb_puts(buf); |
439 | 439 |
motor2_set(args[0], args[1]); |
440 | 440 |
break; |
441 | 441 |
case MOTORS_OFF: |
442 |
new_movement_command_received = 1; |
|
443 |
|
|
442 | 444 |
usb_puts("calling motors_off\n"); |
443 | 445 |
motors_off(); |
444 | 446 |
break; |
445 | 447 |
case MOVE: |
448 |
new_movement_command_received = 1; |
|
449 |
|
|
446 | 450 |
sprintf(buf, "calling move with: %d, %d\n", args[0], args[1]); |
447 | 451 |
usb_puts(buf); |
448 | 452 |
move(args[0], args[1]); |
449 | 453 |
break; |
450 | 454 |
|
451 |
case USB_INIT: |
|
452 |
usb_init(); |
|
453 |
break; |
|
454 |
|
|
455 |
case USB_PUTC: |
|
456 |
usb_putc((char)args[0]); |
|
457 |
break; |
|
458 |
|
|
459 | 455 |
case PRINTF: |
460 |
printf("%s", pkt->data);
|
|
456 |
usb_puts((char*)pkt->data);
|
|
461 | 457 |
break; |
462 | 458 |
case KILL_ROBOT: |
459 |
new_movement_command_received = 1; |
|
460 |
|
|
463 | 461 |
motors_off(); |
464 | 462 |
buzzer_off(); |
465 | 463 |
exit(0); //kill the robot |
trunk/code/projects/colonet/robot/colonet_dragonfly/Makefile | ||
---|---|---|
21 | 21 |
cp libcolonet_dragonfly.a $(COLONYROOT)/code/lib/bin/ |
22 | 22 |
|
23 | 23 |
clean: |
24 |
rm -rf *.o |
|
24 |
rm -rf *.o *.a |
Also available in: Unified diff