Install and start the Microros agent1. Docker starts the microros agentDocker starts the serial port proxyAgent startup failure2. Start microros agent from source codeInstall tinyxml2 dependenciesInstall the python3-rosdep toolCompile the micro_ros_setup environmentCompile the micro_ros_agent environmentStart the microros serial port proxy from source code3. Start the microros agent with the factory image
Note: You can select any one of the three startup methods.
docker run -it --rm -v /dev:/dev -v /dev/shm:/dev/shm --privileged --net=host microros/micro-ros-agent:humble serial --dev /dev/myserial -b 2000000 -v4
Among them, --dev /dev/myserial is the bound serial port device, which can also be changed to /dev/ttyUSB0, etc.
-b 2000000 is the baud rate.
To exit the proxy, press Ctrl+C in the terminal.
Note that you cannot close the terminal directly, otherwise Docker will continue to run in the background.
If the MCU starts the reconnection proxy multiple times, causing ROS2 to search for multiple identical nodes, it will not actually affect the use. Press Ctrl+C to end the proxy and then reset the MCU to reconnect to the proxy.
The microROS agent can only be started in one terminal. If a terminal has already started the microROS agent in the background, an error will be reported when starting the agent again. Please press Ctrl+C to exit the agent in the original agent terminal before running the agent again.
If the next time you start the agent, it fails because you directly closed the terminal, you can restart the virtual machine/computer to solve it, or manually end Docker to solve it.
How to manually end docker:
Please first query the current Docker process number and end the current proxy Docker process.
xxxxxxxxxxdocker ps -a | grep microros/micro-ros-agentdocker stop xxxxxxxxxx
Enter the following command in the terminal to install tinyxml2
xxxxxxxxxxcd ~/git clone https://github.com/leethomason/tinyxml2.gitcd tinyxml2mkdir buildcd buildsudo cmake ..sudo makesudo make install
Enter the following command in the terminal to install the rosdep tool. If it has already been installed, you can skip this step.
xxxxxxxxxxsudo apt install python3-rosdep
Activate the ROS2 environment variables. Here we take the humble version as an example. If it has already been activated, you can skip the activation step.
xxxxxxxxxxsource /opt/ros/humble/setup.bash
Create and enter the workspace uros_ws in the user directory
xxxxxxxxxxmkdir ~/uros_ws && cd ~/uros_wsmkdir src
Download the micro_ros_setup file to the src folder
xxxxxxxxxxgit clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup
Initialize rosdep
xxxxxxxxxxsudo rosdep init
If there is a network problem, please add the -E parameter
xxxxxxxxxxsudo -E rosdep init

If all the above steps return an error and rosdep still cannot be initialized, you can create a new 20-default.list file in the /etc/ros/rosdep/sources.list.d/ directory and add the following content, then proceed to the next step.
x# os-specific listings firstyaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx# genericyaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yamlyaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yamlyaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yamlgbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
Update rosdep and install related driver packages
xxxxxxxxxxrosdep update && rosdep install --from-paths src --ignore-src -y

Compile Workspace
xxxxxxxxxxcolcon build

Activate the micro_ros_setup environment
xxxxxxxxxxsource install/local_setup.bash
xxxxxxxxxxros2 run micro_ros_setup create_agent_ws.shros2 run micro_ros_setup build_agent.sh

If an error occurs when executing build_agent.sh, compile again.
Activate the micro_ros_agent agent environment
xxxxxxxxxxsource ~/uros_ws/install/local_setup.sh
Enter the following command to start the serial port proxy from the ROS2 environment
xxxxxxxxxxros2 run micro_ros_agent micro_ros_agent serial --dev /dev/myserial -b 2000000 -v4
Among them, --dev /dev/myserial is the bound serial port device, which can also be changed to /dev/ttyUSB0, etc.
-b 2000000 is the baud rate.
To exit the proxy, press Ctrl+C in the terminal.
The factory image system has integrated the proxy function and made it into a script. You only need to run the following command to enable the proxy.
xxxxxxxxxxsh ~/start_agent.sh