| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 05:27:38 +08:00
										 |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  *  @file  Event | 
					
						
							|  |  |  |  *  @brief Space-time event | 
					
						
							|  |  |  |  *  @author Frank Dellaert | 
					
						
							|  |  |  |  *  @author Jay Chakravarty | 
					
						
							|  |  |  |  *  @date December 2014 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam/geometry/Point3.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  | #include <gtsam_unstable/dllexport.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | #include <cmath>
 | 
					
						
							| 
									
										
										
										
											2016-11-02 03:11:57 +08:00
										 |  |  | #include <iosfwd>
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * A space-time event models an event that happens at a certain 3D location, at | 
					
						
							|  |  |  |  * a certain time. One use for it is in sound-based or UWB-ranging tracking or | 
					
						
							|  |  |  |  * SLAM, where we have "time of arrival" measurements at a set of sensors. The | 
					
						
							|  |  |  |  * TOA functor below provides a measurement function for those applications. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | class Event { | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   double time_;      ///< Time event was generated
 | 
					
						
							|  |  |  |   Point3 location_;  ///< Location at time event was generated
 | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2014-12-29 01:24:00 +08:00
										 |  |  |   enum { dimension = 4 }; | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// Default Constructor
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   Event() : time_(0), location_(0, 0, 0) {} | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// Constructor from time and location
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   Event(double t, const Point3& p) : time_(t), location_(p) {} | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// Constructor with doubles
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   Event(double t, double x, double y, double z) | 
					
						
							|  |  |  |       : time_(t), location_(x, y, z) {} | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   double time() const { return time_; } | 
					
						
							|  |  |  |   Point3 location() const { return location_; } | 
					
						
							| 
									
										
										
										
											2014-12-11 04:44:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   // TODO(frank) we really have to think of a better way to do linear arguments
 | 
					
						
							|  |  |  |   double height(OptionalJacobian<1, 4> H = boost::none) const { | 
					
						
							|  |  |  |     static const Matrix14 JacobianZ = (Matrix14() << 0, 0, 0, 1).finished(); | 
					
						
							| 
									
										
										
										
											2014-12-11 20:45:15 +08:00
										 |  |  |     if (H) *H = JacobianZ; | 
					
						
							|  |  |  |     return location_.z(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  |   /** print with optional string */ | 
					
						
							| 
									
										
										
										
											2019-07-18 17:09:08 +08:00
										 |  |  |   GTSAM_UNSTABLE_EXPORT void print(const std::string& s = "") const; | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** equals with an tolerance */ | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   GTSAM_UNSTABLE_EXPORT bool equals(const Event& other, | 
					
						
							|  |  |  |                                     double tol = 1e-9) const; | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// Updates a with tangent space delta
 | 
					
						
							|  |  |  |   inline Event retract(const Vector4& v) const { | 
					
						
							| 
									
										
										
										
											2016-02-09 05:27:38 +08:00
										 |  |  |     return Event(time_ + v[0], location_ + Point3(v.tail<3>())); | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Returns inverse retraction
 | 
					
						
							|  |  |  |   inline Vector4 localCoordinates(const Event& q) const { | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |     return Vector4::Zero();  // TODO(frank) implement!
 | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Define GTSAM traits
 | 
					
						
							|  |  |  | template <> | 
					
						
							|  |  |  | struct traits<Event> : internal::Manifold<Event> {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// Time of arrival to given sensor
 | 
					
						
							|  |  |  | class TimeOfArrival { | 
					
						
							|  |  |  |   const double speed_;  ///< signal speed
 | 
					
						
							| 
									
										
										
										
											2020-03-19 05:28:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |  public: | 
					
						
							|  |  |  |   typedef double result_type; | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   /// Constructor with optional speed of signal, in m/sec
 | 
					
						
							|  |  |  |   explicit TimeOfArrival(double speed = 330) : speed_(speed) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Calculate time of arrival
 | 
					
						
							| 
									
										
										
										
											2020-03-19 05:28:40 +08:00
										 |  |  |   double measure(const Event& event, const Point3& sensor) const { | 
					
						
							|  |  |  |     double distance = gtsam::distance3(event.location(), sensor); | 
					
						
							|  |  |  |     return event.time() + distance / speed_; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Calculate time of arrival, with derivatives
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |   double operator()(const Event& event, const Point3& sensor,  //
 | 
					
						
							|  |  |  |                     OptionalJacobian<1, 4> H1 = boost::none,   //
 | 
					
						
							|  |  |  |                     OptionalJacobian<1, 3> H2 = boost::none) const { | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  |     Matrix13 D1, D2; | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |     double distance = gtsam::distance3(event.location(), sensor, D1, D2); | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  |     if (H1) | 
					
						
							|  |  |  |       // derivative of toa with respect to event
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |       *H1 << 1.0, D1 / speed_; | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  |     if (H2) | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  |       // derivative of toa with respect to sensor location
 | 
					
						
							|  |  |  |       *H2 << D2 / speed_; | 
					
						
							|  |  |  |     return event.time() + distance / speed_; | 
					
						
							| 
									
										
										
										
											2014-12-11 02:14:18 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-18 02:34:11 +08:00
										 |  |  | }  // namespace gtsam
 |