Kilobot and collision detection
Posted: Sun Oct 10, 2021 3:07 pm
My kilobots move randomly in the simulator thanks to a random time for advancement and rotation. By means of the advancement and rotation time I can calculate the distance traveled together with the direction. I have a problem. Given a random advance time, if the kilobot encounters another kilobot or a wall it will not travel the full set distance but travel a shorter distance. How can I solve this problem?
Code: Select all
void loop(){
flag = rand() % 1
if(flag == 0){
set_color(RGB(1, 0, 0));
spinup_motors(kilo_turn_left, 0);
randomAngle = rand() % 100 //To be defined.
delay(randomAngle);
}else{
set_color(RGB(1, 0, 0));
spinup_motors(kilo_turn_left, 0);
randomAngle = rand() % 100 //To be defined.
delay(randomAngle);
}
set_color(RGB(0, 1, 0));
spinup_motors();
set_motors(kilo_straighy_left, kilo_straight_right);
randomTime = rand() % 8000 + 1000
distanceM = randomTimeToM(randomTime);
delay(randomTime);
set_color(RGB(1,0,1));
set_motors(0,0);
delay(800);
}