(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Configuring a gvm multicamera sensor

Description: This tutorial walks you through how to configure a gvm multicamera sensor

Tutorial Level: BEGINNER

Next Tutorial: Utility Plugins

Background

If you are not curious about why the configuration of the sensor looks like the way it does, you may skip this section.

We want to have a set of cameras that are running inside Gazebo. Cameras are sensors, and sensors are part of a link in a model. This means, a sensor cannot exist by itself, but we have to attach it to a link. We need to pick a model, create a multicamera sensor, and give ownership of the sensor to a link of that model. This is accomplished with the multicamera bootstrapper plugin.

<plugin
  name="multicamera_bootstrapper_plugin"
  filename="libgvm_multicamera_bootstrapper_plugin.so">
  <sensor name="camera" type="gvm_multicamera">
    ...
  </sensor>
  <sensorReference>
    <model>ground_plane</model>
    <link>link</link>
  </sensorReference>
</plugin>

The configuration of the bootstrapper plugin consists of two parts. The first one has the multicamera sensor configuration, and the second one specifies the model to which we want to give the sensor. The plugin reads this information and gets the sensor up and running for us. The model should be one that we know it's always there, like ground_plane, and exists throughout the duration of the simulation. You want this, so you may delete your robot model at some point but keep the cameras there for your next test.

Bootstrapping

Start with the following boilerplate XML code.

<plugin
  name="multicamera_bootstrapper_plugin"
  filename="libgvm_multicamera_bootstrapper_plugin.so">
  <!-- gvm_multicamera sensor configuration goes here -->
  
  <sensorReference>
    <model>ground_plane</model>
    <link>link</link>
  </sensorReference>
</plugin>

The bootstrapper plugin is a model plugin responsible for spawning the cameras and loading the video plugin of your choice. The code above will create a multicamera sensor and attach it to ground_plane. Mind here that it's the sensor that gets attached to ground_plane. The individual cameras can still be attached to other (robot) links later, and thus move along with them.

Multicamera Sensor

Next, you need to configure the cameras. For this, you must configure a sensor of type gvm_multicamera. A gvm_multicamera sensor is a sensor that produces synchronized frames from a set of cameras. The configuration of the sensor is like the one of the regular camera sensor, only here, there can be multiple instances of the camera code. The number of instances is dependent on the video plugin (described later).

<sensor name="video_monitor_dual_camera" type="gvm_multicamera">
  <update_rate>30</update_rate>
  <!-- <always_on>true</always_on> -->
  <!-- <visualize>true</visualize> -->

  <camera name="world_camera">
    <pose>3.0 0 1.0 0 0 3.1416</pose>
    <horizontal_fov>1.5708</horizontal_fov>
    <image>
      <width>640</width>
      <height>480</height>
      <format>R8G8B8</format>
    </image>
    <clip>
      <near>0.01</near>
      <far>100</far>
    </clip>
  </camera>

  <camera name="robot_camera">
    <pose>-0.5 0 0.3 0 0 0</pose>
    <horizontal_fov>0.823599</horizontal_fov>
    <image>
      <width>640</width>
      <height>480</height>
      <format>R8G8B8</format>
    </image>
    <clip>
      <near>0.01</near>
      <far>10</far>
    </clip>
  </camera>

  <!-- video plugin configuration goes here -->
</sensor>

Inside the sensor configuration, you specify the frame rate (update_rate) of the cameras, and you may also enable the camera visualizations (visualize). The visualizations are useful when you want to position the cameras, as you get immediate feedback on the given poses.

camera-visualization.jpg

For each camera of the sensor, you need to configure the usual parameters, such as resolution, format, and field of view. Furthermore, you may want to give a pose to a camera. This pose is relative to the link that the camera is attached to. Initially, a camera is attached to the same link as the sensor. The link can be changed in the video plugin configuration (described later). The link can also be changed at runtime with a ROS service (also described later).

Video Plugin

A video plugin is responsible for recording the videos. It receives the frames from the cameras, decides which ones to pick, and uses them as the source for the next video frame. A video plugin has one or more recorders. A recorder is actually the one that processes the frames and creates the video. So, a video plugin could record multiple videos at a time.

<plugin name="video_monitor_plugin" filename="libgazebo_video_monitor_plugin.so">
  <setCameraService>gazebo/set_camera</setCameraService>
  <startRecordingService>gazebo/start_recording</startRecordingService>
  <stopRecordingService>gazebo/stop_recording</stopRecordingService>
  <savePath>/var/tmp/gazebo_video_monitor</savePath>
  <recorder>
    <width>640</width>
    <height>480</height>
    <bitRate>590000</bitRate>
    <logMetadata>true</logMetadata>
    <logWallTime>false</logWallTime>
    <addTimestampInFilename>true</addTimestampInFilename>
  </recorder>
  <cameraReference name="robot_camera">
    <model>my_robot</model>
    <link>gripper_link</link>
  </cameraReference>
</plugin>

Each video plugin defines its own custom configuration, but all of them have the same basic configuration shown above.

  • setCameraService: The name of the ROS service for configuring the pose of a camera and the link to which the camera should be attached

  • startRecordingService: The name of the ROS service for starting a video recording

  • stopRecordingService: The name of the ROS service for stopping a video recording

  • savePath: The directory under which all videos are saved

Then follows the configuration of the recorder.

  • width: The width of the video

  • height: The height of the video

  • bitRate: The bit rate of the video

  • logMetadata: A flag to indicate whether to write time metadata on the video

  • logWallTime: A flag to indicate whether log the wall time, instead of the real time, on the video

  • addTimestampInFilename: A flag to indicate whether to append the start timestamp of the recording in the filename of the video

And lastly, there can be zero or more instances of cameraReference. cameraReference is used to configure the link to which a camera should be attached. It has an attribute name that should match the name of a camera configured in the sensor.

  • model: The name of the model with which to associate the camera

  • modelParam: If the name of the model is not always the same, you may skip the model parameter, and specify here the parameter on the parameter server that holds the name of the model

  • link: The name of the link to which to attach the camera

SetCamera Service

All plugins expose a ROS service for dynamically reconfiguring a camera. With the service, you can update the link to which a camera should be attached, as well as the pose of the camera with respect to that link. You may use the camera visualizations to help you with this process.

rosservice call /gazebo/set_camera "{camera_name: robot_camera, model_name: robot-0001, link_name: gripper_link, pose: {x: 0.0, y: -0.05, z: -0.1, roll: -0.2, pitch: 0.0, yaw: 0.0}}"

The service request expects the names of the camera, model, and link, and the pose of the camera in xyz and rpy.

Conclusion

You now know what each parameter of the sensor configuration represents. Move on to the next tutorials to find out what each video plugin does, and how to use it.

Wiki: gazebo_video_monitor_plugins/Tutorials/Configuring a gvm multicamera sensor (last edited 2023-10-22 00:03:02 by NickLamprianidis)