20 #include <Eigen/Dense>
21 #include <Eigen/Geometry>
24 #include <sensor_fusion_comm/ExtState.h>
25 #include <sensor_fusion_comm/DoubleArrayStamped.h>
26 #include <geometry_msgs/PoseWithCovarianceStamped.h>
27 #include <boost/lexical_cast.hpp>
34 template<
typename stateVector_T,
typename StateDefinition_T>
36 inline typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type GenericState_T<
41 "Assumed that boost::fusion would return a reference type here, which is not the case.");
43 return boost::fusion::at < boost::mpl::int_<INDEX> > (statevars);
49 template<
typename stateVector_T,
typename StateDefinition_T>
52 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t::value_t&
57 "Assumed that boost::fusion would return a reference type here, which is not the case.");
59 return boost::fusion::at < boost::mpl::int_<INDEX> > (statevars).state_;
63 template<
typename stateVector_T,
typename StateDefinition_T>
65 const Eigen::Matrix<double, nErrorStatesAtCompileTime, 1>& correction) {
66 boost::fusion::for_each(
69 const Eigen::Matrix<double, nErrorStatesAtCompileTime, 1>,
70 stateVector_T>(correction));
75 template<
typename stateVector_T,
typename StateDefinition_T>
78 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t::Q_T&
81 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t
StateVar_T;
88 "You requested a non-const reference to a Q-Block for a"
89 "core state of the EKF, but this is not allowed! Use the const version to "
90 "get Q-blocks for core states.");
92 return boost::fusion::at < boost::mpl::int_<INDEX> > (statevars).Q;
97 template<
typename stateVector_T,
typename StateDefinition_T>
100 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t::Q_T&
102 typedef typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type
StateVar_T;
103 return boost::fusion::at < boost::mpl::int_<INDEX> > (statevars).Q_;
108 template<
typename stateVector_T,
typename StateDefinition_T>
110 geometry_msgs::PoseWithCovarianceStamped & pose) {
112 pose.pose.pose.position);
114 pose.pose.pose.orientation);
115 getPoseCovariance(pose.pose.covariance);
120 template<
typename stateVector_T,
typename StateDefinition_T>
122 sensor_fusion_comm::ExtState & state) {
124 state.pose.position);
126 state.pose.orientation);
133 template<
typename stateVector_T,
typename StateDefinition_T>
135 sensor_fusion_comm::DoubleArrayStamped & state) {
136 state.data.resize(nStatesAtCompileTime);
137 boost::fusion::for_each(
145 template<
typename stateVector_T,
typename StateDefinition_T>
147 sensor_fusion_comm::DoubleArrayStamped & state) {
148 state.data.resize(nCoreStatesAtCompileTime);
149 boost::fusion::for_each(
155 template<
typename stateVector_T,
typename StateDefinition_T>
156 Eigen::Matrix<double,
159 Eigen::Matrix<double,
162 boost::fusion::for_each(
165 typename Eigen::Matrix<
double,
166 GenericState_T<stateVector_T, StateDefinition_T>::nCoreStatesAtCompileTime,
167 1>, stateVector_T>(data));
172 template<
typename stateVector_T,
typename StateDefinition_T>
174 std::vector<std::tuple<int, int, int> >& vec) {
176 boost::fusion::for_each(
179 stateVector_T>(vec));
182 template<
typename stateVector_T,
typename StateDefinition_T>
184 std::stringstream ss;
186 <<
"s: ---------" << std::endl;
187 boost::fusion::for_each(
190 ss <<
"-------------------------------------------------------";
194 template<
typename stateVector_T,
typename StateDefinition_T>
196 Eigen::Matrix<double,
199 boost::fusion::for_each(
202 typename Eigen::Matrix<
double,
203 GenericState_T<stateVector_T, StateDefinition_T>::nCoreStatesAtCompileTime,
204 1>, stateVector_T>(data));
210 template<
typename stateVector_T,
typename StateDefinition_T>
213 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t::value_t&
218 "Assumed that boost::fusion would return a reference type here, which is "
221 return boost::fusion::at < boost::mpl::int_<INDEX> > (statevars).state_;
224 template<
typename stateVector_T,
typename StateDefinition_T>
227 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t
GenericState_T<
232 "Assumed that boost::fusion would return a reference type here, which is "
235 return boost::fusion::at < boost::mpl::int_<INDEX> > (statevars);
238 template<
typename stateVector_T,
typename StateDefinition_T>
242 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t::value_t& newvalue) {
244 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t
StateVar_T;
251 "You requested to set a new value for a"
252 "core state of the EKF, but this is not allowed! This is an Error.");
254 boost::fusion::at < boost::mpl::int_<INDEX> > (statevars).state_ = newvalue;
257 template<
typename stateVector_T,
typename StateDefinition_T>
261 typename boost::fusion::result_of::at_c<stateVector_T, INDEX>::type>::result_t
StateVar_T;
266 msf_tmp::CorrectionStateLengthForType>::value,
270 Eigen::Matrix<double, lengthInState, lengthInState> cov = P
271 .template block<lengthInState, lengthInState>(startIdxInState,
273 P.template block<lengthInState, nErrorStatesAtCompileTime>(startIdxInState, 0)
275 P.template block<nErrorStatesAtCompileTime, lengthInState>(0, startIdxInState)
278 P.template block<lengthInState, lengthInState>(startIdxInState,
279 startIdxInState) = cov;
288 template<
typename stateVector_T,
typename StateDefinition_T>
304 statevisitor->resetState(*
this);
308 template<
typename stateVector_T,
typename StateDefinition_T>
310 geometry_msgs::PoseWithCovariance::_covariance_type & cov) {
312 typedef typename msf_tmp::getEnumStateType<stateVector_T, StateDefinition_T::p>::value p_type;
313 typedef typename msf_tmp::getEnumStateType<stateVector_T, StateDefinition_T::q>::value q_type;
317 p_type, msf_tmp::CorrectionStateLengthForType>::value;
319 q_type, msf_tmp::CorrectionStateLengthForType>::value;
328 for (
int i = 0; i < 9; i++)
329 cov[i / 3 * 6 + i % 3] = P(
330 (i / 3 + idxstartcorr_p) * nErrorStatesAtCompileTime + i % 3);
332 for (
int i = 0; i < 9; i++)
333 cov[i / 3 * 6 + (i % 3 + 3)] = P(
334 (i / 3 + idxstartcorr_p) * nErrorStatesAtCompileTime + (i % 3 + 6));
336 for (
int i = 0; i < 9; i++)
337 cov[(i / 3 + 3) * 6 + i % 3] = P(
338 (i / 3 + idxstartcorr_q) * nErrorStatesAtCompileTime + i % 3);
340 for (
int i = 0; i < 9; i++)
341 cov[(i / 3 + 3) * 6 + (i % 3 + 3)] = P(
342 (i / 3 + idxstartcorr_q) * nErrorStatesAtCompileTime + (i % 3 + 6));