OpenRAVE Documentation

showsensors Module

Opens a GUI window showing the sensor data of a scene.

../../_images/showsensors.jpg

Running the Example:

openrave.py --example showsensors

Description

See `Sensor Concepts`_ for detailed infromation on sensors. When requesting data from the sensor right after it is powered on, the sensor might not return valid data. Therefore have to make sure the data is good by checking that the time stamps changed.

Camera

The BaseCamera - basesensors interface has a simple implementation of a pinhole camera. This example shows a robot with a camera attached to its wrist. The example opens data/testwamcamera.env.xml and queries image data from the sensor as fast as possible. 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.

../../_images/showsensors_camera.jpg

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

<Robot>
  <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>
</Robot>

Lasers

The BaseLaser2D - basesensors interface has a simple implementation of ray-casting laser sensors.

../../_images/showsensors_laser.jpg

The following OpenRAVE XML attaches a simple 2D laser to the wam1 link of the robot:

<Robot>
  <AttachedSensor name="mylaser">
    <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>

To OpenRAVE XML to attach a flash LIDAR sensor is:

<Robot>
  <AttachedSensor name="myflashlaser">
    <link>wam2</link>
    <translation>-0.2 -0.2 0</translation>
    <rotationaxis>0 1 0 -90</rotationaxis>
    <sensor type="BaseFlashLidar3D">
      <maxrange>5</maxrange>
      <scantime>0.2</scantime>
      <KK>32 24 32 24</KK>
      <width>64</width>
      <height>48</height>
      <color>1 1 0</color>
    </sensor>
  </AttachedSensor>
</Robot>

Command-line

Usage: openrave.py [options]

Displays all images of all camera sensors attached to a robot.

Options:
  -h, --help            show this help message and exit
  --scene=SCENE         OpenRAVE scene to load

  OpenRAVE Environment Options:
    --loadplugin=_LOADPLUGINS
                        List all plugins and the interfaces they provide.
    --collision=_COLLISION
                        Default collision checker to use
    --physics=_PHYSICS  physics engine to use (default=none)
    --viewer=_VIEWER    viewer to use (default=qtcoin)
    --server=_SERVER    server to use (default=None).
    --serverport=_SERVERPORT
                        port to load server on (default=4765).
    --module=_MODULES   module to load, can specify multiple modules. Two
                        arguments are required: "name" "args".
    -l _LEVEL, --level=_LEVEL, --log_level=_LEVEL
                        Debug level, one of
                        (fatal,error,warn,info,debug,verbose,verifyplans)
    --testmode          if set, will run the program in a finite amount of
                        time and spend computation time validating results.
                        Used for testing

Main Python Code

def main(env,options):
    "Main example code."
    env.Load(options.scene)
    ienablesensor = 0
    while True:
        sensors = env.GetSensors()
        for i,sensor in enumerate(sensors):
            if i==ienablesensor:
                sensor.Configure(Sensor.ConfigureCommand.PowerOn)
                sensor.Configure(Sensor.ConfigureCommand.RenderDataOn)
            else:
                sensor.Configure(Sensor.ConfigureCommand.PowerOff)
                sensor.Configure(Sensor.ConfigureCommand.RenderDataOff)
        print 'showing sensor %s, try moving obstacles'%(sensors[ienablesensor].GetName())
        if sensors[ienablesensor].Supports(Sensor.Type.Laser):
            # if laser, wait for the sensor data to be updated and then print it
            olddata = sensors[ienablesensor].GetSensorData(Sensor.Type.Laser)
            while True:
                data = sensors[ienablesensor].GetSensorData(Sensor.Type.Laser)
                if data.stamp != olddata.stamp:
                    break
                time.sleep(0.1)
            print 'sensor data: ',data.ranges                        
        time.sleep(5)
        ienablesensor = (ienablesensor+1)%len(sensors)

Class Definitions

openravepy.examples.showsensors.main(env, options)[source]

Main example code.

openravepy.examples.showsensors.run(*args, **kwargs)[source]

Command-line execution of the example.

Parameters:args – arguments for script to parse, if not specified will use sys.argv

Questions/Feedback

Having problems with OpenRAVE?