小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
PX4-Gazebo-ROS2 如何通过RTPS/DDS接口配置BodyRate飞行模式
-
BodyRate模式,即姿态角速度控制适用于FPV高动态的飞行任务(DJI的FPV摇杆的控制原理就是BodyRate)。
在新的PX4固件版本中,PX4支持利用BodyRate实现Offboard Control帮助大家进行研究,但默认情况下运行PX4_ROS_COM运行Agent(micrortps_agent -t UDP
)并无法得到可以实现BodyRate控制通讯的Topic: fmu/vehicle_attitude_setpoint/in,这就需要我们手动添加新的topic实现与PX4系统的通讯。
具体步骤:- 完成环境配置,参考PX4官方教程中的ROS2 User Guide,在配置环境中遇到任何问题欢迎发帖提问。
- 修改Client的yaml文件,自动生成Topic发布与订阅代码: 在PX4的路径(PX4-Autopilot/msg/tools/urtps_bridge_topics.yaml)下配置Client 的yaml文件,增加BodyRate控制,在yaml文件的最后一行增加如下内容:
- msg: vehicle_attitude_setpoint receive: true
其他可选的msg可以在路径:PX4-Autopilot/msg/中查看。
3. 重新编译PX4工作空间make px4_sitl_rtps gazebo
(在这个过程中会自动启动桥接Client)
4. 修改Agent的yaml文件,自动生成Topic发布与订阅代码: 在PX4_ROS_COM的文件路径下(path_to_colcon_ws/src/px4_ros_com/templates/urtps_bridge_topics.yaml)下配置Agent的yaml文件,增加BodyRate控制,在yaml文件的最后一行增加如下内容:- msg: VehicleAttitudeSetpoint receive: true
注意,这里对应的msg名称与Client所用的大小写略有不同,可见:px4_msgs
5. 最重要的步骤来了,用PX4_ROS_COM自带的脚本构建新的工作空间:$ cd ~/px4_ros_com_ros2/src/px4_ros_com/scripts $ source build_ros2_workspace.bash
另外,scripts文件夹中包含了多种的工具,如果需要构建ROS环境即选用source build_ros1_workspace.bash
6. 重新运行PX4_Gazebo# ctrl+shift+t 打开新的终端 cd PX4路径 make px4_sitl_rtps gazebo # ctrl+shift+t 打开新的终端 source ~/px4_ros_com_ros2/install/setup.bash micrortps_agent -t UDP
可以看到结果如下:
--- MicroRTPS Agent --- [ micrortps_agent ] Starting link... [ micrortps_agent ] UDP transport: ip address: 127.0.0.1; recv port: 2020; send port: 2019 [ micrortps_transport ] UDP transport: Trying to connect... [ micrortps_transport ] UDP transport: Connected to server! --- Subscribers --- - DebugArray subscriber started - DebugKeyValue subscriber started - DebugValue subscriber started - DebugVect subscriber started - OffboardControlMode subscriber started - OpticalFlow subscriber started - PositionSetpoint subscriber started - PositionSetpointTriplet subscriber started - TelemetryStatus subscriber started - Timesync subscriber started - VehicleCommand subscriber started - VehicleLocalPositionSetpoint subscriber started - VehicleTrajectoryWaypoint subscriber started - OnboardComputerStatus subscriber started - TrajectoryBezier subscriber started - VehicleTrajectoryBezier subscriber started - VehicleAttitudeSetpoint subscriber started - TrajectorySetpoint subscriber started - VehicleMocapOdometry subscriber started - VehicleVisualOdometry subscriber started ----------------------- ---- Publishers ---- - Timesync publishers started - TrajectoryWaypoint publisher started - VehicleControlMode publisher started - VehicleOdometry publisher started - VehicleStatus publisher started - CollisionConstraints publisher started - TimesyncStatus publisher started - SensorCombined publisher started - VehicleTrajectoryWaypointDesired publisher started -----------------------
至此VehicleAttitudeSetpoint subscriber 启动成功,测试一下:
ros2 topic list
新的topic已经出现:/fmu/vehicle_attitude_setpoint/in,至此已经成功构建ROS2与PX4的BodyRate模式的控制接口,vehicle_attitude_setpoint.msg具体见msg,控制方法见offboard模式的官方介绍