Changing the camera for the ros3djs Viewer

498 views
Skip to first unread message

Ellis Ratner

unread,
Aug 21, 2013, 1:55:44 PM8/21/13
to robot-w...@googlegroups.com
Hello,

I am attempting to mimic the functionality of the various camera types available in RViz (or through RViz plugins) with the ros3djs Viewer. In particular, I would like the camera to follow a model of the PR2 as it moves through a 3D environment. Additionally, I would like to be able to switch to a top-down camera view. I have tried updating the position of the camera when the pose of the robot changed using camera.position.set(...) and camera.lookAt(...). The camera does move when the robot moves, but it does not track its location. Any ideas on how I can accomplish this?

I do not have too much experience with cameras in 3D space, so perhaps this is an issue with my understanding of it. Also, if there is existing functionality within ros3djs to do this, that I have not yet found, it would be very helpful if someone could point me to that.

Thank you,

Ellis

Chad Jenkins

unread,
Aug 21, 2013, 3:07:14 PM8/21/13
to robot-w...@googlegroups.com

Hi Ellis,

Could you share the exact code you are using to control the camera? 

I have used camera.position.set() and camera.lookAt() without issue in the past.

Chad
___



--
You received this message because you are subscribed to the Google Groups "Robot Web Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robot-web-too...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Russell Toris

unread,
Aug 21, 2013, 3:25:08 PM8/21/13
to robot-w...@googlegroups.com
This is the code I've used to have the camera follow the head of the robot:

// keep the camera centered at the head
tfClient.subscribe('/head_mount_kinect_rgb_link', function(tf) {
viewer.cameraControls.center.x = tf.translation.x;
viewer.cameraControls.center.y = tf.translation.y;
viewer.cameraControls.center.z = tf.translation.z;
});

--
Russell Toris
Graduate Student | WPI Department of Computer Science
rct...@wpi.edu | http://users.wpi.edu/~rctoris/

Ellis Ratner

unread,
Aug 21, 2013, 3:26:37 PM8/21/13
to robot-w...@googlegroups.com
Hi Chad,

Sure. The following code is in the function bound as the callback for the subscriber to the topic on which I publish the robot's base pose (I could also use a TF update callback, but for unrelated reasons I am not at the moment):

  var basePose = new ROSLIB.Pose(message.base_pose);

  this.viewer.camera.position.set(basePose.position.x, basePose.position.y, 6);

  this.viewer.camera.lookAt(new THREE.Vector3(basePose.position.x, basePose.position.y, 0));
  this.viewer.camera.updateMatrixWorld();
 
Here, this.viewer is a ROS3D.Viewer. The idea was to set the camera above the robot in the xy-plane, and then look down on it for a top-down type view. Please let me know if you need more information!

Thanks again,

Ellis


On Wed, Aug 21, 2013 at 3:07 PM, Chad Jenkins <ode...@gmail.com> wrote:

Russell Toris

unread,
Aug 21, 2013, 3:30:45 PM8/21/13
to robot-w...@googlegroups.com

Yeah, I would check the example I posted right before this and try messing with the cameraControls instead of camera!

Russell

Ellis Ratner

unread,
Aug 21, 2013, 3:40:21 PM8/21/13
to robot-w...@googlegroups.com
Hi Russell,

This is very helpful, thank you!

Ellis
Reply all
Reply to author
Forward
0 new messages