question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request - ros2 topic echo --once

See original GitHub issue

Feature 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
clalancettecommented, Jun 11, 2020

You should be able to overlay them. That is, make a workspace with your forked copy of ros2cli, build that, and then source install/setup.bash that is generated in that workspace. You should now be able to use your versions of the commands.

0reactions
fujitatomoyacommented, Feb 22, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding topics — ROS 2 Documentation
Topics are one of the main ways in which data is moved between nodes and therefore between different parts of the system.
Read more >
ros2 topic Command Line Tool - The Robotics Back-End
Use the ros2 topic cmd line tool to debug your topics directly from the terminal. ros2 topic echo, list, pub, hz, bw, etc:...
Read more >
The ROS Command Line Interface - Programming Multiple ...
Many ROS nodes subscribe to one set of topics, process that input data, and then publish to another set of topics. Let's return...
Read more >
16.2. Use ROS 2 with Fast-DDS Discovery Server
The following tutorial gathers the steps to check this functionality and learn how to use it with ROS 2. Discovery Server v2. Prerequisites....
Read more >
ROS 2 Command Line Interface - Ubuntu
One of the central pieces of the ROS ecosystem is its Command Line Interface (CLI). It allows for performing ... ros2 topic echo...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found