Welcome to ROSMASTER M3 repository
17.APP mapping and navigation
APP Mapping and Navigation
APP Mapping and Navigation1. Course Content2. Preparations3. Start the Agent4. APP Mapping Example5. APP Navigation Example6. Source Code Analysis6.1 Launch File
1. Course Content
Control the car to perform mapping and navigation using the mobile app "ROS Robot".
2. Preparations
- First, you need to download the "ROS Robot" app on your phone. Android/iOS users can scan the QR code to download the remote control software. iOS users can also search for and download the mapping and navigation app "ROSRobot" from the App Store.

- The car and the phone must be on the same local network, which can be achieved by connecting to the same Wi-Fi.
3. Start the Agent
Note: 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:

4. APP Mapping Example
- Enter the following command in the car's terminal to start the car's APP mapping service node. Choose one of the following two mapping methods:
[!NOTE]
The launch commands for the different mapping methods are the same here; they are switched using the
slam_modelaunch parameter.
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
- Cartographer mapping method:
xxxxxxxxxxros2 launch m3_bringup bringup_app.launch.py slam_mode:=cartographer
- slam_toolbox mapping method:
xxxxxxxxxxros2 launch m3_bringup bringup_app.launch.py slam_mode:=slam_toolbox
- Open "ROS Robot", and it will display as shown below.
- Enter the car's IP address ->
ROS2->VideoTopic/camera/rgb/image_raw/compressed-> [Connect]

- After a successful connection, it will display as follows:

- Use the joystick to slowly move the car to cover the area you need to map, then click "Save Map", enter a map name, and click "Submit" to save the map.

- The map will be automatically saved to the
~/mapdirectory on the system, and the terminal will indicate that the map has been saved successfully.

5. APP Navigation Example
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
xxxxxxxxxxros2 launch m3_bringup bringup_app.launch.py navigation_mode:=True map:=/xxx/map.yaml[!NOTE]
Optional Parameter Descriptions
map
- The path to the map file. You need to enter the absolute path + map yaml name. The default is
~/map/map.yaml.
- Open "ROS Robot", and it will display as shown below.
- Enter the car's IP address ->
ROS2->VideoTopic/camera/rgb/image_raw/compressed-> [Connect]

- As shown below, select the navigation interface:

- Then, based on the car's actual pose, click "Init Point" to give the car an initial target point. If the Lidar scan area roughly coincides with the actual obstacles, the pose is accurate, as shown below.

- Click "Nav Point" to give the car a destination. The car will plan a path and move to the destination along that path, as shown below:

6. Source Code Analysis
6.1 Launch File
Source code path:
xxxxxxxxxx~/yahboomM3_ws/user_ws/src/m3_bringup/launch/common/bringup_app.launch.py
- The key startup program is as follows:
- The program uses the
slam_modeandnavigation_modelaunch parameters to decide between mapping and navigation modes. It starts a rosbridge WebSocket server to transmit relevant data via the WebSocket protocol.
x # Start the slam_toolbox mapping mode. slam_toolbox_launch= GroupAction( condition=IfCondition(PythonExpression(["'", slam_mode, "' == 'slam_toolbox' and '", navigation_mode, "' == 'False' "])), actions=[ ExecuteProcess( cmd=['ros2', 'launch', 'm3_bringup', 'car_base.launch.py'], output='screen' ), Node( package='slam_toolbox', executable='async_slam_toolbox_node', parameters=[async_slam_params_file], name='async_slam_toolbox', output='screen' ) ] ) # Start Cartographer mapping mode. cartographer_launch=IncludeLaunchDescription( PythonLaunchDescriptionSource(os.path.join(m3_bringup_dir, 'launch', 'slam', 'cartographer', 'cartographer.launch.py')), launch_arguments={ "gui": "False", }.items(), condition=IfCondition(PythonExpression(["'", slam_mode, "' == 'cartographer' and '", navigation_mode, "' == 'False' "])) ) # Start the rosbridge node. bringup_rosbridge_server = ExecuteProcess( cmd=['ros2', 'launch', 'rosbridge_server', 'rosbridge_websocket_launch.xml'], output='screen' ) # Compressed image publishing node rgb_image_node = Node( package='laserscan_to_point_publisher', executable='pub_rgb_image', name='publish_rgb_frame', parameters=[{'rgb_topic':rgb_topic},], output='screen', ) # Radar point cloud publishing node laserscan_to_point_publisher= Node( package='laserscan_to_point_publisher', executable='laserscan_to_point_publisher', name='laserscan_to_point_publisher', output='screen', ) # Robot pose publishing node robot_pose_publisher=Node( package="robot_pose_publisher_ros2", executable="robot_pose_publisher", name="robot_pose_publisher", output="screen", emulate_tty=True, parameters=[ {"use_sim_time": True}, {"is_stamped": True}, {"map_frame": "map"}, {"base_frame": "base_link"} ] ) # App map saving service node yahboom_app_save_map_node = Node( package='yahboom_app_save_map', executable="server", name="yahboom_app_save_map_server", output="screen", ) app_nav= GroupAction( condition=IfCondition(PythonExpression(["'", navigation_mode, "' == 'True'" ])), actions=[ ExecuteProcess( cmd=['ros2', 'launch', 'm3_bringup', 'car_base.launch.py'], output='screen' ), IncludeLaunchDescription( PythonLaunchDescriptionSource(os.path.join(get_package_share_directory("nav2_bringup"), "launch", 'bringup_launch.py')), launch_arguments={ "map": map, "use_sim_time":"False", "params_file": os.path.join(m3_bringup_dir, 'config', 'navigation_config', 'M3_nav2_params.yaml' ), }.items(), ) ] )