Welcome to AI View Depth camera repository
6.ROS node
6.ROS node
In [1. Introduction to ROS]-[1.2.1. Computational graph level], we introduced the concept of nodes. In the previous section, the function package we created is the folder that stores the node program. You can use Python or C++ to write the node program, then compile it into an executable file, and finally run it as what we call the node program.
6.1 roscore
Before running all ros programs, you need to start roscore (this is not required when running the launch file later, roscore will be started when the launch file is started), enter in the terminal,
roscore
Only one roscore can be run. If roscore is started in multiple terminals, it will prompt that roscore has been started, as shown in the figure below.
6.2 rosnode
After starting roscore, a node program is started. We have introduced several common tools of rosnode in the previous [3. ROS common command tools]-[3.1. Node rosnode].We can use rosnode list to view and query all currently running nodes, and enter in the terminal,
xxxxxxxxxxrosnode list
Only one node is started here, which is /rosout. This is the node that we run after starting the roscore program. You can use rosnode info node_name to view the information of the node.(node_name represents the node name, modify it according to the actual node name that needs to be queried), enter the terminal,
xxxxxxxxxxrosnode info /rosout

As shown in the figure above, some relevant information about the node will be printed and listed, such as:
Posted topics and related data types
Publications:
- /rosout_agg [rosgraph_msgs/Log]
Subscribed topics and related data types
Subscriptions:
- /rosout [unknown type]
Services provided and related data types
Services:
- /rosout/get_loggers
- /rosout/set_logger_level
6.3 rosrun
Rosrun is the command to start the ros node program. The previous roscore is special. You can start it by inputting roscore in the terminal. However, most other ros node programs are started by rosrun. The command format is as follows:
xxxxxxxxxxrosrun pkg_name executable_programpkg_name:function package name, the name of the function package folder of the subsequent executable program
executable_program:The name of the executable program, which can be a file generated by C++ compilation, or a file written in Python with a .py executable file at the end.
For example, taking the classic little turtle as an example, after starting roscore, we enter in another terminal,
xxxxxxxxxxrosrun turtlesim turtlesim_node 
After successful startup, a little turtle will appear. We can check the current nodes through rosnode list and enter in the terminal.
xxxxxxxxxxrosnode list

Compared with the previous /rosout, there is an additional /turtlesim. You can also use the rosnode info tool to view node information and enter it in the terminal.
xxxxxxxxxxrosnode info /turtlesim

There will be more content here, but basically the content is similar. The [Publications] section explains which topics the node has published and the corresponding topic data types; [Subscriptions] section explains which topics the node subscribes to and the corresponding topic data types; the [Services] section explains what services the node provides.
Making more use of the rosnode tool to query running nodes and related information is a very important point in the process of debugging ros. For example, we wrote a program and ran it without problems and reported errors, but the topic communication between nodes did not run as we expected. At this time, you can use rosnode info to check whether it is caused by inconsistent topic names or other content. Only by running these tools flexibly can the problem be solved faster.