# Position and attitud controllers diagram

**URL:** <https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186>\
**Category:** PX4 Autopilot\
**Created:** [May 2, 2017, 11:38am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186 "2017-05-02T11:38:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![NestorSANTOS](https://discuss.px4.io/user_avatar/discuss.px4.io/nestorsantos/32/1034_2.png) [@NestorSANTOS](https://discuss.px4.io/u/NestorSANTOS)\
**Post date:** [May 2, 2017, 11:38am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/1 "2017-05-02T11:38:54Z")

</div>

Hi everyone,

For my master’s project I need to create the Simulink model for the position and attitude controllers of the PX4 firmware, so I can perform some analyses on its performances in simulation. I see that they are very dependents of the flight mode but for the moment I am just looking for a general diagram of the controller structure (Inner/Outer loop P, PID). I have review the mc\_att\_control\_main.cpp and I have identified the following block diagram.

 ![](https://discuss.px4.io/uploads/default/original/2X/0/031d64c1529f629c3c43d04c18c1225cbdb34356.PNG)

I see that position control use a similar controller but I do not understand yet how it is connected to the attitude controller.

I would appreciate if someone could confirm the identification I have done and suggest documentation about this problem so I can better understand the code.

Thanks.

---

<div class="post-metadata">

**Author:** ![tumbili](https://discuss.px4.io/user_avatar/discuss.px4.io/tumbili/32/3779_2.png) [@tumbili](https://discuss.px4.io/u/tumbili)\
**Post date:** [May 3, 2017, 6:21am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/2 "2017-05-03T06:21:31Z")

</div>

Hi, you diagram looks pretty good. The feed-forward path is not used for multirotors and it would require a derivative term with it. I think it’s mainly used for helicopter attitude control. Maybe you could use better symbols for the integrator and the derivative, at first I had the saturation confused with an integrator.  
The position controller looks pretty much the same, with an outer position loop feeding the inner velocity loop.  
The output of the position controller is an attitude and a thrust setpoint which is the input for the attitude controller.

---

<div class="post-metadata">

**Author:** ![rousselmanu](https://discuss.px4.io/user_avatar/discuss.px4.io/rousselmanu/32/3537_2.png) [@rousselmanu](https://discuss.px4.io/u/rousselmanu)\
**Post date:** [May 4, 2017, 5:07pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/3 "2017-05-04T17:07:15Z")

</div>

Hi, I think that the input of the D block should be the error (theta-dot\_ref - theta\_dot) and not theta-dot directly (same input as inner-loop P and I). Am I wrong ?

---

<div class="post-metadata">

**Author:** ![NestorSANTOS](https://discuss.px4.io/user_avatar/discuss.px4.io/nestorsantos/32/1034_2.png) [@NestorSANTOS](https://discuss.px4.io/u/NestorSANTOS)\
**Post date:** [May 5, 2017, 7:50am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/4 "2017-05-05T07:50:32Z")

</div>

I really think that angle rate signal is used for derivative component of PID.  
Here there is a section of the mc\_att\_control\_main.cpp code where I believe PID is implemented :

```
/* angular rates error */
math::Vector<3> rates_err = _rates_sp - rates;

_att_control = rates_p_scaled.emult(rates_err) +
	       _rates_int +
	       rates_d_scaled.emult(_rates_prev - rates) / dt +
	       _params.rate_ff.emult(_rates_sp);

_rates_sp_prev = _rates_sp;
_rates_prev = rates;
```

---

<div class="post-metadata">

**Author:** ![rousselmanu](https://discuss.px4.io/user_avatar/discuss.px4.io/rousselmanu/32/3537_2.png) [@rousselmanu](https://discuss.px4.io/u/rousselmanu)\
**Post date:** [May 5, 2017, 10:49am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/5 "2017-05-05T10:49:29Z")

</div>

Ok, then you should have a minus somewhere in the D feedback loop (e.g. in your last sum block)

---

<div class="post-metadata">

**Author:** ![NestorSANTOS](https://discuss.px4.io/user_avatar/discuss.px4.io/nestorsantos/32/1034_2.png) [@NestorSANTOS](https://discuss.px4.io/u/NestorSANTOS)\
**Post date:** [May 5, 2017, 11:50am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/6 "2017-05-05T11:50:03Z")

</div>

Ah that is true, I forgot to specify it in the diagram.

---

<div class="post-metadata">

**Author:** ![Abel](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@Abel](https://discuss.px4.io/u/Abel)\
**Post date:** [May 8, 2017, 3:18am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/7 "2017-05-08T03:18:11Z")

</div>

Hello Nestor,

I’ve been digging deep trying to understand how the position and attitude controller is implemented. I’m some how confused. Could you share with me the final control diagram that you’ve got. It will help me to understand the implementation. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![NestorSANTOS](https://discuss.px4.io/user_avatar/discuss.px4.io/nestorsantos/32/1034_2.png) [@NestorSANTOS](https://discuss.px4.io/u/NestorSANTOS)\
**Post date:** [May 9, 2017, 8:51am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/8 "2017-05-09T08:51:17Z")

</div>

Hi Abel,  
I do not have yet a diagram for position control, but it seems to be very similar to the attitude controller.  
Here is the attitude controller diagram with the corrections suggested before.

 ![](https://discuss.px4.io/uploads/default/original/2X/5/55f1d2bf0271e0ed14a6566938cb4be4e5fd586c.PNG)

Theta is the angle, you just need to replace it by roll, pitch or yaw angle.  
Theta dot is the rate of the angle.  
For yaw, there should be also a feed forward gain added to the proportional gain for the angle error.

---

<div class="post-metadata">

**Author:** ![Abel](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@Abel](https://discuss.px4.io/u/Abel)\
**Post date:** [May 9, 2017, 5:32pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/9 "2017-05-09T17:32:51Z")

</div>

Wow. Thank you so much. You did a nice investigation !

---

<div class="post-metadata">

**Author:** ![yun](https://discuss.px4.io/letter_avatar_proxy/v4/letter/y/bcef8e/32.png) [@yun](https://discuss.px4.io/u/yun)\
**Post date:** [May 11, 2017, 1:28pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/10 "2017-05-11T13:28:54Z")

</div>

So, I have a question about the D. Why it is doing differential with theta\_dot, but not the error between setpoint and estimate value ?

---

<div class="post-metadata">

**Author:** ![yun](https://discuss.px4.io/letter_avatar_proxy/v4/letter/y/bcef8e/32.png) [@yun](https://discuss.px4.io/u/yun)\
**Post date:** [May 11, 2017, 1:31pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/11 "2017-05-11T13:31:01Z")

</div>

Yeah, I agree with you, and I changed it myself. But actually D block does a little affect.

---

<div class="post-metadata">

**Author:** ![bresch](https://discuss.px4.io/user_avatar/discuss.px4.io/bresch/32/2343_2.png) [@bresch](https://discuss.px4.io/u/bresch)\
**Post date:** [May 11, 2017, 4:55pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/12 "2017-05-11T16:55:48Z")

</div>

@yun The D is taken directly on the angular rate (filtered gyro measurement) and not on the angular rate error in order to avoid the so called “derivative kick”. For example, imagine what is the output of the derivative term if the reference is a Heaviside step function…

> **[PID Controller Basics – Eliminating Derivative Kick](https://barela.wordpress.com/2013/07/19/pid-controller-basics-eliminating-derivative-kick/)**
>
> PID Controllers have been around for decades. They’re an extremely simple invention, from a mathematical perspective. Yet still, you see people misuse them – the most common ‘sin&…

---

<div class="post-metadata">

**Author:** ![abdullahmohiuddin](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@abdullahmohiuddin](https://discuss.px4.io/u/abdullahmohiuddin)\
**Post date:** [May 28, 2017, 10:00am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/13 "2017-05-28T10:00:40Z")

</div>

![](https://discuss.px4.io/uploads/default/original/2X/b/b91d091f3f50c3e24177e0aa0d2a49f0e4cc2549.png)

Hi,

I am trying to expand this controller diagram to include the sensors and their frequencies. Please see the diagram attached and kindly please let me know , how may I improve it more. Specially the LPE estimator, how can I dig into it more?

---

<div class="post-metadata">

**Author:** ![abdullahmohiuddin](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@abdullahmohiuddin](https://discuss.px4.io/u/abdullahmohiuddin)\
**Post date:** [May 28, 2017, 10:21am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/14 "2017-05-28T10:21:41Z")

</div>

The final goal is to come up with a diagram like this one, but with LPE and Q-estimator.

 ![](https://discuss.px4.io/uploads/default/original/2X/2/2e33605a284a042ed79a98ce8fc9592ebd39a179.jpg)

---

<div class="post-metadata">

**Author:** ![Mario1577](https://discuss.px4.io/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Mario1577](https://discuss.px4.io/u/Mario1577)\
**Post date:** [May 30, 2017, 12:17am UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/15 "2017-05-30T00:17:11Z")

</div>

Hello!!

What is Kff??

---

<div class="post-metadata">

**Author:** ![annavt](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@annavt](https://discuss.px4.io/u/annavt)\
**Post date:** [July 7, 2017, 4:53pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/16 "2017-07-07T16:53:44Z")

</div>

Very helpful diagram! Where did it come from, or did you make it? I’ve been looking for diagrams to help me understand the attitude control algorithm and haven’t really found anything detailed until now.

---

<div class="post-metadata">

**Author:** ![annavt](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@annavt](https://discuss.px4.io/u/annavt)\
**Post date:** [July 7, 2017, 4:56pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/17 "2017-07-07T16:56:33Z")

</div>

I think Kff is the feed forward gain:

> There is also MC\_YAW\_FF parameter that controls how much of user input need to feed forward to yaw rate controller. 0 means very slow control, controller will start to move yaw only when sees yaw position error, 1 means very responsive control, but with some overshot, controller will move yaw immediately, always keeping yaw error near zero.

-From the [PID Tuning](https://docs.px4.io/en/advanced_config/pid_tuning_guide_multicopter.html) doc.

---

<div class="post-metadata">

**Author:** ![abdullahmohiuddin](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@abdullahmohiuddin](https://discuss.px4.io/u/abdullahmohiuddin)\
**Post date:** [July 7, 2017, 5:15pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/18 "2017-07-07T17:15:29Z")

</div>

![](https://discuss.px4.io/uploads/default/original/2X/0/06bab519d0f258f0bfe644e09ede0f3e584b375c.png)

With LPE and Q-estimator

---

<div class="post-metadata">

**Author:** ![abdullahmohiuddin](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@abdullahmohiuddin](https://discuss.px4.io/u/abdullahmohiuddin)\
**Post date:** [July 7, 2017, 5:16pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/19 "2017-07-07T17:16:29Z")

</div>

If anyone can verify the content of the above diagram or tell me how to improve it, that would be great

---

<div class="post-metadata">

**Author:** ![Abel](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@Abel](https://discuss.px4.io/u/Abel)\
**Post date:** [January 16, 2018, 3:08pm UTC](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186/20 "2018-01-16T15:08:47Z")

</div>

I think there is a constant (thr\_hover ) subtracted from the PID on the outer-loop velocity controller (mc\_pos\_control).

![](https://discuss.px4.io/uploads/default/original/2X/9/9fb422e2c4322dbbdb7a127b3885d2c15adfd1a7.png)

[Next page](https://discuss.px4.io/t/position-and-attitud-controllers-diagram/3186.md?page=2)
