Px4-ROS 2 User Guide 实践测试
原网址:https://docs.px4.io/main/en/ros/ros2_comm.html#setup-xrce-dds-agent-client
日期:20230223
Ros2 rolling 已安装好。
1、安装XRCE-DDS Agent & Client
cd ~/Px4
git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
cd Micro-XRCE-DDS-Agent
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig /usr/local/lib/
2、启动 MicroXRCEAgent
MicroXRCEAgent udp4 -p 8888
3、启动Px4模拟器
make px4_sitl gazebo-classic
4、编译ROS2示例工作空间
4.1、创建工作空间
mkdir -p ~/ws_sensor_combined/src/
cd ~/ws_sensor_combined/src/
4.2、获取实例代码
git clone https://github.com/PX4/px4_msgs.git
git clone https://github.com/PX4/px4_ros_com.git
4.3、导出ROS环境变量(跳过),编译
cd ..
source /opt/ros/rolling/setup.bash
#安装依赖
cd ..
rosdepc install -i --from-path src --rosdistro rolling -y
#编译工具安装
sudo apt install python3-colcon-ros
colcon build
5、运行ROS2实例,在新终端操作
source ./install/local_setup.sh
ros2 launch px4_ros_com sensor_combined_listener.launch.py
5.1、启动时发生错误
[ERROR] [launch]: Caught exception in launch (see debug for traceback): Caught exception when trying to load file of format [py]: invalid syntax (sensor_combined_listener.launch.py, line 56)
根据提示找到文件./install/px4_ros_com/share/px4_ros_com/launch/sensor_combined_listener.launch.py
打开发现第56行缺少一个逗号如下图:
增加逗号后可以正常启动
总结
自动生成的代码也会出错,巨坑!