17 #ifndef SENSORMANAGERROS_H
18 #define SENSORMANAGERROS_H
21 #include <dynamic_reconfigure/server.h>
24 #include <sensor_fusion_comm/DoubleArrayStamped.h>
25 #include <sensor_fusion_comm/ExtState.h>
26 #include <sensor_fusion_comm/ExtEkf.h>
27 #include <geometry_msgs/PoseWithCovarianceStamped.h>
28 #include <sensor_msgs/Imu.h>
29 #include <asctec_hl_comm/mav_imu.h>
30 #include <tf/transform_broadcaster.h>
32 #include <msf_core/MSF_CoreConfig.h>
50 template<
typename EKFState_T>
72 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
76 ReconfigureServer::CallbackType f = boost::bind(
82 ros::NodeHandle nh(
"msf_core");
84 pubState_ = nh.advertise < sensor_fusion_comm::DoubleArrayStamped
86 pubCorrect_ = nh.advertise < sensor_fusion_comm::ExtEkf > (
"correction", 1);
87 pubPose_ = nh.advertise < geometry_msgs::PoseWithCovarianceStamped
90 < geometry_msgs::PoseWithCovarianceStamped > (
"pose_after_update", 100);
91 pubPoseCrtl_ = nh.advertise < sensor_fusion_comm::ExtState
98 ros::this_node::getSubscribedTopics(topics);
99 std::string nodeName = ros::this_node::getName();
100 std::string topicsStr = nodeName +
":\n\tsubscribed to topics:\n";
101 for (
unsigned int i = 0; i < topics.size(); i++)
102 topicsStr += (
"\t\t" + topics.at(i) +
"\n");
104 topicsStr +=
"\tadvertised topics:\n";
105 ros::this_node::getAdvertisedTopics(topics);
106 for (
unsigned int i = 0; i < topics.size(); i++)
107 topicsStr += (
"\t\t" + topics.at(i) +
"\n");
119 virtual void coreConfig(msf_core::MSF_CoreConfig &config, uint32_t level) {
128 void Config(msf_core::MSF_CoreConfig &config, uint32_t level) {
141 return config_.core_fixed_bias;
147 return config_.core_noise_accbias;
153 return config_.core_noise_gyrbias;
163 sensor_fusion_comm::ExtEkf msgCorrect_;
165 msgCorrect_.header.stamp = ros::Time(state->time);
166 msgCorrect_.header.seq = 0;
167 msgCorrect_.angular_velocity.x = 0;
168 msgCorrect_.angular_velocity.y = 0;
169 msgCorrect_.angular_velocity.z = 0;
170 msgCorrect_.linear_acceleration.x = 0;
171 msgCorrect_.linear_acceleration.y = 0;
172 msgCorrect_.linear_acceleration.z = 0;
175 boost::fusion::for_each(
180 msgCorrect_.flag = sensor_fusion_comm::ExtEkf::initialization;
186 const shared_ptr<EKFState_T>& state)
const {
189 static int msg_seq = 0;
191 geometry_msgs::PoseWithCovarianceStamped msgPose;
192 msgPose.header.stamp = ros::Time(state->time);
193 msgPose.header.seq = msg_seq++;
194 msgPose.header.frame_id =
"/world";
195 state->toPoseMsg(msgPose);
198 sensor_fusion_comm::ExtState msgPoseCtrl;
199 msgPoseCtrl.header = msgPose.header;
200 state->toExtStateMsg(msgPoseCtrl);
207 const shared_ptr<EKFState_T>& state)
const {
209 static int msg_seq = 0;
211 sensor_fusion_comm::ExtEkf msgCorrect_;
213 msgCorrect_.header.stamp = ros::Time(state->time);
214 msgCorrect_.header.seq = msg_seq;
215 msgCorrect_.angular_velocity.x = 0;
216 msgCorrect_.angular_velocity.y = 0;
217 msgCorrect_.angular_velocity.z = 0;
218 msgCorrect_.linear_acceleration.x = 0;
219 msgCorrect_.linear_acceleration.y = 0;
220 msgCorrect_.linear_acceleration.z = 0;
227 msgCorrect_.state[i] = 0;
229 msgCorrect_.state[6] = 1;
230 msgCorrect_.flag = sensor_fusion_comm::ExtEkf::initialization;
233 1, __FUNCTION__ <<
" You have connected the external propagation "
234 "topic but at the same time data_playback is on.");
237 const EKFState_T& state_const = *state;
238 msgCorrect_.state[0] =
239 state_const.template get<StateDefinition_T::p>()[0]
241 msgCorrect_.state[1] =
242 state_const.template get<StateDefinition_T::p>()[1]
244 msgCorrect_.state[2] =
245 state_const.template get<StateDefinition_T::p>()[2]
247 msgCorrect_.state[3] =
248 state_const.template get<StateDefinition_T::v>()[0]
250 msgCorrect_.state[4] =
251 state_const.template get<StateDefinition_T::v>()[1]
253 msgCorrect_.state[5] =
254 state_const.template get<StateDefinition_T::v>()[2]
259 Eigen::Quaterniond qbuff_q = hl_q.inverse()
260 * state_const.template get<StateDefinition_T::q>();
261 msgCorrect_.state[6] = qbuff_q.w();
262 msgCorrect_.state[7] = qbuff_q.x();
263 msgCorrect_.state[8] = qbuff_q.y();
264 msgCorrect_.state[9] = qbuff_q.z();
266 msgCorrect_.state[10] =
267 state_const.template get<StateDefinition_T::b_w>()[0]
269 msgCorrect_.state[11] =
270 state_const.template get<StateDefinition_T::b_w>()[1]
272 msgCorrect_.state[12] =
273 state_const.template get<StateDefinition_T::b_w>()[2]
275 msgCorrect_.state[13] =
276 state_const.template get<StateDefinition_T::b_a>()[0]
278 msgCorrect_.state[14] =
279 state_const.template get<StateDefinition_T::b_a>()[1]
281 msgCorrect_.state[15] =
282 state_const.template get<StateDefinition_T::b_a>()[2]
285 msgCorrect_.flag = sensor_fusion_comm::ExtEkf::state_correction;
288 if (state->checkStateForNumeric()) {
292 1,
"Not sending updates to external EKF, because state NaN/inf.");
297 sensor_fusion_comm::DoubleArrayStamped msgState;
298 msgState.header = msgCorrect_.header;
299 state->toFullStateMsg(msgState);
305 geometry_msgs::PoseWithCovarianceStamped msgPose;
306 msgPose.header.stamp = ros::Time(state->time);
307 msgPose.header.seq = msg_seq;
308 msgPose.header.frame_id =
"/world";
310 state->toPoseMsg(msgPose);
315 tf::Transform transform;
316 const EKFState_T& state_const = *state;
317 const Eigen::Matrix<double, 3, 1>& pos = state_const
318 .template get<StateDefinition_T::p>();
319 const Eigen::Quaterniond& ori = state_const
320 .template get<StateDefinition_T::q>();
321 transform.setOrigin(tf::Vector3(pos[0], pos[1], pos[2]));
322 transform.setRotation(
tf::Quaternion(ori.x(), ori.y(), ori.z(), ori.w()));
324 tf::StampedTransform(
325 transform, ros::Time::now() ,
333 #endif // SENSORMANAGERROS_H