当前位置:网站首页>Calculate Euler angle according to rotation matrix R yaw, pitch, roll source code
Calculate Euler angle according to rotation matrix R yaw, pitch, roll source code
2022-06-30 07:33:00 【RobotLife】
///Data storage for the matrix, each vector is a row of the matrix
Vector3 m_el[3];
/**@brief Get the matrix represented as euler angles around YXZ, roundtrip with setEulerYPR
* @param yaw Yaw around Z axis
* @param pitch Pitch around Y axis
* @param roll around X axis */
void getEulerYPR(tfScalar& yaw, tfScalar& pitch, tfScalar& roll, unsigned int solution_number = 1) const
{
struct Euler
{
tfScalar yaw;
tfScalar pitch;
tfScalar roll;
};
Euler euler_out;
Euler euler_out2; //second solution
//get the pointer to the raw data
// Check that pitch is not at a singularity
// Check that pitch is not at a singularity
if (tfFabs(m_el[2].x()) >= 1)
{
euler_out.yaw = 0;
euler_out2.yaw = 0;
// From difference of angles formula
if (m_el[2].x() < 0) //gimbal locked down
{
tfScalar delta = tfAtan2(m_el[0].y(),m_el[0].z());
euler_out.pitch = TFSIMD_PI / tfScalar(2.0);
euler_out2.pitch = TFSIMD_PI / tfScalar(2.0);
euler_out.roll = delta;
euler_out2.roll = delta;
}
else // gimbal locked up
{
tfScalar delta = tfAtan2(-m_el[0].y(),-m_el[0].z());
euler_out.pitch = -TFSIMD_PI / tfScalar(2.0);
euler_out2.pitch = -TFSIMD_PI / tfScalar(2.0);
euler_out.roll = delta;
euler_out2.roll = delta;
}
}
else
{
euler_out.pitch = - tfAsin(m_el[2].x());
euler_out2.pitch = TFSIMD_PI - euler_out.pitch;
euler_out.roll = tfAtan2(m_el[2].y()/tfCos(euler_out.pitch),
m_el[2].z()/tfCos(euler_out.pitch));
euler_out2.roll = tfAtan2(m_el[2].y()/tfCos(euler_out2.pitch),
m_el[2].z()/tfCos(euler_out2.pitch));
euler_out.yaw = tfAtan2(m_el[1].x()/tfCos(euler_out.pitch),
m_el[0].x()/tfCos(euler_out.pitch));
euler_out2.yaw = tfAtan2(m_el[1].x()/tfCos(euler_out2.pitch),
m_el[0].x()/tfCos(euler_out2.pitch));
}
if (solution_number == 1)
{
yaw = euler_out.yaw;
pitch = euler_out.pitch;
roll = euler_out.roll;
}
else
{
yaw = euler_out2.yaw;
pitch = euler_out2.pitch;
roll = euler_out2.roll;
}
}
Source code :ros/LinearMath/Matrix3x3.h
边栏推荐
- Analysys analysis: online audio content consumption market analysis 2022
- Matter protocol
- Label the picture below the uniapp picture
- C language - student achievement management system
- Log service management
- Proteus catalog component names and Chinese English cross reference
- Multi whale capital: report on China's education intelligent hardware industry in 2022
- 系统软件开发基础知识
- Keil serial port redirection
- Video player (I): process
猜你喜欢

C language implementation sequence stack

Double click the idea to solve the problem of downloading again

Network security - packet capture and IP packet header analysis

Account command and account authority

String application -- string violent matching (implemented in C language)

Thread pool - C language

Qtcreator debug code after configuring CDB debugger view variable value display card

Basic knowledge points

halcon:读取摄像头并二值化

期末複習-PHP學習筆記6-字符串處理
随机推荐
DXP software uses shortcut keys
Log service management
STM32 key control LED
Installation software operation manual (continuous update)
Mailbox application routine of running wild fire RT thread
Next initializesecuritycontext failed: unknown error (0x80092012) - the revocation function cannot check whether the certificate is revoked.
Lt268 the most convenient TFT-LCD serial port screen chip in the whole network
Proteus catalog component names and Chinese English cross reference table
02 - bare metal and RTOS development modes: five development modes of bare metal and the introduction of RTOS
Final review -php learning notes 6- string processing
PMIC power management
手机开户股票开户安全吗?开户需要准备什么?
Raspberry pie 4B Getting Started Guide
How to use string branches for switch case
Application of stack -- using stack to realize bracket matching (C language implementation)
Network security - layer 3 switching technology and internal network planning
Basic knowledge points
期末复习-PHP学习笔记6-字符串处理
Socket socket programming -- UDP
LabVIEW program code update is slow