ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Controlling rviz camera programmatically

asked 2021-12-02 10:19:56 -0500

n.dafinski gravatar image

updated 2021-12-06 09:57:40 -0500

lucasw gravatar image

Hi guys, so I'd like to be able to control the rviz camera - meaning zoom in/out and turn the viewport, basically all the controls you have in the viewport when normally using a mouse. but from an outside script/node that is running and receiving commands for the camera from a web client over ros websocket. I'm guessing there should be a way I can send commands and move the camera but any suggestions first before I start diving into the rviz code would be helpful, thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-12-03 19:12:10 -0500

singular.river gravatar image

You can try something like this: Have a node on the server (viewport host) side. Sample Python code:

from rviz import bindings as rviz
frame = rviz.VisualizationFrame()
vc = frame.getManager().getViewManager().getCurrent()
# only if the current view is Orbital type
if vc.getClassId() == 'rviz/Orbit':
    vc.subProp("Focal Point").setValue(1.0)
edit flag offensive delete link more


thank you I will give that a go!

n.dafinski gravatar image n.dafinski  ( 2021-12-06 05:05:41 -0500 )edit

answered 2021-12-05 21:51:15 -0500

lucasw gravatar image

updated 2021-12-05 21:54:38 -0500

Probably you want

A different clunky route is to send those mouse commands via xdotool( orapt-get xdotool) - here if you launch the script, then click in the view section of the rviz view window, then the script will click and move the mouse. A for loop is needed to make the motion smooth though, these move instantly in big jumps (xdotool doesn't have a move speed option?)

#!/usr/bin/env bash
sleep 1.0
xdotool mousedown 1
xdotool mousemove_relative 20 0 sleep 0.5
xdotool mousemove_relative 30 0 sleep 0.5
xdotool mousemove_relative 30 0 sleep 0.5
xdotool mousemove_relative 20 0 sleep 0.5
xdotool mouseup 1
xdotool mouseup 1

If you move the mouse while the script is running then the real mouse input is mixed up with the xdo input.

See also

edit flag offensive delete link more


Hey, thanks for the answer. I actually found the animated_view_controller package after I posted the question and I've been trying to alter the scripts from the view_controller_msgs package like CameraTest, so far haven't got exactly what I want out of them but it might actually be a way to do it. One thing I noticed with the package is that when I set a focus or eye point, whenever I move the mouse anywhere in the viewport manually, the camera snaps back to those previous values where it was set by the script and I still haven't figured out exactly why that is

n.dafinski gravatar image n.dafinski  ( 2021-12-06 05:09:13 -0500 )edit

so I later figured out that the script just keeps publishing messages so that even when I move the camera with my mouse it immediately snaps it back, so now comes probably the weirdest part which would be getting the commands from the web client and sending them to the camera_placement topic

n.dafinski gravatar image n.dafinski  ( 2021-12-06 09:53:57 -0500 )edit

I haven't used rviz_animated_view_controllerbefore but have seen it come up here a few times, I should try it out and could help more. I'd suggest asking on - but there's an existing issue there asking for help with no answer (I wish more repos would enable Discussions for this sort of thing, though there'd probably be no answer there either).

lucasw gravatar image lucasw  ( 2021-12-06 10:00:52 -0500 )edit

Question Tools



Asked: 2021-12-02 10:19:56 -0500

Seen: 619 times

Last updated: Dec 06 '21