I am building a little maze solver project using Webots. I am writing my controller in C programming language. I am using Windows OS.
Can someone let me know if there is a way to pause the simulation when a certain event happens?
Something like :
if(event){
pause(10 seconds);
continue();
}
This is part of the code I wrote (where I want to introduce the pause). while(wb_robot_step(TIME_STEP) != -1)
is in a infinite while loop.
int main(int argc, char **argv) {
//… initialization code for Webots API, not important
// feedback loop: step simulation until an exit event is received
while (wb_robot_step(TIME_STEP) != -1) {
// read sensors outputs
for (i = 0; i < 8 ; i++){
ps_values[i] = wb_distance_sensor_get_value(ps[i]);
}
//program
goForward();
if (forwardWall()==1) {
//pause needed here
turnLeft(1);
}
else if(rightWall()==0){
Uturn();
}
}
// cleanup the Webots API
wb_robot_cleanup();
return 0; //EXIT_SUCCESS
}
EDIT : The solution was using the Sleep()
function. It did not work at first because I was not importing the <windows.h>
library.