How can replace default controller parts of PX4 with custom algorithms controller?

14 views (last 30 days)
I want to change controller algorithms of PX4.
So I am learning 'UAV Toolbox Support Package for PX4 Autopilots'
I want replace controller parts of px4 firmware(default : 'mc_att_control' and 'mc_pos_control)' with custom controller.
Path following flight is performed simply by connecting PX4 to the drone and simply giving a mission with QGC.(Before using UAV Toolbox Support Package for PX4 Autopilots)
if I want to change only the controller of PX4 using the UAV Toolbox Support Package for PX4 Autopilots, I wonder if I can design and build only the controller. Or, I wonder if I should design all the processes (connecting to QGC, transmitting and receiving msg, etc.) from the beginning with simulink. There is no example for this, so it is difficult to proceed.
It would be very helpful if there was an example of flying a real drone by building a custom algorithm in PX4. (not simulation)

Accepted Answer

Jianxin Sun
Jianxin Sun on 15 Feb 2022
Hi SeungWoo,
You can use the support package to replace the PX4 controller only. Please refer to the "integration with general PX4 architecture" doc page for details. You will also need to enable the mavlink module if you want to enable communication with QGC.
The following examples show how to replace multirotor position controller in PX4:
Jianxin Sun
Jianxin Sun on 18 Feb 2022
You can follow and example to replace controller module on PX4 stack. The support package would compile the Simulink model as a controller module, disable the original PX4 controller module, build and deploy this modified PX4 firmware stack to the target according to your hardware configuration.
Since you only need to replace the controller, you only need to design controller in Simulink and reuse other modules in PX4. When you test the controller with SITL/HIL setting, your controller will be running along with other modules in PX4 as a complete software stack.

Sign in to comment.

More Answers (1)

Massimo Satler
Massimo Satler on 15 Mar 2022
Hi Jianxin Sun, I saw the system requirements section where it is recommended Ubuntu 18.04 Is it possible to use the support packets with Ubuntu 20.04 and matlab 2022a?


Find more on UAV in Help Center and File Exchange



Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by