27 #include "geometry_msgs/TransformStamped.h" 33 nh_private_(nh_private),
58 std::string world_frame;
62 ROS_WARN(
"Deprecation Warning: The parameter world_frame was not set, default is 'nwu'.");
63 ROS_WARN(
"Starting with ROS Lunar, world_frame will default to 'enu'!");
66 if (world_frame ==
"ned") {
68 }
else if (world_frame ==
"nwu"){
70 }
else if (world_frame ==
"enu"){
73 ROS_ERROR(
"The parameter world_frame was set to invalid value '%s'.", world_frame.c_str());
74 ROS_ERROR(
"Valid values are 'enu', 'ned' and 'nwu'. Setting to 'enu'.");
89 ROS_INFO(
"Using dt computed from message headers");
94 ROS_INFO(
"The gravity vector will be removed from the acceleration");
96 ROS_INFO(
"The gravity vector is kept in the IMU message.");
166 boost::mutex::scoped_lock lock(
mutex_);
168 const geometry_msgs::Vector3& ang_vel = imu_msg_raw->angular_velocity;
169 const geometry_msgs::Vector3& lin_acc = imu_msg_raw->linear_acceleration;
171 ros::Time time = imu_msg_raw->header.stamp;
176 geometry_msgs::Quaternion init_q;
179 ROS_WARN_THROTTLE(5.0,
"The IMU seems to be in free fall, cannot determine gravity direction!");
187 ROS_INFO(
"First IMU message received.");
204 " The filter will not update the orientation.");
211 ang_vel.x, ang_vel.y, ang_vel.z,
212 lin_acc.x, lin_acc.y, lin_acc.z,
221 const ImuMsg::ConstPtr& imu_msg_raw,
222 const MagMsg::ConstPtr& mag_msg)
224 boost::mutex::scoped_lock lock(
mutex_);
226 const geometry_msgs::Vector3& ang_vel = imu_msg_raw->angular_velocity;
227 const geometry_msgs::Vector3& lin_acc = imu_msg_raw->linear_acceleration;
228 const geometry_msgs::Vector3& mag_fld = mag_msg->magnetic_field;
230 ros::Time time = imu_msg_raw->header.stamp;
234 geometry_msgs::Vector3 mag_compensated;
235 mag_compensated.x = mag_fld.x -
mag_bias_.x;
236 mag_compensated.y = mag_fld.y -
mag_bias_.y;
237 mag_compensated.z = mag_fld.z -
mag_bias_.z;
246 if(!std::isfinite(mag_fld.x) || !std::isfinite(mag_fld.y) || !std::isfinite(mag_fld.z))
251 geometry_msgs::Quaternion init_q;
254 ROS_WARN_THROTTLE(5.0,
"The IMU seems to be in free fall or close to magnetic north pole, cannot determine gravity direction!");
262 ROS_INFO(
"First pair of IMU and magnetometer messages received.");
279 " The filter will not update the orientation.");
286 ang_vel.x, ang_vel.y, ang_vel.z,
287 lin_acc.x, lin_acc.y, lin_acc.z,
288 mag_compensated.x, mag_compensated.y, mag_compensated.z,
297 geometry_msgs::Quaternion orientation;
310 geometry_msgs::TransformStamped transform;
311 transform.header.stamp = imu_msg_raw->header.stamp;
316 transform.transform.rotation.w = q0;
317 transform.transform.rotation.x = -q1;
318 transform.transform.rotation.y = -q2;
319 transform.transform.rotation.z = -q3;
324 transform.transform.rotation.w = q0;
325 transform.transform.rotation.x = q1;
326 transform.transform.rotation.y = q2;
327 transform.transform.rotation.z = q3;
340 boost::make_shared<ImuMsg>(*imu_msg_raw);
342 imu_msg->orientation.w = q0;
343 imu_msg->orientation.x = q1;
344 imu_msg->orientation.y = q2;
345 imu_msg->orientation.z = q3;
348 imu_msg->orientation_covariance[1] = 0.0;
349 imu_msg->orientation_covariance[2] = 0.0;
350 imu_msg->orientation_covariance[3] = 0.0;
352 imu_msg->orientation_covariance[5] = 0.0;
353 imu_msg->orientation_covariance[6] = 0.0;
354 imu_msg->orientation_covariance[7] = 0.0;
361 imu_msg->linear_acceleration.x -= gx;
362 imu_msg->linear_acceleration.y -= gy;
363 imu_msg->linear_acceleration.z -= gz;
370 geometry_msgs::Vector3Stamped rpy;
373 rpy.header = imu_msg_raw->header;
379 float roll,
float pitch,
float yaw)
381 geometry_msgs::Vector3Stamped rpy;
383 rpy.vector.y = pitch;
385 rpy.header.stamp = t;
394 boost::mutex::scoped_lock lock(
mutex_);
399 ROS_INFO(
"Imu filter gain set to %f", gain);
400 ROS_INFO(
"Gyro drift bias set to %f", zeta);
411 mag_msg.header = mag_vector_msg->header;
412 mag_msg.magnetic_field = mag_vector_msg->vector;
void getRPY(tf2Scalar &roll, tf2Scalar &pitch, tf2Scalar &yaw, unsigned int solution_number=1) const
boost::shared_ptr< MagVectorSubscriber > vector_mag_subscriber_
#define ROS_WARN_THROTTLE(rate,...)
message_filters::Subscriber< ImuMsg > ImuSubscriber
void publish(const boost::shared_ptr< M > &message) const
message_filters::sync_policies::ApproximateTime< ImuMsg, MagMsg > SyncPolicy
bool publish_debug_topics_
boost::shared_ptr< Synchronizer > sync_
double orientation_variance_
void publishRawMsg(const ros::Time &t, float roll, float pitch, float yaw)
void imuMagVectorCallback(const MagVectorMsg::ConstPtr &mag_vector_msg)
void imuMagCallback(const ImuMsg::ConstPtr &imu_msg_raw, const MagMsg::ConstPtr &mav_msg)
void setOrientation(double q0, double q1, double q2, double q3)
ros::Publisher rpy_raw_debug_publisher_
void madgwickAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz, float dt)
void getGravity(float &rx, float &ry, float &rz, float gravity=9.80665)
imu_filter_madgwick::ImuFilterMadgwickConfig FilterConfig
bool use_magnetic_field_msg_
message_filters::Synchronizer< SyncPolicy > Synchronizer
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
message_filters::Subscriber< MagMsg > MagSubscriber
void checkTopicsTimerCallback(const ros::TimerEvent &)
void getOrientation(double &q0, double &q1, double &q2, double &q3)
boost::shared_ptr< FilterConfigServer > config_server_
ImuFilterRos(ros::NodeHandle nh, ros::NodeHandle nh_private)
void setAlgorithmGain(double gain)
ros::NodeHandle nh_private_
boost::shared_ptr< ImuSubscriber > imu_subscriber_
sensor_msgs::MagneticField MagMsg
bool remove_gravity_vector_
void madgwickAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az, float dt)
message_filters::Subscriber< MagVectorMsg > MagVectorSubscriber
ros::Publisher imu_publisher_
dynamic_reconfigure::Server< FilterConfig > FilterConfigServer
void setWorldFrame(WorldFrame::WorldFrame frame)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
ros::Publisher mag_republisher_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void publishTransform(const ImuMsg::ConstPtr &imu_msg_raw)
#define ROS_WARN_STREAM(args)
#define ROS_WARN_STREAM_THROTTLE(rate, args)
ros::Timer check_topics_timer_
static bool computeOrientation(WorldFrame::WorldFrame frame, geometry_msgs::Vector3 acceleration, geometry_msgs::Vector3 magneticField, geometry_msgs::Quaternion &orientation)
void setDriftBiasGain(double zeta)
void reconfigCallback(FilterConfig &config, uint32_t level)
bool getParam(const std::string &key, std::string &s) const
void publishFilteredMsg(const ImuMsg::ConstPtr &imu_msg_raw)
WorldFrame::WorldFrame world_frame_
tf2_ros::TransformBroadcaster tf_broadcaster_
void imuCallback(const ImuMsg::ConstPtr &imu_msg_raw)
boost::shared_ptr< MagSubscriber > mag_subscriber_
ros::Publisher rpy_filtered_debug_publisher_
geometry_msgs::Vector3 mag_bias_