How to implement an algorithm developed in matlab into ready to fly drone

Hello,

My name is Jeremy, I’m a doctoral student in control field. I developed an algorithm in Matlab Simulink and I would like to implement it in the ready to fly drone described in the link below : https://docs.px4.io/en/flight_controller/intel_aero.html

The point is that I’m not familiar with coding into PX4 controllers and I hesitate between two directions. Maybe you can help me to choose the most appropriate one : The first one proposed by Mathworks presented in the link below propose to install an environment in Matlab able to build directly from Simulink to the PX4 target.


It’s a pretty attractive solution because it seems like “magical”. But there is also a lack of control on how things are performed and I’m not sure it’s done properly. Do you have any experience with this tool ? Does it work well ?

The second one would be to code directly in C++ the code download from github (https://github.com/PX4/Firmware) and then upload it into the ready to fly drone. But as I said I’m not familiar in coding and I’m a little bit afraid to go in this direction because it could take many many times I think. But anyway, if it’s valuable because it’s a safe way to make a clean job I could go in that direction. In this case would you have a good tutorial that explain specifically how to modify and implement a controller into a flight controller ? For instance if I want to change the PID for a LQR controller, how can I do that?

I’m not natural in English but if there is any need of clarifications don’t hesitate to ask me,

Thank you for answering,

Jérémy

2 Likes

Hi Jérémy i am a doctoral student in control field like you
and i want to develop an algorithm and a new controler for a quad home made
it’s seems that the solution of mathworks is good to try becuse coding with C will take you many time than the time that you spent on developing

1 Like

Hi @ismatitou, thank you for your feedback. Indeed, we will try the mathworks solutions which is probably much faster.

Hey @Jeremy,

Did you finally end up using this method? I’m trying to do the same. Did you find any useful resources (ex. tutorials)?

Hi @Safat,

The most usfull informations I found are here :

It explains how to install PSP to implement your algorithm from matlab into PX4 firmware.

Unfortunalty on my side I wasn’t able to install PSP on my computer. I have some error message I’m not able to debug it…

May be you will be more lucky than me if you try :wink:

1 Like

When you say that you found the explanation/information from that link, do you mean that the User Guide is included as part of the PSP installation package?

I tried to download the PSP and it gave me a file for Matlab and steps on installation. I was more interested in the User Guide so that I can follow it and learn how to actually implement it.

Sorry for the late response by the way.

Hello,
Im engineering student I try to implemant an adaptative PID in the Pixhawk using Simulink.
Im using " [PX4 Autopilots Support from Embedded Coder" I secceed to read sensors and to implemant a simple PID but I’ve always problem.
one or two rotor stop while incrresing thrust.
have u eny progress in your project which can help us ?
thank u in advance.

Hey!

I am also an engineering student trying to implement a Robust Controller. Could you please tell me if the px4 support was of any use? Any kind of resource related to the same would be really helpful.

Also, I noticed that examples in Simulink are mostly for a quadrotor. Any idea how to proceed if I want to do the same for any other configuration say a fixed wing for example?

Thank You!