ROBOOP, A Robotics Object Oriented Package in C++
quaternion.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2004 Etienne Lachance
3 
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8 
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 Report problems and direct all questions to:
20 
21 email: etienne.lachance@polymtl.ca or richard.gourdeau@polymtl.ca
22 
23 Reference:
24 
25 [1] J.C.K. Chou, "Quaternion Kinematic and Dynamic Differential Equations",
26  IEEE Transaction on Robotics and Automation, vol 8, p53-64.
27 
28 [2] S. Chiaverini, B. Siciliano, "The Unit Quaternion: A Useful Tool for
29  Inverse Kinematics of Robot Manipulators", Systems Analysis, Modelling
30  and Simulation, vol. 35, pp.45-60, 1999.
31 
32 [3] C. Natale, "Quaternion-Based Representation of Rigid Bodies Orientation",
33  PRISMA LAB, PRISMA Technical Report no. 97-05, Oct 1997.
34 
35 [4] M. Lillholm, E.B. Dam, M. Koch, "Quaternions, Interpolation and Animation",
36  Technical Report DIKU-TR-98/5, University of Copenhagen, July 1998.
37 
38 [5] D. Eberly, "Quaternion Algebra and Calculus", Magic Software Inc.,
39  http://www.magic-software.com, March 1999.
40 -------------------------------------------------------------------------------
41 Revision_history:
42 
43 2003/05/28: Etienne Lachance
44  -Added functions Slerp, Slerp_prime, Squad, Squad_prime.
45  -Added the following member functions:+=, -=, *=, /=, Exp, d_dt, Ln, Ln_4, E
46 
47 2004/05/21: Etienne Lachance
48  -Added Doxygen comments.
49 
50 2004/07/01: Ethan Tira-Thompson
51  -Added support for newmat's use_namespace #define, using ROBOOP namespace
52 
53 2005/11/06: Etienne Lachance
54  - No need to provide a copy constructor and the assignment operator
55  (operator=) for Quaternion class. Instead we use the one provide by the
56  compiler.
57 
58 2005/11/13: Etienne Lachance
59  - operator* and operator/ are now non-member functions when one of the
60  operand is a real. With these modifications we support q2 = c * q1 and
61  q2 = q1 * c
62 ------------------------------------------------------------------------------
63 */
64 
65 
66 #ifndef QUATERNION_H
67 #define QUATERNION_H
68 
74 #include "robot.h"
75 
76 #ifdef use_namespace
77 namespace ROBOOP {
78  using namespace NEWMAT;
79 #endif
80 
81 #define BASE_FRAME 0
82 #define BODY_FRAME 1
83 #define EPSILON 0.0000001
84 
90 {
91 public:
92  Quaternion();
93  Quaternion(const Real angle_in_rad, const ColumnVector & axis);
94  Quaternion(const Real s, const Real v1, const Real v2,
95  const Real v3);
96  Quaternion(const Matrix & R);
97 
98  Quaternion operator+(const Quaternion & q)const;
99  Quaternion operator-(const Quaternion & q)const;
100  Quaternion operator*(const Quaternion & q)const;
101  Quaternion operator/(const Quaternion & q)const;
102  Quaternion conjugate()const;
103 
104 // Quaternion i()const { return conjugate(); }
105  Quaternion i()const;
106  Quaternion & unit();
107  Quaternion exp() const;
108  Quaternion power(const Real t) const;
109  Quaternion Log() const;
110 
111  Quaternion dot(const ColumnVector & w, const short sign)const;
112  ReturnMatrix E(const short sign)const;
113 
114  Real norm()const;
115  Real dot_prod(const Quaternion & q)const;
116  Real s()const { return s_; }
117  void set_s(const Real s){ s_ = s; }
118  ReturnMatrix v()const { return v_; }
119  void set_v(const ColumnVector & v);
120  ReturnMatrix R()const;
121  ReturnMatrix T()const;
122 
123 private:
124  Real s_;
125  ColumnVector v_;
126 };
127 
128 // ----------------------------------------------------------------------------
129 
130 Quaternion operator*(const Real c, const Quaternion & rhs);
131 Quaternion operator*(const Quaternion & lhs, const Real c);
132 Quaternion operator/(const Real c, const Quaternion & rhs);
133 Quaternion operator/(const Quaternion & lhs, const Real c);
134 
135 ReturnMatrix Omega(const Quaternion & q, const Quaternion & q_dot);
136 
137 short Integ_quat(Quaternion & dquat_present, Quaternion & dquat_past,
138  Quaternion & quat, const Real dt);
139 Real Integ_Trap_quat_s(const Quaternion & present, Quaternion & past,
140  const Real dt);
141 ReturnMatrix Integ_Trap_quat_v(const Quaternion & present, Quaternion & past,
142  const Real dt);
143 
144 Quaternion Slerp(const Quaternion & q0, const Quaternion & q1, const Real t);
145 Quaternion Slerp_prime(const Quaternion & q0, const Quaternion & q1, const Real t);
146 
147 Quaternion Squad(const Quaternion & p, const Quaternion & a, const Quaternion & b,
148  const Quaternion & q, const Real t);
149 Quaternion Squad_prime(const Quaternion & p, const Quaternion & a, const Quaternion & b,
150  const Quaternion & q, const Real t);
151 
152 #ifdef use_namespace
153 }
154 #endif
155 
156 #endif