Tahir Mahmood
Tahir Mahmood

Reputation: 313

Controlling Webots simulation step

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?

Upvotes: 2

Views: 2178

Answers (2)

FabienRohrer
FabienRohrer

Reputation: 1834

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)

Upvotes: 2

FabienRohrer
FabienRohrer

Reputation: 1834

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.

Upvotes: 4

Related Questions