![]() |
5.3 Webots Execution Scheme5.3.1 From the controller's point of viewEach robot controller program is built in the same manner. An initialization with the function robot_live is necessary before starting the robot. A callback function is provided to the robot_live function in order to identify the devices of the robot (see section 5.4). Then an endless loop (usually implemented as a for(;;) { } statement) runs the controller continuously until the simulator decides to terminate it. This endless loop must contain at least one call to the robot_step function which asks the simulator to advance the simulation time a given number of milliseconds, thus advancing the simulation. Before calling robot_step, the controller can enable sensor reading and set actuator commands. Sensor data can be read immediately after calling robot_step. Then you can perform your calculations to determine the appropriate actuator commands for the next step. 5.3.2 From the point of view of WebotsWebots receives controller requests from possibly several robots controllers. Each request is divided into two parts: an actuator command part which takes place immediately, and a sensor measuring part which is scheduled to take place after a given number of milliseconds (as defined by the parameter of the step function). Each request is queued in the scheduler and the simulator advances the simulation time as soon as it receives new requests. 5.3.3 Synchronous versus Asynchronous controllersEach robot (DifferentialWheels or Supervisor) may be either synchronous or asynchronous. Webots waits for the requests of synchronous robots before it advances the simulation time; it doesn't wait for asynchronous ones. Hence an asynchronous robot may be late (if the controller is computationally expensive, or runs on a remote computer with a slow network connection). In this case, the actuator command occurs later than expected. If the controller is very late, the sensor measurement may also occur later than expected. However, this delay can be verified by the robot controller by reading the return value of the robot_step function (see the Reference Manual for more details). In this way the controller can adapt its behavior and compensate. Synchronous controllers are recommended for robust control, while asynchronous controllers are recommended for running robot competitions where computer resources are limited, or for networked simulations involving several robots dispatched over a computer network with an unpredictable delay (like the Internet). ![]() ![]() ![]() ^ page top ^ |
E-mail to webmaster | Last updated: | Copyright © 2002 Cyberbotics Ltd. |