i am using ROS2 foxy on Ubuntu 20.04, i have implemented a publisher node, which publishes data into a msg, i start the publisher and i can see the published data using ros2 topic echo /topic_name, but i want to see the plotted data using ros2 run rqt_plot rqt_plot, i call this line the plotting figure is opened and i select the required topic but it is not showing anything, do you have any idea?
1 Answer
To plot the information published on a specific topic, we need to know the topic name and message type and member names. Suppose we have a topic called /topic_name
that carries messages of type std_msgs/Float64
. In your case, you can know the message type with the following command.
ros2 topic info /topic_name
This command outputs the following:
Type: std_msgs/msg/Float64
Publisher count: 1
Subscription count: 0
We now know the message type is std_msgs/msg/Float64
. Next, we need to know how the data is structured inside this message type to know the names of the individual pieces of information. This can be done with the following command: (notice to replace std_msgs/msg/Float64
with your message type)
ros2 interface show std_msgs/msg/Float64
This command prints the following.
# This was originally provided as an example message.
# It is deprecated as of Foxy
# It is recommended to create your own semantically meaningful message.
# However if you would like to continue using this please use the equivalent in example_msgs.
float64 data
This message type has a single member named data and of type Float64. This name is what we want to give to rqt_plot with the topic name.
Then, we reached the answer to your question. Open the rqt_plot window, and what you need to plot is as follows. /topic_name/message_member_name
. In our case, this would be /topic_name/data
. Press the green plus button to plot this data.
Notice for the sake of a complete answer. If the internal data is an array like std_msgs/Float64MultiArray
, we can retrieve its individual elements as /topic_name/data[0]
, /topic_name/data[1]
, and so on when giving inputs to rqt_plot.
-
$\begingroup$ hello Robotawi, thanks a lot for your replay, in my case inside the message i have std_msgs/Header header float64[] x_des, and i am applaying a trajectory which i publish on this message on x_des, what i want is to see the whole x_des but not x_des[0]..... $\endgroup$– lockiCommented Jan 24 at 15:24
-
$\begingroup$ With pleasure, locki! Do you mean to plot the whole trajectory in one step? If yes, I do not think this is possible because rqt_plot is expecting individual elements as input. Give all the array elements to the rqt_plot one by one like
/topic_name/x_des[0]
,/topic_name/x_des[1]
, .../topic_name/x_des[6]
. I have done the same before when debugging a trjectory. It works well and plots for you every joint with a different color to clearly examine them. It was very satisfactory for the debugging task. $\endgroup$– RobotawiCommented Jan 24 at 15:37 -
$\begingroup$ Notice that plotting the individual joints one by one will add all of them to the same plot. This means you will end up plotting the whole trajectory in the same plot as you want. $\endgroup$– RobotawiCommented Jan 24 at 15:45
-
-
$\begingroup$ You are welcome, @locki! If you found this answer helpful, please mark it as accepted so that it can serve as a reliable resource for fellows who may encounter similar issues. $\endgroup$– RobotawiCommented Jan 25 at 15:23