px4 uses PID control algorithm for attitude control of multi-copters. I want to change that control algorithm to a robust controller. I am using MATLAB toolboxes to design the controller (which gives me the controller transfer function). I am confused about how to implement the controller in form of a px4 code?
Thanks for your time! I appreciate any advice or feedback!
I assume that you have designed SISO controllers (because you speak about transfer function), then you will need to discretize your controller to the according sampling time of the attitude multicopter controller and replace PID “code lines” with yours. I don’t know in which file the PID is implemented in the PX4, you need to check the source code. May an other forum member can be more helpful.
Here an other approach:
I can recommend the following if you have the lizenze for Simulink and the embedded coder:
- Implement the transfer function in Simulink (check the sampling time)
- Use the embedded coder of Simulink to generate C++ code (maybe good idea to convert from double to single precision)
- Write a C++ wrapper class (your new controller class) for the generated code from point 2 → maybe good idea to copy the code from the multicopter attitude controller for the signal listeners and publishers.
- Replace the original multicopter attitude controller with the wrapper class from point 3.
Just out of curiosity: Based on what model data did you designed the robust controller? By identification or/and calculations?
Hope this helps
Thank you for the reply.
Yes, I have designed SISO transfer functions. Could you please tell me how can I discretize the controller? In PX4 the controller is implemented in mc_rate_control.cpp
I didn’t think of the embedded coder since I am pretty new to this. I’ll definitely try it and keep this thread updated on how it goes.
I designed the controller based on calculations. Now I’m trying to implement the code in PX4 to verify it in gazebo and eventually in hardware (Pixhawk).
Thanks again for the help!