observation.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2011, Willow Garage, Inc.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of Willow Garage, Inc. nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  * Author: Sebastian Klose
00036  *********************************************************************/
00037 
00038 #ifndef IMU_FILTER_OBSERVATION_H
00039 #define IMU_FILTER_OBSERVATION_H
00040 
00041 #include <ros/ros.h>
00042 #include <Eigen/Geometry>
00043 #include <imu_filter/imu_state.h>
00044 
00045 namespace imu_filter
00046 {
00047         //* Base class for EKF observation model
00048         class Observation
00049         {
00050                 public:
00051                         static const size_t Dimension = 7;
00052                         typedef Eigen::Matrix<double, Dimension, 1> Vector;
00053                         typedef Eigen::Matrix<double, Dimension, Dimension> CovMat;
00054                         typedef Eigen::Matrix<double, Dimension, ImuState::Dimension> JacMat;
00055 
00056                         Observation() : 
00057                                 observation_( Vector::Zero() ),
00058                                 measCov_( CovMat::Zero() ),
00059                                 measJacobian_( JacMat::Zero() ),
00060                                 body2ImuTransform_( Eigen::Affine3d::Identity() ),
00061                                 lastBodyTransform_( Eigen::Affine3d::Identity() ),
00062                                 lastWorld2Imu_( Eigen::Affine3d::Identity() ),
00063                                 deltaTransform_( Eigen::Affine3d::Identity() )
00064                         {
00065                         }
00066 
00067                         virtual ~Observation()
00068                         {
00069                         }
00070 
00075                         void set( const Vector & v ) { observation_ = v; }
00076 
00080                         const Vector & vector() const { return observation_; }
00081 
00086                         void setCovariance( const CovMat & covariance  ) { measCov_ = covariance; }
00087 
00092                         void setCovarianceFromStdDev( const Vector & stdDevs )
00093                         {
00094                                 measCov_.setZero();
00095                                 for( int i = 0; i < stdDevs.rows(); i++ )
00096                                         measCov_( i, i ) = utils::square( stdDevs[ i ] );
00097                         }
00098 
00102                         const CovMat & covariance() const { return measCov_; }
00103                         
00107                         const JacMat & jacobian() const { return measJacobian_; }
00108 
00109         
00115                         void setBody2ImuTransform( const Eigen::Quaterniond & q, const Eigen::Vector3d & t ) 
00116                         { 
00117                                 body2ImuTransform_.linear() = q.toRotationMatrix();
00118                                 body2ImuTransform_.translation() = t;
00119                         }
00120 
00125                         void setBody2ImuTransform( const Eigen::Affine3d & T ) { body2ImuTransform_ = T; }
00126 
00130                         const Eigen::Affine3d & body2ImuTransform() const { return body2ImuTransform_; }
00131 
00139                         void updateLastStateInformation( const ImuState & state )
00140                         {
00141                                 lastWorld2Imu_.linear() = state.orientation().toRotationMatrix();
00142                                 lastWorld2Imu_.translation() = state.position();
00143                         }
00144 
00148                         const Eigen::Affine3d & lastWorld2Imu() const { return lastWorld2Imu_; }
00149 
00153                         virtual void updateJacobian( const ImuState & state ) = 0;
00154 
00155                 protected:
00156                         Vector  observation_;
00157                         CovMat  measCov_;
00158                         JacMat  measJacobian_;
00159 
00160                         Eigen::Affine3d         body2ImuTransform_;
00161 
00162                         Eigen::Affine3d         lastBodyTransform_;
00163 
00164                         // last state information of the IMU to create the pseudo measurement
00165                         Eigen::Affine3d         lastWorld2Imu_;
00166 
00167                         // delta transformation between last and current IMU frame, computed from last two full body transformations
00168                         Eigen::Affine3d         deltaTransform_;
00169 
00170                         // compute delta translation and delta position between last imu measures
00171                         void computeDeltaFromAbsolute( const Eigen::Affine3d & currentObservation )
00172                         {
00173                                 // compute delta transformation of the IMU w.r.t. to the last measurements 
00174                                 deltaTransform_ = body2ImuTransform_.inverse() * lastBodyTransform_.inverse() * currentObservation * body2ImuTransform_; 
00175                         }
00176 
00177                         void updateObservationFromDelta()
00178                         {
00179                                 Eigen::Affine3d pseudoTrans     = lastWorld2Imu_ * deltaTransform_;
00180 
00181                                 Eigen::Quaterniond pseudoQ;
00182                                 pseudoQ = pseudoTrans.rotation();
00183                                 pseudoQ.normalize();
00184 
00185                                 observation_.head<4>() = pseudoQ.coeffs();
00186                                 observation_.tail<3>() = pseudoTrans.translation();
00187                         }
00188         };
00189 
00190 }
00191 
00192 #endif


imu_filter
Author(s): Sebastian Klose
autogenerated on Thu Dec 12 2013 11:24:42