ROS2 Topics "ros2 topic echo /cmd_vel" fails

Hi,
I am working on the ROS2 in 5 days (Python) course Unit 3 about Topics and I have issues with the following command:

ros2 topic echo /cmd_vel

The terminal then outputs the following:

Traceback (most recent call last):
  File "/opt/ros/foxy/bin/ros2", line 11, in <module>
    load_entry_point('ros2cli==0.9.7', 'console_scripts', 'ros2')()
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/command/topic.py", line 41, in main
    return extension.main(args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/echo.py", line 81, in main
    return main(args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/echo.py", line 95, in main
    message_type = get_msg_class(node, args.topic_name, include_hidden_topics=True)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/api/__init__.py", line 88, in get_msg_class
    msg_class = _get_msg_class(node, topic, include_hidden_topics)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/api/__init__.py", line 133, in _get_msg_class
    return get_message(message_type)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_runtime_py/utilities.py", line 30, in get_message
    raise ValueError("Expected the full name of a message, got '{}'".format(identifier))
ValueError: Expected the full name of a message, got 'geometry_msgs/msg/Twist'

I have initiated the ROS2 environment with:

source /opt/ros/foxy/setup.bash

I receive similar errors when I try to echo another topic.

And when I try to publish into a topic with:

ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.1, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}"

I receive the following output:

Traceback (most recent call last):
  File "/opt/ros/foxy/bin/ros2", line 11, in <module>
    load_entry_point('ros2cli==0.9.7', 'console_scripts', 'ros2')()
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/command/topic.py", line 41, in main
    return extension.main(args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 93, in main
    return main(args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 103, in main
    return publisher(
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 125, in publisher
    msg_module = get_message(message_type)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_runtime_py/utilities.py", line 30, in get_message
    raise ValueError("Expected the full name of a message, got '{}'".format(identifier))
ValueError: Expected the full name of a message, got 'geometry_msgs/msg/Twist'

Am I doing something wrong or why doesn’t it work? I would expect that it simply echoes the topic content rsp. publish something into the topic.

Hello @dave.vandermeer1 ,

I’ve been doing some tests here with the commands you provided and it’s working ok for me. Therefore, I’d guess that it might be something wrong with you Shells. I’d suggest you restart the Shell to fix any possible sourcing issues and then try again the commands. To restart a Shell just click on the red cross icon:

Captura de pantalla 2022-01-28 a las 9.38.43

Please let me know if this doesn’t solve your issue.

try ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist ‘{linear: {x: 0.1, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}’

Hi @albertoezquerro,

I have tried it again, with no success.

I have set up the following in my .bashrc file, could this temper with the shell?

Instead of sourcing ROS2 and the workspace manually, I thought it is easier to put it in the .bashrc. It should not change anything, right?

Except that, when I run ros2 topic echo /cmd_vel right after starting the shell, I still get the same error. When I do ros2 topic info /cmd_vel, it works fine.

Thanks for the input. I tried and I got the following result:

usage: ros2 [-h] Call `ros2 <command> -h` for more detailed usage. ...
ros2: error: unrecognized arguments: {x: 0.1, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}'

I guess the quotes are incorrect.

Hello @dave.vandermeer1 ,

I’ve done some tests directly with your user in order to reproduce the error, and it seems that the problem is, indeed, with the sources you added to the .bashrc file. I’ve removed the sources from the file and now it works properly. The weird thing is that if you run the sources manually from the shell:

source /opt/ros/foxy/setup.bash
source /home/simulations/ros2_sims_ws/install/setup.bash

Then it works ok. I’m not sure about the reason for this behavior, but there must be something wrong with the .bashrc file. I’ll investigate more on this when I have the time. In any case, you should be able to run the commands normally now.

Thanks, this actually solved it. I will do the source manually from now on. It would be nice though if I wouldn’t need to.

I might create an alias for sourcing the setup.bash files.