当前位置:网站首页>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
边栏推荐
- 将本地电脑文件复制到虚拟机系统中详细方法
- 期末复习-PHP学习笔记11-PHP-PDO数据库抽象层.
- 单测调用对象的私有方法
- STM32 infrared communication 2
- 期末複習-PHP學習筆記6-字符串處理
- C51 minimum system board infrared remote control LED light on and off
- [implemented] server jar package startup script and shell script
- Basic knowledge points
- Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)
- [most complete] install MySQL on a Linux server
猜你喜欢

Analysys analysis: online audio content consumption market analysis 2022

期末复习-PHP学习笔记11-PHP-PDO数据库抽象层.

期末複習-PHP學習筆記6-字符串處理

Cubemx completes STM32F103 dual serial port 485 transceiver transmission

RT thread kernel application development message queue experiment

C language implements sequential queue, circular queue and chain queue

Application of stack -- using stack to realize bracket matching (C language implementation)

MySQL encounters the problem of expression 1 of select list is not in group by claim and contains nonaggre

STM32 register

Tencent and Fudan University "2021-2022 yuan universe report" with 102 yuan universe collections
随机推荐
Use of ecostruxure (2) IEC61499 to establish function blocks
Basic knowledge of system software development
The simulation interface does not declare an exception and throws an exception
Xiashuo think tank: 50 planet updates reported today (including the global architects Summit Series)
视频播放器(一):流程
网络安全-路由原理
Video player (I): process
Label the picture below the uniapp picture
01 - embedded learning route and career planning: embedded basic knowledge and development process
Matter protocol
系统软件开发基础知识
Ad\dxp how to solve the problem of not knowing the schematic Library
Ad usage notes
How to use string branches for switch case
Experiment 1: comprehensive experiment [process on]
Embedded test process
Network security ARP protocol and defense
Basic knowledge points
Use of ecostruxure (3) creating composite function blocks
How to batch modify packaging for DXP schematic diagram