ISPose.h
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2021 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 #include "ISMatrix.h"
21 #include "ISConstants.h"
22 
23 #if (!defined (__cplusplus) && (!defined (inline)))
24 # define inline __inline // allow "inline" keyword to work in windows w/ c program
25 #endif
26 
27 
28 /*
29  * Initialize Quaternion q = [w, x, y, z]
30  */
31 void quat_init( ixQuat q );
32 
33 /* Quaternion Conjugate: q* = [ w, -x, -y, -z ] of quaterion q = [ w, x, y, z ]
34  * Rotation in opposite direction.
35  */
36 void quatConj( ixQuat result, const ixQuat q );
37 
38 /*
39 * Product of two Quaternions. Order of q1 and q2 matters (same as applying two successive DCMs)!!!
40 * Combines two quaternion rotations into one rotation.
41 * result = q1 * q2.
42 * Reference: http://www.mathworks.com/help/aeroblks/quaternionmultiplication.html
43 */
44 void mul_Quat_Quat( ixQuat result, const ixQuat q1, const ixQuat q2 );
45 
46 /*
47 * Product of two Quaternions. Order of q1 and q2 matters (same as applying two successive DCMs)!!!
48 * Combines two quaternion rotations into one rotation.
49 * result = quatConj(q1) * q2.
50 * Reference: http://www.mathworks.com/help/aeroblks/quaternionmultiplication.html
51 */
52 void mul_ConjQuat_Quat( ixQuat result, const ixQuat qc, const ixQuat q2 );
53 
54 /*
55 * Product of two Quaternions. Order of q1 and q2 matters (same as applying two successive DCMs)!!!
56 * Combines two quaternion rotations into one rotation.
57 * result = q1 * quatConj(q2)
58 * Reference: http://www.mathworks.com/help/aeroblks/quaternionmultiplication.html
59 */
60 void mul_Quat_ConjQuat(ixQuat result, const ixQuat q1, const ixQuat qc);
61 
62 /*
63  * Division of two Quaternions. Order matters!!!
64  * result = q1 / q2.
65  * Reference: http://www.mathworks.com/help/aeroblks/quaterniondivision.html
66  */
67 void div_Quat_Quat( ixQuat result, const ixQuat q1, const ixQuat q2 );
68 
69 /*
70  * Quaternion rotation from vector v1 to vector v2.
71  */
72 void quat_Vec3_Vec3( ixQuat result, const ixVector3 v1, const ixVector3 v2 );
73 
74 /* Computationally simple means to apply quaternion rotation to a vector.
75  * Requires quaternion be normalized first.
76  * If quaternion describes current attitude, then rotation is body frame -> reference frame.
77  */
78 void quatRot( ixVector3 result, const ixQuat q, const ixVector3 v );
79 
80 /* Computationally simple means to apply quaternion conjugate (opposite) rotation to a vector
81  * Requires quaternion be normalized first
82  * If quaternion describes current attitude, then rotation is reference frame -> body frame.
83  */
84 void quatConjRot( ixVector3 result, const ixQuat q, const ixVector3 v );
85 
86 /*
87  * This will convert from quaternions to euler angles
88  * q(W,X,Y,Z) -> euler(phi,theta,psi) (rad)
89  *
90  * Reference: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
91  */
92 void quat2euler(const ixQuat q, ixEuler theta);
93 void quat2phiTheta(const ixQuat q, f_t *phi, f_t *theta);
94 void quat2psi(const ixQuat q, f_t *psi);
95 
96 /*
97  * This will convert from euler angles to quaternion vector
98  * euler(phi,theta,psi) (rad) -> q(W,X,Y,Z)
99  */
100 void euler2quat(const ixEuler euler, ixQuat q );
101 
102 
103 /*
104  * Quaternion rotation to NED with respect to ECEF at specified LLA
105  */
106 // void quatEcef2Ned(ixVector4 Qe2n, const ixVector3d lla);
107 
108 /* Attitude quaternion for NED frame in ECEF */
109 void quat_ecef2ned(float lat, float lon, float *qe2n);
110 
111 /*
112 * Convert ECEF quaternion to NED euler at specified ECEF
113 */
114 void qe2b2EulerNedEcef(ixVector3 theta, const ixVector4 qe2b, const ixVector3d ecef);
115 void qe2b2EulerNedLLA(ixVector3 eul, const ixVector4 qe2b, const ixVector3d lla);
116 
117 /*
118  * This will construct a direction cosine matrix from
119  * the psi angle - rotates from NE to body frame
120  *
121  * body = tBL(2,2)*NE
122  *
123  */
124 void psiDCM(const f_t psi, ixMatrix2 m);
125 
126 /*
127 * This will extract the psi euler angle from a direction cosine matrix in the
128 * standard rotation sequence, for either a 2x2 or 3x3 DCM matrix.
129 * [phi][theta][psi] from NED to body frame
130 *
131 * body = tBL(2,2)*NE
132 * body = tBL(3,3)*NED
133 *
134 * reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
135 */
136 f_t DCMpsi(const f_t *m );
137 
138 /*
139  * This will construct a direction cosine matrix from
140  * euler angles in the standard rotation sequence
141  * [phi][theta][psi] from NED to body frame
142  *
143  * body = tBL(3,3)*NED
144  *
145  * Reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
146  */
147 //const Matrix<3,3> eulerDCM( const Vector<3> & euler )
148 void eulerDCM(const ixEuler euler, ixMatrix3 m );
149 // Only use phi and theta (exclude psi) in rotation
150 void phiThetaDCM(const ixEuler euler, ixMatrix3 m );
151 
152 /*
153  * This will construct the transpose matrix of
154  * the direction cosine matrix from
155  * euler angles in the standard rotation sequence
156  * [phi][theta][psi] from NED to body frame
157  *
158  * body = tBL(3,3)*NED
159  *
160  * reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
161  */
162 void eulerDCM_Trans(const ixEuler euler, ixMatrix3 m );
163 
164 /*
165  * This will extract euler angles from a direction cosine matrix in the
166  * standard rotation sequence.
167  * [phi][theta][psi] from NED to body frame
168  *
169  * body = tBL(3,3)*NED
170  *
171  * Reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
172  */
173 void DCMeuler(const ixMatrix3 m, ixEuler euler);
174 
175 
176 /*
177  * This will construct a direction cosine matrix from
178  * quaternions in the standard rotation sequence
179  * [phi][theta][psi] from NED to body frame
180  *
181  * body = tBL(3,3)*NED
182  * q(4,1)
183  *
184  * Reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
185  */
186 void quatDCM(const ixQuat q, ixMatrix3 mat);
187 void quatdDCM(const ixVector4d q, ixMatrix3 mat);
188 
189 /*
190  * This will construct a quaternion from direction
191  * cosine matrix in the standard rotation sequence
192  * [phi][theta][psi] from NED to body frame
193  *
194  * body = tBL(3,3)*NED
195  * q(4,1)
196  *
197  * Reference: http://en.wikipedia.org/wiki/Rotation_representation_%28mathematics%29
198  */
199 void DCMquat(const ixMatrix3 mat, ixQuat q);
200 
201 /*
202  * This will construct the euler omega-cross matrix
203  * wx(3,3)
204  * p, q, r (rad/sec)
205  */
206 void eulerWx(const ixEuler euler, ixMatrix3 mat);
207 
208 /*
209  * This will construct the quaternion omega matrix
210  * W(4,4)
211  * p, q, r (rad/sec)
212  */
213 void quatW(const ixEuler euler, ixMatrix4 mat);
214 
215 /*
216 * Convert quaternion to rotation axis (and angle). Quaternion must be normalized.
217 */
218 void quatRotAxis(const ixQuat q, ixVector3 pqr);
219 
220 /*
221  * Compute the derivative of the ixEuler angle psi with respect
222  * to the quaternion Q. The result is a row vector
223  *
224  * d(psi)/d(q0)
225  * d(psi)/d(q1)
226  * d(psi)/d(q2)
227  * d(psi)/d(q3)
228  */
229 void dpsi_dq(const ixQuat q, ixQuat dq);
230 
231 /*
232  * NED to ixEuler
233  */
234 void nedEuler(const ixVector3 ned, ixEuler e);
235 
236 /*
237  * ixEuler to NED
238  */
239 void eulerNed(const ixEuler e, ixVector3 ned);
240 
241 /*
242  * Rotate theta eulers from body frame to reference frame by eulers, in order: phi, theta, psi
243  */
244 void eulerBodyToReference(const ixEuler e, const ixEuler rot, ixEuler result);
245 
246 /*
247  * Rotate theta eulers from reference frame to body frame by eulers, in order: psi, theta, phi
248  */
249 void eulerReferenceToBody(const ixEuler e, const ixEuler rot, ixEuler result);
250 
251 /*
252  * Rotate vector from body frame to reference frame by euler angles, in order: phi, theta, psi
253  */
254 void vectorBodyToReference(const ixVector3 v, const ixEuler rot, ixVector3 result);
255 
256 /*
257  * Rotate vector from reference frame to body frame by euler angles, in order: psi, theta, phi
258  */
259 void vectorReferenceToBody(const ixVector3 v, const ixEuler rot, ixVector3 result);
260 
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 #endif /* POSE_H_ */
void DCMeuler(const ixMatrix3 m, ixEuler euler)
Definition: ISPose.c:447
void quat2euler(const ixQuat q, ixEuler theta)
Definition: ISPose.c:185
ixVector4 ixQuat
Definition: ISConstants.h:796
f_t ixVector3[3]
Definition: ISConstants.h:791
float f_t
Definition: ISConstants.h:786
void eulerBodyToReference(const ixEuler e, const ixEuler rot, ixEuler result)
Definition: ISPose.c:670
void vectorReferenceToBody(const ixVector3 v, const ixEuler rot, ixVector3 result)
Definition: ISPose.c:717
void quat2phiTheta(const ixQuat q, f_t *phi, f_t *theta)
Definition: ISPose.c:195
void eulerDCM(const ixEuler euler, ixMatrix3 m)
Definition: ISPose.c:355
void quatDCM(const ixQuat q, ixMatrix3 mat)
Definition: ISPose.c:466
void quatRotAxis(const ixQuat q, ixVector3 pqr)
Definition: ISPose.c:602
f_t ixMatrix4[16]
Definition: ISConstants.h:800
void DCMquat(const ixMatrix3 mat, ixQuat q)
Definition: ISPose.c:527
void phiThetaDCM(const ixEuler euler, ixMatrix3 m)
Definition: ISPose.c:380
void psiDCM(const f_t psi, ixMatrix2 m)
Definition: ISPose.c:316
void nedEuler(const ixVector3 ned, ixEuler e)
Definition: ISPose.c:648
double ixVector3d[3]
Definition: ISConstants.h:790
f_t ixMatrix2[4]
Definition: ISConstants.h:798
double ixVector4d[4]
Definition: ISConstants.h:792
void quatRot(ixVector3 result, const ixQuat q, const ixVector3 v)
Definition: ISPose.c:142
void eulerNed(const ixEuler e, ixVector3 ned)
Definition: ISPose.c:659
void quatW(const ixEuler euler, ixMatrix4 mat)
Definition: ISPose.c:570
void div_Quat_Quat(ixQuat result, const ixQuat q1, const ixQuat q2)
Definition: ISPose.c:105
ixVector3 ixEuler
Definition: ISConstants.h:797
void quatdDCM(const ixVector4d q, ixMatrix3 mat)
Definition: ISPose.c:491
f_t ixMatrix3[9]
Definition: ISConstants.h:799
void euler2quat(const ixEuler euler, ixQuat q)
Definition: ISPose.c:218
void quat2psi(const ixQuat q, f_t *psi)
Definition: ISPose.c:204
void quatConjRot(ixVector3 result, const ixQuat q, const ixVector3 v)
Definition: ISPose.c:161
void qe2b2EulerNedEcef(ixVector3 theta, const ixVector4 qe2b, const ixVector3d ecef)
Definition: ISPose.c:281
void quat_Vec3_Vec3(ixQuat result, const ixVector3 v1, const ixVector3 v2)
Definition: ISPose.c:118
void mul_Quat_Quat(ixQuat result, const ixQuat q1, const ixQuat q2)
Definition: ISPose.c:64
void mul_Quat_ConjQuat(ixQuat result, const ixQuat q1, const ixQuat qc)
Definition: ISPose.c:92
void quat_init(ixQuat q)
Definition: ISPose.c:34
void eulerReferenceToBody(const ixEuler e, const ixEuler rot, ixEuler result)
Definition: ISPose.c:686
void eulerDCM_Trans(const ixEuler euler, ixMatrix3 m)
Definition: ISPose.c:413
void dpsi_dq(const ixQuat q, ixQuat dq)
Definition: ISPose.c:632
void qe2b2EulerNedLLA(ixVector3 eul, const ixVector4 qe2b, const ixVector3d lla)
Definition: ISPose.c:294
void quat_ecef2ned(float lat, float lon, float *qe2n)
Definition: ISPose.c:267
void vectorBodyToReference(const ixVector3 v, const ixEuler rot, ixVector3 result)
Definition: ISPose.c:702
f_t ixVector4[4]
Definition: ISConstants.h:793
f_t DCMpsi(const f_t *m)
Definition: ISPose.c:340
void eulerWx(const ixEuler euler, ixMatrix3 mat)
Definition: ISPose.c:545
void quatConj(ixQuat result, const ixQuat q)
Definition: ISPose.c:49
void mul_ConjQuat_Quat(ixQuat result, const ixQuat qc, const ixQuat q2)
Definition: ISPose.c:78


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57