ROS Control

1. Functional Description

This function enables control of the robot's speed, buzzer, and servos through ROS2 topic tools. It also enables access to low-level data, such as radar data, IMU data, and version information.

2. Preparation

2.1. Pre-use Instructions

This lesson uses the Raspberry Pi as an example. For Raspberry Pi and Jetson-Nano boards, you need to open a terminal on the host computer and enter the command to enter the Docker container. Once inside the Docker container, enter the commands mentioned in this lesson in the terminal. For instructions on entering the Docker container from the host computer, refer to [01. Robot Configuration and Operation Guide] -- [5.Enter Docker (For JETSON Nano and RPi 5)]. For Orin boards, simply open a terminal and enter the commands mentioned in this lesson.

2.2 Pre-use Configuration

This vehicle is equipped with a USB camera, a depth camera, and two different LiDAR models. However, since the device cannot be automatically recognized, the machine type and LiDAR model must be manually configured.

For the Raspberry Pi 5 controller, you must first enter the Docker container. This is not necessary for the Orin .

Change the LiDAR and camera types according to the vehicle model as follows.

image-20250814094649374

Find this location and press i on your keyboard to change the camera and LiDAR models to the corresponding ones. The default values ​​are Tmini and Nuwa.

image-20250814094659974

After completing the modification, save and exit vim, then execute:

image-20250814094717521

3. Program Startup

3.1. Startup Command

For the Raspberry Pi 5 controller, you must first enter the Docker container. For the Orin controller, this is not necessary.

Enter the Docker container (for steps, see [Docker Course] --- [4. Docker Startup Script]).

All the following commands must be executed from the Docker terminal within the same Docker container.(For steps, see [Docker Course] --- [3. Docker Submission and Multi-Terminal Access]).

To start chassis data, enter the following command in the terminal:

image-20250814095645240

You can view the current node name by entering the following command:

image-20250814101047515

Enter the following command in the terminal to view the available topics.

image-20250814100527181

Topic NameTopic Content
/BuzzerBuzzer
/ServoServo s1, s2
/cmd_velSpeed ​​Control
/editionVersion Information
/imu/data_rawIMU Sensor Data
/imu/magIMU Magnetometer Data
/vel_rawVehicle Speed ​​Information
/voltageBattery voltage information

Then enter the following command to query the topic message data types of the topics published/subscribed by this node.

image-20250814101241298

3.2. Publishing Control Commands

Based on the table of subscribed topics, use the following command format: ros2 topic pub topic name topic message data type message data --once to publish a frame of control data.

For the first test, it's recommended to set up the car and test it without its wheels touching the ground. We'll set the car to move forward at a linear velocity of 0.1 m/s. Enter the following command in the terminal:

After running, the car will move forward at a speed of 0.1 m/s. Similarly, to control the car to move at an angle of 1.0 rad/s, assign the z value of angular_r to the value of angular_r (note that turning requires not only the angular velocity but also the linear velocity, as Ackerman chassis turning requires forward velocity).** The command is as follows:

After running, the robot will rotate. To stop the robot, simply publish both the linear velocity and angular velocity to 0. When the velocity reaches 0, the front wheel servo automatically corrects. The command is as follows:

The "--once" flag indicates that only one frame of message data will be sent. For other parameters of pub, refer to [19. Common ROS2 Command Tools] in [15. ROS2 Basics Course] of this product course.

3.3. Controlling the Buzzer

To turn on the buzzer, enter the following command in the terminal:

To turn off the buzzer, enter the following command in the terminal:

3.4. Controlling the Servo

Note: This command is only required if you purchased the gimbal USB camera version; it is not required for the depth camera version

To control the servo, enter the following command in the terminal:

image-20250814110718635

3.5. Reading Battery Voltage

Terminal Input:

image-20250814110957684

3.6. Reading Firmware Version

Terminal Input:

image-20250814111215203

4. Program Core Source Code Analysis

Using Ackman_driver_A1.py as an example,