1 概述

micro-ROS Agent 是运行在 PC 上的桥接程序,负责接收 MCU 发出的 XRCE-DDS 消息,并转发到 ROS 2 网络中(DDS).

alt text

1
2
3
4
5
# Creating a FreeRTOS + micro-ROS firmware workspace
ros2 run micro_ros_setup create_firmware_ws.sh freertos olimex-stm32-e407

# Creating a Zephyr + micro-ROS firmware workspace
ros2 run micro_ros_setup create_firmware_ws.sh zephyr olimex-stm32-e407

2 安装

2.1 Agent

1
2
3
4
5
6
7
8
# clone 代码
# 这里以为 jazzy 为例
git clone -b jazzy https://github.com/micro-ROS/micro-ROS-Agent.git

# 初始化工作空间
cd micro-ROS-Agent
# 若出现问题详见
colcon build

2.2 开发板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mkdir -p microros_ws/src
cd microros_ws

# 拉取 micro_ros_setup 源码
# 这里根据 ros2 的版本切换分支
git clone -b jazzy https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup

# 构建 setup 工具
colcon build
source install/local_setup.bash

# 构建固件
# host: 不需要单片机,在本地机器上直接运行 micro-ROS 程序
# nuttx(RTOS): 适用于 NuttX RTOS 平台, 如 PX4 飞控系统
# freertos: 将 micro-ROS 和一起运行在 FreeRTOS 上, 比如 STM32、ESP32 等
ros2 run micro_ros_setup create_firmware_ws.sh freertos

# 以stm32, esp32为例.
ros2 run micro_ros_setup configure_firmware.sh freertos stm32f103c8
ros2 run micro_ros_setup configure_firmware.sh freertos esp32

# 构建firmware
ros2 run micro_ros_setup build_firmware.sh

以上是构建 micro-ros 的整体流程, 我们也可以在这里构建 agent

1
2
ros2 run micro_ros_setup create_agent_ws.sh
ros2 run micro_ros_setup build_agent.sh

2.3 特定平台集成

1
ros2 run micro_ros_setup component --help

2.3.1 platformio

1
2
3
4
5
6
7
8
9
10
lib_deps =
https://github.com/micro-ROS/micro_ros_platformio

# 或者

lib_deps =
https://gitee.com/ohhuo/micro_ros_platformio.git

# 如果是 wifi 需要加入
board_microros_transport = wifi

3 运行

1
2
3
4
5
6
7
8
9
10
11
12
13
source install/setup.bash

# 串口
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0

# UDP
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888

# TCP
ros2 run micro_ros_agent micro_ros_agent tcp4 --port 8888

# help
ros2 run micro_ros_agent micro_ros_agent --help

4 烧录

1
ros2 run micro_ros_setup flash_firmware.sh

5 QA

4.1 colcon build 报错

若遇到下面问题.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CMake Error at CMakeLists.txt:153 (find_package):
By not providing "Findfastcdr.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "fastcdr", but
CMake did not find one.

Could not find a package configuration file provided by "fastcdr"
(requested version 2) with any of the following names:

fastcdrConfig.cmake
fastcdr-config.cmake

Add the installation prefix of "fastcdr" to CMAKE_PREFIX_PATH or set
"fastcdr_DIR" to a directory containing one of the above files. If
"fastcdr" provides a separate development package or SDK, be sure it has
been installed.
1
2
3
4
5
6
7
git clone https://github.com/eProsima/fastcdr.git

cd fastcdr
mkdir build && cd build
cmake ..
make -j$(nproc)
sudo make install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Starting >>> micro_ros_agent
[Processing: micro_ros_agent]
--- stderr: micro_ros_agent
CMake Error at CMakeLists.txt:51 (find_package):
By not providing "Findmicro_ros_msgs.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"micro_ros_msgs", but CMake did not find one.

Could not find a package configuration file provided by "micro_ros_msgs"
with any of the following names:

micro_ros_msgsConfig.cmake
micro_ros_msgs-config.cmake

Add the installation prefix of "micro_ros_msgs" to CMAKE_PREFIX_PATH or set
"micro_ros_msgs_DIR" to a directory containing one of the above files. If
"micro_ros_msgs" provides a separate development package or SDK, be sure it
has been installed.

1
sudo apt install ros-jazzy-micro-ros-msgs

6 References