当前位置:网站首页>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
边栏推荐
- TC397 QSPI(CPU)
- Stm32g0 porting FreeRTOS
- Lt268 the most convenient TFT-LCD serial port screen chip in the whole network
- Analysys analysis: online audio content consumption market analysis 2022
- STM32 key control LED
- Use of ecostruxure (2) IEC61499 to establish function blocks
- 网络安全-三层交换技术和内部网络规划
- Tencent and Fudan University "2021-2022 yuan universe report" with 102 yuan universe collections
- 1.someip introduction
- 24C02
猜你喜欢
网络安全-路由原理
Network security - routing principle
Idea running run and services
How to determine the size of the platform byte order?
Tencent and Fudan University "2021-2022 yuan universe report" with 102 yuan universe collections
Matter protocol
C51 minimum system board infrared remote control LED light on and off
Next initializesecuritycontext failed: unknown error (0x80092012) - the revocation function cannot check whether the certificate is revoked.
网络安全-抓包和IP包头分析
Dynamic memory management
随机推荐
Global digital industry strategy and policy observation in 2021 (China Academy of ICT)
Deloitte: investment management industry outlook in 2022
Test enumeration types with STM32 platform running RT thread
Xiashuo think tank: 28 updates of the planet reported today (including the information of flirting with girls and Han Tuo on Valentine's day)
Shell command, how much do you know?
Halcon: read the camera and binary it
24C02
MySQL encounters the problem of expression 1 of select list is not in group by claim and contains nonaggre
Analysys analysis: online audio content consumption market analysis 2022
STM32 register
Firewall firewalld
STM32 infrared communication 3 brief
网络安全-单臂路由、DHCP中继和ICMP协议
期末复习-PHP学习笔记11-PHP-PDO数据库抽象层.
Basic operation command
Thread network
Error reporting record
MAX6675 usage notes
342 maps covering exquisite knowledge, one of which is classic and pasted on the wall
Stm32g0 Tim interrupt use