2009-08-22 06:23:24 +08:00
|
|
|
/**
|
|
|
|
* @file simulated2D.h
|
|
|
|
* @brief measurement functions and derivatives for simulated 2D robot
|
|
|
|
* @author Frank Dellaert
|
|
|
|
*/
|
|
|
|
|
|
|
|
// \callgraph
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2010-01-19 13:33:44 +08:00
|
|
|
#include "Point2.h"
|
|
|
|
#include "TupleConfig.h"
|
2009-08-22 06:23:24 +08:00
|
|
|
#include "NonlinearFactor.h"
|
|
|
|
|
|
|
|
// \namespace
|
|
|
|
|
2010-01-18 13:38:53 +08:00
|
|
|
namespace gtsam {
|
|
|
|
|
|
|
|
namespace simulated2D {
|
Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just says something like
if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
2010-01-14 06:25:03 +08:00
|
|
|
|
2010-01-19 13:33:44 +08:00
|
|
|
// Simulated2D robots have no orientation, just a position
|
|
|
|
typedef TypedSymbol<Point2, 'x'> PoseKey;
|
|
|
|
typedef TypedSymbol<Point2, 'l'> PointKey;
|
|
|
|
typedef PairConfig<PoseKey, Point2, PointKey, Point2> Config;
|
2010-01-14 10:50:06 +08:00
|
|
|
|
2010-01-19 13:33:44 +08:00
|
|
|
/**
|
|
|
|
* Prior on a single pose, and optional derivative version
|
|
|
|
*/
|
|
|
|
inline Point2 prior(const Point2& x) {
|
|
|
|
return x;
|
2010-01-14 10:50:06 +08:00
|
|
|
}
|
2010-01-19 13:33:44 +08:00
|
|
|
Point2 prior(const Point2& x, boost::optional<Matrix&> H = boost::none);
|
2010-01-14 10:50:06 +08:00
|
|
|
|
2010-01-19 13:33:44 +08:00
|
|
|
/**
|
|
|
|
* odometry between two poses, and optional derivative version
|
|
|
|
*/
|
|
|
|
inline Point2 odo(const Point2& x1, const Point2& x2) {
|
|
|
|
return x2 - x1;
|
2010-01-14 10:50:06 +08:00
|
|
|
}
|
2010-01-19 13:33:44 +08:00
|
|
|
Point2 odo(const Point2& x1, const Point2& x2, boost::optional<Matrix&> H1 =
|
|
|
|
boost::none, boost::optional<Matrix&> H2 = boost::none);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* measurement between landmark and pose, and optional derivative version
|
|
|
|
*/
|
|
|
|
inline Point2 mea(const Point2& x, const Point2& l) {
|
|
|
|
return l - x;
|
2010-01-14 10:50:06 +08:00
|
|
|
}
|
2010-01-19 13:33:44 +08:00
|
|
|
Point2 mea(const Point2& x, const Point2& l, boost::optional<Matrix&> H1 =
|
|
|
|
boost::none, boost::optional<Matrix&> H2 = boost::none);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unary factor encoding a soft prior on a vector
|
|
|
|
*/
|
2010-02-23 13:06:16 +08:00
|
|
|
template<class Cfg = Config, class Key = PoseKey>
|
2010-02-10 03:47:39 +08:00
|
|
|
struct GenericPrior: public NonlinearFactor1<Cfg, Key, Point2> {
|
2010-01-19 13:33:44 +08:00
|
|
|
|
|
|
|
Point2 z_;
|
|
|
|
|
2010-02-10 03:47:39 +08:00
|
|
|
GenericPrior(const Point2& z, const SharedGaussian& model, const Key& key) :
|
|
|
|
NonlinearFactor1<Cfg, Key, Point2> (model, key), z_(z) {
|
2010-01-19 13:33:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector evaluateError(const Point2& x, boost::optional<Matrix&> H =
|
|
|
|
boost::none) const {
|
|
|
|
return (prior(x, H) - z_).vector();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binary factor simulating "odometry" between two Vectors
|
|
|
|
*/
|
2010-02-23 13:06:16 +08:00
|
|
|
template<class Cfg = Config, class Key = PoseKey>
|
2010-02-10 03:47:39 +08:00
|
|
|
struct GenericOdometry: public NonlinearFactor2<Cfg, Key, Point2, Key,
|
2010-01-19 13:33:44 +08:00
|
|
|
Point2> {
|
|
|
|
Point2 z_;
|
|
|
|
|
2010-02-23 13:06:16 +08:00
|
|
|
GenericOdometry(const Point2& z, const SharedGaussian& model,
|
|
|
|
const Key& i1, const Key& i2) :
|
|
|
|
z_(z), NonlinearFactor2<Cfg, Key, Point2, Key, Point2> (model, i1, i2) {
|
2010-01-19 13:33:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector evaluateError(const Point2& x1, const Point2& x2, boost::optional<
|
|
|
|
Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 = boost::none) const {
|
|
|
|
return (odo(x1, x2, H1, H2) - z_).vector();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binary factor simulating "measurement" between two Vectors
|
|
|
|
*/
|
2010-02-23 13:06:16 +08:00
|
|
|
template<class Cfg = Config, class XKey = PoseKey, class LKey = PointKey>
|
|
|
|
class GenericMeasurement: public NonlinearFactor2<Cfg, XKey, Point2, LKey,
|
|
|
|
Point2> {
|
|
|
|
public:
|
|
|
|
|
|
|
|
Point2 z_;
|
|
|
|
|
|
|
|
GenericMeasurement(const Point2& z, const SharedGaussian& model,
|
|
|
|
const XKey& i, const LKey& j) :
|
|
|
|
z_(z), NonlinearFactor2<Cfg, XKey, Point2, LKey, Point2> (model, i, j) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector evaluateError(const Point2& x1, const Point2& x2, boost::optional<
|
|
|
|
Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 = boost::none) const {
|
|
|
|
return (mea(x1, x2, H1, H2) - z_).vector();
|
|
|
|
}
|
2010-01-19 13:33:44 +08:00
|
|
|
|
|
|
|
};
|
Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just says something like
if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
2010-01-14 06:25:03 +08:00
|
|
|
|
2010-02-05 22:49:40 +08:00
|
|
|
/** Typedefs for regular use */
|
2010-02-10 03:47:39 +08:00
|
|
|
typedef GenericPrior<Config, PoseKey> Prior;
|
|
|
|
typedef GenericOdometry<Config, PoseKey> Odometry;
|
|
|
|
typedef GenericMeasurement<Config, PoseKey, PointKey> Measurement;
|
2010-02-05 22:49:40 +08:00
|
|
|
|
2010-01-18 13:38:53 +08:00
|
|
|
} // namespace simulated2D
|
|
|
|
} // namespace gtsam
|