Webots Reference Manual - chapter 3 - section 21

Webots Reference Manual


3.21 DistanceSensor

Derived from Device.

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

3.21.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 rays and the bounding objects of Solid nodes in the environment.

The rays of the DistanceSensor nodes can be displayed by checking the menu View > Optional Rendering > Show Distance Sensor Rays. The red/green transition on the rays indicates the points of intersection with the bounding objects.

3.21.2 Field Summary

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.21.3 DistanceSensor types

This table summarizes the difference between the three types of DistanceSensor.

type (field)"infra-red""sonar""laser"
numberOfRays (field)> 0> 0must be exactly 1
Distance calculationAverage of all raysNearest collision of any rayNearest collision of the ray
gaussianWidth (field)UsedIgnoredIgnored
Sensitive to red objectsYesNoNo
Draws a red spotNoNoYes

Table 3.3: Summary of DistanceSensor types

3.21.4 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, so in this case, an infra-red sensor behaves like the other types of sensors.

3.21.5 Line Following Behavior

Some support for DistanceSensor nodes used for reading the red color level of a textured floor is 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). The ground texture must be placed in a Plane.

3.21.6 DistanceSensor Functions



NAME

   wb_distance_sensor_enable, wb_distance_sensor_disable, wb_distance_sensor_get_sampling_period, wb_distance_sensor_get_value - enable, disable and read distance sensor measurements

SYNOPSIS [C++] [Java] [Python] [Matlab]

  #include <webots/distance_sensor.h>

  void wb_distance_sensor_enable(WbDeviceTag tag, int ms);
  void wb_distance_sensor_disable(WbDeviceTag tag);
  int wb_distance_sensor_get_sampling_period(WbDeviceTag tag);
  double wb_distance_sensor_get_value(WbDeviceTag tag);

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.

The wb_distance_sensor_get_sampling_period() function returns the period given into the wb_distance_sensor_enable() function, or 0 if the device is disabled.

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.

release 7.0.2
Copyright © 2012 Cyberbotics Ltd. All right reserved.