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

Writing a panel for RViz in Python / accessing RosTopicHz from C++

asked 2018-04-07 15:03:09 -0500

ce_guy gravatar image

updated 2018-04-07 15:15:46 -0500

Hey guys,

I would like to write a RViz panel where I can see the actual publishing rate on a given topic (same thing I can do with "rostopic hz" from command line).

I have seen in the tutorial that panels for RViz are written in C++ and the class ROSTopicHz is written in Python.

Is there any way to access the class to get the actual publishing rate based on a given topic name from C++?

I could implement the functionality from ROSTopicHz in C++ but the problem I am facing is that I won't know prior which topics and message types I will subscribe to (this should be selectable during runtime). So I would need a way to dynamically create subscriber objects and callback functions in C++.

Does anyone have an idea how to do this or a way to write a panel for RViz in Python directly?

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-04-08 03:08:24 -0500

gvdhoorn gravatar image

updated 2018-04-08 11:25:54 -0500

Without (quite) some trickery, writing RViz panels in Python is probably going to be difficult.

Dynamically subscribing to topics can be done both in Python as well as in C++ though, I don't immediately see why that would be any more difficult. Almost all RViz display plugins and quite some Panel plugins do it. See rviz/default_plugin/marker_display.cpp for instance.


It would be somewhat involved, but one way to get this info into RViz could be to write a Python publisher that wraps rostopic.ROSTopicHz, publishes the data you're after and then write a regular C++ panel plugin (something like InstitutMaupertuis/simple_rviz_plugin) to display it inside RViz.

If you don't absolutely need it to be an RViz panel, you could perhaps take a look at rqt_topic, which shows the same statistics (and more), but is an rqt plugin. RQT can also host an RViz instance.


Edit:

Thank you for your great answer! The problem I am seeing with C++ is that I need to create callback functions on runtime for new subscribers (so I can distinguish them for measuring publishing rate) because the messages have different types. I don't know at compile time the message types.

The topic_tools pkg also has a C++ side to it. That provides the ShapeShifter class, which allows you to subscribe to any topic at runtime. See also ros_type_introspection/Tutorials/GenericTopicSubscriber.

To clarify my idea a bit more: I have a system with quite many devices (all of them are publishing data in ROS) and several people are working on the system. Sometimes one or two devices are not running (because somene forgot to plug in a cable again for example). Since we don't have a mechanism to track these problems down with the nodes directly (legacy code problems) we just check with rostopic hz if there is data on the desired topics. So the panel should be reconfigurable to measure the publishing rate on all types of topics.

I should've asked you why you wanted to this, but reading this description makes me wonder whether we're not solving an xy-problem.

What you're describing sounds more like a task for diagnostics.

edit flag offensive delete link more

Comments

Thank you for your great answer! The problem I am seeing with C++ is that I need to create callback functions on runtime for new subscribers (so I can distinguish them for measuring publishing rate) because the messages have different types. I don't know at compile time the message types.

ce_guy gravatar image ce_guy  ( 2018-04-08 06:23:58 -0500 )edit

I have thought about using a template function but how can I detect which topic I am getting the callback function call from at the moment? Thank you very much for your help!

ce_guy gravatar image ce_guy  ( 2018-04-08 06:28:43 -0500 )edit

To clarify my idea a bit more: I have a system with quite many devices (all of them are publishing data in ROS) and several people are working on the system. Sometimes one or two devices are not running (because somene forgot to plug in a cable again for example). 1-2

ce_guy gravatar image ce_guy  ( 2018-04-08 06:32:22 -0500 )edit

2-2 Since we don't have a mechanism to track these problems down with the nodes directly (legacy code problems) we just check with rostopic hz if there is data on the desired topics. So the panel should be reconfigurable to measure the publishing rate on all types of topics.

ce_guy gravatar image ce_guy  ( 2018-04-08 06:35:50 -0500 )edit

I don't think it was a xy-problem. I just didn't know about the GenericTopicSubscriber. The panel will meet all our requirements in the current project status.

ce_guy gravatar image ce_guy  ( 2018-04-08 11:26:01 -0500 )edit

Slightly pedantic, but: you seem to be after a way to monitor the status of various topics (or really: the status of various nodes). You picked something that you believe could be a viable approach: monitoring publications using ROSTopicHz. The problem is that it's a Python class, ..

gvdhoorn gravatar image gvdhoorn  ( 2018-04-08 11:30:27 -0500 )edit

.. and you want to write an RViz panel (another approach you've already selected). Now the issue is that Python and RViz panels are not compatible, so you ask a question about your already selected (and implicit until your last comment) solution, instead of the real problem. That would seem to ..

gvdhoorn gravatar image gvdhoorn  ( 2018-04-08 11:31:30 -0500 )edit

.. have the characteristics of an xy-problem.

I don't mind at all really, but thought it was good to mention it.

gvdhoorn gravatar image gvdhoorn  ( 2018-04-08 11:32:21 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-04-07 15:03:09 -0500

Seen: 1,266 times

Last updated: Apr 08 '18