Offboard control - /mavros/setpoint_raw/attitude : Altitude control using thrust setpoint

Hello everyone !
I want to control altitude using thrust command in /mavros/setpoint_raw/attitude. I needed some guidance and advice regarding it. I tried implementing a PD controller in SITL. However the drone just keeps on bouncing.
Thank you for helping me in this !

1 Like

@Vrinda It means either your P gain is too large or your D gain is too small. Clipping the error also helps preventing large thrust inputs which makes it overshoot

Your thrust should also take account your attitude to be bale to maintain altitude while pitching / rolling

1 Like

Thanks much @Jaeyoung-Lim ! Tuning is taking a while in SITL. Is the tuning difficult ? Have you tried it on hardware ? Furthermore,

  1. I am clipping the error, as in, I have an if else loop which limits my thrust between 0 and 1. Is it fine? Is this what you mean ?
  2. How should I integrate attitude control with thrust (your second point above) ? I am just considering error between current z position and desired z position in my PD controller.

@Vrinda Yes, I have tried it on hardware.

  1. No, what you mentioned is clipping the output of the PD controller. That is not a good approach as it will saturate the outputs. What I meant is when you calculate the output of the controller, the error term needs to be clipped. For example, for a PD controller,
F = k_p * e + k_v * v_e

You need to clip the error e

  1. It is quite straight forward. If your body is tilted, you need more thrust to stay in the air. You need to calculate the amount of thrust needed for the vertical acceleration required to stay in the air + control the altitude according to your PD controller

Thanks much @Jaeyoung-Lim for the clear explanation. I will do as you suggested,

  1. I understood this. I will clip the error.
  2. I am little confused here. I have two queries
    i. will my thrust controller also have attitude terms other than errror. I mean
    F = kpe + kd e_dot +(function of attitude setpoint) ?
    ii. Will this effect not be compensated with proper choice of PID gains ?

Thanks again for your time ! Apologize for silly questions.


i. I don’t think that is a good idea. There are tons of literature on controllers that can successfully control the position of the drone such as this paper. You can look only at the position controller and ignore the attitude controlling part.

ii. No, it will not be compensated. It will if the small angle assumption holds, but this will be vulnerable on real systems


Thanks much for the information @Jaeyoung-Lim ! I am working on it ! I will keep you posted regarding my progress.