Welcome to ROSMASTER M3 repository
01.ROS control
ROS Control
ROS Control1. Course Content2. Preparations2.1 Content Description2.2 Start the Agent3. Launch Commands3.1 Function Description3.2 Program Start3.2.1 View Node Information3.2.2 Publish Control Commands3.2.3 Control the Car's Buzzer3.2.4 Control the Car's Light Strip3.2.5 Subscribe to LiDAR Data3.2.6 Subscribe to Battery Level Data3.2.7 Subscribe to IMU Data3.2.8 Subscribe to Odometry Data
1. Course Content
- Learn the basic method of controlling a robot via ROS.
This function allows for controlling the car's speed and buzzer using the ros2 topic tool, and also for reading low-level data such as LiDAR data, IMU data, odometry data, etc.
2. Preparations
2.1 Content Description
This lesson uses the Jetson Orin NX as an example. For Raspberry Pi and Jetson Nano boards, you need to open a terminal on the host machine, enter the command to get into the Docker container, and then input the commands mentioned in this lesson in the terminal within the Docker container. A tutorial on how to enter the Docker container from the host can be found in this product's guide [00.Configuration and Operation Guide]-[3.Enter the Docker (For RPI5)]. For Orin and RDKX5 boards, you can directly open a terminal and enter the commands mentioned in this lesson.
2.2 Start the Agent
Note: To test all examples, you must start the Docker agent first. If it is already running, you do not need to start it again. The agent starts by default on boot, so there is no need to restart it.
Enter the command in the vehicle's terminal:
start_agent
The terminal will print the following information, indicating a successful connection:

3. Launch Commands
3.1 Function Description
This function allows for controlling the car's speed and buzzer using the ros2 topic tool, and also for reading low-level data such as LiDAR data, IMU data, odometry data, etc.
3.2 Program Start
3.2.1 View Node Information
After successfully connecting to the agent, you can enter ros2 node list in the terminal to see which nodes are available.
For Raspberry Pi 5 users, if the ROS container is not started, you need to start it first,
xxxxxxxxxxbringup_m3
Open a terminal inside the container,
xxxxxxxxxxexec_m3
Enter the command,
xxxxxxxxxxros2 node listThe execution screenshot is as follows,

Here, /YB_Node indicates that the low-level control node has started. Enter the following command in the terminal to query information about this node,
xxxxxxxxxxros2 node info /YB_NodeThe execution screenshot is as follows,

A table has been compiled here to show which topics the node publishes and subscribes to, along with the message data type for each topic. The table is as follows,
Subscription Topics Table
| Subscribed Topic | Topic Message Type | Topic Attribute |
|---|---|---|
| /beep | std_msgs/msg/UInt16 | Control Buzzer |
| /cmd_vel | geometry_msgs/msg/Twist | Control Car Speed |
| /rgb | std_msgs/msg/ColorRGBA | Control Light |
Publication Topics Table
| Published Topic | Topic Message Type | Topic Attribute |
|---|---|---|
| /battery | std_msgs/msg/Float32 | Publish Battery Level Data |
| /imu/data_raw | sensor_msgs/msg/Imu | Publish IMU Data |
| /odom_raw | nav_msgs/msg/Odometry | Publish Odometry Data |
LiDAR Topics for Dual-LiDAR Version
| Published Topic | Topic Message Type | Topic Attribute |
|---|---|---|
| /scan0 | sensor_msgs/msg/LaserScan | Left-Rear LiDAR Data of the Car |
| /scan1 | sensor_msgs/msg/LaserScan | Right-Front LiDAR Data of the Car |
LiDAR Topics for Single-LiDAR Version
| Published Topic | Topic Message Type | Topic Attribute |
|---|---|---|
| /scan2 | sensor_msgs/msg/LaserScan | LiDAR First-Half Scan Data |
| /scan3 | sensor_msgs/msg/LaserScan | LiDAR Second-Half Scan Data |
3.2.2 Publish Control Commands
Based on the subscription topics table, use the command format ros2 topic pub <topic_name> <message_type> <data> --once to publish a single frame of control data.
For the first test, it is recommended to lift the car so that its wheels are off the ground. We will make the car move forward at a linear velocity of 0.1m/s. Enter the following command in the terminal,
xxxxxxxxxxros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.1, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}" --onceAfter execution, the car will move forward at a speed of 0.1m/s. Similarly, to control the car to rotate at an angular velocity of 1.0rad/s, assign a value to the angular z component. The command is as follows,
xxxxxxxxxxros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}" --onceAfter execution, the car will rotate. If we want to stop the car, we can publish a message with both linear and angular velocities set to 0. The command is as follows,
xxxxxxxxxxros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}" --onceThe --once flag means that only one frame of the message is sent. For other parameters of ros2 topic pub, please refer to this product's course [15. ROS2 Basic Course] under [19. Common ROS2 Command Tools].
3.2.3 Control the Car's Buzzer
To activate the buzzer, enter the following command in the terminal,
xxxxxxxxxxros2 topic pub /beep std_msgs/msg/UInt16 "data: 1" --onceTo deactivate the buzzer, enter the following command in the terminal,
xxxxxxxxxxros2 topic pub /beep std_msgs/msg/UInt16 "data: 0" --once3.2.4 Control the Car's Light Strip
To publish the color red, enter the following command in the terminal,
xxxxxxxxxxros2 topic pub /rgb std_msgs/msg/ColorRGBA "{r: 1.0, g: 0.0, b: 0.0, a: 1.0}" --onceParameters related to a:
a: 101.0 Flowing light
a: 102.0 Marquee light
a: 103.0 Breathing light
a: 104.0 Gradient light
a: 105.0 Starlight effect
a: 106.0 Battery level display
Based on the publication table, use the command format ros2 topic echo <topic_name> to receive sensor data published by the car's node.
3.2.5 Subscribe to LiDAR Data
Dual-LiDAR version: The topic name for the left-rear LiDAR is /scan0, and for the right-front LiDAR is /scan1. Here we use the right-front LiDAR data as an example.
Single-LiDAR version: The complete data for one scan of the LiDAR is published on two topics, /scan2 and /scan3, with each topic representing half a scan.
- Here is an example using the
/scan1topic from the dual-LiDAR version:
xxxxxxxxxxros2 topic echo /scan1The subscribed data is shown in the figure below:

3.2.6 Subscribe to Battery Level Data
The normal operating voltage of this product is theoretically between 9.6V and 12V. If the voltage drops below 10.3V, the buzzer will beep to indicate a low battery, and the battery needs to be charged. You can enter the following command in the terminal to check the battery voltage:
[!CAUTION]
Special Note!!!: For lithium batteries, the relationship between voltage and charge level is not linear. It is not always the case that a lower voltage means a lower charge. When the vehicle's alarm sounds, it means the battery level is already too low and needs to be charged promptly.
- Over-discharging lithium batteries is prohibited, as long-term over-discharging can cause the battery to swell and become damaged.
xxxxxxxxxxros2 topic echo /batteryThe subscribed data is shown in the figure below:

This indicates that the battery voltage is 11.8V.
3.2.7 Subscribe to IMU Data
The control board is equipped with a 9-axis IMU sensor that can provide feedback on the car's attitude. Enter the following command in the terminal to get the IMU data,
xxxxxxxxxxros2 topic echo /imu/data_rawThe subscribed IMU data is shown in the figure below:

3.2.8 Subscribe to Odometry Data
The four motors of this product are equipped with encoders. The ROS control board reads the encoder information and then publishes the calculated odometry data. Enter the following command in the terminal to read the odometry data,
xxxxxxxxxxros2 topic echo /odom_rawThe subscribed odometry data is shown in the figure below,
