Webots Reference Manual

previous page go up next page

Thanks

1. Introduction

2. Node Chart

3. Nodes and API Functions

4. Motion Functions

5. Prototypes

6. Physics Plugin

7. Fast2D Plugin

8. MTN Functions

9. Webots World Files

     

3.15 DistanceSensor

Derived from Solid.

DistanceSensor {
  MFVec3f    lookupTable     [ 0 0 0, 0.1 1000 0 ]
  SFString   type            "infra-red"
  SFInt32    numberOfRays    1   # [1,inf)
  SFFloat    aperture        0   # [0,2pi]
  SFFloat    gaussianWidth   1
}

3.15.1 Description

The DistanceSensor node can be used to model an infra-red sensor, a sonar sensor, or a laser range-finder. This device simulation is performed by detecting the collisions between one or several sensor ray and the bounding objects of Solid nodes in the environment.

The rays of a DistanceSensor can be displayed by checking the Display sensor rays box in the Tools -> Preferences... -> Rendering menu. The red/green transition on the rays indicates the points of intersection with the bounding objects.

3.15.2 Field Summary

  • type: one of "infra-red" (the default), "sonar" or "laser". Sensors of type "infra-red" are sensitive to the objects' colors; light and red (RGB) obstacles have a higher response than dark and non-red obstacles (see below for more details). Sensors of type "sonar" and "laser" are not sensitive to the color of obstacles. Sensors of type "laser" have the particularity to draw a red dot at the point where the simulated laser beam hits the obstacle. This red spot is visible on the camera images.

  • lookupTable: a table used for specifying the desired response curve and noise of the device. This table indicates how the ray intersection distances measured by Webots must be mapped to response values returned by the function distance_sensor_get_value(). The first column of the table specifies the input distances, the second column specifies the corresponding desired response values, and the third comlun indicates the desired noise. The noise on the return value is computed according to a uniform random number distribution whose range is calculated as a percent of the response value. Let us consider an example:

    lookupTable [ 0     1000  0,
                  0.1   1000  0.1,
                  0.2    400  0.1,
                  0.3     50  0.1,
                  0.37    30  0   ]

    The above lookup table means that for a distance of 0 meters, the sensor will return a value of 1000 without noise (0); for a distance of 0.1 meter, the sensor will return 1000 with a noise of up to 10 percent (100); for a distance value of 0.2 meters, the sensor will return 400 plus or minus up to 10 percent (40), etc. Distance values not directly specified in the lookup table will be linearly interpolated. This can be better understood in the figure below. Note that the input values of a lookup table must always be positive and sorted in increasing order.

    infrared

    Figure 3.6: Sensor response versus to obstacle distance

  • numberOfRays: number of rays cast by the sensor. The number of rays must be equal to, or greater than 1 for "infra-red" and "sonar" sensors. numberOfRays must be exactly 1 for "laser" sensors. If this number is larger than 1, then several rays are used and the sensor measurement value is computed from the weighted average of the individual rays' responses. By using multiple rays, a more accurate model of the physical infra-red or ultrasound sensor can be obtained. The sensor rays are distributed inside 3d-cones whose opening angles can be tuned through the aperture parameter. See figure 3.7 for the ray distributions from one to ten rays. The spacial distribution of the rays is as much as possible uniform and has a left/right symmetry. There is no upper limit on the number of rays; however, Webots' performance drops as the number of rays increases.

    ray_orbits

    Figure 3.7: Predefined configurations for 1 through 10 sensor rays

  • aperture: sensor aperture angle or laser beam radius. For the "infra-red" and "sonar" sensor types, this parameter controls the opening angle (in radians) of the cone of rays when multiple rays are used. For the "laser" sensor type, this parameter specifies (in meters) the radius of the red spot drawn where the laser beam hits an obstacle.

    weight_formula

    Figure 3.8: Weight distribution formula

  • gaussianWidth: width of the Gaussian distribution of sensor ray weights. When averaging the sensor's response, the individual weight of each sensor ray is computed according to a Gaussian distribution as described in figure 3.8. where wi is the weight of the ith ray, ti is the angle between the ith ray and the sensor axis, a is the aperture angle of the sensor, g is the Gaussian width, and n is the number of rays. As depicted in figure 3.9, rays in the center of the sensor cone are given a greater weight than rays in the periphery. A wider or narrower distribution can be obtained by tuning the gaussianWidth parameter. An approximation of a flat distribution is obtained if a sufficiently large number is chosen for the gaussianWidth.

    weight_distribution

    Figure 3.9: Example distribution for 10 rays using a Gaussian width of 1.0 (default)

Note: In fast2d mode, the sensor rays are arranged in 2d-fans instead of 3d-cones and the aperture parameter controls the opening angle of the fan. In fast2d mode, Gaussian averaging is also applied, and the ti parameter of the above formula corresponds to the 2D angle between the ith ray and the sensor axis.

3.15.3 Infra-Red Sensors

In the case of an "infra-red" sensor, the value returned by the lookup table is modified by a reflection factor depending on the color properties of the object hit by the sensor ray. In fact, if the object is a Solid node with a bounding object, the color of the bounding object is used for computing the reflection factor rather that the actual color of the object. The reflection factor is computed as follows: f = 0.2 + 0.8 * red_level where red_level is the level of red color (diffuseColor) of the object hit by the sensor ray. The distance value computed by the simulator is divided by this factor before the lookup table is used to compute the output value. This reflection factor is not taken into consideration in fast2d mode and therefore, in this case, an infra-red sensor behaves like the other types of sensors.

3.15.4 Line Following Behavior

Primitive support for DistanceSensor nodes used for reading the red color level of a textured floor has been implemented. This is useful to simulate line following behaviors. This feature is demonstrated in the rover.wbt example (see in the projects/robots/mindstorms/worlds directory of Webots). To work properly, the ground texture should be placed in a rectangular IndexedFaceSet node centered at (0,0,0).

3.15.5 DistanceSensor Functions

NAME

   wb_distance_sensor_enable, wb_distance_sensor_disable - enable and disable distance sensor measurements

C SYNOPSIS

  #include <webots/distance_sensor.h>

  void wb_distance_sensor_enable(WbDeviceTag sensor, int ms);
  void wb_distance_sensor_disable(WbDeviceTag sensor);

C++ SYNOPSIS

  #include <webots/DistanceSensor.hpp>

  void DistanceSensor::enable(int ms);
  void DistanceSensor::disable();

JAVA SYNOPSIS

  import com.cyberbotics.webots.controller.DistanceSensor;

  void DistanceSensor.enable(int ms);
  void DistanceSensor.disable();

PYTHON SYNOPSIS

  from controller import DistanceSensor

  none DistanceSensor.enable(int ms)
  none DistanceSensor.disable()

DESCRIPTION

wb_distance_sensor_enable() allows the user to enable a distance sensor measurement each ms milliseconds.

wb_distance_sensor_disable() turns the distance sensor off, saving computation time.

NAME

   wb_distance_sensor_get_value - get a distance sensor measurement

C SYNOPSIS

  #include <webots/distance_sensor.h>

  double wb_distance_sensor_get_value(WbDeviceTag sensor);

C++ SYNOPSIS

  #include <webots/DistanceSensor.hpp>

  double DistanceSensor::getValue();

JAVA SYNOPSIS

  import com.cyberbotics.webots.controller.DistanceSensor;

  double DistanceSensor.getValue();

PYTHON SYNOPSIS

  from controller import DistanceSensor

  float DistanceSensor::getValue()

DESCRIPTION

wb_distance_sensor_get_value() returns the last value measured by the specified distance sensor. This value is computed by the simulator according to the lookup table of the DistanceSensor node. Hence, the range of the return value is defined by this lookup table.

previous page go up next page
^ page top ^

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