mocap_pose_estimate.cpp
Go to the documentation of this file.
1 
10 /*
11  * Copyright 2014,2015,2016 Vladimir Ermakov, Tony Baltovski.
12  *
13  * This file is part of the mavros package and subject to the license terms
14  * in the top-level LICENSE file of the mavros repository.
15  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
16  */
17 
18 #include <mavros/mavros_plugin.h>
20 
21 #include <geometry_msgs/PoseStamped.h>
22 #include <geometry_msgs/TransformStamped.h>
23 
24 
25 namespace mavros {
26 namespace extra_plugins {
33 {
34 public:
36  mp_nh("~mocap")
37  { }
38 
39  void initialize(UAS &uas_) override
40  {
42 
43  bool use_tf;
44  bool use_pose;
45 
47  mp_nh.param("use_tf", use_tf, false);
48 
50  mp_nh.param("use_pose", use_pose, true);
51 
52  if (use_tf && !use_pose) {
54  }
55  else if (use_pose && !use_tf) {
57  }
58  else {
59  ROS_ERROR_NAMED("mocap", "Use one motion capture source.");
60  }
61  }
62 
64  {
65  return { /* Rx disabled */ };
66  }
67 
68 private:
70 
73 
74  /* -*- low-level send -*- */
75  void mocap_pose_send
76  (uint64_t usec,
77  Eigen::Quaterniond &q,
78  Eigen::Vector3d &v)
79  {
80  mavlink::common::msg::ATT_POS_MOCAP pos = {};
81 
82  pos.time_usec = usec;
84  pos.x = v.x();
85  pos.y = v.y();
86  pos.z = v.z();
87 
88  UAS_FCU(m_uas)->send_message_ignore_drop(pos);
89  }
90 
91  /* -*- mid-level helpers -*- */
93  {
94  Eigen::Quaterniond q_enu;
95 
96  tf::quaternionMsgToEigen(pose->pose.orientation, q_enu);
99 
100  auto position = ftf::transform_frame_enu_ned(
101  Eigen::Vector3d(
102  pose->pose.position.x,
103  pose->pose.position.y,
104  pose->pose.position.z));
105 
106  mocap_pose_send(pose->header.stamp.toNSec() / 1000,
107  q,
108  position);
109  }
110 
111  /* -*- callbacks -*- */
113  {
114  Eigen::Quaterniond q_enu;
115 
116  tf::quaternionMsgToEigen(trans->transform.rotation, q_enu);
119 
120  auto position = ftf::transform_frame_enu_ned(
121  Eigen::Vector3d(
122  trans->transform.translation.x,
123  trans->transform.translation.y,
124  trans->transform.translation.z));
125 
126  mocap_pose_send(trans->header.stamp.toNSec() / 1000,
127  q,
128  position);
129  }
130 };
131 } // namespace extra_plugins
132 } // namespace mavros
133 
mavros::ftf::transform_frame_enu_ned
T transform_frame_enu_ned(const T &in)
mavros::extra_plugins::MocapPoseEstimatePlugin
MocapPoseEstimate plugin.
Definition: mocap_pose_estimate.cpp:32
mavros::plugin::PluginBase::m_uas
UAS * m_uas
mavros::plugin::PluginBase::Subscriptions
std::vector< HandlerInfo > Subscriptions
mavros::plugin::PluginBase::PluginBase
PluginBase()
UAS_FCU
#define UAS_FCU(uasobjptr)
mavros::UAS
mavros::extra_plugins::MocapPoseEstimatePlugin::mp_nh
ros::NodeHandle mp_nh
Definition: mocap_pose_estimate.cpp:69
tf::quaternionMsgToEigen
void quaternionMsgToEigen(const geometry_msgs::Quaternion &m, Eigen::Quaterniond &e)
ConstPtr
std::shared_ptr< MAVConnInterface const > ConstPtr
mavros::extra_plugins::MocapPoseEstimatePlugin::mocap_pose_cb
void mocap_pose_cb(const geometry_msgs::PoseStamped::ConstPtr &pose)
Definition: mocap_pose_estimate.cpp:92
ROS_ERROR_NAMED
#define ROS_ERROR_NAMED(name,...)
mavros::extra_plugins::MocapPoseEstimatePlugin::mocap_tf_sub
ros::Subscriber mocap_tf_sub
Definition: mocap_pose_estimate.cpp:72
mavros::extra_plugins::MocapPoseEstimatePlugin::mocap_pose_sub
ros::Subscriber mocap_pose_sub
Definition: mocap_pose_estimate.cpp:71
mavros::extra_plugins::MocapPoseEstimatePlugin::initialize
void initialize(UAS &uas_) override
Definition: mocap_pose_estimate.cpp:39
mavros::extra_plugins::MocapPoseEstimatePlugin::MocapPoseEstimatePlugin
MocapPoseEstimatePlugin()
Definition: mocap_pose_estimate.cpp:35
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
mavros_plugin.h
pos
ssize_t pos
mavros::extra_plugins::MocapPoseEstimatePlugin::mocap_pose_send
void mocap_pose_send(uint64_t usec, Eigen::Quaterniond &q, Eigen::Vector3d &v)
Definition: mocap_pose_estimate.cpp:76
eigen_msg.h
mavros::ftf::transform_orientation_baselink_aircraft
T transform_orientation_baselink_aircraft(const T &in)
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
mavros
mavros::ftf::transform_orientation_enu_ned
T transform_orientation_enu_ned(const T &in)
initialize
virtual void initialize(UAS &uas)
mavros::plugin::PluginBase
class_list_macros.hpp
mavros::extra_plugins::MocapPoseEstimatePlugin::mocap_tf_cb
void mocap_tf_cb(const geometry_msgs::TransformStamped::ConstPtr &trans)
Definition: mocap_pose_estimate.cpp:112
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
mavros::extra_plugins::MocapPoseEstimatePlugin::get_subscriptions
Subscriptions get_subscriptions() override
Definition: mocap_pose_estimate.cpp:63
ros::NodeHandle
ros::Subscriber
mavros::ftf::quaternion_to_mavlink
void quaternion_to_mavlink(const Eigen::Quaternion< _Scalar > &q, std::array< float, 4 > &qmsg)


mavros_extras
Author(s): Vladimir Ermakov , Amilcar Lucas
autogenerated on Tue May 6 2025 02:34:08