Welcome to ROSMASTER M3 repository
11.Comprehensive Autonomous Driving Applications
Comprehensive Autonomous Driving Applications
Comprehensive Autonomous Driving Applications1. Course Content2. Start Example Program2.1 Start Chassis Communication Agent2.2 Start Autonomous Driving Program3. Source Code Analysis
1. Course Content
- Start the autonomous driving program, combining lane-keeping autonomous driving and traffic sign recognition responses to complete the entire autonomous driving process in the sandbox map
- Site layout reference:

Here is an example reference autonomous driving process as follows:
- Lane-keeping driving ----------> Sidewalk ----------> Honking ----------> Speed limit ----------> Right turn ----------> Parking ----------> Exit parking ----------> Lane-keeping driving

2. Start Example Program
2.1 Start Chassis Communication Agent
- Use the following command to start microROS agent to connect to the chassis
[!WARNING]
If the agent has already been started, there is no need to start it repeatedly
start_agent
2.2 Start Autonomous Driving Program
- Start the autonomous driving main program
xxxxxxxxxxros2 launch m3_bringup auto_drive.launch.py- Start dynamic parameter configuration panel
xxxxxxxxxxros2 run rqt_reconfigure rqt_reconfigure- Click AutoDrive to enter the parameter control panel. If there is no
AutoDriveon the left side when you first open it, clickRefreshbelow

- Click
START_AutoDriveto start autonomous driving and lane-keeping functionality

After running the above commands, the startup interface is as follows, where
Sign-Detect Panelis the display window for YOLO traffic sign recognitionAuto-Drive Panelis the display window for autonomous driving lane line detectionrqt_reconfigureis a visual window used to dynamically adjust parameters and start autonomous driving switches
Click the
START_AutoDriveswitch to start autonomous driving

Intersection turning
- When a right turn road sign is detected, it will automatically move forward a certain distance to the three-way intersection in lane-keeping mode, then turn to the specified angle, and finally return to lane-keeping mode to continue moving forward.

Autonomous parking
- When road sign PA or PB is detected, trigger automatic autonomous parking, drive forward until aligned with the parking space, then translate into the garage.


One-click exit parking
- In the
rqt_reconfigurepanel parameters, click to checkout_park, the vehicle will automatically translate out of the parking space, then return to lane-keeping autonomous driving mode to continue driving, and will turn right at the three-way intersection and continue driving.
- In the


[!TIP]
- If the autonomous driving effect does not meet expectations, refer to this chapter's [12-Autonomous Driving Debugging Module] for parameter optimization.
3. Source Code Analysis
- The new actions that appear here are as follows:
- The basic principle is to control chassis movement through speed control, where the movement distance and rotation angle are adjusted through parameters.
xdef turn_right(self): '''Turn''' self.get_logger().info('turn_right') drive_time=self.turn_distance/self.drive_speed time.sleep(drive_time) self.enable_auto_drive(False) self.__turn_by_angle(self.turn_angle) time.sleep(0.5) self.enable_auto_drive(True)def parking_A(self): ''''Parking A''' self.get_logger().info('parking A') drive_time_1=self.park_distance_1/self.drive_speed drive_time_2=self.park_distance_2/0.2 time.sleep(drive_time_1) self.enable_auto_drive(False) time.sleep(0.5) self.__set_current_speed(linear_y=-0.2) time.sleep(drive_time_2) self.__set_current_speed()def parking_B(self): '''Parking B''' self.get_logger().info('parking B') drive_time_1=self.park_distance_1/self.drive_speed drive_time_2=self.park_distance_2/0.2 time.sleep(drive_time_1) self.enable_auto_drive(False) time.sleep(0.5) self.__set_current_speed(linear_y=-0.2) time.sleep(drive_time_2) self.__set_current_speed()def out_parking(self): '''Vehicle leaving the depot''' drive_time=self.park_distance_2/0.2 self.__set_current_speed(linear_y=0.2) time.sleep(drive_time) self.enable_auto_drive(True)