Ask Your Question

Programatically set the camera pose in gazebo or rviz.

asked 2011-06-21 03:36:12 -0500

updated 2011-06-21 05:13:57 -0500

Wim gravatar image

Hello, I am trying to automatically generate a bunch of videos of a robot manipulating objects. I figured out a way to record the screen from gazebo or rviz, but I can't find any tutorial about how to programatically move the camera around the robot.

Do you know if in either gazebo or rviz the viewpoint can be set programatically? Gazebo shows XYZ and RPY as you move with the mouse so it seems reasonable to think that one can set those. Maybe in rviz, I should set the fixed frame to be a frame offset of the head of the robot?

edit retag flag offensive close merge delete


This may be off topic, but what method are you using for video capture?
JonW gravatar image JonW  ( 2011-06-21 14:37:58 -0500 )edit
glc, look at The glc installation script appear to be broken for me but I hacked my way though it and now it works fine. Let me know if you encounter any troubles and I can send you my version of the install script.
Dimitar Simeonov gravatar image Dimitar Simeonov  ( 2011-06-21 15:09:42 -0500 )edit

Hi, I'm currently trying to record RViz via GLC. Since I'm doing this via a RViz plugin, the software should execute the Shift+F8 command for GLC programmatically. Do you have any idea how to do this? Did you only hack the install script or also the source code?

Josch gravatar image Josch  ( 2013-03-13 03:14:31 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2011-06-21 15:47:04 -0500

hsu gravatar image

If you're using glc-capture, one way to do this is to can write a plugin to move the cameras, for example, by putting this code in UpdateChild() of the plugin:

gazebo::OgreCamera *cam = gazebo::CameraManager::Instance()->GetCamera("UserCamera(0)");
gazebo::Pose3d pose = cam->GetCameraWorldPose();
pose.pos.z = pose.pos.z + 0.001;

should make the gui view camera move upwards in z-direction 1mm on every udpate.

Alternatively, you can spawn a single urdf link with a camera sensor attached, e.g.

<?xml version="1.0" ?>
<robot name="camera" xmlns:body="" xmlns:controller="" xmlns:geom=""  xmlns:sensor="" xmlns:xacro="">
  <link name="camera_link">
      <mass value="1"/>
      <origin xyz="0 0 0"/>
      <inertia ixx="0.1" ixy="0.0" ixz="0.0" iyy="0.1" iyz="0.0" izz="0.1"/>
  <gazebo reference="camera_link">
    <sensor:camera name="camera_sensor">
      <imageSize>640 480</imageSize>
      <controller:gazebo_ros_camera name="camera_controller" plugin="">
        <!-- image_width / (2*tan(hfov_radian /2)) -->
        <!-- 320 for wide and 772.55 for narrow stereo camera -->

and use ros service /gazebo/set_model_state to update the camera pose. Using ''rosbag record'' to capture a series of images.

edit flag offensive delete link more


Your second approach seems better for my needs - thanks for the XML!
Dimitar Simeonov gravatar image Dimitar Simeonov  ( 2011-06-22 00:45:24 -0500 )edit
hsu, this has been very helpful and I was able to create an artificial camera. Can you point me to the documentation format for sensor:camera I am seeing few images overlap in RVIZ when I look at the camera, and I'd like to try different camera options.
Dimitar Simeonov gravatar image Dimitar Simeonov  ( 2011-06-24 10:50:21 -0500 )edit
There isn't one but we are actively working on it right now. In the mean time you can see everything being read by gazebo's camera sensor in We'll make an announcement as soon as we are done updating xml/docs.
hsu gravatar image hsu  ( 2011-06-26 07:49:16 -0500 )edit
thanks a lot! Do you know how frameName is used - I couldn't find it referenced in the code that you linked to. When I look at the camera in rviz it shows me two superimposed images- the correct one and the one from the origin of frameName as seen in rviz - I'd like to turn this second image off.
Dimitar Simeonov gravatar image Dimitar Simeonov  ( 2011-07-08 09:55:24 -0500 )edit
I believe if you set "Overlay Alpha" to 1 for your camera in rviz, then you should not see the superimposed image.
hsu gravatar image hsu  ( 2011-07-08 10:14:05 -0500 )edit

answered 2013-03-13 03:18:33 -0500

Josch gravatar image

For all the googlers that are coming to this thread: There is a way to programmatically set the camera perspectives completely custom in RViz: You have to create a RViz plugin and override the onInitialize() method. This will allow you to access the RViz VisualizationManager, which contains a ViewController instance. That's all you need. You can have a look at the answers to my question when you need further information.

edit flag offensive delete link more

answered 2017-03-04 06:05:59 -0500

peci1 gravatar image

CameraManager is no longer a part of Gazebo, but if you want, you can create a Gazebo plugin that publishes to gazebo topic ~/user_camera/joy_pose. Don't care about the name, it's just a function that sets the default (gzclient) camera pose. Interestingly, you can also set camera twist (aka velocity) in a similar way.

Also, since Gazebo 8, video recording is integrated right into gzclient.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2011-06-21 03:36:12 -0500

Seen: 4,756 times

Last updated: Mar 04 '17