当前位置:网站首页>Mobile Robotics (II) posture solution
Mobile Robotics (II) posture solution
2022-07-18 11:47:00 【U kid】
Four yuan number
Definition and basic operation of quaternion
Quaternion is generally used to express rotation in aircraft attitude calculation , Personal understanding , Rotate matrix with 3*3 Matrix and additional 6 A nonlinear constraint ( The column vectors are orthogonal to each other and the module length is 1) Describes rotation , And quaternions pass 4 Number and a constraint ( The unit is 4 yuan ) Describes the same amount of information , Similar to a system of linear equations , Reduce constraints by substituting elimination , Reduce the number of variables , To reduce the amount of calculation . actually , In inertial navigation system, quaternion is used to realize fast cycle iteration , It can take 1000Hz Update the pose of the moving object at the speed of .
Three dimensional rotation representation
- The unit is 4 yuan q ~ = c o s ( θ / 2 ) + w ^ s i n ( θ / 2 ) \tilde{q}=cos(\theta/2)+\widehat{w}sin(\theta/2) q~=cos(θ/2)+wsin(θ/2) It can represent walking around in three-dimensional space ( Unit vector ) w ^ \widehat{w} w rotate θ \theta θ Rotation operator of angle . Be careful , w ^ \widehat{w} w Here, it is regarded as a vector in three-dimensional space rather than a hypercomplex .
- The rotation of the vector :
a. Vector “ Quaternization ”: x ~ = 0 + x → \tilde{x}=0+\overrightarrow{x} x~=0+x;
b. Rotate the vector around the axis w ^ \widehat{w} w rotate θ \theta θ horn , Get the new vector x ~ ′ = q ~ x ~ q ~ ∗ \tilde{x}^{'}=\tilde{q}\tilde{x}\tilde{q}^{*} x~′=q~x~q~∗. - Equivalent rotation matrix :
For quaternions q = q 0 + q 1 i + q 2 j + q 3 k q=q_0+q_1i+q_2j+q_3k q=q0+q1i+q2j+q3k
take x ~ ′ = q ~ x ~ q ~ ∗ \tilde{x}^{'}=\tilde{q}\tilde{x}\tilde{q}^{*} x~′=q~x~q~∗ an , Merge similar items to get
R = [ 2 ( q 0 2 + q 1 2 ) − 1 2 ( q 1 q 2 − q 0 q 3 ) 2 ( q 1 q 3 + q 0 q 2 ) 2 ( q 1 q 2 + q 0 q 3 ) 2 ( q 0 2 + q 2 2 ) − 1 2 ( q 2 q 3 − q 0 q 1 ) 2 ( q 1 q 3 − q 0 q 2 ) 2 ( q 0 q 1 + q 2 q 3 ) 2 ( q 0 2 + q 3 2 ) − 1 ] R = \left [ \begin{matrix} 2(q_0^2+q_1^2)-1 & 2(q_1q_2-q_0q_3) & 2(q_1q_3+q_0q_2) \\ 2(q_1q_2+q_0q_3) & 2(q_0^2+q_2^2)-1 & 2(q_2q_3-q_0q_1) \\ 2(q_1q_3-q_0q_2) & 2(q_0q_1+q_2q_3) & 2(q_0^2+q_3^2)-1 \\ \end{matrix} \right ] R=⎣⎡2(q02+q12)−12(q1q2+q0q3)2(q1q3−q0q2)2(q1q2−q0q3)2(q02+q22)−12(q0q1+q2q3)2(q1q3+q0q2)2(q2q3−q0q1)2(q02+q32)−1⎦⎤
The above is the expression under the left hand system , About left / The distinction between right-handed systems : Hand to hand “ gun ” The shape of the , Point your index finger at your opponent (You), representative Y Axis , The thumb is for aiming (x Does it seem to be accurate ), So it is X Axis , The remaining middle finger represents Z Axis . here , The coordinate system corresponding to the left hand is the left-handed system , The right hand corresponds to the right hand .
Right hand system expresses :
R = [ 1 − 2 ( q 2 2 + q 3 2 ) 2 ( q 1 q 2 − q 0 q 3 ) 2 ( q 1 q 3 + q 0 q 2 ) 2 ( q 1 q 2 + q 0 q 3 ) 1 − 2 ( q 1 2 + q 3 2 ) 2 ( q 2 q 3 − q 0 q 1 ) 2 ( q 1 q 3 − q 0 q 2 ) 2 ( q 0 q 1 + q 2 q 3 ) 1 − 2 ( q 1 2 + q 2 2 ) ] R = \left [ \begin{matrix} 1-2(q_2^2+q_3^2) & 2(q_1q_2-q_0q_3) & 2(q_1q_3+q_0q_2) \\ 2(q_1q_2+q_0q_3) & 1-2(q_1^2+q_3^2) & 2(q_2q_3-q_0q_1) \\ 2(q_1q_3-q_0q_2) & 2(q_0q_1+q_2q_3) & 1-2(q_1^2+q_2^2) \\ \end{matrix} \right ] R=⎣⎡1−2(q22+q32)2(q1q2+q0q3)2(q1q3−q0q2)2(q1q2−q0q3)1−2(q12+q32)2(q0q1+q2q3)2(q1q3+q0q2)2(q2q3−q0q1)1−2(q12+q22)⎦⎤
hinder code It's right-handed , The left hand system in books , It can also be used in other places , Pay attention to distinguish between .
Attitude calculation
Mainly combined with a four axis flight control project .
First, let's explain the navigation coordinate system n The definition of : x/y/z The axis points east in turn 、 north 、 God , Set the yaw angle as ψ \psi ψ ( Be careful : Clockwise is positive , Traditionally, north by East is positive ), The pitch angle is θ \theta θ, The rolling angle is γ \gamma γ , Body coordinate system b And n The relationship is
T n b = [ c γ c ψ + s γ s ψ s θ − c γ s ψ + s γ c ψ s θ − s γ c θ s ψ c θ c ψ c θ s θ s γ c ψ − c γ s ψ s θ − s γ s ψ − c γ c ψ s θ c γ c θ ] T^b_n=\left [ \begin{matrix} c\gamma{c}\psi+s\gamma{s}\psi{s}\theta & -c\gamma{s}\psi+s\gamma{c}\psi{s}\theta & -s\gamma{c}\theta \\ {s}\psi{c}\theta & {c}\psi{c}\theta & {s}\theta \\ s\gamma{c}\psi-c\gamma{s}\psi{s}\theta & -s\gamma{s}\psi-c\gamma{c}\psi{s}\theta & c\gamma{c}\theta \\ \end{matrix} \right ] Tnb=⎣⎡cγcψ+sγsψsθsψcθsγcψ−cγsψsθ−cγsψ+sγcψsθcψcθ−sγsψ−cγcψsθ−sγcθsθcγcθ⎦⎤
- The acceleration of gravity is normalized to a unit vector ;
// Acceleration normalization
NormQuat = Q_rsqrt(squa(MPU6050.accX) + squa(MPU6050.accY) + squa(MPU6050.accZ));
// Q_rsqrt: Fast calculation 1/Sqrt(x)
Acc.x = pMpu->accX * NormQuat;
Acc.y = pMpu->accY * NormQuat;
Acc.z = pMpu->accZ * NormQuat;
- Extract the gravity component in the quaternion equivalent rotation matrix , Is to rotate the matrix by gravity ( Set to 1, step 1 The acceleration normalization in the ) Convert to the body coordinate system ;
// Extract the gravity component in the equivalent rotation matrix
Gravity.x = 2 * (NumQ.q1 * NumQ.q3 - NumQ.q0 * NumQ.q2);
Gravity.y = 2 * (NumQ.q0 * NumQ.q1 + NumQ.q2 * NumQ.q3);
Gravity.z = 1 - 2 * (NumQ.q1 * NumQ.q1 + NumQ.q2 * NumQ.q2);
- The vector cross product yields the attitude error ,Acc It is measured by accelerometer ,AccGravity It is calculated by gyro integral , In essence, it represents a quantity , The cross product is still in the body coordinate system , And its size is directly proportional to the gyro integration error , Used to correct gyro , This reflects the fusion of sensor data ;
// The value of vector cross multiplication
AccGravity.x = (Acc.y * Gravity.z - Acc.z * Gravity.y);
AccGravity.y = (Acc.z * Gravity.x - Acc.x * Gravity.z);
AccGravity.z = (Acc.x * Gravity.y - Acc.y * Gravity.x);
- Make compensation ;
// Then do the acceleration integral compensation and the compensation value of angular velocity
GyroIntegError.x += AccGravity.x * KiDef;
GyroIntegError.y += AccGravity.y * KiDef;
GyroIntegError.z += AccGravity.z * KiDef;
// Angular velocity fusion acceleration integral compensation value
Gyro.x = pMpu->gyroX * Gyro_Gr + KpDef * AccGravity.x + GyroIntegError.x; // Radian system
Gyro.y = pMpu->gyroY * Gyro_Gr + KpDef * AccGravity.y + GyroIntegError.y;
Gyro.z = pMpu->gyroZ * Gyro_Gr + KpDef * AccGravity.z + GyroIntegError.z;
- First order Runge-Kutta Update quaternion ;
// First order Runge Kutta method , Update quaternion
q0_t = (-NumQ.q1 * Gyro.x - NumQ.q2 * Gyro.y - NumQ.q3 * Gyro.z) * HalfTime;
q1_t = (NumQ.q0 * Gyro.x - NumQ.q3 * Gyro.y + NumQ.q2 * Gyro.z) * HalfTime;
q2_t = (NumQ.q3 * Gyro.x + NumQ.q0 * Gyro.y - NumQ.q1 * Gyro.z) * HalfTime;
q3_t = (-NumQ.q2 * Gyro.x + NumQ.q1 * Gyro.y + NumQ.q0 * Gyro.z) * HalfTime;
NumQ.q0 += q0_t;
NumQ.q1 += q1_t;
NumQ.q2 += q2_t;
NumQ.q3 += q3_t;
- Quaternion normalization ;
// Quaternion normalization
NormQuat = Q_rsqrt(squa(NumQ.q0) + squa(NumQ.q1) + squa(NumQ.q2) + squa(NumQ.q3));
NumQ.q0 *= NormQuat;
NumQ.q1 *= NormQuat;
NumQ.q2 *= NormQuat;
NumQ.q3 *= NormQuat;
边栏推荐
- 2个群晖使用同一域名不能同时登录,WHY?
- 【C语言】结构体、枚举、联合体
- thinkphp5 读取多行文本、读取文件分割多行文本
- 无线通信安全作业1-无线通信安全最新消息
- [step on pit] attaching a row → dataframe
- ForCO: Global debut, violent appreciation, best currency circle outlet of the year
- Which machine learning model is suitable for different evaluation methods?
- 晴空一“鹤”排“云”上:以数为翅的中国飞鹤
- [es practice] spark writes es support
- thinkphp 3 增加分词权重搜索功能 phpanalysis插件
猜你喜欢
随机推荐
redis数据类型
Professional qualities of network security practitioners
【C】动态内存管理(相关函数、常见错误、笔试题)
tmux使用
Development of upper computer -- a series of database problems are solved in a net
com. alibaba. fastjson. JSONException: unclosed string
uboot 增加硬件看门狗
Take you to brush (niuke.com) C language hundred questions (the next day)
What effective measures can be taken to improve the efficiency of discussing research issues?
Talking about software defect management
jol-core
[MySQL] create a MySQL account and authorize the correct posture
ForCO: Global debut, violent appreciation, best currency circle outlet of the year
【C语言】动态通讯录
Intel helps open medical service and promote the intellectualization of ultrasonic prenatal examination
Redis入门
flutter EventBus
Redis概述、安装、可视化访问
Jol Core
Financial industry open platform









