From 14e353ce47e5b0cc4a718db7628092aec7aad764 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Mon, 19 Sep 2016 16:18:04 +0200 Subject: [PATCH] react to collision detection randomized --- source/application/collision_ctrl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/application/collision_ctrl.c b/source/application/collision_ctrl.c index 4b878d4..002fc7f 100644 --- a/source/application/collision_ctrl.c +++ b/source/application/collision_ctrl.c @@ -37,6 +37,7 @@ static void collision_ctrl_loop(void *arg) { drv_open(&pwm5_c2); /* trigger pwm */ drv_open(&pwm2_c4); /* read pwm */ + drv_open(&rng); while(1) { int pulse_ns = drv_ioctl(&pwm2_c4, IOCTL_PWM_GET_PULSE_WIDTH_NS, NULL); 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"); shell_write(print_buffer, strlen(print_buffer)); drive_ctrl_backward(); - sleep_ms(3000); /* todo: randomize */ + sleep_ms(500); drive_ctrl_halt(); sprintf(print_buffer, "start turning...\r\n"); shell_write(print_buffer, strlen(print_buffer)); drive_ctrl_turn_left(); - sleep_ms(3000); + sleep_ms(drv_read(&rng, Null, 0) % 3500 + 500); // rand between 500 and 4000 drive_ctrl_halt(); sprintf(print_buffer, "restart forward...\r\n");