like ROS1, the resources in ROS2 are connected through a calculation diagram ("ROS (2) graph"). The calculation diagram is a network composed of various ROS2 elements, which jointly complete the data transmission. Each module that completes the specific function is called "Node". Each Node in the ROS shall be responsible for a single module purpose (for example, one Node is used to control the wheel motor, one Node is used to control the laser rangefinder, etc.). Nodes send and receive data through topics, services, Actions or parameters.
a complete robot system is composed of multiple nodes. Each node performs its own duties and completes its own work. In ROS2, each executable program (C + +, Python) can contain one or more nodes, which is different from that in ROS1. Next, continue to be familiar with the commands related to the next node in the little turtle routine.
1 ros2 run
ros2 run is equivalent to rosrun in ROS1. It is mainly used to run the executable program in a function package. The syntax is as follows:
ros2 run <package_name> <executable_name>
for example, the little turtle simulation interface is the execution program of the node, which is located in the turnlesim function package. The command to start it is:
ros2 run turtlesim turtlesim_node
After running the above command, the little turtle will appear on the interface:
but you should note that the name of the turnlesim here is the name of the function package, and the turnlesim_ Node is only the name of the executable file, not the node name. To know the name of the node, we need to run the following command.
2 ros2 node list
ros2 node list will display the names of all running nodes, which is equivalent to rosnode list in ROS1. This is especially useful when you want to interact with one node, or when your system runs many nodes and needs to track them. After starting the turtle simulator, open a terminal and input the following commands:
ros2 node list
The terminal will return the node name:
reopen a terminal and enter the following command to start the keyboard controlled turtle simulator:
ros2 run turtlesim turtle_teleop_key
After rerunning the ros2 node list, you can find one more running node:
the remapping mechanism in ROS can help us redefine the attributes of nodes, such as node name, topic name, service name, etc. For example, if we want to modify the node name turnlesim, we can do this:
ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle
now that you call ros2 run on turtle SIM, the simulation interface of another little turtle will open. However, now if you go back to the terminal running ros2 node list and run it again, you will see three node names:
/my_turtle /turtlesim /teleop_turtle
There is no conflict here because the newly started simulation node is called "my_turtle", which is not the default "turtle SIM".
4 ros2 node info
now that you know the name of the node, you can access more information about the node in the following ways:
ros2 node info <node_name>
check your latest node_ Tuttle, run the following command:
ros2 node info /my_turtle
You can see a lot of information about the node, including subscribers, publishers, services, actions, and so on.
/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: