17 #ifndef POSITION_POSE_SENSOR_MANAGER_H
18 #define POSITION_POSE_SENSOR_MANAGER_H
26 #include <msf_updates/pose_sensor_handler/pose_sensorhandler.h>
27 #include <msf_updates/pose_sensor_handler/pose_measurement.h>
28 #include <msf_updates/position_sensor_handler/position_sensorhandler.h>
29 #include <msf_updates/position_sensor_handler/position_measurement.h>
30 #include <msf_updates/PositionPoseSensorConfig.h>
32 namespace msf_updates {
34 typedef msf_updates::PositionPoseSensorConfig
Config_T;
39 msf_updates::EKFState> {
41 typedef msf_pose_sensor::PoseSensorHandler<
43 friend class msf_pose_sensor::PoseSensorHandler<
44 msf_updates::pose_measurement::PoseMeasurement,
this_T>;
45 typedef msf_position_sensor::PositionSensorHandler<
47 friend class msf_position_sensor::PositionSensorHandler<
48 msf_updates::position_measurement::PositionMeasurement, this_T>;
55 ros::NodeHandle pnh = ros::NodeHandle("~/position_pose_sensor")) {
60 bool distortmeas =
false;
71 ReconfigureServer::CallbackType f = boost::bind(&
this_T::config,
this, _1,
83 shared_ptr<msf_core::IMUHandler_ROS<msf_updates::EKFState> >
imu_handler_;
96 config.pose_noise_meas_q);
102 if ((level & msf_updates::PositionPoseSensor_INIT_FILTER)
103 && config.core_init_filter ==
true) {
104 init(config.pose_initial_scale);
105 config.core_init_filter =
false;
109 if ((level & msf_updates::PositionPoseSensor_SET_HEIGHT)
110 && config.core_set_height ==
true) {
111 Eigen::Matrix<double, 3, 1>
p =
pose_handler_->getPositionMeasurement();
114 "No measurements received yet to initialize position. Height init "
118 double scale = p[2] / config.core_height;
120 config.core_set_height =
false;
124 void init(
double scale)
const {
125 Eigen::Matrix<double, 3, 1>
p,
v,
b_w,
b_a, g, w_m, a_m,
p_ic, p_vc,
p_wv,
127 Eigen::Quaternion<double>
q,
q_wv,
q_ic, q_vc;
150 "initial measurement vision: pos:["<<p_vc.transpose()<<
"] orientation: "
153 "initial measurement position: pos:["<<p_pos.transpose()<<
"]");
156 if (p_vc.norm() == 0)
158 "No measurements received yet to initialize vision position - using [0 0 0]");
159 if (p_pos.norm() == 0)
161 "No measurements received yet to initialize absolute position - using [0 0 0]");
164 "No measurements received yet to initialize attitude - using [1 0 0 0]");
166 ros::NodeHandle pnh(
"~");
167 pnh.param(
"pose_sensor/init/p_ic/x", p_ic[0], 0.0);
168 pnh.param(
"pose_sensor/init/p_ic/y", p_ic[1], 0.0);
169 pnh.param(
"pose_sensor/init/p_ic/z", p_ic[2], 0.0);
171 pnh.param(
"pose_sensor/init/q_ic/w", q_ic.w(), 1.0);
172 pnh.param(
"pose_sensor/init/q_ic/x", q_ic.x(), 0.0);
173 pnh.param(
"pose_sensor/init/q_ic/y", q_ic.y(), 0.0);
174 pnh.param(
"pose_sensor/init/q_ic/z", q_ic.z(), 0.0);
180 pnh.param(
"position_sensor/init/p_ip/x", p_ip[0], 0.0);
181 pnh.param(
"position_sensor/init/p_ip/y", p_ip[1], 0.0);
182 pnh.param(
"position_sensor/init/p_ip/z", p_ip[2], 0.0);
187 double yawinit =
config_.position_yaw_init / 180 * M_PI;
188 Eigen::Quaterniond yawq(cos(yawinit / 2), 0, 0, sin(yawinit / 2));
192 q_wv = (q * q_ic * q_vc.conjugate()).conjugate();
197 Eigen::Matrix<double, 3, 1> p_vision = q_wv.conjugate().toRotationMatrix()
198 * p_vc / scale - q.toRotationMatrix() *
p_ic;
203 p = p_pos - q.toRotationMatrix() *
p_ip;
215 shared_ptr < msf_core::MSF_InitMeasurement<EKFState_T>
224 > (Eigen::Matrix<double, 1, 1>::Constant(scale));
232 meas->get_w_m() = w_m;
233 meas->get_a_m() = a_m;
234 meas->time = ros::Time::now().toSec();
243 Eigen::Matrix<double, 1, 1> scale;
252 const msf_core::Vector3 nqwvv = msf_core::Vector3::Constant(
254 const msf_core::Vector3 npwvv = msf_core::Vector3::Constant(
256 const msf_core::Vector3 nqicv = msf_core::Vector3::Constant(
258 const msf_core::Vector3 npicv = msf_core::Vector3::Constant(
260 const msf_core::Vector1 n_L = msf_core::Vector1::Constant(
268 (dt * nqwvv.cwiseProduct(nqwvv)).asDiagonal();
270 (dt * npwvv.cwiseProduct(npwvv)).asDiagonal();
272 (dt * nqicv.cwiseProduct(nqicv)).asDiagonal();
274 (dt * npicv.cwiseProduct(npicv)).asDiagonal();
286 Eigen::Matrix<double, EKFState_T::nErrorStatesAtCompileTime, 1>& correction)
const {
293 Eigen::Matrix<double, EKFState_T::nErrorStatesAtCompileTime, 1>& correction)
const {
302 Eigen::Matrix<double, 1, 1> L_;