Webots Reference Manual

previous page go up next page

Thanks

1.Introduction

2.Controller API

3.Webots File Format

     

2.1 Robot

robot_die
robot_get_device
robot_live
robot_step

robot_die

NAME

   robot_die -- declare an exit function

SYNOPSIS

  #include <device/robot.h>

  void robot_die(void (*exit_function)(void));

DESCRIPTION

This function declares an exit function to be used whenever a controller quits. A controller can quit for the following reasons: the simulator quits, or the robot quits the simulator by entering an HyperGate to be transfered to another simulation server. In the latter case, it might be useful for the robot to save important data (like an acquired behaviour) before it quits, so that this data can be transfered to the target simulator corresponding to the HyperGate. Hence, when the robot restarts on the other side of the HyperGate, it can retrieve its data in its reset function before it starts running again.

SEE ALSO

robot_live

robot_get_device

NAME

   robot_get_device -- get a pointer to a device

SYNOPSIS

  #include <device/robot.h>

  DeviceTag robot_get_device(const gchar *name);

DESCRIPTION

This function returns a pointer to a device corresponding to a specified DEF name. For example, if the robot contains a DistanceSensor node which DEF name is "ds1", the function will return a pointer to that device. This DeviceTag pointer will be used subsequently for enabling, sending command to, or reading data from this device.

SEE ALSO

robot_live

robot_live

NAME

   robot_live -- initialize a robot controller

SYNOPSIS

  #include <device/robot.h>

  void robot_live(void (*reset_function)(void));

DESCRIPTION

This function must be called before any other controller API function. It is necessary to initialize the robot controller and optionally to provide a reset function to the controller. This reset function is useful to perform some initializations, so that the controller knows which sensors and actuators are available. The reset function should be a void function without any argument. It is called once at the beginning of the simualtion and may be called again if the simulator needs to reset the robot. However, this rarely happens in practise.

EXAMPLE


#include <device/robot.h>

static DeviceTag my_sensor, my_actuator;

void my_reset_function() { /* called at init. */
  printf("hello!\n");
  my_sensor = robot_get_device("my_sensor");
  my_actuator = robot_get_device("my_actuator");
}

void my_exit_function() { /* called before quitting  */
  printf("bye bye!\n");
}

int main() {
 robot_live(my_reset_function); /* called when robot starts */
 robot_die(my_exit_function); /* called when robot quits */
 for(;;) { /* infinit loop */
    /* read the sensors and write to the actuators */
    ...
    robot_step(64);
  }
  return 0; /* this statement will never be reached */
}
    

SEE ALSO

robot_get_device

robot_die

robot_step

robot_step

NAME

   robot_step -- execute a simulation step

SYNOPSIS

  #include <device/robot.h>

  guint32 robot_step(guint32 ms);

DESCRIPTION

This function requests the simulator to perform a simulation step of ms milliseconds, that is to advance in the simulated time of this amount of time. In synchronous simulation mode, the request is always fulfilled and the function always return 0. In asynchronous mode, the request may not be fulfilled. In this case, the return value dt, representing the delay, may not be 0. Let controller_date be the current time of the controller, the return value be interpreted as follow:

  • if dt = 0, then, the behavior is equivalent to the one of synchronous mode.

  • if 0 <= dt > ms, then the actuator values were set at controller_date + dt and the sensor values where measured at controller_date + ms, as requested. It means that the step actually lasted the requested number of milliseconds, but the actuators command could not be executed on time.

  • if dt > ms, then the actuators values were set at controller_date + dt and the sensors values where measured also at controller_date + dt. It means that the requested step duration could not be respected.

SEE ALSO

robot_live

previous page go up next page
^ page top ^

  E-mail to webmaster Last updated: Copyright © 2002 Cyberbotics Ltd.