update_rate_bf_targets()

Hello, I'm trying to understand how Ardupilot  implements PID control. I'm able to follow the code and see that the errors from the set point are converted into rate targets which are sent to a PID controller. However puzzled by the following code:

_rate_bf_target.x += _angle_bf_error.y * _ahrs.get_gyro().z;
_rate_bf_target.y += -_angle_bf_error.x * _ahrs.get_gyro().z;

in update_rate_bf_targets()

why is this done? Seems to make no sense. The rate_bf_target.x already has the Kp*angle_bf_error.x applied to it, so not seeing why we are adding the above to it.. 

Anyone knows why?

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Probably to counter roll/pitch oscillations during yaw events.

    • scaling the target_rate by the error in the perpendicular axis times yaw rate? Still seems to make no sense. Can anyone who understands this code throw some light? 

      • It's not scaling target rate, it's adding/subtracting from it.

        The only time these lines have effect is when there is yaw/pitch angle error AND the aircraft is rotating around the z-axis (yaw).  But lifting/dropping the part of the aircraft that that is about to enter the spot that previously was in error, the oscillations will be reduced.  Notice that the correction is applied at an 90deg offset from the error (X error ===> Y rate, and Y error ===> X rate).

        • Ok thanks for the explanation Phillip. That makes some sense. I'll try without this code first and see if adding it helps to reduce any oscillations I might experience. 

This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…