00001 #ifndef TAG_MEASUREMENTS_H
00002 #define TAG_MEASUREMENTS_H
00003
00004 #include <TooN/se3.h>
00005
00006 namespace tag {
00007
00013
00017 template <class State>
00018 class IncrementalPose {
00019 public:
00020 static const int M_DIMENSION = 6;
00021
00022 TooN::Matrix<M_DIMENSION> covariance;
00023 TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> jacobian;
00024 TooN::Vector<M_DIMENSION> measurement;
00025
00026 IncrementalPose(void){
00027 TooN::Identity(covariance);
00028 TooN::Zero(jacobian);
00029 TooN::Identity(jacobian.template slice<0,0,6,6>());
00030 TooN::Zero(measurement);
00031 }
00032
00033 inline TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ){
00034 return jacobian;
00035 }
00036
00037 inline TooN::Matrix<M_DIMENSION> & getMeasurementCovariance( const State & state ){
00038 return covariance;
00039 }
00040
00041 inline TooN::Vector<M_DIMENSION> & getInnovation( const State & state ){
00042 return measurement;
00043 }
00044
00045 inline void setMeasurement( const TooN::SE3 & increment ){
00046 measurement = increment.ln();
00047 }
00048 };
00049
00053 template <class State>
00054 class WorldPose {
00055 public:
00056 static const int M_DIMENSION = 6;
00057
00058 TooN::Matrix<M_DIMENSION> covariance;
00059 TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> jacobian;
00060 TooN::SE3 measurement;
00061
00062 WorldPose(void){
00063 TooN::Identity(covariance);
00064 TooN::Zero(jacobian);
00065 TooN::Identity(jacobian.template slice<0,0,6,6>());
00066 }
00067
00068 inline TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ){
00069 return jacobian;
00070 }
00071
00072 inline const TooN::Matrix<M_DIMENSION> & getMeasurementCovariance( const State & state ) const {
00073 TooN::Matrix<M_DIMENSION> localCovariance = covariance;
00074 state.pose.adjoint(localCovariance);
00075 return localCovariance;
00076 }
00077
00078 inline const TooN::Vector<M_DIMENSION> & getInnovation( const State & state ) const {
00079 return (measurement * state.pose.inverse()).ln();
00080 }
00081 };
00082
00086 template <class State>
00087 class WorldPosition {
00088 public:
00089
00090 static const int M_DIMENSION = 3;
00091 TooN::Vector<M_DIMENSION> position;
00092 TooN::Matrix<M_DIMENSION> covariance;
00093 TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> jacobian;
00094
00095 WorldPosition(void){
00096 TooN::Identity(covariance);
00097 TooN::Zero(position);
00098 TooN::Zero(jacobian);
00099 TooN::Identity(jacobian.template slice<0,0,3,3>());
00100 }
00101
00102 inline const TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ) const {
00103 return jacobian;
00104 }
00105
00106 inline const TooN::Matrix<M_DIMENSION> getMeasurementCovariance( const State & state ) const {
00107 TooN::Matrix<2 * M_DIMENSION> localCovariance;
00108 TooN::Zero(localCovariance);
00109 localCovariance.template slice<0,0,3,3>() = covariance;
00110 state.pose.adjoint(localCovariance);
00111 return localCovariance.template slice<0,0,3,3>();
00112 }
00113
00114 inline const TooN::Vector<M_DIMENSION> getInnovation( const State & state ) const {
00117 return -(state.pose * position);
00118 }
00119
00120 inline void setCovariance( double sigma ){
00121 TooN::Identity(covariance, sigma);
00122 }
00123
00124 inline void setCovariance( const TooN::Vector<M_DIMENSION> & sigma ){
00125 TooN::Zero(covariance);
00126 for(int i = 0; i < M_DIMENSION; ++i){
00127 covariance(i,i) = sigma[i];
00128 }
00129 }
00130 };
00131
00134 template <class State>
00135 class AngularVelocity {
00136 public:
00137
00138 static const int M_DIMENSION = 3;
00139
00140 TooN::Vector<3> gyro;
00141 TooN::Matrix<M_DIMENSION> covariance;
00142 TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> jacobian;
00143
00144 AngularVelocity(void){
00145 TooN::Identity(covariance);
00146 TooN::Zero(gyro);
00147
00148 TooN::Zero(jacobian);
00149 TooN::Identity(jacobian.template slice<0,9,3,3>());
00150 }
00151
00152 inline TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ){
00153 return jacobian;
00154 }
00155
00156 inline TooN::Matrix<M_DIMENSION> & getMeasurementCovariance( const State & state ){
00157 return covariance;
00158 }
00159
00160 inline TooN::Vector<M_DIMENSION> getInnovation( const State & state ){
00161
00163 return (-gyro - state.angularVelocity);
00164 }
00165
00166 inline void setCovariance( double sigma ){
00167 TooN::Identity(covariance, sigma);
00168 }
00169 };
00170
00174 template <class State>
00175 class WorldDirection {
00176 public:
00177
00178 static const int M_DIMENSION = 3;
00179
00180 TooN::Vector<3> measurement;
00181 TooN::Vector<3> reference;
00182
00183 TooN::Matrix<M_DIMENSION> covariance;
00184
00185 WorldDirection(void){
00186 TooN::Identity(covariance);
00187 TooN::Zero(measurement);
00188 TooN::Zero(reference);
00189 }
00190
00191 inline TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> & getMeasurementJacobian( const State & state ){
00192 TooN::Matrix<M_DIMENSION,State::STATE_DIMENSION> result;
00193 TooN::Zero(result);
00194
00195 TooN::Vector<M_DIMENSION> local = state.pose.get_rotation() * reference;
00196 result.template slice<0,3,3,1>() = TooN::SO3::generator_field(0, local ).as_col();
00197 result.template slice<0,4,3,1>() = TooN::SO3::generator_field(1, local ).as_col();
00198 result.template slice<0,5,3,1>() = TooN::SO3::generator_field(2, local ).as_col();
00199 return result;
00200 }
00201
00202 inline TooN::Matrix<M_DIMENSION> & getMeasurementCovariance( const State & state ){
00203 return covariance;
00204 }
00205
00206 inline TooN::Vector<M_DIMENSION> & getInnovation( const State & state ){
00207 return (measurement - (state.pose.get_rotation() * reference));
00208 }
00209
00210 inline void setCovariance( double sigma ){
00211 TooN::Identity(covariance, sigma);
00212 }
00213 };
00214
00215 }
00216
00217 #endif