Can not trigger subscriber for mavros/local_position/pose, ... topics

asked 2023-03-15 08:19:00 -0500

marcusnorgren gravatar image


I am using a PX4 Gazebo simulation in ROS2-Foxy, with a MAVROS-node to forward the MAVLINK-data to ROS(2). I have written ROS-subscribers which subscribe to the following topics (published on by MAVROS via PX4): /mavros/local_position/pose /mavros/local_position/odom /mavros/global_position/global /mavros/global_position/local

I can see that these are being published on, since if I do: ros2 topic echo , or: ros2 topic hz - I can see all the regular data, with correct freqencies. In the rqt-graph I can see that the [mavros/local_position]-node has publishing connections to the above topics, and I subscribe to the exact same topics with my subscriber node (which also shows with connections to it).

I can subscribe to topics like /mavros/home_position or mavros/state, and the subscriber callbacks are triggered as expected. But I can never get the position-topics to trigger their callbacks. If I myself publish on these topics, they are triggered, but only my messages (and Hz) show in rqt, however in the terminal the frequencies are added (i.e. PX4 + my publisher). I have experimented with different rates and subscriber-queue-sizes, but nothing makes a difference.

Are the position-topics being treated differently in PX4 (or MAVROS) than other topics? Why are ros2 topic telling me that the topics are being published on but I can never trigger the callbacks for the same functions, when the publishing is done via PX4-MAVROS?

Perhaps this is a MAVROS issue, but it might be a PX4 specific as well. I get no errors in any output terminal regarding the topics. I also have QGC running and the MAVLINK topics (e.g LOCAL_POSITION_NED) are published at the same rate as they are forwarded by MAVROS. I am very grateful for any help!

Best, Marcus

Additional info:

Ubuntu 20.04, MAVROS via binary install. PX4-Autopilot from this repo.
MAVROS is started on udp-port 14540.
I run my nodes with a multithread executor, i.e.
executor = MultiThread(), then
executor.add_node(nodes), then
edit retag flag offensive close merge delete



quick comment: make sure the QoS on both sides is compatible. ros2 topic has command line options to show QoS information. If there's a mismatch, your callbacks won't get called.

gvdhoorn gravatar image gvdhoorn  ( 2023-03-17 01:57:16 -0500 )edit

Yes I found that that was the problem. Thanks anyway! This is not something people seem to mention in general publisher-subscriber tutorials. Do you know which settings specifically must match? Because queue-size seems to be able to differ, so curious which settings need to match.

marcusnorgren gravatar image marcusnorgren  ( 2023-03-20 04:36:21 -0500 )edit

I'm not sure whether mavlink changes anything, but perhaps About Quality of Service settings can provide some insight.

gvdhoorn gravatar image gvdhoorn  ( 2023-03-20 07:01:43 -0500 )edit