[英]Webots pause simulation
我正在使用 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>
库。
我正在使用 Windows。 我尝试使用 Sleep(1000),但收到警告...
这个小例子将使用GCC编译和运行:
#include <windows.h> //Sleep()
#include <stdio.h> //printf()
int main(void)
{
Sleep(10000); // 10 seconds
printf("process continuing...\n");
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.