### Help with the frame conversion from earth frame to body frame in AC_attitude_control library, thanks!

Hi~

I am new to the attitude control method of arducopter codes. In the AC_attitude_control library,  in the function:

void AC_AttitudeControl::angle_ef_roll_pitch_rate_ef_yaw_smooth

there is a frame conversion from earth frame to body frame:

frame_conversion_ef_to_bf(angle_ef_error, _angle_bf_error);

I am confused about this point since I think roll and pitch angles are used to describe the transforming relationship between the body frame and the earth frame, so what is the meaning of this frame conversion here?

Thanks a lot for you help!

#### Replies

• Hi Henry. Sorry that I don't have an answer to your question, but I have a related question and I hope that you wouldn't mind I posting it here:

What are the definitions of "earth frame" and "body frame" exactly?

I thought the transformation was from NED to body-fixed, but from the code I don't think it is the case, actually I was really confused of the transformation and that's why I am searching for threads on the forum.

//
// earth-frame <-> body-frame conversion functions
//
// frame_conversion_ef_to_bf - converts earth frame vector to body frame vector
void AC_AttitudeControl::frame_conversion_ef_to_bf(const Vector3f& ef_vector, Vector3f& bf_vector)
{
// convert earth frame rates to body frame rates
bf_vector.x = ef_vector.x - _ahrs.sin_pitch() * ef_vector.z;
bf_vector.y = _ahrs.cos_roll()  * ef_vector.y + _ahrs.sin_roll() * _ahrs.cos_pitch() * ef_vector.z;
bf_vector.z = -_ahrs.sin_roll() * ef_vector.y + _ahrs.cos_pitch() * _ahrs.cos_roll() * ef_vector.z;
}

Now when I compare the code with this link:

http://www.pixhawk.org/dev/know-how/frames_of_reference

I would expect something like (take the x-axis as an example):

bf_vector.x = _ahrs.cos_pitch() * ef_vector.x - _ahrs.sin_pitch() * ef_vector.z;

I think I am getting something wrong here... Would someone be kind enough to help me out? Many thanks~

• I was running into the same confusion...but I think I've sorted it out. It's a terminology problem in the code.

To me, the Euler angles (Phi, Theta, and Psi) are the set of rotations that define the transformation between the earth frame and the body frame. To go from earth to body we rotate by yaw about the z axis, then pitch about the y and finally roll about the x. To go from body to earth we undo the angular rotations in reverse order. The angles themselves aren't in one coordinate system or the other; they describe the transformations between the coordinate systems.

But, it's important to remember that the derivatives of the Euler angles (Phi dot, Theta dot, and Psi dot) are not equal to the body axis rates (P, Q and R). This is what the "earth frame to body frame" conversion accomplishes. The attitude controller establishes a desired Euler angle (Phi, Theta, Psi), and a ultimately a target rate to get there (Phi dot, Theta dot, and Psi dot), then we need to turn those into the desired roll pitch and yaw rates (P,Q,R) for use in the inner loop PID controller.

P = Phi_dot - Psi_dot*sinTheta

Q = Theta_dot*cosPhi + Psi_dot*cosTheta*sinPhi

R = Psi_dot*cosTheta*cosPhi - Theta_dot*sinTheta

Cheers

Kris

This reply was deleted.

### Activity

DIY Robocars via Twitter
yesterday
DIY Robocars via Twitter
yesterday
DIY Drones via Twitter
Thursday
DIY Robocars via Twitter
RT @Heavy02011: @diyrobocars : A Home-brew computer club* for Connected Autonomous Driving on Jan 23rd, 2021 https://www.meetup.com/Connected-Autonomous-Driving/events/275728684/ #Meetu…
Thursday
DIY Robocars via Twitter
Thursday
David Hori liked Isabella Domi's profile
Wednesday
DIY Robocars via Twitter
RT @Heavy02011: ⁦@diyrobocars⁩ Autonomous Driving Assembly at #rC3. join us at https://rc3.world/rc3/assembly/diyrobocars-f1tenth/ ⁦@f1tenth⁩ ⁦@DAVGtech⁩ ⁦@DWalmroth⁩…
Monday
DIY Robocars via Twitter
RT @chr1sa: New car designs coming for our next @DIYRobocars @donkey_car virtual race on the 23rd. Choose any one you want at race time Le…
Monday
DIY Robocars via Twitter
RT @RoboticMasters: Thanks to @EllerbachMaxime and the Sydney Uni Capstone Students the @donkey_car @diyrobocars simulator is getting a ma…
Monday
DIY Robocars via Twitter
Dec 28, 2020
DIY Robocars via Twitter
An interesting line-following simulator to use with with your robocars: https://github.com/ron-grant/LFS
Dec 23, 2020
DIY Robocars via Twitter
Dec 23, 2020
DIY Robocars via Twitter
An improved version of the @IntelAIResearch OpenBot: https://diyrobocars.com/2020/12/14/an-improved-version-of-the-intel-openbot/
Dec 14, 2020
DIY Drones via Twitter
An improved version of the Intel OpenBot https://ift.tt/2KkHT8Q
Dec 14, 2020
DIY Robocars via Twitter
Dec 10, 2020