KalmanStateEstimator.hpp
Go to the documentation of this file.
00001 /*
00002  * KalmanStateEstimator.hpp
00003  *
00004  *  Created on: Jun 19, 2012
00005  *      Author: rspica
00006  */
00007 
00008 #ifndef KALMANSTATEESTIMATOR_HPP_
00009 #define KALMANSTATEESTIMATOR_HPP_
00010 
00011 #include <telekyb_defines/telekyb_defines.hpp>
00012 #include <telekyb_base/Options.hpp>
00013 
00014 #include <tk_state/StateEstimator.hpp>
00015 #include <EigenTools.hpp>
00016 // plugin stuff
00017 #include <pluginlib/class_list_macros.h>
00018 
00019 // ROS
00020 #include <sensor_msgs/Imu.h>
00021 #include <telekyb_msgs/TKState.h>
00022 #include <geometry_msgs/TransformStamped.h>
00023 #include <telekyb_base/Time.hpp>
00024 
00025 #include <stdint.h>
00026 #include <deque>
00027 
00028 #include <StateEstimators/MeasureHandler.hpp>
00029 
00030 // Boost
00031 #include <boost/thread/mutex.hpp>
00032 
00033 using namespace TELEKYB_NAMESPACE;
00034 
00035 namespace telekyb_state {
00036 
00037 class KalmanStateEstimatorOptions : public OptionContainer {
00038 public:
00039         Option<std::string>* imuTopic;
00040         Option<std::string>* viconTopic;
00041         Option<std::string>* stateTopic;
00042 
00043         Option<Eigen::Matrix<double,6,6> >* imuCov;
00044         Option<Eigen::Matrix<double,6,6> >* vicCov;
00045         Option<Eigen::Matrix<double,9,9> >* discCov;
00046 
00047         Option<Eigen::Matrix<double,9,9> >* initStateCov;
00048 
00049 
00050         Option<Eigen::Vector3d>* imuAccBias;
00051         Option<Eigen::Vector3d>* imuGyrBias;
00052 
00053         Option<Eigen::Vector3d>* vicPosition;
00054         Option<Eigen::Quaterniond>* vicOrientation;
00055 
00056         Option<double>* predStep;
00057         Option<double>* minStep;
00058         Option<double>* saveStep;
00059         Option<double>* lTpred;
00060 
00061         Option<int>* maxStateBufferSize;
00062         Option<int>* maxMeasureBufferSize;
00063         Option<int>* maxInputBufferSize;
00064 
00065         KalmanStateEstimatorOptions();
00066 };
00067 
00068 class KalmanStateEstimator : public TELEKYB_NAMESPACE::StateEstimator {
00069 public:
00070 
00071         virtual void initialize();
00072         virtual void willBecomeActive();
00073         virtual void willBecomeInActive();
00074         virtual void destroy();
00075 
00076         virtual std::string getName() const;
00077 
00078         void imuCallback(const sensor_msgs::Imu::ConstPtr& msg);
00079         void viconCallback(const geometry_msgs::TransformStamped::ConstPtr& msg);
00080 
00081 protected:
00082         KalmanStateEstimatorOptions options;
00083 
00084         ros::NodeHandle nodeHandle;
00085 
00086         ros::Subscriber imuSub;
00087         ros::Subscriber vicSub;
00088 
00089         ros::Publisher statePub;
00090 
00091         std::deque<StateBufferElement, Eigen::aligned_allocator<StateBufferElement> > stateBuffer;
00092         std::deque<MeasureBufferElement, Eigen::aligned_allocator<MeasureBufferElement> >  measureBuffer;
00093         std::deque<InputBufferElement, Eigen::aligned_allocator<InputBufferElement> > inputBuffer;
00094 
00095         std::deque<MeasureBufferElement, Eigen::aligned_allocator<StateBufferElement> >::const_iterator nextMeasureIndex;
00096         std::deque<InputBufferElement, Eigen::aligned_allocator<InputBufferElement> >::const_iterator currentInputIndex;
00097 
00098         StateBufferElement internalState;
00099         bool isInitialized;
00100         bool isInitializedLinVel;
00101         bool isInitializedPose;
00102         bool isInitializedAngVel;
00103 
00104         bool newMeasureReceived;
00105         bool newInputReceived;
00106         MeasureBufferElement newMeasure;
00107         InputBufferElement newInput;
00108 
00109         // Mutexes
00110         boost::mutex newMeasureMutex;
00111         boost::mutex newInputMutex;
00112 
00113 
00114         //Core functions
00115         void core();
00116         void prediction(StateBufferElement& state, const InputBufferElement& u, double Tpred);
00117         //void update(StateBufferElement& state, const MeasureBufferElement& z);
00118         MeasureHandler viconHanler;
00119         void publishEstimate(const StateBufferElement & estimate);
00120 
00121         // Timers
00122         Time intTime;
00123         double predTime;
00124         Timer saveTimer;
00125 
00126         // Eigen tools;
00127         EigenTools tools;
00128 
00129         template <typename _BufferElement>
00130         typename std::deque<_BufferElement, Eigen::aligned_allocator<_BufferElement> >::iterator searchInBuffer(std::deque<_BufferElement, Eigen::aligned_allocator<_BufferElement> >& buffer, double time);
00131 
00132 };
00133 
00134 
00135 template <typename _BufferElement>
00136 typename std::deque<_BufferElement, Eigen::aligned_allocator<_BufferElement> >::iterator KalmanStateEstimator::searchInBuffer(std::deque<_BufferElement, Eigen::aligned_allocator<_BufferElement> >& buffer, double time) {
00137         typename std::deque<_BufferElement, Eigen::aligned_allocator<_BufferElement> >::iterator current;
00138         for(current = buffer.begin(); current <= buffer.end(); current++)
00139         {
00140                 if (time >= current->timeStamp) break;
00141         }
00142         return current;
00143 }
00144 
00145 } /* namespace telekyb_state */
00146 #endif /* KALMANSTATEESTIMATOR_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


tk_state
Author(s): Dr. Antonio Franchi and Martin Riedel
autogenerated on Mon Nov 11 2013 11:13:03