Crash during AutoTune - uncommanded pitch movement during roll tuning - ArduCopter 4.7.0-beta3

Follow up to my post above. I found two more issues with the same cause. Code in the rate path that assumes it runs once per main loop, which isn’t true with the fast-rate thread any more. Checked against Copter-4.7.1 and master (755258d).

rate_controller_run_dt() runs once per rate-thread sample with fast rate, but calls two helpers assuming main-loop timing:

  1. PD boost compounds: update_throttle_gain_boost() multiplies _pd_scale by (1+ATC_THR_G_BOOST) on every rate-thread call and it is only reset once per main loop which results in (1+G_BOOST)^n, no limit (my post above). This is not confined to autotuning. It happens in normal flight as well.

  2. Angle P boost is never applied without fast rate, compounds with fast rate: since c683d8c16 (4.7.0) _angle_P_scale is reset in rate_controller_target_reset(), right after the rate run applies the boost and before update_flight_mode() runs the angle controller. So the angle controller reads 1.0, while ATSC.AngPScX logs the boost. With fast rate the rate thread keeps multiplying after the reset. QuadPlane (Q_A_THR_G_BOOST) has the same order, so its angle P boost is also dead since 4.7.0.

  3. THR_MIX slews too fast: update_throttle_rpy_mix() steps by the main loop _dt_s but runs at the rate loop rate, so both ramps are (rate loop / main loop) times too fast. With defaults the 0.8 s ramp down becomes 0.32 s at 1 kHz / 400 Hz, 0.16 s at 2 kHz.

Conditions: FSTRATE_ENABLE ≠ 0 for 1 and 3, ATC_THR_G_BOOST > 0 for 1 and 2 (both default 0).

Claude reproduced all three in SITL for me, on master with ATC_THR_G_BOOST = 0.4 and an extra log message for the angle P scale the angle controller actually reads. SITL’s gyro is fixed at 1 kHz, so the rate thread can’t run faster than that. To get more rate-thread runs per main loop, SCHED_LOOP_RATE was lowered instead: 400 / 200 / 100 Hz gives 2.5 / 5 / 10 runs per main loop.

  • Without fast rate: max ATSC.PDScX is 1.4. ATSC.AngPScX logs 1.96, but the angle controller reads 1.0 in every boosted loop.
  • With fast rate: max ATSC.PDScX is 1.4^8 / 1.4^9 / 1.4^16, and the angle controller reads between 1.96^1 and 1.96^6. The exponents vary with how SITL schedules the threads.
  • THR_MIX slews at 5.0 / 10 / 20 per s up and 1.25 / 2.5 / 5.0 per s down, instead of 2.0 and 0.5.

I’ll open a PR with a SITL test that shows the problem and a suggested fix. Just give me a couple days to get this right. I could also fly before/after logs on my 7" to not only rely on the simulations.

Hi @RobinIJ,

Thanks again for this. The PR is greatly appreciated!

FYI @Leonardthall @andyp1per

Hi @RobinIJ if you could leave it with me I would be grateful - you have identified several different issues here and some of them are going to get caught up with other PR’s in motion. Very nice catch!

@rmackay9 this could explain why sysid does not currently work with fast rates

Yes of course. Glad I could hep figure this one out.
I went through both PRs. #34583 matches what I found for all three issues, and applying the PD boost to a local copy is cleaner than what I had in mind.
#34584 fits what I see in my 7" logs: ACRO rate-loop-only at 2 kHz / 400 Hz, 13% of rate controller runs with I scale 1 instead of ATC_ANG_*_P. That’s the same gap as for the landed gain reduction.
Thanks for the quick fixes!

This also negatively impacts ACRO_OPTIONS=2 as well - so again a very good find!