我正在使用Webots构建一个小的迷宫求解器项目。我正在用C编程语言编写控制器。
有人可以让我知道发生特定事件时是否可以暂停模拟吗?
类似:
if(event){
pause(10 seconds);
continue();
}
这是我编写的代码的一部分(我想在其中引入暂停)。 while(wb_robot_step(TIME_STEP) != -1)
处于无限while循环中。
int main(int argc, char **argv) {
// initialize the Webots API
wb_robot_init();
// internal variables
WbDeviceTag ps[8];
char ps_names[8][4] = {
"ps0", "ps1", "ps2", "ps3",
"ps4", "ps5", "ps6", "ps7"
};
// initialize devices
for (i = 0; i < 8 ; i++) {
ps[i] = wb_robot_get_device(ps_names[i]);
wb_distance_sensor_enable(ps[i], TIME_STEP);
}
left_motor = wb_robot_get_device("left wheel motor");
right_motor = wb_robot_get_device("right wheel motor");
wb_motor_set_position(left_motor, INFINITY);
wb_motor_set_position(right_motor, INFINITY);
wb_motor_set_velocity(left_motor, 0.0);
wb_motor_set_velocity(right_motor, 0.0);
// 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) {
Sleep(10000);
turnLeft(1);
}
else if(rightWall()==0){
Uturn();
}
}
// cleanup the Webots API
wb_robot_cleanup();
return 0; //EXIT_SUCCESS
}
此小示例将使用GCC:]编译并运行
#include <windows.h> //Sleep()
#include <stdio.h> //printf()
int main(void)
{
Sleep(10000); // 10 seconds
printf("process continuing...\n");
return 0;
}