00001
00002
00003 #include <StateEstimators/MeasureHandler.hpp>
00004 #include <EigenTools.hpp>
00005
00006
00007 namespace telekyb_state {
00008
00009 MeasureHandlerOption::MeasureHandlerOption()
00010 : OptionContainer("MeasureHandler")
00011 {
00012
00013
00014 Eigen::Matrix<double,6,6> qt;
00015 qt.Zero();
00016 vicCov = addOption<Eigen::Matrix<double,6,6> >("vicCov", "Vicon noise covariance matrix", qt, false, true);
00017
00018 vicPosition = addOption<Eigen::Vector3d>("initState", "Initial estimate for Vicon position", Eigen::Vector3d(0.0,0.0,0.0), false, true);
00019 vicOrientation = addOption<Eigen::Quaterniond>("vicOrientation", "Initial estimate for Vicon orientation", Eigen::Quaterniond(1.0,0.0,0.0,0.0), false, true);
00020 }
00021
00022
00023 void MeasureHandler::update(StateBufferElement& state, const MeasureBufferElement& z)
00024 {
00025
00026 EigenTools tools;
00027
00028
00029 Eigen::Vector3d r(state.state.pose.position.x,state.state.pose.position.y,state.state.pose.position.z);
00030 Eigen::Vector3d dr(state.state.twist.linear.x,state.state.twist.linear.y,state.state.twist.linear.z);
00031 Eigen::Quaterniond q(state.state.pose.orientation.w,state.state.pose.orientation.x,state.state.pose.orientation.y,state.state.pose.orientation.z);
00032
00033
00034 Eigen::Vector3d zr(state.state.pose.position.x,state.state.pose.position.y,state.state.pose.position.z);
00035 Eigen::Quaterniond zq(state.state.pose.orientation.w,state.state.pose.orientation.x,state.state.pose.orientation.y,state.state.pose.orientation.z);
00036 Eigen::Matrix<double, 6, 6> Qt = options.vicCov->getValue();
00037
00038 Eigen::Vector3d BrBM = options.vicPosition->getValue();
00039 Eigen::Quaterniond BqM = options.vicOrientation->getValue();
00040 Eigen::Quaterniond WqM = q*BqM;
00041
00042 Eigen::Matrix<double, 6, 9> H;
00043 H << Eigen::Matrix3d::Identity(), Eigen::Matrix3d::Zero(), tools.gamma(q,BrBM)*tools.jacqp(q),
00044 Eigen::Matrix3d::Zero(), Eigen::Matrix3d::Zero(), Eigen::Matrix3d::Identity();
00045
00046 Eigen::Matrix<double, 6, 6> Hn;
00047 Hn.Identity();
00048
00049 Eigen::Matrix<double, 9, 6> K = state.covariance*H.transpose()*(H*state.covariance*H.transpose()+Hn*Qt*Hn.transpose());
00050
00051
00052 Eigen::Vector3d perr = tools.toRodrigues(zq*WqM.conjugate());
00053
00054 Eigen::Matrix<double, 6, 1> error;
00055 error << zr-(r+q*BrBM),
00056 perr;
00057 Eigen::Matrix<double, 9, 1> update = K*error;
00058
00059 r+=update.block<3,1>(0,0);
00060 dr+=update.block<3,1>(3,3);
00061 q = tools.toQuaternion((Eigen::Vector3d)update.block<3,1>(6,0))*q;
00062
00063 state.state.pose.position.x = r(0);
00064 state.state.pose.position.y = r(1);
00065 state.state.pose.position.z = r(2);
00066
00067 state.state.twist.linear.x = dr(0);
00068 state.state.twist.linear.y = dr(1);
00069 state.state.twist.linear.z = dr(2);
00070
00071 state.state.pose.orientation.w = q.w();
00072 state.state.pose.orientation.x = q.x();
00073 state.state.pose.orientation.y = q.y();
00074 state.state.pose.orientation.z = q.z();
00075
00076
00077 state.covariance = (Eigen::Matrix<double, 9, 9>::Identity()-K*H)*state.covariance*(Eigen::Matrix<double, 9, 9>::Identity()-K*H).transpose() + K*Qt*K.transpose();
00078 }
00079
00080
00081 }