# Cannot make an Alt Hold stable

**URL:** <https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605>\
**Category:** Flight Testing & Log Analysis\
**Created:** [February 13, 2019, 2:55pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605 "2019-02-13T14:55:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ekci](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/958977/32.png) [@Ekci](https://discuss.px4.io/u/Ekci)\
**Post date:** [February 13, 2019, 2:55pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/1 "2019-02-13T14:55:02Z")

</div>

Hey, I have an around 250 mm Quad with PX4 1.8.2 and LPE estimator. I am flying indoors without a GPS. Here are logs from last flight where I tested Alt Hold:  
[https://logs.px4.io/plot\_app?log=6933f388-8e5e-4445-8a18-b126543655f9](https://logs.px4.io/plot_app?log=6933f388-8e5e-4445-8a18-b126543655f9)

As you can see the LPE is working great (the `local_position_estimator.z` follows the data from Lidar) but I cannot make the quad hover in place. You can also see that I have played with P and PIDv of `MPC_Z`. What’s wrong? Which parameters should I tune?

Here are zoomed parts of the graph where I am actually in Alt Hold:

 ![](https://discuss.px4.io/uploads/default/original/2X/5/5cc7a47d843466536e17f5c86de5d9ea5f24d903.png)  
 ![](https://discuss.px4.io/uploads/default/original/2X/7/717889d25a5f0ff644c88bb9070b1b3a6b06f6ed.png)  
 ![](https://discuss.px4.io/uploads/default/original/2X/8/81335ef08a0b0147fd454b7449bafed442dd2b3b.png)

Thanks!

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [February 13, 2019, 3:24pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/2 "2019-02-13T15:24:24Z")

</div>

You could try to improve the tuning with the params:  
[https://dev.px4.io/en/advanced/parameter\_reference.html#MPC\_Z\_VEL\_P](https://dev.px4.io/en/advanced/parameter_reference.html#MPC_Z_VEL_P)  
[https://dev.px4.io/en/advanced/parameter\_reference.html#MPC\_Z\_VEL\_I](https://dev.px4.io/en/advanced/parameter_reference.html#MPC_Z_VEL_I)  
[https://dev.px4.io/en/advanced/parameter\_reference.html#MPC\_Z\_VEL\_D](https://dev.px4.io/en/advanced/parameter_reference.html#MPC_Z_VEL_D)

Best to change one param at the time maybe in 10 or 20% increments and see if you see a positive or negative effect and then iterate.

---

<div class="post-metadata">

**Author:** ![Ekci](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/958977/32.png) [@Ekci](https://discuss.px4.io/u/Ekci)\
**Post date:** [February 13, 2019, 9:19pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/3 "2019-02-13T21:19:05Z")

</div>

I have tried changing all `MPC-Z_*` parameters, even drastically… Couldn’t see any difference to better or worse.  
Is there a chance that this is a vibration problem? I saw that some people here mentioned that as a stability problem.

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [February 14, 2019, 7:43am UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/4 "2019-02-14T07:43:39Z")

</div>

Good point, your accelerometer data looks quite noisy:  
[https://logs.px4.io/plot\_app?log=6933f388-8e5e-4445-8a18-b126543655f9#Nav-Raw-Acceleration](https://logs.px4.io/plot_app?log=6933f388-8e5e-4445-8a18-b126543655f9#Nav-Raw-Acceleration)

The other thing is that the local position estimate is tracking the distance sensor very closely which means that you should see very good performance if your distance sensor is accurate and has little delay but not otherwise.  
I don’t know how LPE fuses accelerometer, baro, and distance sensor data which is crucial.  
I’m going to tag @mhkabir and @jgoppert who should be able to help you with everything LPE.

---

<div class="post-metadata">

**Author:** ![Ekci](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/958977/32.png) [@Ekci](https://discuss.px4.io/u/Ekci)\
**Post date:** [February 14, 2019, 4:02pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/5 "2019-02-14T16:02:08Z")

</div>

Thank you @JulianOes. I have tried the current master and it works a lot worse. After entering ALTCTL the drone shoots to the ceiling even if throttle is below 50%. I am pretty sure that it’s not the problem with LPE but with mc\_pos\_control.  
Do you know what’s wrong in these logs? Look at the velocity setpoint, it’s like the drone is doing the opposite: [https://logs.px4.io/plot\_app?log=c01f4bd4-9bd9-4618-8557-2808cad64f69](https://logs.px4.io/plot_app?log=c01f4bd4-9bd9-4618-8557-2808cad64f69)  
Maybe @mhkabir will help?

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [February 14, 2019, 4:48pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/6 "2019-02-14T16:48:21Z")

</div>

So with current master, you’re using EKF2? And is the range sensor still working and used?

---

<div class="post-metadata">

**Author:** ![Ekci](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/958977/32.png) [@Ekci](https://discuss.px4.io/u/Ekci)\
**Post date:** [February 14, 2019, 6:20pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/7 "2019-02-14T18:20:13Z")

</div>

Still on LPE with range sensor and without an external vision or flow. In short: the althold is not stable or shoots upwards. I will test it without the lidar or outdoors to let it go few meters up before terminating.

---

<div class="post-metadata">

**Author:** ![charles-blouin](https://discuss.px4.io/user_avatar/discuss.px4.io/charles-blouin/32/3932_2.png) [@charles-blouin](https://discuss.px4.io/u/charles-blouin)\
**Post date:** [February 15, 2019, 10:01pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/8 "2019-02-15T22:01:21Z")

</div>

Are you hardmounting the flight controller? It can affect the accelerometer and pose estimation significantly.

---

<div class="post-metadata">

**Author:** ![Ekci](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/958977/32.png) [@Ekci](https://discuss.px4.io/u/Ekci)\
**Post date:** [February 17, 2019, 9:24pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/9 "2019-02-17T21:24:36Z")

</div>

It’s mounted on fairy stiff and thick mounting tape. But… I have tested the `EKF`2 estimator on the same setup and `MPC*` parameters and it worked perfectly! Rock solid altitude hold. It confuses me a lot: how come the `mc_pos_control` works differently with different estimator? And I am pretty sure that the `LPE` is fine: the position follows the LIDAR without any significant delays…  
I have also tested the `LPE v 1.7.0` and it did not help. Here are some logs:  
LPE: [https://logs.px4.io/plot\_app?log=6f315b12-3887-4432-9aa5-1a47b14f6eee](https://logs.px4.io/plot_app?log=6f315b12-3887-4432-9aa5-1a47b14f6eee)  
PX4: [https://logs.px4.io/plot\_app?log=4e6c8836-fd98-44be-a7df-637eb7fd08fa](https://logs.px4.io/plot_app?log=4e6c8836-fd98-44be-a7df-637eb7fd08fa)

---

<div class="post-metadata">

**Author:** ![charles-blouin](https://discuss.px4.io/user_avatar/discuss.px4.io/charles-blouin/32/3932_2.png) [@charles-blouin](https://discuss.px4.io/u/charles-blouin)\
**Post date:** [February 18, 2019, 11:08pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/10 "2019-02-18T23:08:00Z")

</div>

I understand that LPE is not supported anymore, so people will probably not spend too much time supporting it. I have had other problems with LPE and motion capture, I would not recommend it. If it works with EKF2 and you are sure that it is the only difference, it must be a problem with the LPE estimator.

You velocity looks weird in position hold mode with the LPE estimator. The derivative of the Z position does not look like it matches the Z velocity in the graph underneath when the vehicle is in altitude hold.

---

<div class="post-metadata">

**Author:** ![Ekci](https://discuss.px4.io/letter_avatar_proxy/v4/letter/e/958977/32.png) [@Ekci](https://discuss.px4.io/u/Ekci)\
**Post date:** [February 19, 2019, 2:36pm UTC](https://discuss.px4.io/t/cannot-make-an-alt-hold-stable/9605/11 "2019-02-19T14:36:04Z")

</div>

Yeah, that’s what I am thinking. I will move to EKF2. The only problem is that it was a lot easier to initialize the PX4 without a mag sensor onboard.

Thanks you all for you help 🙂
