Welcome to ROSMASTER M3 repository
06.Line velocity calibration
Linear Velocity Calibration
Linear Velocity Calibration1. Course Content2. Preparations2.1 Content Description2.2 Start the Agent3. Run the Example3.1 Start the Program3.2 Start Calibration3.3 Write Calibration Parameters to the Chassis4. Code Explanation4.1 View Node Relationship Graph4.2 Source Code Analysis
1. Course Content
- Learn how to calibrate the robot's linear velocity. After running the program, click "start" in the visualization interface, and the robot chassis will begin to move forward, stopping when the error is less than the tolerance value.
[!IMPORTANT]
- The vehicle has been calibrated before leaving the factory. Under normal circumstances, recalibration is not necessary. If there is a significant error in the actual vehicle due to special circumstances, refer to this tutorial to calibrate the linear velocity.
2. Preparations
2.1 Content Description
This lesson uses the Jetson Orin NX as an example. For Raspberry Pi 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 RDK 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.
Enter the command in the vehicle's terminal:
start_agent
The terminal will print the following information, indicating a successful connection:

3. Run the Example
Note:
- For the Raspberry Pi series, you need to enter the Docker container first.
3.1 Start the Program
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
Run the linear velocity calibration node:
xxxxxxxxxxros2 launch m3_bringup calibration.launch.py
- Open the dynamic parameter panel, run in the terminal:
xxxxxxxxxxros2 run rqt_reconfigure rqt_reconfigure
Click the calibrate_linear node in the node options on the left:

[!WARNING]
- When you first open it, the above node may not be present. Click
Refreshto see all the nodes. The displayed calibrate_linear node is the one for calibrating linear velocity.
RQT interface parameter description:
test_distance: The distance for the calibration test. Here, it's set to move forward 1 meter.speed: The linear velocity.tolerance: The allowable error tolerance.odom_linear_scale_correction: The linear velocity scale factor. If the test results are not ideal, modify this value.start_test: The test switch.direction: Can be ignored. This value is for Mecanum wheel cars and can be modified to calibrate the linear velocity for side-to-side movement.base_frame: The name of the base coordinate frame.odom_frame: The name of the odometry coordinate frame.
3.2 Start Calibration
- Choose an object of known length on the ground as a reference (e.g., a measuring tape, floor tiles). Change test_distance to the actual test distance. Here, we use a measuring tape for measurement, and you can use either the front or the back of the car as the measurement point.

- Check the start_test box to begin the calibration test.

After clicking
start_test, the calibration begins. The car will listen to the TF transform betweenbase_footprintandodom, calculate the theoretical distance traveled, and when the error is less thantolerance, it will publish a stop command and the terminal will printdone.- If the actual distance the car travels is less than 1m, increase the odom_linear_scale_correction parameter appropriately. After modifying it, click on a blank area, then uncheck and recheck
start_testto reset it. - Then, click
start_testagain to calibrate. The process is the same for modifying other parameters; you need to click a blank area to write the modified parameter. Record the final calibrated odom_linear_scale_correction parameter.
- If the actual distance the car travels is less than 1m, increase the odom_linear_scale_correction parameter appropriately. After modifying it, click on a blank area, then uncheck and recheck
Repeat the above steps until you find a suitable odom_linear_scale_correction parameter.

3.3 Write Calibration Parameters to the Chassis
- To write parameters to the chassis, you must first disconnect the chassis agent by pressing Ctrl+C or closing the chassis connection agent terminal.
- Open the config_robot.py file in the home directory on the vehicle.

- Uncomment line 551, fill in the previous calibration coefficient in the parentheses of robot.set_ros_scale_line(xx), and then click save.

- Open a terminal on the vehicle and enter the command:
xxxxxxxxxxpython3 config_robot.py
Wait for the parameters to be written. The ros_scale_line:0.890 in the terminal's printed information is the written parameter. The chassis linear velocity calibration is complete.
4. Code Explanation
Source code path:
xxxxxxxxxx/home/jetson/yahboomM3_ws/code_ws/src/m3_common_demo/m3_common_demo/calibration/calibrate_linear.py
4.1 View Node Relationship Graph
Open a terminal and enter the command:
xxxxxxxxxxros2 run rqt_graph rqt_graph

In the node relationship diagram above:
- The /ekf_filter_node subscribes to the chassis's raw odometry /odom_raw and IMU data /imu/data_raw, and after data fusion, it publishes the /odom topic.
- The calibrate_linear node listens to the TF transform from
odomtobase_footprintand publishes the/cmd_veltopic to control the robot chassis movement.
4.2 Source Code Analysis
Listening to the TF coordinate transformation is implemented in the get_position method of the CalibrateLinear class:
xdef get_position(self): try: now = rclpy.time.Time() transform = self.tf_buffer.lookup_transform( self.base_frame, self.odom_frame, now, timeout=rclpy.duration.Duration(seconds=1.0)) return transform except (LookupException, ConnectivityException, ExtrapolationException): self.get_logger().info('transform not ready') raise
Judging the robot chassis's displacement and controlling its movement is implemented in the on_timer method (timer callback function) of the CalibrateLinear class:
xxxxxxxxxxdef on_timer(self): move_cmd = Twist() #self.get_param() self.start_test = self.get_parameter('start_test').get_parameter_value().bool_value self.odom_linear_scale_correction = self.get_parameter('odom_linear_scale_correction').get_parameter_value().double_value self.direction = self.get_parameter('direction').get_parameter_value().bool_value self.test_distance = self.get_parameter('test_distance').get_parameter_value().double_value self.tolerance = self.get_parameter('tolerance').get_parameter_value().double_value self.speed = self.get_parameter('speed').get_parameter_value().double_value if self.start_test: '''trans = self.tf_buffer.lookup_transform(