How to Override PX4 Default Controller with the Custom controller

Hi ,

I want to implement the custom flight controller instead of the PX4 default controller(Controller Diagrams | PX4 Guide (main)) in OFFBOARD mode .
Or from my custom controller i am already getting the torques and thrust from which i can also calculate the individal motor’s thrust and angular speed.
so, is there any way to send the obtained desired torques of roll,pitch,yaw and desired thrust to the pixhawk or mapping them to the roll,pitch,yaw or their rates for sending through the SET_ATTITUDE_TARGET .

which is the better way to implement and how to implement.

Firmware:PX4 v1.15
Flight controller:Pixhawk 6X
This is my custom flight controller .

Thanks in Advance!

You can use offboard control via MAVLink (or MAVSDK to make it easier), or you can hook into the uORB messages via the ROS 2 bridge.

Thanks for your response, Sir!

So it means i shouldn’t use my custom flight controller to override entirely the pixhawk internal controller.
If that is the case that’s also ok for me but I would like to know: when using offboard control, is there any MAVLink command available to directly send the desired torques and thrust, or the individual motor thrusts?

If that’s not possible, could you please suggest a way to map my computed torques and thrust to attitude setpoints, so that I can use commands like SET_ATTITUDE_TARGET or any other suitable alternatives?

Thanks once again !

Hi @Allu_Sreekanth

px4_msgs::msg::VehicleThrustSetpoint
As you can see in document it is possible. But I think offboard mode should only take control to perform high level navigation works not directly drive motor and servos along entire flight. Document already have a warning about this
“The following offboard control modes bypass all internal PX4 control loops and should be used with great care.”

If you want to completely change default controllers with your own controllers I think bypass the actual system with offboard mode not the desired way. Instead of this you can use PX4 support package for simulink and replace only desired part of actual system with your controllers.

For example you can build an outer loop it producing attitude commands and if you publish this commands with right uORB topic(vehicle_attitude_setpoint), rate controller,mixer etc. of PX4 will still work. So you should only disable position controller for this example.(Only one source should publish attitude setpoints). You can implement this logic also for other low level controller loops. Another example while PX4 navigator and position controller working and publishing desired attitude commands to follow waypoints you can take this setpoints and publish desired motor/servo pwm values …

You can check MathWorks official document for more info.
https://www.mathworks.com/help/uav/px4/ref/PX4-HITL-with-VTOL-UAV-in-simulink.html
Also you can check our implementation wtih this method.

Thank you for your response and for the detailed explanation and guidance. It really helped clarify the approach.I will follow the steps you’ve outlined and get back to you with an update soon.

1 Like