21 #include <sensor_msgs/Imu.h> 22 #include <sensor_msgs/MagneticField.h> 23 #include <sensor_msgs/Temperature.h> 24 #include <sensor_msgs/FluidPressure.h> 25 #include <geometry_msgs/Vector3.h> 28 namespace std_plugins {
48 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
63 PluginBase::initialize(uas_);
65 double linear_stdev, angular_stdev, orientation_stdev, mag_stdev;
74 imu_nh.
param(
"linear_acceleration_stdev", linear_stdev, 0.0003);
75 imu_nh.
param(
"angular_velocity_stdev", angular_stdev, 0.02 * (M_PI / 180.0));
76 imu_nh.
param(
"orientation_stdev", orientation_stdev, 1.0);
147 double sr = stdev * stdev;
148 c.diagonal() << sr, sr, sr;
164 Eigen::Quaterniond &orientation_ned, Eigen::Vector3d &gyro_flu, Eigen::Vector3d &gyro_frd)
166 auto imu_ned_msg = boost::make_shared<sensor_msgs::Imu>();
167 auto imu_enu_msg = boost::make_shared<sensor_msgs::Imu>();
195 if (!received_linear_accel) {
197 imu_enu_msg->linear_acceleration_covariance[0] = -1;
198 imu_ned_msg->linear_acceleration_covariance[0] = -1;
231 Eigen::Vector3d &accel_flu, Eigen::Vector3d &accel_frd)
233 auto imu_msg = boost::make_shared<sensor_msgs::Imu>();
236 imu_msg->header = header;
242 linear_accel_vec_flu = accel_flu;
243 linear_accel_vec_frd = accel_frd;
244 received_linear_accel =
true;
259 void publish_mag(std_msgs::Header &header, Eigen::Vector3d &mag_field)
261 auto magn_msg = boost::make_shared<sensor_msgs::MagneticField>();
264 magn_msg->header = header;
281 void handle_attitude(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::ATTITUDE &att)
297 auto gyro_frd = Eigen::Vector3d(att.rollspeed, att.pitchspeed, att.yawspeed);
317 publish_imu_data(att.time_boot_ms, enu_baselink_orientation, ned_aircraft_orientation, gyro_flu, gyro_frd);
335 auto ned_aircraft_orientation = Eigen::Quaterniond(att_q.q1, att_q.q2, att_q.q3, att_q.q4);
342 auto gyro_frd = Eigen::Vector3d(att_q.rollspeed, att_q.pitchspeed, att_q.yawspeed);
359 publish_imu_data(att_q.time_boot_ms, enu_baselink_orientation, ned_aircraft_orientation, gyro_flu, gyro_frd);
368 void handle_highres_imu(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::HIGHRES_IMU &imu_hr)
382 if (imu_hr.fields_updated & ((7 << 3) | (7 << 0))) {
385 auto accel_frd = Eigen::Vector3d(imu_hr.xacc, imu_hr.yacc, imu_hr.zacc);
396 if (imu_hr.fields_updated & (7 << 6)) {
397 auto mag_field = ftf::transform_frame_aircraft_baselink<Eigen::Vector3d>(
398 Eigen::Vector3d(imu_hr.xmag, imu_hr.ymag, imu_hr.zmag) *
GAUSS_TO_TESLA);
408 if (imu_hr.fields_updated & (1 << 9)) {
409 auto static_pressure_msg = boost::make_shared<sensor_msgs::FluidPressure>();
411 static_pressure_msg->header = header;
412 static_pressure_msg->fluid_pressure = imu_hr.abs_pressure;
414 static_press_pub.
publish(static_pressure_msg);
422 if (imu_hr.fields_updated & (1 << 10)) {
423 auto differential_pressure_msg = boost::make_shared<sensor_msgs::FluidPressure>();
425 differential_pressure_msg->header = header;
426 differential_pressure_msg->fluid_pressure = imu_hr.diff_pressure;
428 diff_press_pub.
publish(differential_pressure_msg);
436 if (imu_hr.fields_updated & (1 << 12)) {
437 auto temp_msg = boost::make_shared<sensor_msgs::Temperature>();
439 temp_msg->header = header;
440 temp_msg->temperature = imu_hr.temperature;
442 temp_imu_pub.
publish(temp_msg);
453 void handle_raw_imu(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::RAW_IMU &imu_raw)
458 if (has_hr_imu || has_scaled_imu)
461 auto imu_msg = boost::make_shared<sensor_msgs::Imu>();
466 auto gyro_flu = ftf::transform_frame_aircraft_baselink<Eigen::Vector3d>(
467 Eigen::Vector3d(imu_raw.xgyro, imu_raw.ygyro, imu_raw.zgyro) *
MILLIRS_TO_RADSEC);
468 auto accel_frd = Eigen::Vector3d(imu_raw.xacc, imu_raw.yacc, imu_raw.zacc);
469 auto accel_flu = ftf::transform_frame_aircraft_baselink<Eigen::Vector3d>(accel_frd);
484 linear_accel_vec_flu.setZero();
485 linear_accel_vec_frd.setZero();
492 auto mag_field = ftf::transform_frame_aircraft_baselink<Eigen::Vector3d>(
493 Eigen::Vector3d(imu_raw.xmag, imu_raw.ymag, imu_raw.zmag) *
MILLIT_TO_TESLA);
505 void handle_scaled_imu(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::SCALED_IMU &imu_raw)
511 has_scaled_imu =
true;
513 auto imu_msg = boost::make_shared<sensor_msgs::Imu>();
516 auto gyro_flu = ftf::transform_frame_aircraft_baselink<Eigen::Vector3d>(
517 Eigen::Vector3d(imu_raw.xgyro, imu_raw.ygyro, imu_raw.zgyro) *
MILLIRS_TO_RADSEC);
518 auto accel_frd = Eigen::Vector3d(Eigen::Vector3d(imu_raw.xacc, imu_raw.yacc, imu_raw.zacc) * MILLIG_TO_MS2);
519 auto accel_flu = ftf::transform_frame_aircraft_baselink<Eigen::Vector3d>(accel_frd);
526 auto mag_field = ftf::transform_frame_aircraft_baselink<Eigen::Vector3d>(
527 Eigen::Vector3d(imu_raw.xmag, imu_raw.ymag, imu_raw.zmag) *
MILLIT_TO_TESLA);
545 auto temp_msg = boost::make_shared<sensor_msgs::Temperature>();
546 temp_msg->header = header;
547 temp_msg->temperature = press.temperature / 100.0;
548 temp_baro_pub.
publish(temp_msg);
550 auto static_pressure_msg = boost::make_shared<sensor_msgs::FluidPressure>();
551 static_pressure_msg->header = header;
552 static_pressure_msg->fluid_pressure = press.press_abs * 100.0;
553 static_press_pub.
publish(static_pressure_msg);
555 auto differential_pressure_msg = boost::make_shared<sensor_msgs::FluidPressure>();
556 differential_pressure_msg->header = header;
557 differential_pressure_msg->fluid_pressure = press.press_diff * 100.0;
558 diff_press_pub.
publish(differential_pressure_msg);
565 has_scaled_imu =
false;
566 has_att_quat =
false;
ros::Publisher diff_press_pub
MAVROS Plugin base class.
std_msgs::Header synchronized_header(const std::string &frame_id, const T time_stamp)
Create message header from time_boot_ms or time_usec stamps and frame_id.
#define ROS_WARN_THROTTLE_NAMED(rate, name,...)
#define ROS_INFO_COND_NAMED(cond, name,...)
void publish(const boost::shared_ptr< M > &message) const
static constexpr double GAUSS_TO_TESLA
Gauss to Tesla coeff.
void quaternionEigenToMsg(const Eigen::Quaterniond &e, geometry_msgs::Quaternion &m)
HandlerInfo make_handler(const mavlink::msgid_t id, void(_C::*fn)(const mavlink::mavlink_message_t *msg, const mavconn::Framing framing))
IMU and attitude data publication plugin.
Eigen::Vector3d linear_accel_vec_flu
ftf::Covariance3d magnetic_cov
void handle_raw_imu(const mavlink::mavlink_message_t *msg, mavlink::common::msg::RAW_IMU &imu_raw)
Handle RAW_IMU MAVlink message. Message specification: https://mavlink.io/en/messages/common.html/#RAW_IMU.
void publish_imu_data(uint32_t time_boot_ms, Eigen::Quaterniond &orientation_enu, Eigen::Quaterniond &orientation_ned, Eigen::Vector3d &gyro_flu, Eigen::Vector3d &gyro_frd)
Fill and publish IMU data message.
ros::Publisher imu_raw_pub
void connection_cb(bool connected) override
void handle_attitude_quaternion(const mavlink::mavlink_message_t *msg, mavlink::common::msg::ATTITUDE_QUATERNION &att_q)
Handle ATTITUDE_QUATERNION MAVlink message. Message specification: https://mavlink.io/en/messages/common.html/#ATTITUDE_QUATERNION.
PluginBase()
Plugin constructor Should not do anything before initialize()
void update_attitude_imu_enu(sensor_msgs::Imu::Ptr &imu)
Store IMU data [ENU].
ftf::Covariance3d angular_velocity_cov
ftf::Covariance3d linear_acceleration_cov
T transform_frame_aircraft_baselink(const T &in)
Transform data expressed in Aircraft frame to Baselink frame.
bool received_linear_accel
ftf::Covariance3d unk_orientation_cov
EIGEN_MAKE_ALIGNED_OPERATOR_NEW IMUPlugin()
Subscriptions get_subscriptions() override
Return vector of MAVLink message subscriptions (handlers)
void initialize(UAS &uas_) override
Plugin initializer.
void vectorEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Vector3 &m)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool is_ardupilotmega()
Check that FCU is APM.
ros::Publisher temp_baro_pub
static constexpr double MILLIG_TO_MS2
millG to m/s**2 coeff
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static constexpr double MILLIMS2_TO_MS2
millm/s**2 to m/s**2 coeff
Eigen::Vector3d linear_accel_vec_frd
Eigen::Map< Eigen::Matrix< double, 3, 3, Eigen::RowMajor > > EigenMapCovariance3d
Eigen::Map for Covariance3d.
void publish_mag(std_msgs::Header &header, Eigen::Vector3d &mag_field)
Publish magnetic field data.
sensor_msgs::Imu::_angular_velocity_covariance_type Covariance3d
Type matching rosmsg for 3x3 covariance matrix.
void handle_scaled_pressure(const mavlink::mavlink_message_t *msg, mavlink::common::msg::SCALED_PRESSURE &press)
Handle SCALED_PRESSURE MAVlink message. Message specification: https://mavlink.io/en/messages/common...
void publish_imu_data_raw(std_msgs::Header &header, Eigen::Vector3d &gyro_flu, Eigen::Vector3d &accel_flu, Eigen::Vector3d &accel_frd)
Fill and publish IMU data_raw message; store linear acceleration for IMU data.
Eigen::Quaterniond quaternion_from_rpy(const Eigen::Vector3d &rpy)
Convert euler angles to quaternion.
void handle_attitude(const mavlink::mavlink_message_t *msg, mavlink::common::msg::ATTITUDE &att)
Handle ATTITUDE MAVlink message. Message specification: https://mavlink.io/en/messages/common.html#ATTITUDE.
void enable_connection_cb()
std::vector< HandlerInfo > Subscriptions
Subscriptions vector.
ros::Publisher static_press_pub
ftf::Covariance3d orientation_cov
T transform_orientation_ned_enu(const T &in)
Transform from attitude represented WRT NED frame to attitude represented WRT ENU frame...
void handle_scaled_imu(const mavlink::mavlink_message_t *msg, mavlink::common::msg::SCALED_IMU &imu_raw)
Handle SCALED_IMU MAVlink message. Message specification: https://mavlink.io/en/messages/common.html/#SCALED_IMU.
void setup_covariance(ftf::Covariance3d &cov, double stdev)
Setup 3x3 covariance matrix.
void update_attitude_imu_ned(sensor_msgs::Imu::Ptr &imu)
Store IMU data [NED].
static constexpr double MILLIT_TO_TESLA
millTesla to Tesla coeff
T transform_orientation_aircraft_baselink(const T &in)
Transform from attitude represented WRT aircraft frame to attitude represented WRT base_link frame...
ros::Publisher temp_imu_pub
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
bool is_px4()
Check that FCU is PX4.
static constexpr double MILLIRS_TO_RADSEC
millRad/Sec to Rad/Sec coeff
static constexpr double RAD_TO_DEG
Radians to degrees.
static constexpr double MILLIBAR_TO_PASCAL
millBar to Pascal coeff
void handle_highres_imu(const mavlink::mavlink_message_t *msg, mavlink::common::msg::HIGHRES_IMU &imu_hr)
Handle HIGHRES_IMU MAVlink message. Message specification: https://mavlink.io/en/messages/common.html/#HIGHRES_IMU.