[Getting started with ROS2] Understanding ROS 2 nodes

        Hello everyone, I am Brother Hu. Starting today, I will spend a while and start switching myself from ROS1 to ROS2. In the previous article, we relied on the Turtlesim demo node to gradually expand and introduced the rqt tool. This chapter , we will focus on the main concept "node" in ROS2, and understand the functions of nodes in ROS 2 and the tools to interact with them.

Table of contents

The ROS 2 graph

1. Nodes in ROS2 (Nodes in ROS 2)

prerequisites

1、ROS2 RUN

2、ros2 node list

3、Remapping

4、 ros2 node info

5. Summary:


The ROS 2 graph

  • Over the next few tutorials, you'll learn about a set of core ROS2 concepts that make up the so-called "ROS(2) graph".

  • A ROS graph is a network of ROS 2 elements processing data simultaneously. It contains all the executables and the connections between them, if you want to map and visualize them all.

1. Nodes in ROS2 (Nodes in ROS 2)

Each node in ROS should be responsible for a single module purpose (e.g. one node to control the wheel motors, one to control the laser rangefinder, etc.). Each node can send and receive data to other nodes through topics, services, operations or parameters.

        A complete robot system consists of many nodes working together. In ROS 2, a single executable (C++ program, Python program, etc.) can contain one or more nodes.

prerequisites

The previous tutorial showed you how to install the turtlesim package used here. As always, don't forget to provide ROS 2 in every new terminal you open.

1、ROS2 RUN

Launch executable from package

ros2 run <package_name> <executable_name>

For example, we started turtlesim earlier with

ros2 run turtlesim turtlesim_node

As you saw in the previous tutorial, turtlesim will open. Here, the package name is turtlesim and the executable file name is turtle sim_node.

However, we still don't know the node names. The node names can be found using ros2 node list.

2、ros2 node list

ros2 node list will show the names of all running nodes. This is especially useful when you want to interact with a node, or when your system runs multiple nodes and you need to keep track of them. Open a new terminal while running turtlesim on another terminal, and enter the following command:

ros2 node list

Open another new terminal and start the teleoperation node with the following command:

ros2 run turtlesim turtle_teleop_key

Continue to use ros2 node list to view the node list:

3、Remapping

Remapping allows you to reassign default node properties (such as node name, topic name, service name, etc.) to custom values. In the previous tutorial, you used remapping of the turtle_teleop_key to change the default turtle to control.

Now, let's reassign the name of the /turtlesim node. In a new terminal, run the following command:

ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle

Since you call ros2 run again in turtlesim, another turtlesim will open. Now, however, if you go back to the terminal where you ran ros2 nodelist, and run it again, you'll see three node names:

4、 ros2 node info

Now that you know the names of the nodes, you can access more information about them with:

ros2 node info <node_name>

Using your last command as an example, my_turtleexecute the following command:

ros2 node info /my_turtle

You will get the following reply:

nvidia@ubuntu:~$ ros2 node info /my_turtle
/my_turtle
  Subscribers:
    /parameter_events: rcl_interfaces/msg/ParameterEvent
    /turtle1/cmd_vel: geometry_msgs/msg/Twist
  Publishers:
    /parameter_events: rcl_interfaces/msg/ParameterEvent
    /rosout: rcl_interfaces/msg/Log
    /turtle1/color_sensor: turtlesim/msg/Color
    /turtle1/pose: turtlesim/msg/Pose
  Service Servers:
    /clear: std_srvs/srv/Empty
    /kill: turtlesim/srv/Kill
    /my_turtle/describe_parameters: rcl_interfaces/srv/DescribeParameters
    /my_turtle/get_parameter_types: rcl_interfaces/srv/GetParameterTypes
    /my_turtle/get_parameters: rcl_interfaces/srv/GetParameters
    /my_turtle/list_parameters: rcl_interfaces/srv/ListParameters
    /my_turtle/set_parameters: rcl_interfaces/srv/SetParameters
    /my_turtle/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically
    /reset: std_srvs/srv/Empty
    /spawn: turtlesim/srv/Spawn
    /turtle1/set_pen: turtlesim/srv/SetPen
    /turtle1/teleport_absolute: turtlesim/srv/TeleportAbsolute
    /turtle1/teleport_relative: turtlesim/srv/TeleportRelative
  Service Clients:
  Action Servers:
    /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute
  Action Clients:

Now, try looking at the node teolep_turtle, run the same command and see how it connects differently than my_turtle.

5. Summary:

        A node is a fundamental ROS 2 element used in robotic systems for a single modular purpose. In this tutorial, you utilized the nodes created from the turtlesim package by running the executables turtlesim_node and turtle_teleop_key. You learned how to use ros2 node list to discover active node names and ros2 node info. These tools are critical to understanding data flow in complex real-world robotic systems.

The above is what I want to share today. Error correction, questions, communication: [email protected]

Guess you like

Origin blog.csdn.net/cau_weiyuhu/article/details/128685678