I’m opening this as a kind of walkthrough about how to enter offboard mode using ROS2 and the FastRTPS bridge. It might be used as an starting point for somebody trying to start working with ROS2. The example is not fully working since a failsafe is triggered as soon as you change to offboard mode.
You’ll find the ROS2 node code example here.
I’ll try to do a walk-through of the procedure to get it done. This is the problem we’ll try to solve:
- Enter offboard control mode, by publishing
offboard_control_modemessages at 10Hz.
- Subscribe the vehicle_control_mode topic and print something when we are in the offboard mode.
PX4 side: Generate the needed FastRTPS messages
- Modify the file
firmware->msg->uorb_rtps_message_ids.yamlby adding the line
msg: offboard_control_mode. Similarly, add
send: trueto the message
- As we are gonna test this with the SITL version compile the PX4 as follows:
make px4_sitl_rtps. If you’ve compiled this version before with an old version of the yaml file you’ll probably have to do
make px4_sitl_rtps cleanfirst.
Now, the FastRTPS module inside px4 will know that it can receive offboard_control_mode messages.
- Change the file
ros2_ws->templates->uorb_rtps_messages_ids.yamlby adding the line
receive: trueto the message
OffboardControlMode. Similarly, add the line
send: trueto the message
- Clone the repo with the ROS2 node at the specified branch in the src directory of your ROS2 workspace:
git clone --single-branch --branch px4_ros2_offboard https://github.com/PepMS/px4_mpc.git
- Build your workspace:
3.1 You can do it by using the px4_ros_com scripts:
3.2 You can also do
Run the simulation
- In a terminal run PX4:
make px4_sitl_rtps gazebo
1.1. Execute the rtps client module inside px4:
micrortps_client start -t UDP
- In a separate terminal, start the FastRTPS Agent:
./install/px4_ros_com/bin/micrortps_agent -t UDP
- In a separate terminal you should see how the VehicleControlMode is being published:
ros2 topic echo /VehicleControlMode_PubSubTopic
3.2. Before doing the above instruction make sure you’ve sourced the file
- Now it’s time to run our node. In a separate terminal, inside the ros2_ws do
4.1. You can check that the offboard messages are being published by doing in a separate:
ros2 topic echo /VehicleControlMode_PubSubTopic.
4.2. You can check in the PX4 that the messages are being received at 10Hz by doing:
4.3. You can switch now to offboard mode using the commander or QGC.
You’ll see that the offboard control gets activated but a failsafe is immetidately triggered saying:
WARN [mc_pos_control] Offboard activation failed with error: Activation Failed. Probably I should publish some other messages like a position setpoint or something but I certainly don’t know what.
Tried this with PX4 at: 743898d5748da7d811308619c517c9e4c0701585