Controlling Webots simulation step

被刻印的时光 ゝ 提交于 2020-02-05 19:53:18

问题


Is it possible to calculate the Webots simulation step programatically, i.e. each time one module finishes its planing than the Webots should calculate the next simulation step dependent upon the output of the module.

I have checked the Supervisor mode but it does not seems to have some control over the simulation run apart from setting the simulation mode.

Edit 1:

How to "execute one simulation step (ctrl + 1 in the Webots environment)" from the script after the planning completion of one other ROS node?


回答1:


In a Supervisor controller, you can also access to all the Robot API. Therefore, it's possible to get the global discrete time step constant (defined by the WorldInfo.basicTimeStep field) using the wb_robot_get_basic_time_step() function, and to get the simulated time in seconds using the wb_robot_get_time() function.

The simulation basic time step is a constant which cannot be modified during the simulation. The simulation goes ahead when controllers (including supervisors) call the wb_robot_step(int duration) function, and the hand will be given back to the controller after this "duration". During this period, one (or more if "duration" is strictly bigger than "WorldInfo.basicTimeStep") simulation steps can be applied.




回答2:


After your edition, here is a more specific answer. My previous answer remains correct but is more general.

When a controller is synchronized (the default case of the Robot.synchronization field), Webots is waiting that the controller calls the wb_robot_step(int duration) function to perform simulation steps.

So if you would like to perform a single step from a controller (like when pressing to Ctrl + 1, you simply need to call the wb_robot_step(int duration) function once.

To illustrate this, the following controller performs one simulation step every 3 seconds:

"""Perform one simulation step after some event."""

from controller import Robot
import time

robot = Robot()
timestep = int(robot.getBasicTimeStep())

while True:
    time.sleep(3)  # Wait 3 real seconds to simulate a blocking event.

    print 'Perform a simulation step.'
    robot.step(timestep)


来源:https://stackoverflow.com/questions/56953420/controlling-webots-simulation-step

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!