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

ROS2 topic echo Selected field

asked 2020-10-22 01:28:20 -0500

mhallak gravatar image

In ROS1, you could perform:

rostopic echo /mavros/state/armed for topic rostopic echo /mavros/state

In ROS2, I didn't succed to find how to do it.

edit retag flag offensive close merge delete

Comments

Hi! Did you find how to do it without grep?

sabrinaacardoso gravatar image sabrinaacardoso  ( 2022-03-18 08:56:37 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2022-05-28 23:16:10 -0500

808brick gravatar image

You can use the --field flag of the ros2 topic echo command. Here is an example:

ros2 topic echo /imu_test --field linear_acceleration

which will give the output

x: 0.0
y: 0.0
z: 0.0
---

You can go further into the field by putting periods after each subsection, so

ros2 topic echo /imu_test --field linear_acceleration.x

will give you

0.0
---
edit flag offensive delete link more
0

answered 2020-10-22 07:36:26 -0500

Phgo gravatar image

I do not know a ROS2 equivalent of the command you described . However a simple workaround to get a similar behavior could be to use grep for this purpose. You can specify the number of lines that should be visible after your search key with the -A [num lines after match] option. Just set it to the size of the data field of interest.

For example to view the linear acceleration of an sensor_msgs/msg/Imu one could write:

ros2 topic echo /imu_topic | grep -A 3 "linear"
 linear:
   x: 0.0
   y: 0.0
   z: 0.0
(...)
edit flag offensive delete link more

Comments

This was my go-to workaround too, but it works really laggy with the | grep. Greps seem to come through in batches. Any idea how to solve that?

RokusO gravatar image RokusO  ( 2022-05-12 06:52:21 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2020-10-22 01:28:20 -0500

Seen: 6,421 times

Last updated: May 28 '22