Question about loiter controller

Hi Ardupilot community,
I’m working on a positioning control for quadcopter using my indoor positioning system. I choose Ardupilot Loiter controller as my preference. I have a question about loiter implementation on AC_PosControl.cpp

Why does roll_target = atan(accel_right * cos_pitch_target/g) while pitch_target = atan(-accel_forward/g) . I though they are independent, why we need to multiply the cos_pitch_target?

I’m trying to understand the way loiter works. Any explanation or any documents related to loiter controller is appreciated. Thanks.

Because rotation matrix。

Hi @APMMaster, can you explain what you said in more details? Thank you.

Hi Nghia,

If you pitch forward by 89 degrees and roll 89 degrees to you get the same acceleration forward and sideways?

The answer is no of course because the roll and pitch are not independent.

Another way of putting it is if the roll angle is held constant and you increase the pitch angle the thrust must increase to account for the extra pitch angle. That increases the thrust in the sideways direction.

A little difficult to explain without pictures but it is all well known and understood so you should be able to find your way from here.