Welcome to MicroROS Robot repository
5. Linear speed calibration
Line speed calibration
Note: The virtual machine needs to be in the same LAN as the car, and the ROS_DOMAIN_ID needs to be consistent. You can check [Must read before use] to set the IP and ROS_DOMAIN_ID on the board.
1、Program function description
The car connects to the agent, runs the program, and adjusts the parameters here through the dynamic parameter regulator to calibrate the linear speed of the car. The intuitive reflection of the calibrated linear speed is to give the car an instruction to go straight forward for 1 meter to see how far it actually ran and whether it is within the error range.
2、Start and connect to the agent
Taking the supporting virtual machine as an example, enter the following command to start the agent.
sudo docker run -it --rm -v /dev:/dev -v /dev/shm:/dev/shm --privileged --net=host microros/micro-ros-agent:humble udp4 --port 8090 -v4
Then, turn on the car switch and wait for the car to connect to the agent. The connection is successful, as shown in the figure below.

3、starting program
First, start the car's underlying data processing program. This program will release the TF transformation of odom->base_footprint. With this TF change, you can calculate "how far the car has gone" and input it at the terminal.
xxxxxxxxxxros2 launch yahboomcar_bringup yahboomcar_bringup_launch.py
Then, start the car linear speed calibration program and enter in the terminal,
xxxxxxxxxxros2 run yahboomcar_bringup calibrate_linear
Finally, open the dynamic parameter adjuster and enter in the terminal,
xxxxxxxxxxros2 run rqt_reconfigure rqt_reconfigure

Note: There may not be the above nodes when you first open it. You can see all nodes after clicking Refresh. The displayed calibrate_linear node is the node for calibrating linear speed.
4、Start calibration
In the rqt_reconfigure interface, select the calibrate_linear node. There is start_test below and click the box to the right to start calibration. Other parameters in the rqt interface are explained as follows:
test_distance:Calibrate the test distance, here the test goes forward 1 meter;
speed:Linear speed;
tolerance:tolerance for error;
odom_linear_scale_correction:Linear speed proportional coefficient, if the test result is not ideal, just modify this value;
start_test:test switch:
direction:It can be ignored. This value is used for the wheel structure trolley. After modification, the linear speed of left and right movement can be calibrated;
base_frame:The name of the base coordinate system;
odom_frame:The name of the odometer coordinate system.
Click start_test to start calibration. The car will monitor the TF transformation of base_footprint and odom, calculate the theoretical distance traveled by the car, wait until the error is less than the tolerance, and issue a parking instruction.

If the actual distance the car runs is not 1m, then modify the odom_linear_scale_correction parameter in rqt. After modification, click on the blank space, click start_test again, reset start_test, and then click start_test again to calibrate. The same goes for modifying other parameters. You need to click on the blank space to write the modified parameters.
5、Code analysis
Source code reference path (taking the supporting virtual machine as an example):
xxxxxxxxxx/home/yahboom/yahboomcar_ws/src/yahboomcar_bringup/yahboomcar_bringupcalibrate_linear.py, the core code is as follows,
x
#Monitor the TF transformation of base_footprint and odomdef get_position(self): try: now = rclpy.time.Time() trans = self.tf_buffer.lookup_transform(self.odom_frame,self.base_frame,now) #print("trans: ",trans) return trans except (LookupException, ConnectivityException, ExtrapolationException): self.get_logger().info('transform not ready') raise return#Get the current coordinatesself.position.x = self.get_position().transform.translation.xself.position.y = self.get_position().transform.translation.y#Calculate how far distance and error aredistance = sqrt(pow((self.position.x - self.x_start), 2) +pow((self.position.y - self.y_start), 2))distance *= self.odom_linear_scale_correctionprint("distance: ",distance)error = distance - self.test_distance