Tutorials:Sensors

From OpenRAVE

Jump to: navigation, search

by Rosen Diankov

Contents

Running the Example

Running camera:

python:

openrave.py --example testcamerasensor

program options/description:

openrave.py --example testcamerasensor --help

Note: The python example shows how to effectively use environment clones to keep the environment used for planning separate from the real environment updated with sensor data.

Octave/Matlab: (first start openrave)

 cd `openrave-config --octave-dir`/examples
 octave --eval testcamerasensor

Description

The base class for a sensor is [1], and a robot can be attached with any number of sensors through the XML file using the attachedsensor field. Each sensor can attach to a link of the robot, so it will move as the robot moves. OpenRAVE only defines a rough set of guidelines for sensor formats and how users can extract the sensor data. Each sensor can be sent text commands using SensorBase::SendCmd. If a sensor is attached to a robot, then the Octave/Matlab scripts can send it commands through orRobotSensorSend.

Check out the basesensors plugin for an example of how to implement a 2D laser range finder. The sensor has a special rendering option that allows it to render its data to the GUI window. Call

orRobotSensorSend(robotid,sensorindex,'render 1')

to enable rendering. An example showing how all the pieces come together in Octave/Matlab can be seen in examples/testlasersensor.m. Just execute the script by changing directions and typing:

testlasersensor(0)

The script first loads a robot with an attached laser, the robot file includes a previously defined robot and just appends the sensor definition onto it. For more information on the XML file format look at Attached Robot Sensors

<Robot file="barrettwam.robot.xml">
 <AttachedSensor>
   <link>wam1</link>
   <translation>0 0.2 0.4</translation>
   <rotationaxis>0 0 1 90</rotationaxis>
   <sensor type="BaseLaser2D" args="">
     <minangle>-135</minangle>
     <maxangle>135</maxangle>
     <resolution>0.35</resolution>
     <maxrange>5</maxrange>
     <scantime>0.1</scantime>
   </sensor>
 </AttachedSensor>
</Robot>

Then the script creates some objects and enables the rendering of the sensors. After that it uses orRobotSensorGetData to get the laser data. The format of the returned data is described by typing help orRobotSensorGetData. Here's a snapshot of the scene:

By default, all the sensors defined in basesensors start with a sensor power off, meaning that the sensor does not gather data. The power can be turned on by sending each sensor the power 1 command, or by adding the <power>1</power> XML tag in the sensor description. All the demos manually turn sensor power on.

Spinning Laser

The default plugin and testlasersensor also support a spinning laser called BaseSpinningLaser2D. A spinning laser includes all the XML parameters from the regular BaseLaser2D along with

spinaxis - the second axis to spin on
spinpos - center of rotation of second spin axis
spinspeed - how fast to spin in rad/s

To see a rendering of a spinning laser run

testlasersensor(1)

3D Laser

There is also a Flash LIDAR simulation sensor in the test script called BaseFlashLidar3D. To see a rendering of the flash rider run

testlasersensor(2)

A Flash LIDAR has the same projection parameters as a camera except each pixel is an active element that measures distance. The XML parameters are the same as BaseLaser2D along with

KK - 4 element vector that constructs the intrinsic matrix of the flash lidar (KK[0] 0 KK[2]; 0 KK[1] KK[3]; 0 0 1]. 
width - the number of active elements along the x-axis.
height - the number of active elements along the y-axis.

Below is a screenshot of the Flash LIDAR rendering.

Pinhole Camera

The basesensors plugin also has a simple implementation of a pinhole camera. Run examples/testcamerasensor.m to see a robot with a camera attached to its wrist. The example opens bin/data/testwamcamera.env.xml and queries image data from the sensor as fast as possible. The image data is displayed in Octave/Matlab using imshow. The image will change in real-time as the robot is moved around the scene. The wireframe frustum rendered next to the robot shows the camera's field of view.

The XML required to attach a camera to the robot similar to the example above is:

<AttachedSensor>
  <link>wam4</link>
  <translation>0 -0.2 0</translation>
  <rotationaxis>0 1 0 -90</rotationaxis>
  <sensor type="BaseCamera" args="">
    <KK>640 480 320 240</KK>
    <width>640</width>
    <height>480</height>
    <framerate>5</framerate>
    <color>0.5 0.5 1</color>
  </sensor>
</AttachedSensor>
Personal tools