Feature Request - ros2 topic echo --once
See original GitHub issueFeature request
Add an option --once
to the ros2 topic echo
command, that will cause the command to exit after it has received and printed one message. Also add a --timeout
option that will cause the command to exit if a certain period of time has elapsed.
Feature description
If messages are being published representing the state of the system, then the ros2 topic echo
is useful for querying the current state. The last message is often all that the user is interested in. ros2 topic echo --qos-durability=transient_local --once
will be a quick way of sending a “Get” command, that gets the current value of something in the system.
It will also be useful for writing tests. e.g
source /opt/ros/eloquent/setup.bash
source ./install/setup.sh
#Launch all nodes in a background process
ros2 launch -a launch/my_launch.py &>ros_out_log &
pid=$!
#Test initial state of robot1
pos=$(ros2 topic echo --qos-durability=transient_local --once robot1/position msgs/PositionMsg)
#test $pos...
#Send move command
ros2 service call robot1/move srvs/MoveSrv {x: 1, y: 2}
sleep 2
#Test new poistion of robot1
pos=$(ros2 topic echo --qos-durability=transient_local --once robot1/position msgs/PositionMsg)
#test $pos...
#Shutdown all nodes
kill -2 $pid
echo "waiting for nodes to shutdown..."
nodes=$(ros2 node list)
numnodes=$(echo $nodes | wc -w)
while [[ $numnodes != 0 ]]; do
nodes=$(ros2 node list)
numnodes=$(echo $nodes | wc -w)
echo "$numnodes remaining"
sleep 1
done
This is much easier than having to create subscribers, clients, etc in a python file and testing it that way.
Implementation considerations
This should be pretty easy to implement. Instead of rclpy.spin(node)
here, replace with rclpy.spin_untill_future_complete()
(which already has a timeout feature built into it), and then set the future as complete in the subscription callback.
I’ve made a start here: https://github.com/craigh92/ros2cli/commit/10e716dacfd838799a0510bbf67f45f87eff152c
I’ve not contributed before so I’m not sure if I’m using parser.add_argument
correctly.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top GitHub Comments
You should be able to overlay them. That is, make a workspace with your forked copy of
ros2cli
, build that, and then sourceinstall/setup.bash
that is generated in that workspace. You should now be able to use your versions of the commands.reopen this in favor of https://github.com/ros2/ros2cli/pull/695