The conversion between Euler angle and four-yuan number in flight control attitude calculation

Source: Internet
Author: User

Euler angle turn four yuan

void Cjx_from_euler (float roll, float pitch, float yaw)

{

float Cr2 = COSF (roll*0.5f);

float CP2 = COSF (pitch*0.5f);

float cy2 = COSF (yaw*0.5f);

Float SR2 = Sinf (roll*0.5f);

Float SP2 = Sinf (pitch*0.5f);

float sy2 = Sinf (yaw*0.5f);


Q1 = cr2*cp2*cy2 + sr2*sp2*sy2;

q2 = Sr2*cp2*cy2-cr2*sp2*sy2;

Q3 = Cr2*sp2*cy2 + sr2*cp2*sy2;

Q4 = CR2*CP2*SY2-SR2*SP2*CY2;

}


#define RAD_TO_DEG 57.29577951f

Radian to Angle

Float degrees (float rad)

{

Return rad * RAD_TO_DEG;

}


Four Yuan to Euler angle

void Cjx_to_euler (float *roll, float *pitch, float *yaw)

{

if (roll) {

*roll = Degrees (atan2f (2.0f* (q1*q2 + q3*q4), 1-2.0f* (Q2*Q2 + q3*q3));

}

if (pitch) {

Use Safe_asin () to handle singularities when pitch approaches 90/-90

*pitch = Degrees (Safe_asin (2.0f* (Q1*Q3-Q2*Q4)));

}

if (yaw) {

*yaw = Degrees (atan2f (2.0f* (q2*q3-q1*q4), 2.0f* (q1*q1 + q2*q2)-1));

}

}




This article is from the "C Little Wolf" blog, please make sure to keep this source http://caijinxun.blog.51cto.com/9101387/1872102

The conversion between Euler angle and four-yuan number in flight control attitude calculation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.