ISPose.h
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2020 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #ifndef POSE_H_
14 #define POSE_H_
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 
21 #include "ISMatrix.h"
22 #include "ISConstants.h"
23 
24 //_____ M A C R O S ________________________________________________________
25 
26 //_____ D E F I N I T I O N S ______________________________________________
27 
28 //typedef f_t Quat_t[4]; // [w, x, y, z]
29 //typedef f_t Euler_t[3];
30 
31 #if 1
35 typedef Vector3_t Euler_t; // phi, theta, psi (roll, pitch, yaw)
36 typedef Vector4_t Quat_t; // [w, x, y, z]
37 typedef f_t q_t;
41 #else
42 
43 #endif
44 
45 
46 #if (!defined (__cplusplus) && (!defined (inline)))
47 # define inline __inline // allow "inline" keyword to work in windows w/ c program
48 #endif
49 
50 
51 //_____ G L O B A L S ______________________________________________________
52 
53 //_____ P R O T O T Y P E S ________________________________________________
54 
55 
56 
57 /*
58  * Initialize Quaternion q = [w, x, y, z]
59  */
60 void quat_init( Quat_t q );
61 
62 /* Quaternion Conjugate: q* = [ w, -x, -y, -z ] of quaterion q = [ w, x, y, z ]
63  * Rotation in opposite direction.
64  */
65 void quatConj( Quat_t result, const Quat_t q );
66 
67 /*
68 * Product of two Quaternions. Order of q1 and q2 matters (same as applying two successive DCMs)!!!
69 * Combines two quaternion rotations into one rotation.
70 * result = q1 * q2.
71 * Reference: http://www.mathworks.com/help/aeroblks/quaternionmultiplication.html
72 */
73 void mul_Quat_Quat( Quat_t result, const Quat_t q1, const Quat_t q2 );
74 
75 /*
76 * Product of two Quaternions. Order of q1 and q2 matters (same as applying two successive DCMs)!!!
77 * Combines two quaternion rotations into one rotation.
78 * result = quatConj(q1) * q2.
79 * Reference: http://www.mathworks.com/help/aeroblks/quaternionmultiplication.html
80 */
81 void mul_ConjQuat_Quat( Quat_t result, const Quat_t qc, const Quat_t q2 );
82 
83 /*
84 * Product of two Quaternions. Order of q1 and q2 matters (same as applying two successive DCMs)!!!
85 * Combines two quaternion rotations into one rotation.
86 * result = q1 * quatConj(q2)
87 * Reference: http://www.mathworks.com/help/aeroblks/quaternionmultiplication.html
88 */
89 void mul_Quat_ConjQuat(Quat_t result, const Quat_t q1, const Quat_t qc);
90 
91 /*
92  * Division of two Quaternions. Order matters!!!
93  * result = q1 / q2.
94  * Reference: http://www.mathworks.com/help/aeroblks/quaterniondivision.html
95  */
96 void div_Quat_Quat( Quat_t result, const Quat_t q1, const Quat_t q2 );
97 
98 /*
99  * Quaternion rotation from vector v1 to vector v2.
100  */
101 void quat_Vec3_Vec3( Quat_t result, const Vector3_t v1, const Vector3_t v2 );
102 
103 /* Computationally simple means to apply quaternion rotation to a vector.
104  * Requires quaternion be normalized first.
105  * If quaternion describes current attitude, then rotation is body frame -> reference frame.
106  */
107 void quatRot( Vector3_t result, const Quat_t q, const Vector3_t v );
108 
109 /* Computationally simple means to apply quaternion conjugate (opposite) rotation to a vector
110  * Requires quaternion be normalized first
111  * If quaternion describes current attitude, then rotation is reference frame -> body frame.
112  */
113 void quatConjRot( Vector3_t result, const Quat_t q, const Vector3_t v );
114 
115 /*
116  * This will convert from quaternions to euler angles
117  * q(W,X,Y,Z) -> euler(phi,theta,psi) (rad)
118  *
119  * Reference: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
120  */
121 void quat2euler(const Quat_t q, Euler_t theta);
122 void quat2phiTheta(const Quat_t q, f_t *phi, f_t *theta);
123 void quat2psi(const Quat_t q, f_t *psi);
124 
125 /*
126  * This will convert from euler angles to quaternion vector
127  * euler(phi,theta,psi) (rad) -> q(W,X,Y,Z)
128  */
129 void euler2quat(const Euler_t euler, Quat_t q );
130 
131 
132 /*
133  * Quaternion rotation to NED with respect to ECEF at specified LLA
134  */
135 // void quatEcef2Ned(Vector4 Qe2n, const Vector3d lla);
136 
137 /* Attitude quaternion for NED frame in ECEF */
138 void quat_ecef2ned(float lat, float lon, float *qe2n);
139 
140 /*
141 * Convert ECEF quaternion to NED euler at specified ECEF
142 */
143 void qe2b2EulerNedEcef(Vector3 theta, const Vector4 qe2b, const Vector3d ecef);
144 void qe2b2EulerNedLLA(Vector3 eul, const Vector4 qe2b, const Vector3d lla);
145 
146 /*
147  * This will construct a direction cosine matrix from
148  * the psi angle - rotates from NE to body frame
149  *
150  * body = tBL(2,2)*NE
151  *
152  */
153 void psiDCM(const f_t psi, Matrix2_t m);
154 
155 /*
156 * This will extract the psi euler angle from a direction cosine matrix in the
157 * standard rotation sequence, for either a 2x2 or 3x3 DCM matrix.
158 * [phi][theta][psi] from NED to body frame
159 *
160 * body = tBL(2,2)*NE
161 * body = tBL(3,3)*NED
162 *
163 * reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
164 */
165 f_t DCMpsi(const f_t *m );
166 
167 /*
168  * This will construct a direction cosine matrix from
169  * euler angles in the standard rotation sequence
170  * [phi][theta][psi] from NED to body frame
171  *
172  * body = tBL(3,3)*NED
173  *
174  * Reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
175  */
176 //const Matrix<3,3> eulerDCM( const Vector<3> & euler )
177 void eulerDCM(const Euler_t euler, Matrix3_t m );
178 // Only use phi and theta (exclude psi) in rotation
179 void phiThetaDCM(const Euler_t euler, Matrix3_t m );
180 
181 /*
182  * This will construct the transpose matrix of
183  * the direction cosine matrix from
184  * euler angles in the standard rotation sequence
185  * [phi][theta][psi] from NED to body frame
186  *
187  * body = tBL(3,3)*NED
188  *
189  * reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
190  */
191 void eulerDCM_Trans(const Euler_t euler, Matrix3_t m );
192 
193 /*
194  * This will extract euler angles from a direction cosine matrix in the
195  * standard rotation sequence.
196  * [phi][theta][psi] from NED to body frame
197  *
198  * body = tBL(3,3)*NED
199  *
200  * Reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
201  */
202 void DCMeuler(const Matrix3_t m, Euler_t euler);
203 
204 
205 /*
206  * This will construct a direction cosine matrix from
207  * quaternions in the standard rotation sequence
208  * [phi][theta][psi] from NED to body frame
209  *
210  * body = tBL(3,3)*NED
211  * q(4,1)
212  *
213  * Reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
214  */
215 void quatDCM(const Quat_t q, Matrix3_t mat);
216 void quatdDCM(const Vector4d q, Matrix3_t mat);
217 
218 /*
219  * This will construct a quaternion from direction
220  * cosine matrix in the standard rotation sequence
221  * [phi][theta][psi] from NED to body frame
222  *
223  * body = tBL(3,3)*NED
224  * q(4,1)
225  *
226  * Reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
227  */
228 void DCMquat(const Matrix3_t mat, Quat_t q);
229 
230 /*
231  * This will construct the euler omega-cross matrix
232  * wx(3,3)
233  * p, q, r (rad/sec)
234  */
235 void eulerWx(const Euler_t euler, Matrix3_t mat);
236 
237 /*
238  * This will construct the quaternion omega matrix
239  * W(4,4)
240  * p, q, r (rad/sec)
241  */
242 void quatW(const Euler_t euler, Matrix4_t mat);
243 
244 /*
245 * Convert quaternion to rotation axis (and angle). Quaternion must be normalized.
246 */
247 void quatRotAxis(const Quat_t q, Vector3_t pqr);
248 
249 /*
250  * Compute the derivative of the Euler_t angle psi with respect
251  * to the quaternion Q. The result is a row vector
252  *
253  * d(psi)/d(q0)
254  * d(psi)/d(q1)
255  * d(psi)/d(q2)
256  * d(psi)/d(q3)
257  */
258 void dpsi_dq(const Quat_t q, Quat_t dq);
259 
260 /*
261  * NED to Euler_t
262  */
263 void nedEuler(const Vector3_t ned, Euler_t e);
264 
265 /*
266  * Euler_t to NED
267  */
268 void eulerNed(const Euler_t e, Vector3_t ned);
269 
270 /*
271  * Rotate theta eulers from body frame to reference frame by eulers, in order: phi, theta, psi
272  */
273 void eulerBodyToReference(const Euler_t e, const Euler_t rot, Euler_t result);
274 
275 /*
276  * Rotate theta eulers from reference frame to body frame by eulers, in order: psi, theta, phi
277  */
278 void eulerReferenceToBody(const Euler_t e, const Euler_t rot, Euler_t result);
279 
280 /*
281  * Rotate vector from body frame to reference frame by euler angles, in order: phi, theta, psi
282  */
283 void vectorBodyToReference(const Vector3_t v, const Euler_t rot, Vector3_t result);
284 
285 /*
286  * Rotate vector from reference frame to body frame by euler angles, in order: psi, theta, phi
287  */
288 void vectorReferenceToBody(const Vector3_t v, const Euler_t rot, Vector3_t result);
289 
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 
295 #endif /* POSE_H_ */
void quat_init(Quat_t q)
Definition: ISPose.c:34
void eulerNed(const Euler_t e, Vector3_t ned)
Definition: ISPose.c:659
void quat2psi(const Quat_t q, f_t *psi)
Definition: ISPose.c:204
float f_t
Definition: ISConstants.h:786
f_t Vector2[2]
Definition: ISConstants.h:789
void DCMeuler(const Matrix3_t m, Euler_t euler)
Definition: ISPose.c:447
Vector4 Vector4_t
Definition: ISPose.h:34
void qe2b2EulerNedLLA(Vector3 eul, const Vector4 qe2b, const Vector3d lla)
Definition: ISPose.c:294
f_t Matrix2[4]
Definition: ISConstants.h:798
void div_Quat_Quat(Quat_t result, const Quat_t q1, const Quat_t q2)
Definition: ISPose.c:105
f_t q_t
Definition: ISPose.h:37
Matrix3 Matrix3_t
Definition: ISPose.h:39
Matrix4 Matrix4_t
Definition: ISPose.h:40
void mul_Quat_ConjQuat(Quat_t result, const Quat_t q1, const Quat_t qc)
Definition: ISPose.c:92
void nedEuler(const Vector3_t ned, Euler_t e)
Definition: ISPose.c:648
void quat_Vec3_Vec3(Quat_t result, const Vector3_t v1, const Vector3_t v2)
Definition: ISPose.c:118
void DCMquat(const Matrix3_t mat, Quat_t q)
Definition: ISPose.c:527
void eulerWx(const Euler_t euler, Matrix3_t mat)
Definition: ISPose.c:545
f_t Matrix4[16]
Definition: ISConstants.h:800
Vector3_t Euler_t
Definition: ISPose.h:35
f_t Vector4[4]
Definition: ISConstants.h:793
void quatConjRot(Vector3_t result, const Quat_t q, const Vector3_t v)
Definition: ISPose.c:161
void quatRot(Vector3_t result, const Quat_t q, const Vector3_t v)
Definition: ISPose.c:142
void vectorReferenceToBody(const Vector3_t v, const Euler_t rot, Vector3_t result)
Definition: ISPose.c:717
void eulerDCM(const Euler_t euler, Matrix3_t m)
Definition: ISPose.c:355
void mul_ConjQuat_Quat(Quat_t result, const Quat_t qc, const Quat_t q2)
Definition: ISPose.c:78
Vector4_t Quat_t
Definition: ISPose.h:36
Matrix2 Matrix2_t
Definition: ISPose.h:38
void quatConj(Quat_t result, const Quat_t q)
Definition: ISPose.c:49
void quat2phiTheta(const Quat_t q, f_t *phi, f_t *theta)
Definition: ISPose.c:195
Vector3 Vector3_t
Definition: ISPose.h:33
void euler2quat(const Euler_t euler, Quat_t q)
Definition: ISPose.c:218
f_t Matrix3[9]
Definition: ISConstants.h:799
void qe2b2EulerNedEcef(Vector3 theta, const Vector4 qe2b, const Vector3d ecef)
Definition: ISPose.c:281
void quatRotAxis(const Quat_t q, Vector3_t pqr)
Definition: ISPose.c:602
double Vector3d[3]
Definition: ISConstants.h:790
void psiDCM(const f_t psi, Matrix2_t m)
Definition: ISPose.c:316
void vectorBodyToReference(const Vector3_t v, const Euler_t rot, Vector3_t result)
Definition: ISPose.c:702
void quatW(const Euler_t euler, Matrix4_t mat)
Definition: ISPose.c:570
void quatDCM(const Quat_t q, Matrix3_t mat)
Definition: ISPose.c:466
void quatdDCM(const Vector4d q, Matrix3_t mat)
Definition: ISPose.c:491
void mul_Quat_Quat(Quat_t result, const Quat_t q1, const Quat_t q2)
Definition: ISPose.c:64
void eulerReferenceToBody(const Euler_t e, const Euler_t rot, Euler_t result)
Definition: ISPose.c:686
void quat_ecef2ned(float lat, float lon, float *qe2n)
Definition: ISPose.c:267
void phiThetaDCM(const Euler_t euler, Matrix3_t m)
Definition: ISPose.c:380
Vector2 Vector2_t
Definition: ISPose.h:32
void eulerDCM_Trans(const Euler_t euler, Matrix3_t m)
Definition: ISPose.c:413
f_t DCMpsi(const f_t *m)
Definition: ISPose.c:340
void quat2euler(const Quat_t q, Euler_t theta)
Definition: ISPose.c:185
void eulerBodyToReference(const Euler_t e, const Euler_t rot, Euler_t result)
Definition: ISPose.c:670
void dpsi_dq(const Quat_t q, Quat_t dq)
Definition: ISPose.c:632
double Vector4d[4]
Definition: ISConstants.h:792


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:04