Welcome to MicroROS Self-balancing Robot Car repository
9.ROS Robot APP mapping
ROS Robot App Map Building
Note: The virtual machine needs to be in the same LAN as the car, and the ROS_DOMAIN_ID needs to be the same. 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 proxy, runs the program, opens the [ROS Robot] app downloaded on the phone, enters the IP address of the car, selects ROS2, clicks Connect, and the car can be connected. You can control the car by sliding the wheel on the interface, slowly control the car to walk through the map building area, and finally click Save Map, the car will save the current built map.
2. Start and connect the agent
Take the supporting virtual machine as an example, enter the following command to start the agent (the agent can be started once without shutting down, no need to restart),
#Car agentsudo docker run -it --rm -v /dev:/dev -v /dev/shm:/dev/shm --privileged --net=host microros/micro-ros-agent:humble udp4 --port 8899 -v4#Camera agent (start the agent first and then turn on the car switch)docker run -it --rm -v /dev:/dev -v /dev/shm:/dev/shm --privileged --net=host microros/micro-ros-agent:humble udp4 --port 9999 -v4 
Then, turn on the car switch and wait for the car to connect to the proxy. The connection is successful as shown in the figure below.

Camera proxy, the connection is successful as shown in the figure below.

3. Start the program
First, start the car to process the underlying data program, and enter the terminal.
xxxxxxxxxxros2 launch yahboomcar_bringup yahboomcar_bringup_launch.py mode:=appslamxxxxxxxxxx#Parameter description, adjust the speed of the car, the mode is app mapping modemode:=appslam
Start the APP mapping command, enter in the terminal,
xxxxxxxxxx#Choose one of the following mappingros2 launch yahboomcar_nav map_gmapping_app_launch.xmlros2 launch yahboomcar_nav map_cartographer_app_launch.xml#Start ESP32 cameraros2 run yahboom_esp32_camera sub_imgThe mobile phone APP displays the following figure, enter the IP address of the car, [zh] means Chinese, [en] means English; select ROS2, the video below Tpoic selects /usb_cam/image_raw/compressed, and finally clicks [Connect]

After successfully connecting, the display is as follows,

Use the sliding wheel to control the car to slowly move through the area where the map needs to be built, then click Save Map, enter the map name and click Submit to save the map

The location where the map is saved is,
/home/yahboom/yahboomcar_ws/src/yahboomcar_nav/maps

4. Code analysis
Here is the launch file for opening the APP map, taking gmapping map as an example,
map_gmapping_app_launch.xml
xxxxxxxxxx<launch> <arg name="use_rviz" default="false" /> <include file="$(find-pkg-share rosbridge_server)/launch/rosbridge_websocket_launch.xml"/> <node name="laserscan_to_point_publisher" pkg="laserscan_to_point_publisher" exec="laserscan_to_point_publisher"/> <include file="$(find-pkg-share yahboomcar_nav)/launch/map_gmapping_launch.py"> <arg name="use_rviz" value="$(var use_rviz)"/> </include> <include file="$(find-pkg-share robot_pose_publisher_ros2)/launch/robot_pose_publisher_launch.py"/> <include file="$(find-pkg-share yahboom_app_save_map)/yahboom_app_save_map.launch.py"/></launch>
Here are several launch files and nodes:
rosbridge_websocket_launch.xml: Open rosbridge service related nodes. After startup, you can connect to ROS through the network
laserscan_to_point_publisher: Publish the point cloud conversion of the radar to the APP for visualization
map_gmapping_launch.py: gmapping mapping program
robot_pose_publisher_launch.py: Car pose publishing program, car pose is visualized in the APP
yahboom_app_save_map.launch.py: Program for saving maps