ethzasl-msf - Modular Sensor Fusion
Time delay compensated single and multi sensor fusion framework based on an EKF
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
msf_IMUHandler_ROS.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2013 Simon Lynen, ASL, ETH Zurich, Switzerland
3  * You can contact the author at <slynen at ethz dot ch>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MSF_IMUHANDLER_ROS_H_
18 #define MSF_IMUHANDLER_ROS_H_
19 
21 
22 namespace msf_core {
23 
24 template<typename EKFState_T>
25 class IMUHandler_ROS : public IMUHandler<EKFState_T> {
26  ros::Subscriber subState_;
27  ros::Subscriber subImu_;
28  ros::Subscriber subImuCustom_;
29 
30  public:
32  const std::string& topic_namespace,
33  const std::string& parameternamespace)
34  : IMUHandler<EKFState_T>(mng, topic_namespace, parameternamespace) {
35 
36  ros::NodeHandle nh(topic_namespace);
37 
38  subImu_ = nh.subscribe("imu_state_input", 100, &IMUHandler_ROS::imuCallback,
39  this);
40  subImuCustom_ = nh.subscribe("imu_state_input_asctec", 10,
42  subState_ = nh.subscribe("hl_state_input", 10,
44  }
45 
46  virtual ~IMUHandler_ROS() {
47  }
48  ;
49 
50  void stateCallback(const sensor_fusion_comm::ExtEkfConstPtr & msg) {
51 
52  static_cast<MSF_SensorManagerROS<EKFState_T>&>(this->manager_)
53  .setHLStateBuffer(*msg);
54 
55  //get the imu values
56  msf_core::Vector3 linacc;
57  linacc << msg->linear_acceleration.x, msg->linear_acceleration.y, msg
58  ->linear_acceleration.z;
59 
60  msf_core::Vector3 angvel;
61  angvel << msg->angular_velocity.x, msg->angular_velocity.y, msg
62  ->angular_velocity.z;
63 
64  int32_t flag = msg->flag;
65  //make sure we tell the HL to ignore if data playback is on
66  if (this->manager_.data_playback())
67  flag = sensor_fusion_comm::ExtEkf::ignore_state;
68 
69  bool isnumeric = true;
70  if (flag == sensor_fusion_comm::ExtEkf::current_state) {
71  isnumeric = checkForNumeric(
72  Eigen::Map<const Eigen::Matrix<float, 10, 1> >(msg->state.data()),
73  "before prediction p,v,q");
74  }
75 
76  //get the propagated states
77  msf_core::Vector3 p, v;
79 
80  p = Eigen::Matrix<double, 3, 1>(msg->state[0], msg->state[1],
81  msg->state[2]);
82  v = Eigen::Matrix<double, 3, 1>(msg->state[3], msg->state[4],
83  msg->state[5]);
84  q = Eigen::Quaternion<double>(msg->state[6], msg->state[7], msg->state[8],
85  msg->state[9]);
86  q.normalize();
87 
88  bool is_already_propagated = false;
89  if (flag == sensor_fusion_comm::ExtEkf::current_state && isnumeric) {
90  is_already_propagated = true;
91  }
92 
93  this->process_state(linacc, angvel, p, v, q, is_already_propagated,
94  msg->header.stamp.toSec(), msg->header.seq);
95  }
96 
97  void imuCallback_asctec(const asctec_hl_comm::mav_imuConstPtr & msg) {
98 
99  msf_core::Vector3 linacc;
100  linacc << msg->acceleration.x, msg->acceleration.y, msg->acceleration.z;
101 
102  msf_core::Vector3 angvel;
103  angvel << msg->angular_velocity.x, msg->angular_velocity.y, msg
104  ->angular_velocity.z;
105 
106  this->process_imu(linacc, angvel, msg->header.stamp.toSec(),
107  msg->header.seq);
108 
109  }
110 
111  void imuCallback(const sensor_msgs::ImuConstPtr & msg) {
112  static int lastseq = -1;
113  if ((int) msg->header.seq != lastseq + 1 && lastseq != -1) {
115  "msf_core: imu message drop curr seq:" << msg->header.seq
116  << " expected: " << lastseq + 1);
117  }
118  lastseq = msg->header.seq;
119 
120  msf_core::Vector3 linacc;
121  linacc << msg->linear_acceleration.x, msg->linear_acceleration.y, msg
122  ->linear_acceleration.z;
123 
124  msf_core::Vector3 angvel;
125  angvel << msg->angular_velocity.x, msg->angular_velocity.y, msg
126  ->angular_velocity.z;
127 
128  this->process_imu(linacc, angvel, msg->header.stamp.toSec(),
129  msg->header.seq);
130  }
131 
132  virtual bool initialize() {
133  return true;
134  }
135 };
136 }
137 
138 #endif /* MSF_IMUHANDLER_ROS_H_ */