Offboard control using ROS2

Hi everyone,

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:

  1. Enter offboard control mode, by publishing offboard_control_mode messages at 10Hz.
  2. Subscribe the vehicle_control_mode topic and print something when we are in the offboard mode.

PX4 side: Generate the needed FastRTPS messages

  1. Modify the file firmware->msg->uorb_rtps_message_ids.yaml by adding the line receive: true to msg: offboard_control_mode. Similarly, add send: true to the message vehicle_control_mode.
  2. 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 clean first.

Now, the FastRTPS module inside px4 will know that it can receive offboard_control_mode messages.

ROS2 side:

  1. Change the file ros2_ws->templates->uorb_rtps_messages_ids.yaml by adding the line receive: true to the message OffboardControlMode. Similarly, add the line send: true to the message VehicleControlMode.
  2. 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
  3. Build your workspace:
    3.1 You can do it by using the px4_ros_com scripts: ./src/px4_ros_com/scripts/build_ros2_workspace.bash
    3.2 You can also do colcon build

Run the simulation

  1. In a terminal run PX4: make px4_sitl_rtps gazebo
    1.1. Execute the rtps client module inside px4: micrortps_client start -t UDP
  2. In a separate terminal, start the FastRTPS Agent: ./install/px4_ros_com/bin/micrortps_agent -t UDP
  3. In a separate terminal you should see how the VehicleControlMode is being published:
    3.1. ros2 topic echo /VehicleControlMode_PubSubTopic
    3.2. Before doing the above instruction make sure you’ve sourced the file ros2_ws/install/setup.bash
  4. Now it’s time to run our node. In a separate terminal, inside the ros2_ws do ./build/px4_mpc/offboard_controller
    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: uorb top
    4.3. You can switch now to offboard mode using the commander or QGC.

Something’s wrong

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

1 Like

Were you able to get this working?

I haven’t tried it any more. However, I think that the problem is that I wasn’t publishing any waypoint before changing the flight mode to offboard mode.