Custom postion control

In the position control and velocity control , i want to custom my own controller like sliding mode controller , instead of PID . :grin:

I do some research but they all talk about mavros off-board , but they are all in simulation.
And i think in other way ,it’s change the file /PX4-Autopilot/src/modules/PositionControl

I can’t find any document about this topic .
That very help full , if you guys can share just your i ideal , or something relative .

Thanks !!


Hi, i’m trying to use a customized controller too, the problem is that i cannot handle the scaled control value used by PX4, how you scale your control action accordingly?

i dont understand , what you mean scale value .
But if you want , that my custom controller in position loop * with sliding mode control
I also test in real pihawk2 , and the results look a litter better than pid .

*position loop = position control + velocity control in px4
Slidingmode-sim/Position control at main · kslhuy/Slidingmode-sim · GitHub .

Thanks for answering me, I’ve taken a brief look at your code, so let me understand you have simplify replaced the position and velocity control block but you kept untouched the rate and attitude, so you are simply setting your thrust, not the moments required.

My project is a bit different I’m trying to substitute the whole control architecture so everything before the mixing phase, using an HOSM +Feedback Linearization.
I have some questions for you , how have you handled the update frequency? Your sliding mode which frequency is using?

I’ve tried to reduce the sampling time between calls but I failed in SITL.

in the simulation and real , its almost 50hz (position loop) or dt = 0.02,
in the altitude i dont know but i think at least not bigger than 0,02 , (i see every article say that 200hz or 250hz )
I understand, , you use feed back lineariztion for position control and HOSM for attitude. i do the same in my simulation but i not test in real.
But overall its the same logic , you just dont need to care much to sample , because i dont know to handle that :rofl: just debug to see this value . Also your algorithm its not heavy to calculate, so 50hz its ok .

1 Like

I dont quite understand how the controller is implemented into the PX4 firmware. So to understand how your controller works, you model the translational dynamics and implement a SMC based controller that guarantees tracking where the control input to the translational dynamics are these virtual controller inputs. So when these virtual inputs are designed you are able to relate them to the total thrust and desired pitch and roll angles? Where the total thrust is normalized and eventually converted to set points for the angle controller and a yaw set point in the PX4? I am also not sure how these relationships are derived (converting virtual control inputs to thrust etc), probably because I am not overly familiar with the controller. I also could be completely misinterpreting the implementation.

that true what you said. ALL! i have struggled when i start.
they have a different in theory and the way PX4 implement.
They not use Euler angle for the control . they use Quaternion . you can find in internet the formula math
What I did that only the virtual control SMC to improve the tracking trajectory. So the relationship you said, i don’t touched at all.

and if look deep inside the code ControlMath.cpp you will see also. Keep patient, you will find that.

u can see that file pdf , that can have u , an overview

Yes I see they use quaternions as the setpoint for the angle controller. So you designed the virtual control inputs then those relations calculate the requirements for the PX4 with the non linear decoupling equations.

I seen your question.pdf. Does U1 correspond to Fsp in that controller diagram? Which is then normalized?