| 
									
										
										
										
											2012-05-04 01:03:16 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file PoseRTV.h | 
					
						
							|  |  |  |  * @brief Pose3 with translational velocity | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-14 02:56:21 +08:00
										 |  |  | #include <gtsam_unstable/base/dllexport.h>
 | 
					
						
							| 
									
										
										
										
											2012-05-04 01:03:16 +08:00
										 |  |  | #include <gtsam/geometry/Pose3.h>
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  | #include <gtsam/base/ProductLieGroup.h>
 | 
					
						
							| 
									
										
										
										
											2012-05-04 01:03:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// Syntactic sugar to clarify components
 | 
					
						
							|  |  |  | typedef Point3 Velocity3; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Robot state for use with IMU measurements | 
					
						
							|  |  |  |  * - contains translation, translational velocity and rotation | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  | class GTSAM_UNSTABLE_EXPORT PoseRTV : public ProductLieGroup<Pose3,Velocity3> { | 
					
						
							| 
									
										
										
										
											2012-05-04 01:03:16 +08:00
										 |  |  | protected: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   typedef ProductLieGroup<Pose3,Velocity3> Base; | 
					
						
							| 
									
										
										
										
											2014-12-23 06:42:52 +08:00
										 |  |  |   typedef OptionalJacobian<9, 9> ChartJacobian; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-04 01:03:16 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2014-12-15 01:59:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // constructors - with partial versions
 | 
					
						
							|  |  |  |   PoseRTV() {} | 
					
						
							| 
									
										
										
										
											2015-05-26 08:13:08 +08:00
										 |  |  |   PoseRTV(const Point3& t, const Rot3& rot, const Velocity3& vel) | 
					
						
							|  |  |  |   : Base(Pose3(rot, t), vel) {} | 
					
						
							|  |  |  |   PoseRTV(const Rot3& rot, const Point3& t, const Velocity3& vel) | 
					
						
							|  |  |  |   : Base(Pose3(rot, t), vel) {} | 
					
						
							|  |  |  |   explicit PoseRTV(const Point3& t) | 
					
						
							|  |  |  |   : Base(Pose3(Rot3(), t),Velocity3()) {} | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   PoseRTV(const Pose3& pose, const Velocity3& vel) | 
					
						
							| 
									
										
										
										
											2015-05-26 08:13:08 +08:00
										 |  |  |   : Base(pose, vel) {} | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   explicit PoseRTV(const Pose3& pose) | 
					
						
							| 
									
										
										
										
											2015-05-26 08:13:08 +08:00
										 |  |  |   : Base(pose,Velocity3()) {} | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   // Construct from Base
 | 
					
						
							|  |  |  |   PoseRTV(const Base& base) | 
					
						
							|  |  |  |   : Base(base) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** build from components - useful for data files */ | 
					
						
							|  |  |  |   PoseRTV(double roll, double pitch, double yaw, double x, double y, double z, | 
					
						
							|  |  |  |       double vx, double vy, double vz); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** build from single vector - useful for Matlab - in RtV format */ | 
					
						
							|  |  |  |   explicit PoseRTV(const Vector& v); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // access
 | 
					
						
							| 
									
										
										
										
											2015-05-26 08:13:08 +08:00
										 |  |  |   const Pose3& pose() const { return first; } | 
					
						
							|  |  |  |   const Velocity3& v() const { return second; } | 
					
						
							|  |  |  |   const Point3& t() const { return pose().translation(); } | 
					
						
							|  |  |  |   const Rot3& R() const { return pose().rotation(); } | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // longer function names
 | 
					
						
							| 
									
										
										
										
											2015-05-26 08:13:08 +08:00
										 |  |  |   const Point3& translation() const { return pose().translation(); } | 
					
						
							|  |  |  |   const Rot3& rotation() const { return pose().rotation(); } | 
					
						
							|  |  |  |   const Velocity3& velocity() const { return second; } | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Access to vector for ease of use with Matlab
 | 
					
						
							|  |  |  |   // and avoidance of Point3
 | 
					
						
							|  |  |  |   Vector vector() const; | 
					
						
							| 
									
										
										
										
											2015-05-26 08:13:08 +08:00
										 |  |  |   Vector translationVec() const { return pose().translation().vector(); } | 
					
						
							|  |  |  |   Vector velocityVec() const { return velocity().vector(); } | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // testable
 | 
					
						
							|  |  |  |   bool equals(const PoseRTV& other, double tol=1e-6) const; | 
					
						
							|  |  |  |   void print(const std::string& s="") const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   /// @name Manifold
 | 
					
						
							|  |  |  |   /// @{
 | 
					
						
							|  |  |  |   using Base::dimension; | 
					
						
							|  |  |  |   using Base::dim; | 
					
						
							|  |  |  |   using Base::Dim; | 
					
						
							|  |  |  |   using Base::retract; | 
					
						
							|  |  |  |   using Base::localCoordinates; | 
					
						
							|  |  |  |   /// @}
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   /// @name measurement functions
 | 
					
						
							|  |  |  |   /// @{
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   /** range between translations */ | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   double range(const PoseRTV& other, | 
					
						
							| 
									
										
										
										
											2014-12-23 06:42:52 +08:00
										 |  |  |                OptionalJacobian<1,9> H1=boost::none, | 
					
						
							|  |  |  |                OptionalJacobian<1,9> H2=boost::none) const; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   /// @}
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   /// @name IMU-specific
 | 
					
						
							|  |  |  |   /// @{
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// Dynamics integrator for ground robots
 | 
					
						
							|  |  |  |   /// Always move from time 1 to time 2
 | 
					
						
							|  |  |  |   PoseRTV planarDynamics(double vel_rate, double heading_rate, double max_accel, double dt) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Simulates flying robot with simple flight model
 | 
					
						
							|  |  |  |   /// Integrates state x1 -> x2 given controls
 | 
					
						
							|  |  |  |   /// x1 = {p1, r1, v1}, x2 = {p2, r2, v2}, all in global coordinates
 | 
					
						
							|  |  |  |   /// @return x2
 | 
					
						
							|  |  |  |   PoseRTV flyingDynamics(double pitch_rate, double heading_rate, double lift_control, double dt) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// General Dynamics update - supply control inputs in body frame
 | 
					
						
							|  |  |  |   PoseRTV generalDynamics(const Vector& accel, const Vector& gyro, double dt) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Dynamics predictor for both ground and flying robots, given states at 1 and 2
 | 
					
						
							|  |  |  |   /// Always move from time 1 to time 2
 | 
					
						
							|  |  |  |   /// @return imu measurement, as [accel, gyro]
 | 
					
						
							| 
									
										
										
										
											2014-11-04 22:41:14 +08:00
										 |  |  |   Vector6 imuPrediction(const PoseRTV& x2, double dt) const; | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// predict measurement and where Point3 for x2 should be, as a way
 | 
					
						
							|  |  |  |   /// of enforcing a velocity constraint
 | 
					
						
							|  |  |  |   /// This version splits out the rotation and velocity for x2
 | 
					
						
							|  |  |  |   Point3 translationIntegration(const Rot3& r2, const Velocity3& v2, double dt) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// predict measurement and where Point3 for x2 should be, as a way
 | 
					
						
							|  |  |  |   /// of enforcing a velocity constraint
 | 
					
						
							|  |  |  |   /// This version takes a full PoseRTV, but ignores the existing translation for x2
 | 
					
						
							|  |  |  |   inline Point3 translationIntegration(const PoseRTV& x2, double dt) const { | 
					
						
							|  |  |  |     return translationIntegration(x2.rotation(), x2.velocity(), dt); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// @return a vector for Matlab compatibility
 | 
					
						
							|  |  |  |   inline Vector translationIntegrationVec(const PoseRTV& x2, double dt) const { | 
					
						
							|  |  |  |     return translationIntegration(x2, dt).vector(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Apply transform to this pose, with optional derivatives | 
					
						
							|  |  |  |    * equivalent to: | 
					
						
							|  |  |  |    * local = trans.transform_from(global, Dtrans, Dglobal) | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Note: the transform jacobian convention is flipped | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   PoseRTV transformed_from(const Pose3& trans, | 
					
						
							| 
									
										
										
										
											2014-12-23 06:42:52 +08:00
										 |  |  |       ChartJacobian Dglobal = boost::none, | 
					
						
							|  |  |  |       OptionalJacobian<9, 6> Dtrans = boost::none) const; | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   /// @}
 | 
					
						
							|  |  |  |   /// @name Utility functions
 | 
					
						
							|  |  |  |   /// @{
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// RRTMbn - Function computes the rotation rate transformation matrix from
 | 
					
						
							|  |  |  |   /// body axis rates to euler angle (global) rates
 | 
					
						
							|  |  |  |   static Matrix RRTMbn(const Vector& euler); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static Matrix RRTMbn(const Rot3& att); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// RRTMnb - Function computes the rotation rate transformation matrix from
 | 
					
						
							|  |  |  |   /// euler angle rates to body axis rates
 | 
					
						
							|  |  |  |   static Matrix RRTMnb(const Vector& euler); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static Matrix RRTMnb(const Rot3& att); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:50:00 +08:00
										 |  |  |   /// @}
 | 
					
						
							| 
									
										
										
										
											2012-06-06 21:04:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-04 01:03:16 +08:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** Serialization function */ | 
					
						
							|  |  |  |   friend class boost::serialization::access; | 
					
						
							|  |  |  |   template<class Archive> | 
					
						
							| 
									
										
										
										
											2015-03-06 23:12:09 +08:00
										 |  |  |   void serialize(Archive & ar, const unsigned int /*version*/) { | 
					
						
							| 
									
										
										
										
											2015-05-26 08:13:08 +08:00
										 |  |  |     ar & BOOST_SERIALIZATION_NVP(first); | 
					
						
							|  |  |  |     ar & BOOST_SERIALIZATION_NVP(second); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-05-04 01:03:16 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-22 00:02:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							| 
									
										
										
										
											2015-05-26 13:04:04 +08:00
										 |  |  | struct traits<PoseRTV> : public internal::LieGroup<PoseRTV> {}; | 
					
						
							| 
									
										
										
										
											2014-10-22 00:02:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-04 01:03:16 +08:00
										 |  |  | } // \namespace gtsam
 |