21 #include <boost/algorithm/string.hpp> 23 #include <nav_msgs/Odometry.h> 24 #include <geometry_msgs/TransformStamped.h> 27 namespace extra_plugins {
28 using mavlink::common::MAV_FRAME;
29 using mavlink::common::MAV_ESTIMATOR_TYPE;
30 using Matrix6d = Eigen::Matrix<double, 6, 6, Eigen::RowMajor>;
46 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
91 Eigen::Affine3d &tf_source2target)
117 void handle_odom(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::ODOMETRY &odom_msg)
122 Eigen::Affine3d tf_parent2parent_des;
123 Eigen::Affine3d tf_child2child_des;
129 Matrix6d cov_pose = Matrix6d::Zero();
133 Matrix6d cov_vel = Matrix6d::Zero();
136 Eigen::Vector3d position {};
137 Eigen::Quaterniond orientation {};
138 Eigen::Vector3d lin_vel {};
139 Eigen::Vector3d ang_vel {};
143 auto odom = boost::make_shared<nav_msgs::Odometry>();
151 position = Eigen::Vector3d(tf_parent2parent_des.linear() * Eigen::Vector3d(odom_msg.x, odom_msg.y, odom_msg.z));
158 Eigen::Affine3d tf_childDes2parentDes = tf_parent2parent_des * q_child2parent * tf_child2child_des.inverse();
159 orientation = Eigen::Quaterniond(tf_childDes2parentDes.linear());
166 lin_vel = Eigen::Vector3d(tf_child2child_des.linear() * Eigen::Vector3d(odom_msg.vx, odom_msg.vy, odom_msg.vz));
167 ang_vel = Eigen::Vector3d(tf_child2child_des.linear() * Eigen::Vector3d(odom_msg.rollspeed, odom_msg.pitchspeed, odom_msg.yawspeed));
174 r_pose.block<3, 3>(0, 0) = r_pose.block<3, 3>(3, 3) = tf_parent2parent_des.linear();
176 cov_pose = r_pose * cov_pose * r_pose.transpose();
177 Eigen::Map<Matrix6d>(odom->pose.covariance.data(), cov_pose.rows(), cov_pose.cols()) = cov_pose;
180 r_vel.block<3, 3>(0, 0) = r_vel.block<3, 3>(3, 3) = tf_child2child_des.linear();
181 cov_vel = r_vel * cov_vel * r_vel.transpose();
182 Eigen::Map<Matrix6d>(odom->twist.covariance.data(), cov_vel.rows(), cov_vel.cols()) = cov_vel;
203 Eigen::Affine3d tf_parent2parent_des;
204 Eigen::Affine3d tf_child2child_des;
220 Eigen::Vector3d position {};
221 Eigen::Quaterniond orientation {};
222 Eigen::Vector3d lin_vel {};
223 Eigen::Vector3d ang_vel {};
227 mavlink::common::msg::ODOMETRY
msg {};
235 position = Eigen::Vector3d(tf_parent2parent_des.linear() *
ftf::to_eigen(odom->pose.pose.position));
240 Eigen::Quaterniond q_child2parent(
ftf::to_eigen(odom->pose.pose.orientation));
241 Eigen::Affine3d tf_childDes2parentDes = tf_parent2parent_des * q_child2parent * tf_child2child_des.inverse();
242 orientation = Eigen::Quaterniond(tf_childDes2parentDes.linear());
247 lin_vel = Eigen::Vector3d(tf_child2child_des.linear() *
ftf::to_eigen(odom->twist.twist.linear));
248 ang_vel = Eigen::Vector3d(tf_child2child_des.linear() *
ftf::to_eigen(odom->twist.twist.angular));
251 r_pose.block<3, 3>(0, 0) = r_pose.block<3, 3>(3, 3) = tf_parent2parent_des.linear();
252 r_vel.block<3, 3>(0, 0) = r_vel.block<3, 3>(3, 3) = tf_child2child_des.linear();
253 cov_pose_map = r_pose * cov_pose_map * r_pose.transpose();
254 cov_vel_map = r_vel * cov_vel_map * r_vel.transpose();
260 msg.time_usec = odom->header.stamp.toNSec() / 1e3;
269 msg.x = position.x();
270 msg.y = position.y();
271 msg.z = position.z();
272 msg.vx = lin_vel.x();
273 msg.vy = lin_vel.y();
274 msg.vz = lin_vel.z();
275 msg.rollspeed = ang_vel.x();
276 msg.pitchspeed = ang_vel.y();
277 msg.yawspeed = ang_vel.z();
void lookup_static_transform(const std::string &target, const std::string &source, Eigen::Affine3d &tf_source2target)
Lookup static transform with error handling.
std::shared_ptr< MAVConnInterface const > ConstPtr
std_msgs::Header synchronized_header(const std::string &frame_id, const T time_stamp)
Subscriptions get_subscriptions() override
ros::Subscriber odom_sub
nav_msgs/Odometry subscriber
#define ROS_DEBUG_STREAM_NAMED(name, args)
void publish(const boost::shared_ptr< M > &message) const
void quaternionEigenToMsg(const Eigen::Quaterniond &e, geometry_msgs::Quaternion &m)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
Eigen::Matrix< double, 6, 6, Eigen::RowMajor > Matrix6d
HandlerInfo make_handler(const mavlink::msgid_t id, void(_C::*fn)(const mavlink::mavlink_message_t *msg, const mavconn::Framing framing))
Eigen::Quaterniond mavlink_to_quaternion(const std::array< float, 4 > &q)
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
Eigen::Map< Eigen::Matrix< double, 6, 6, Eigen::RowMajor > > EigenMapCovariance6d
void quaternion_to_mavlink(const Eigen::Quaternion< _Scalar > &q, std::array< float, 4 > &qmsg)
std::string fcu_odom_child_id_des
desired orientation of the fcu odometry message's child frame
EIGEN_MAKE_ALIGNED_OPERATOR_NEW OdometryPlugin()
void mavlink_urt_to_covariance_matrix(const std::array< float, ARR_SIZE > &covmsg, T &covmat)
tf2_ros::Buffer tf2_buffer
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
ros::NodeHandle odom_nh
node handler
#define UAS_FCU(uasobjptr)
void handle_odom(const mavlink::mavlink_message_t *msg, mavlink::common::msg::ODOMETRY &odom_msg)
Handle ODOMETRY MAVlink message.
#define ROS_ERROR_THROTTLE_NAMED(rate, name,...)
Eigen::Vector3d to_eigen(const geometry_msgs::Point r)
void covariance_urt_to_mavlink(const T &covmap, std::array< float, ARR_SIZE > &covmsg)
geometry_msgs::PoseWithCovariance::_covariance_type Covariance6d
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void pointEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Point &m)
void odom_cb(const nav_msgs::Odometry::ConstPtr &odom)
Sends odometry data msgs to the FCU.
std::vector< HandlerInfo > Subscriptions
void initialize(UAS &uas_) override
ros::Publisher odom_pub
nav_msgs/Odometry publisher
std::string fcu_odom_parent_id_des
desired orientation of the fcu odometry message's parent frame
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
Eigen::Isometry3d transformToEigen(const geometry_msgs::Transform &t)
void initialize(UAS &uas_) override
constexpr std::underlying_type< _T >::type enum_value(_T e)