Drone unstable in offboard direct motor control

Hello community,

I have implemented an LQR controller to control a quadcopter using direct motor commands. I finally want this to perform some trajectory tracking. I developed and evaluated the code and performance in sim using the toolchain available for ROS2 and PX4. Then I moved to hardware implementation, but the drone is unstable, and it crashes in the end. I need help, ideas from you all to figure out why it is happening in hardware implementation but not in sim.

Drone: Holybro S500
Board: pixhawk 4
firmware: release/1.14
motion capture: Optitrack mocap

A simple hover experiment:
In sim and experiment I am trying to get the drone to hover at some altitude.

I subscribe to VehicleLocalPosition, VehicleAttitude and VehicleAngularVelocity messages to get the full state feedback. Then calculate the thrust using this equation u = u_0 + K * (x - x_0) and publish the thrust values at 100hz to ActuatorMotors message. Here is the video of the simulation VIDEO.

I do the same as above. One thing extra I do is take the mocap position and attitude data and pass it to EKF2 message for better estimates.
Here is the video of the experiment VIDEO. After the crash I kill the motors.


  • Is the publishing frequency of thrust values slow? Should I go higher than 100hz? It works in sim at 100hz but some assumptions in sim might not be valid in experiment.
  • In the sim I tried going higher, but nothing works above 125hz. Drone is stable between only 40-125hz. Weird! Why?
  • Is there any way to get EKF2 feedback at higher frequencies? I get feedback at 80hz, 165hz, 350hz for the above three messages that I subscribe respectively in experiment. I get feedback at 125hz, 250hz, 250hz for the above three messages that I subscribe respectively in gazebo simulation.

hello,Have you considered the issue of signal conflicts.I don’t know if mixer_module will still publish actutor_outputs in offboard director_actuator mode. Can you check if there is any vibration in the PWM value by QGC.

Maybe you need to prevent other modules (mainly the control allocation module) for publishing on those topics(actuators_motors).

Thanks for your reply.

I already knew about the module conflict. Motors stutter because of that. I had taken it in account.

Right now I think it’s the feedback that is the issue. Mocap gives estimates over Wi-Fi and latency is high. I am calculating the exact latency so that the EKF2 module can correctly give me estimates. Right now, the estimates are lagging.

Flying wired on ethernet is not the solution. What do you think?

How do you solve the module conflict.I have the problem.
Your idea is a train of thought. Has QGC displayed automatic switching of control mode? I think all delays will be converted to the period of the LQR control signal. The minimum frequency of the off board mode signal is 2Hz, but it may not get the real-time requirements even at 2Hz.
Yes,Flying wired on ethernet is not the good solution.but you can try it exclude whether it is a network issue.If you are certain it is a network issue,writing a process in the PX4 source code may be a method.

Module conflict: So I just commented a line in the control allocator module and compiled the firmware. Later I did something more, I can help you with that. Later I also saw a github commit where they have solved this issue. https://github.com/PX4/PX4-Autopilot/pull/22222
This is merged into main so I am not using this as I was already working with PX4v1.14 branch.

While flying yes the QGC does show switching of control mode.

Regarding the delay I am thinking of getting a separate router with no internet just for streaming mocap. I will try this and reply about the performance.

Thank you for your help.
Good luck!

hello ,prakritt.
Have you reprocessed the data of VehicleAngularVelocity topic.the topic vehicle_angular_velocity that Kalman filtering has not been applied.I want to use vehicle_angular_velocity too,but it looks trustworthy,and has high signal noise.Maybe it’s a problem.

I have not processed feedback data. Are you sure Kalam Filter has not been applied to VehicleAngularVelocity topic?

You can also try Vehicleodometry topic. It has angular velocity data.