eigen_mav_msgs.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Fadri Furrer, ASL, ETH Zurich, Switzerland
3  * Copyright 2015 Michael Burri, ASL, ETH Zurich, Switzerland
4  * Copyright 2015 Markus Achtelik, ASL, ETH Zurich, Switzerland
5  * Copyright 2015 Helen Oleynikova, ASL, ETH Zurich, Switzerland
6  * Copyright 2015 Mina Kamel, ASL, ETH Zurich, Switzerland
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef MAV_MSGS_EIGEN_MAV_MSGS_H
22 #define MAV_MSGS_EIGEN_MAV_MSGS_H
23 
24 #include <Eigen/Eigen>
25 #include <deque>
26 #include <iostream>
27 
28 #include "mav_msgs/common.h"
29 
30 namespace mav_msgs {
31 
33 enum MavActuation { DOF4 = 4, DOF6 = 6 };
34 
37  : attitude(Eigen::Quaterniond::Identity()),
38  thrust(Eigen::Vector3d::Zero()) {}
39  EigenAttitudeThrust(const Eigen::Quaterniond& _attitude,
40  const Eigen::Vector3d& _thrust) {
41  attitude = _attitude;
42  thrust = _thrust;
43  }
44 
45  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
46  Eigen::Quaterniond attitude;
47  Eigen::Vector3d thrust;
48 };
49 
51  // TODO(ffurrer): Find a proper way of initializing :)
52 
53  EigenActuators(const Eigen::VectorXd& _angular_velocities) {
54  angular_velocities = _angular_velocities;
55  }
56 
57  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
58  Eigen::VectorXd angles; // In rad.
59  Eigen::VectorXd angular_velocities; // In rad/s.
60  Eigen::VectorXd normalized; // Everything else, normalized [-1 to 1].
61 };
62 
65  : angular_rates(Eigen::Vector3d::Zero()),
66  thrust(Eigen::Vector3d::Zero()) {}
67 
68  EigenRateThrust(const Eigen::Vector3d& _angular_rates,
69  const Eigen::Vector3d _thrust)
70  : angular_rates(_angular_rates), thrust(_thrust) {}
71 
72  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
73  Eigen::Vector3d angular_rates;
74  Eigen::Vector3d thrust;
75 };
76 
79  : torque(Eigen::Vector3d::Zero()), thrust(Eigen::Vector3d::Zero()) {}
80 
81  EigenTorqueThrust(const Eigen::Vector3d& _torque,
82  const Eigen::Vector3d _thrust)
83  : torque(_torque), thrust(_thrust) {}
84 
85  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
86  Eigen::Vector3d torque;
87  Eigen::Vector3d thrust;
88 };
89 
92  : roll(0.0), pitch(0.0), yaw_rate(0.0), thrust(Eigen::Vector3d::Zero()) {}
93 
94  EigenRollPitchYawrateThrust(double _roll, double _pitch, double _yaw_rate,
95  const Eigen::Vector3d& _thrust)
96  : roll(_roll), pitch(_pitch), yaw_rate(_yaw_rate), thrust(_thrust) {}
97 
98  double roll;
99  double pitch;
100  double yaw_rate;
101  Eigen::Vector3d thrust;
102 };
103 
112  public:
113  typedef std::vector<EigenMavState,
114  Eigen::aligned_allocator<EigenMavState>> Vector;
115  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
116 
119  : position_W(Eigen::Vector3d::Zero()),
120  velocity_W(Eigen::Vector3d::Zero()),
121  acceleration_B(Eigen::Vector3d::Zero()),
122  orientation_W_B(Eigen::Quaterniond::Identity()),
123  angular_velocity_B(Eigen::Vector3d::Zero()),
124  angular_acceleration_B(Eigen::Vector3d::Zero()) {}
125 
126  EigenMavState(const Eigen::Vector3d& position_W,
127  const Eigen::Vector3d& velocity_W,
128  const Eigen::Vector3d& acceleration_B,
129  const Eigen::Quaterniond& orientation_W_B,
130  const Eigen::Vector3d& angular_velocity_B,
131  const Eigen::Vector3d& angular_acceleration_B)
132  : position_W(position_W),
133  velocity_W(velocity_W),
134  acceleration_B(acceleration_B),
135  orientation_W_B(orientation_W_B),
136  angular_velocity_B(angular_velocity_B),
137  angular_acceleration_B(angular_acceleration_B) {}
138 
139  std::string toString() const {
140  std::stringstream ss;
141  ss << "position: " << position_W.transpose() << std::endl
142  << "velocity: " << velocity_W.transpose() << std::endl
143  << "acceleration_body: " << acceleration_B.transpose() << std::endl
144  << "orientation (w-x-y-z): " << orientation_W_B.w() << " "
145  << orientation_W_B.x() << " " << orientation_W_B.y() << " "
146  << orientation_W_B.z() << " " << std::endl
147  << "angular_velocity_body: " << angular_velocity_B.transpose()
148  << std::endl
149  << "angular_acceleration_body: " << angular_acceleration_B.transpose()
150  << std::endl;
151 
152  return ss.str();
153  }
154 
155  Eigen::Vector3d position_W;
156  Eigen::Vector3d velocity_W;
157  Eigen::Vector3d acceleration_B;
158  Eigen::Quaterniond orientation_W_B;
159  Eigen::Vector3d angular_velocity_B;
160  Eigen::Vector3d angular_acceleration_B;
161 };
162 
164  typedef std::vector<EigenTrajectoryPoint,
165  Eigen::aligned_allocator<EigenTrajectoryPoint>> Vector;
167  : timestamp_ns(-1),
168  time_from_start_ns(0),
169  position_W(Eigen::Vector3d::Zero()),
170  velocity_W(Eigen::Vector3d::Zero()),
171  acceleration_W(Eigen::Vector3d::Zero()),
172  jerk_W(Eigen::Vector3d::Zero()),
173  snap_W(Eigen::Vector3d::Zero()),
174  orientation_W_B(Eigen::Quaterniond::Identity()),
175  angular_velocity_W(Eigen::Vector3d::Zero()),
176  angular_acceleration_W(Eigen::Vector3d::Zero()),
177  degrees_of_freedom(MavActuation::DOF4) {}
178 
179  EigenTrajectoryPoint(int64_t _time_from_start_ns,
180  const Eigen::Vector3d& _position,
181  const Eigen::Vector3d& _velocity,
182  const Eigen::Vector3d& _acceleration,
183  const Eigen::Vector3d& _jerk,
184  const Eigen::Vector3d& _snap,
185  const Eigen::Quaterniond& _orientation,
186  const Eigen::Vector3d& _angular_velocity,
187  const Eigen::Vector3d& _angular_acceleration,
188  const MavActuation& _degrees_of_freedom = MavActuation::DOF4)
189  : time_from_start_ns(_time_from_start_ns),
190  position_W(_position),
191  velocity_W(_velocity),
192  acceleration_W(_acceleration),
193  jerk_W(_jerk),
194  snap_W(_snap),
195  orientation_W_B(_orientation),
196  angular_velocity_W(_angular_velocity),
197  angular_acceleration_W(_angular_acceleration),
198  degrees_of_freedom(_degrees_of_freedom) {}
199 
200  EigenTrajectoryPoint(int64_t _time_from_start_ns,
201  const Eigen::Vector3d& _position,
202  const Eigen::Vector3d& _velocity,
203  const Eigen::Vector3d& _acceleration,
204  const Eigen::Vector3d& _jerk,
205  const Eigen::Vector3d& _snap,
206  const Eigen::Quaterniond& _orientation,
207  const Eigen::Vector3d& _angular_velocity,
208  const MavActuation& _degrees_of_freedom = MavActuation::DOF4)
209  : EigenTrajectoryPoint(_time_from_start_ns, _position, _velocity,
210  _acceleration, _jerk, _snap, _orientation,
211  _angular_velocity, Eigen::Vector3d::Zero(), _degrees_of_freedom) {}
212 
213  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
214  int64_t timestamp_ns; // Time since epoch, negative value = invalid timestamp.
216  Eigen::Vector3d position_W;
217  Eigen::Vector3d velocity_W;
218  Eigen::Vector3d acceleration_W;
219  Eigen::Vector3d jerk_W;
220  Eigen::Vector3d snap_W;
221 
222  Eigen::Quaterniond orientation_W_B;
223  Eigen::Vector3d angular_velocity_W;
224  Eigen::Vector3d angular_acceleration_W;
226 
227  // Accessors for making dealing with orientation/angular velocity easier.
228  inline double getYaw() const { return yawFromQuaternion(orientation_W_B); }
229  inline double getYawRate() const { return angular_velocity_W.z(); }
230  inline double getYawAcc() const { return angular_acceleration_W.z(); }
231  // WARNING: sets roll and pitch to 0.
232  inline void setFromYaw(double yaw) {
233  orientation_W_B = quaternionFromYaw(yaw);
234  }
235  inline void setFromYawRate(double yaw_rate) {
236  angular_velocity_W.x() = 0.0;
237  angular_velocity_W.y() = 0.0;
238  angular_velocity_W.z() = yaw_rate;
239  }
240  inline void setFromYawAcc(double yaw_acc) {
241  angular_acceleration_W.x() = 0.0;
242  angular_acceleration_W.y() = 0.0;
243  angular_acceleration_W.z() = yaw_acc;
244  }
245 
246  std::string toString() const {
247  std::stringstream ss;
248  ss << "position: " << position_W.transpose() << std::endl
249  << "velocity: " << velocity_W.transpose() << std::endl
250  << "acceleration: " << acceleration_W.transpose() << std::endl
251  << "jerk: " << jerk_W.transpose() << std::endl
252  << "snap: " << snap_W.transpose() << std::endl
253  << "yaw: " << getYaw() << std::endl
254  << "yaw_rate: " << getYawRate() << std::endl
255  << "yaw_acc: " << getYawAcc() << std::endl;
256 
257  return ss.str();
258  }
259 };
260 
261 // Operator overload to transform Trajectory Points according to the Eigen
262 // interfaces (uses operator* for this).
263 // Has to be outside of class.
264 // Example:
265 // Eigen::Affine3d transform; EigenTrajectoryPoint point;
266 // EigenTrajectoryPoint transformed = transform * point;
267 inline EigenTrajectoryPoint operator*(const Eigen::Affine3d& lhs,
268  const EigenTrajectoryPoint& rhs) {
269  EigenTrajectoryPoint transformed(rhs);
270  transformed.position_W = lhs * rhs.position_W;
271  transformed.velocity_W = lhs.rotation() * rhs.velocity_W;
272  transformed.acceleration_W = lhs.rotation() * rhs.acceleration_W;
273  transformed.jerk_W = lhs.rotation() * rhs.jerk_W;
274  transformed.snap_W = lhs.rotation() * rhs.snap_W;
275  transformed.orientation_W_B = lhs.rotation() * rhs.orientation_W_B;
276  transformed.angular_velocity_W = lhs.rotation() * rhs.angular_velocity_W;
277  transformed.angular_acceleration_W =
278  lhs.rotation() * rhs.angular_acceleration_W;
279  return transformed;
280 }
281 
284  : timestamp_ns(-1),
285  position_W(Eigen::Vector3d::Zero()),
286  orientation_W_B(Eigen::Quaterniond::Identity()),
287  velocity_B(Eigen::Vector3d::Zero()),
288  angular_velocity_B(Eigen::Vector3d::Zero()) {}
289 
290  EigenOdometry(const Eigen::Vector3d& _position,
291  const Eigen::Quaterniond& _orientation,
292  const Eigen::Vector3d& _velocity_body,
293  const Eigen::Vector3d& _angular_velocity)
294  : position_W(_position),
295  orientation_W_B(_orientation),
296  velocity_B(_velocity_body),
297  angular_velocity_B(_angular_velocity) {}
298 
299  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
300  int64_t timestamp_ns; // Time since epoch, negative value = invalid timestamp.
301  Eigen::Vector3d position_W;
302  Eigen::Quaterniond orientation_W_B;
303  Eigen::Vector3d velocity_B; // Velocity in expressed in the Body frame!
304  Eigen::Vector3d angular_velocity_B;
305  Eigen::Matrix<double, 6, 6> pose_covariance_;
306  Eigen::Matrix<double, 6, 6> twist_covariance_;
307 
308  // Accessors for making dealing with orientation/angular velocity easier.
309  inline double getYaw() const { return yawFromQuaternion(orientation_W_B); }
310  inline void getEulerAngles(Eigen::Vector3d* euler_angles) const {
311  getEulerAnglesFromQuaternion(orientation_W_B, euler_angles);
312  }
313  inline double getYawRate() const { return angular_velocity_B.z(); }
314  // WARNING: sets roll and pitch to 0.
315  inline void setFromYaw(double yaw) {
316  orientation_W_B = quaternionFromYaw(yaw);
317  }
318  inline void setFromYawRate(double yaw_rate) {
319  angular_velocity_B.x() = 0.0;
320  angular_velocity_B.y() = 0.0;
321  angular_velocity_B.z() = yaw_rate;
322  }
323 
324  inline Eigen::Vector3d getVelocityWorld() const {
325  return orientation_W_B * velocity_B;
326  }
327  inline void setVelocityWorld(const Eigen::Vector3d& velocity_world) {
328  velocity_B = orientation_W_B.inverse() * velocity_world;
329  }
330 };
331 
332 // TODO(helenol): replaced with aligned allocator headers from Simon.
333 #define MAV_MSGS_CONCATENATE(x, y) x##y
334 #define MAV_MSGS_CONCATENATE2(x, y) MAV_MSGS_CONCATENATE(x, y)
335 #define MAV_MSGS_MAKE_ALIGNED_CONTAINERS(EIGEN_TYPE) \
336  typedef std::vector<EIGEN_TYPE, Eigen::aligned_allocator<EIGEN_TYPE>> \
337  MAV_MSGS_CONCATENATE2(EIGEN_TYPE, Vector); \
338  typedef std::deque<EIGEN_TYPE, Eigen::aligned_allocator<EIGEN_TYPE>> \
339  MAV_MSGS_CONCATENATE2(EIGEN_TYPE, Deque);
340 
342 MAV_MSGS_MAKE_ALIGNED_CONTAINERS(EigenActuators)
343 MAV_MSGS_MAKE_ALIGNED_CONTAINERS(EigenRateThrust)
344 MAV_MSGS_MAKE_ALIGNED_CONTAINERS(EigenTrajectoryPoint)
345 MAV_MSGS_MAKE_ALIGNED_CONTAINERS(EigenRollPitchYawrateThrust)
347 }
348 
349 #endif // MAV_MSGS_EIGEN_MAV_MSGS_H
#define MAV_MSGS_MAKE_ALIGNED_CONTAINERS(EIGEN_TYPE)
Eigen::VectorXd normalized
Eigen::Vector3d getVelocityWorld() const
Eigen::Vector3d position_W
void setFromYawRate(double yaw_rate)
EigenRateThrust(const Eigen::Vector3d &_angular_rates, const Eigen::Vector3d _thrust)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW int64_t timestamp_ns
void setFromYawRate(double yaw_rate)
EigenMavState(const Eigen::Vector3d &position_W, const Eigen::Vector3d &velocity_W, const Eigen::Vector3d &acceleration_B, const Eigen::Quaterniond &orientation_W_B, const Eigen::Vector3d &angular_velocity_B, const Eigen::Vector3d &angular_acceleration_B)
std::string toString() const
double getYaw() const
EigenActuators(const Eigen::VectorXd &_angular_velocities)
MavActuation
Actuated degrees of freedom.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EigenMavState()
Initializes all members to zero / identity.
Eigen::Vector3d velocity_B
EigenTrajectoryPoint(int64_t _time_from_start_ns, const Eigen::Vector3d &_position, const Eigen::Vector3d &_velocity, const Eigen::Vector3d &_acceleration, const Eigen::Vector3d &_jerk, const Eigen::Vector3d &_snap, const Eigen::Quaterniond &_orientation, const Eigen::Vector3d &_angular_velocity, const Eigen::Vector3d &_angular_acceleration, const MavActuation &_degrees_of_freedom=MavActuation::DOF4)
EigenOdometry(const Eigen::Vector3d &_position, const Eigen::Quaterniond &_orientation, const Eigen::Vector3d &_velocity_body, const Eigen::Vector3d &_angular_velocity)
std::vector< EigenMavState, Eigen::aligned_allocator< EigenMavState > > Vector
std::string toString() const
void setFromYaw(double yaw)
Eigen::Matrix< double, 6, 6 > twist_covariance_
Eigen::Matrix< double, 6, 6 > pose_covariance_
Eigen::Quaterniond orientation_W_B
void setVelocityWorld(const Eigen::Vector3d &velocity_world)
void getEulerAnglesFromQuaternion(const Eigen::Quaternion< double > &q, Eigen::Vector3d *euler_angles)
Definition: common.h:134
EigenAttitudeThrust(const Eigen::Quaterniond &_attitude, const Eigen::Vector3d &_thrust)
EigenTrajectoryPoint(int64_t _time_from_start_ns, const Eigen::Vector3d &_position, const Eigen::Vector3d &_velocity, const Eigen::Vector3d &_acceleration, const Eigen::Vector3d &_jerk, const Eigen::Vector3d &_snap, const Eigen::Quaterniond &_orientation, const Eigen::Vector3d &_angular_velocity, const MavActuation &_degrees_of_freedom=MavActuation::DOF4)
EigenTorqueThrust(const Eigen::Vector3d &_torque, const Eigen::Vector3d _thrust)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d angular_rates
Eigen::VectorXd angular_velocities
EIGEN_MAKE_ALIGNED_OPERATOR_NEW int64_t timestamp_ns
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::VectorXd angles
EigenRollPitchYawrateThrust(double _roll, double _pitch, double _yaw_rate, const Eigen::Vector3d &_thrust)
Eigen::Quaterniond orientation_W_B
std::vector< EigenTrajectoryPoint, Eigen::aligned_allocator< EigenTrajectoryPoint > > Vector
Eigen::Vector3d position_W
Eigen::Vector3d angular_acceleration_B
double yawFromQuaternion(const Eigen::Quaterniond &q)
Extracts the yaw part from a quaternion, using RPY / euler (z-y&#39;-z&#39;&#39;) angles. RPY rotates about the f...
Definition: common.h:107
void getEulerAngles(Eigen::Vector3d *euler_angles) const
void setFromYawAcc(double yaw_acc)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Quaterniond attitude
Container holding the state of a MAV: position, velocity, attitude and angular velocity. In addition, holds the acceleration expressed in body coordinates, which is what the accelerometer usually measures.
Eigen::Vector3d angular_velocity_B
double getYawRate() const
Eigen::Vector3d angular_acceleration_W
Eigen::Quaterniond orientation_W_B
Eigen::Quaterniond quaternionFromYaw(double yaw)
Definition: common.h:112
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d torque
Eigen::Vector3d velocity_W
Eigen::Vector3d angular_velocity_B
Eigen::Vector3d acceleration_B
EigenTrajectoryPoint operator*(const Eigen::Affine3d &lhs, const EigenTrajectoryPoint &rhs)


mav_msgs
Author(s): Simon Lynen, Markus Achtelik, Pascal Gohl, Sammy Omari, Michael Burri, Fadri Furrer, Helen Oleynikova, Mina Kamel, Karen Bodie, Rik Bähnemann
autogenerated on Thu Jan 23 2020 03:14:00