Welcome to RDK S600 Developer Kit repository
6.ROS2 node
6. ROS2 Nodes
Note: The accompanying reference video uses the ROS Humble version, for reference only
1. Node Overview
During communication, regardless of the method used, the construction of communication objects depends on Nodes. In ROS2, each node generally corresponds to a single functional module (for example: the LiDAR driver node may be responsible for publishing LiDAR messages, the camera driver node may be responsible for publishing image messages). A complete robot system may consist of many nodes working together. A single executable file (C++ program or Python program) in ROS2 can contain one or more nodes.
2. Node Creation Process
Create program file
Import related ROS libraries
Write node functionality
Write configuration files
Build and run
3. Hello World Node Example
Here we use a Python package as an example for explanation.
3.1. Create Python Package
Replace workspace with your actual workspace path:
cd workspace/srcros2 pkg create pkg_helloworld_py --build-type ament_python --dependencies rclpy --node-name helloworld
3.2. Write Code
After executing the above command, pkg_helloworld_py will be created, and a helloworld.py file will be generated for writing the node:

Delete the original helloworld.py code and write the following code:
x
import rclpy # ROS2 Python interface libraryfrom rclpy.node import Node # ROS2 Node classimport time
"""Create a HelloWorld node that outputs "hello world" log during initialization"""class HelloWorldNode(Node): def __init__(self, name): super().__init__(name) # ROS2 node parent class initialization while rclpy.ok(): # Check if ROS2 system is running normally self.get_logger().info("Hello World") # ROS2 log output time.sleep(0.5) # Sleep to control loop timing
def main(args=None): # ROS2 node main entry point rclpy.init(args=args) # ROS2 Python interface initialization node = HelloWorldNode("helloworld") # Create ROS2 node object and initialize rclpy.spin(node) # Loop waiting for ROS2 exit node.destroy_node() # Destroy node object rclpy.shutdown() # Shutdown ROS2 Python interface
After completing the code, you need to configure the package's build options so the system knows the entry point for the Python program. Open the package's setup.py file and add the following entry point configuration:

3.3. Build Package
Build the package:
xxxxxxxxxxcolcon build --packages-select pkg_helloworld_pyRefresh environment variables in the workspace:
xxxxxxxxxxsource install/setup.bash
3.4. Run Node