我正在构建一个使用Webots的小迷宫解决方案。我正在用C语言编写控制器。我在使用Windows操作系统。
当某一事件发生时,有人能告诉我是否有办法暂停模拟吗?
类似于:
if(event){
pause(10 seconds);
continue();
}这是我编写的代码的一部分(我想在这里介绍暂停)。while(wb_robot_step(TIME_STEP) != -1)处于无限时间循环中。
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
}编辑:解决方案使用的是Sleep()函数。它一开始不起作用,因为我没有导入<windows.h>库。
发布于 2020-01-08 13:31:21
我在使用Windows。我试过使用睡眠(1000),但我收到警告.
这个小例子将使用https://gcc.gnu.org/编译和运行。
#include <windows.h> //Sleep()
#include <stdio.h> //printf()
int main(void)
{
Sleep(10000); // 10 seconds
printf("process continuing...\n");
return 0;
}https://stackoverflow.com/questions/59646140
复制相似问题