react to collision detection randomized
This commit is contained in:
parent
53215d9815
commit
14e353ce47
@ -37,6 +37,7 @@ static void collision_ctrl_loop(void *arg)
|
|||||||
{
|
{
|
||||||
drv_open(&pwm5_c2); /* trigger pwm */
|
drv_open(&pwm5_c2); /* trigger pwm */
|
||||||
drv_open(&pwm2_c4); /* read pwm */
|
drv_open(&pwm2_c4); /* read pwm */
|
||||||
|
drv_open(&rng);
|
||||||
while(1) {
|
while(1) {
|
||||||
int pulse_ns = drv_ioctl(&pwm2_c4, IOCTL_PWM_GET_PULSE_WIDTH_NS, NULL);
|
int pulse_ns = drv_ioctl(&pwm2_c4, IOCTL_PWM_GET_PULSE_WIDTH_NS, NULL);
|
||||||
collision_ctrl_object.distance_mm = 343 * pulse_ns / 1000 / 2;
|
collision_ctrl_object.distance_mm = 343 * pulse_ns / 1000 / 2;
|
||||||
@ -49,13 +50,13 @@ static void collision_ctrl_loop(void *arg)
|
|||||||
sprintf(print_buffer, "going back...\r\n");
|
sprintf(print_buffer, "going back...\r\n");
|
||||||
shell_write(print_buffer, strlen(print_buffer));
|
shell_write(print_buffer, strlen(print_buffer));
|
||||||
drive_ctrl_backward();
|
drive_ctrl_backward();
|
||||||
sleep_ms(3000); /* todo: randomize */
|
sleep_ms(500);
|
||||||
drive_ctrl_halt();
|
drive_ctrl_halt();
|
||||||
|
|
||||||
sprintf(print_buffer, "start turning...\r\n");
|
sprintf(print_buffer, "start turning...\r\n");
|
||||||
shell_write(print_buffer, strlen(print_buffer));
|
shell_write(print_buffer, strlen(print_buffer));
|
||||||
drive_ctrl_turn_left();
|
drive_ctrl_turn_left();
|
||||||
sleep_ms(3000);
|
sleep_ms(drv_read(&rng, Null, 0) % 3500 + 500); // rand between 500 and 4000
|
||||||
drive_ctrl_halt();
|
drive_ctrl_halt();
|
||||||
|
|
||||||
sprintf(print_buffer, "restart forward...\r\n");
|
sprintf(print_buffer, "restart forward...\r\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user