Setting trajectory setpoint using ROS 2 and microRTPS-bridge


We are trying to control a Pixhawk 4 mini externally using an companion computer (Raspberry Pi CM4). We communicate with the Pixhawk using UART and we are using the microRTPS-bridge.

We are having some problems getting the drone into “offboard” mode.

When we try to set the drone into “offboard” mode via ROS 2, nothing happens.
When we try to set the drone into “offboard” mode via QGroundControl or a radio we get “offboard rejected” error.

What we have done

  • Written ROS 2 packages based on the “offboard control” example.
  • Simulated the system in Gazebo using the “software in the loop” simulation from PX4-Autopilot repo.
  • Setting everything up on the real drone and checked that the “trajectory_setpoint” messages reaches the Pixhawk using the command “listener trajectory_setpoint” in the pixhawk shell (via QGroundControl).

What we know

  • The code should work, by simulating in Gazebo.
  • Pixhawk receives a constant stream of setpoints, 20Hz.

We have used hours on this and do not know why it does not work.

One single time, we actually were able to set the Pixhawk into “offboard” mode from QGroundControl, and then when changing setpoint to z=-5.0, the motors increased speed. But, did not work before or after. Seems random that it worked that one time.

By listening to the “trajectory setpoint” topic on the Pixhawk from the Pixhawk-shell, it sometime seems like there is some other application also publishing setpoint data. Could this potentially mess with the “constant stream of setpoint” requirement?

Any suggestions are appreciated, thanks :slight_smile:


When you state you know that thr Pixhawk receives a constant stream of setpoints at 20Hz, how exactly are you confirming that?

Also, can you please load a log into Otherwise it’s rather difficult to understand what’s happening. My first bet would be that the default topics setup to be sent and received are occupying too much bandwidth of your serial link. So my advise on that would be to remove some of the topics of the yaml file in both the PX4-Autopilot file and the px4_ros_com side. In the other hand, also try to increase the baud rate you are setting for your UART link.


Thank you for the quick response.

We do not exactly know how fast the pixhawk receives the messages, what we ment was that we send the messages at 20Hz from our companion computer. May have been a bit unclear…

However, when we read the last trajectory setpoint using the “listener trajectory_setpoint” command in the pixhawk-console, there is a field displaying that the last message was received 0.02 ish seconds ago. We have just assumed that the setpoints therefore are received fast enough.

We have tried to both increase the bandwith to 921600 Baud and removed SensorCombinedListener and Odometry messages. This made no difference…

Here is a link to a log:

The problem is now solved. Maybe a bit of a rookie mistake, however we can now move on.

Solution: GPS needs to have lock (flashing green instead of blue) for the Pixhawk to enter offboard mode.