The article directories

    • (1) background
    • (2) the premise
    • (3) task
      • Ⅰ preparation
      • Ⅱ rqt_graph
      • ⅲ ROS2 topic command
        • ros2 topic list
        • ros2 topic echo
        • ros2 topic info
        • Eloquent ros2 Interface Show eloquent ros2 interface Show
          • Dashing version
          • Eloquent version
          • Both versions work
        • ros2 topic pub
        • ros2 topic hz
    • (4) summarize

(1) background

ROS 2 decomposes a complex system into many modular nodes. A topic is an important element of the ROS diagram, acting as a bus for nodes to exchange messages. Nodes can publish data to any number of topics and have subscriptions to any number of topics simultaneously. Topics are one of the important ways in which data is moved between nodes, and therefore between different parts of the system. We communicate with each other through topic and discover each other through Node

(2) the premise

  • Install ros2
  • Configure the environment
  • Put the turtle

(3) task

Ⅰ preparation

Start the turtle command:

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key
Copy the code

Ⅱ rqt_graph

This is a tool to manipulate, command:

rqt_graph
Copy the code

Not like Ros1 and Rosrun



This is a self-test tool

ⅲ ROS2 topic command

ros2 topic list

Ros2 topic list list of all topics ros2 topic list -t list of topics with the message type incidentally, this is good.

usage: ros2 topic list [-h] [--spin-time SPIN_TIME] [-t] [-c]
                       [--include-hidden-topics]

Output a list of available topics

optional arguments:
  -h, --help            show this help message and exit
  --spin-time SPIN_TIME
                        Spin time in seconds to wait for discovery (only
                        applies when not using an already running daemon)
  -t, --show-types      Additionally show the topic type
  -c, --count-topics    Only display the number of topics discovered
  --include-hidden-topics
                        Consider hidden topics as well
Copy the code



Rqt_graph: rqt_graph: rqt_graph: rqt_graph

ros2 topic echo

Publish > publish > publish > publish > publish

ros2 topic echo <topic_name>
Copy the code

Example of the little turtle:

ros2 topic echo /turtle1/cmd_vel
Copy the code

This will get you straight

ros2 topic info

For details on topic, command:ros2 topic info /turtle1/cmd_vel

Eloquent ros2 Interface Show eloquent ros2 interface Show

Using ros2 topic list-t we see that the message type for cmd_vel is geometry_MSgs/MSG /Twist

Dashing version
  • We can useros2 msg show geometry_msgs/msg/Twist

Eloquent version
  • We can useros2 interface show geometry_msgs/msg/Twist.msg

Both versions work

ros2 topic pub

Messages can be sent from the command line

ros2 topic pub <topic_name> <msg_type> '<args>'
Copy the code

We control the turtle by giving orders

ros2 topic pub  --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist '{linear: {x: 2.0, y: 0.0, z: 0.0}, presents: {x: 0.0, y: 0.0, z: 1.8}}'
Copy the code

options--rate 1Or publish at 1HZ instead of adding,--onceOnly once

ros2 topic hz

Statistics topic message frequency in real time

ros2 topic hz topic_name
Copy the code

(4) summarize

This is not very different from ROs1