Robotics StackExchange | Archived questions

Controlling rviz camera programmatically

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!

Asked by n.dafinski on 2021-12-02 11:19:56 UTC

Comments

Answers

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("Distance").setValue(1.0))
    vc.subProp("Focal Point").setValue(1.0)

Asked by singular.river on 2021-12-03 20:12:10 UTC

Comments

thank you I will give that a go!

Asked by n.dafinski on 2021-12-06 06:05:41 UTC

Probably you want http://wiki.ros.org/rviz_animated_view_controller

A different clunky route is to send those mouse commands via xdotool (https://github.com/jordansissel/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 https://answers.ros.org/question/228956/node-that-generates-key-or-mouse-events-at-low-level/

Asked by lucasw on 2021-12-05 22:51:15 UTC

Comments

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

Asked by n.dafinski on 2021-12-06 06:09:13 UTC

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

Asked by n.dafinski on 2021-12-06 10:53:57 UTC

I haven't used rviz_animated_view_controller before but have seen it come up here a few times, I should try it out and could help more. I'd suggest asking on https://github.com/ros-visualization/rviz_animated_view_controller/issues - 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).

Asked by lucasw on 2021-12-06 11:00:52 UTC