简体   繁体   English

Webots暂停模拟

[英]Webots pause simulation

I am building a little maze solver project using Webots.我正在使用 Webots 构建一个小迷宫求解器项目。 I am writing my controller in C programming language.我正在用 C 编程语言编写我的控制器。 I am using Windows OS.我正在使用 Windows 操作系统。

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. 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
}

EDIT : The solution was using the Sleep() function.编辑:解决方案是使用Sleep()函数。 It did not work at first because I was not importing the <windows.h> library.起初它不起作用,因为我没有导入<windows.h>库。

I am using Windows.我正在使用 Windows。 I tried using Sleep(1000), but I got a warning...我尝试使用 Sleep(1000),但收到警告...

This small example will compile and run using GCC :这个小例子将使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM