21 #include <geometry_msgs/PoseStamped.h> 23 #include <mavros_msgs/SetMavFrame.h> 24 #include <mavros_msgs/GlobalPositionTarget.h> 26 #include <GeographicLib/Geocentric.hpp> 30 namespace std_plugins {
31 using mavlink::common::MAV_FRAME;
41 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
44 sp_nh(
"~setpoint_position"),
52 PluginBase::initialize(uas_);
62 << tf_frame_id <<
" -> " << tf_child_frame_id);
78 std::string mav_frame_str;
126 using mavlink::common::MAV_FRAME;
134 const uint16_t ignore_all_except_xyz_y = (1 << 11) | (7 << 6) | (7 << 3);
137 if (static_cast<MAV_FRAME>(mav_frame) == MAV_FRAME::BODY_NED ||
static_cast<MAV_FRAME>(
mav_frame) == MAV_FRAME::BODY_OFFSET_NED) {
145 if (mav_frame == MAV_FRAME::BODY_NED || mav_frame == MAV_FRAME::BODY_OFFSET_NED) {
155 ignore_all_except_xyz_y,
157 Eigen::Vector3d::Zero(),
158 Eigen::Vector3d::Zero(),
196 GeographicLib::Geocentric earth(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
198 Eigen::Vector3d goal_gps(req->latitude, req->longitude, req->altitude);
201 Eigen::Vector3d current_ecef;
202 earth.Forward(current_gps.x(), current_gps.y(), current_gps.z(),
203 current_ecef.x(), current_ecef.y(), current_ecef.z());
206 Eigen::Vector3d goal_ecef;
207 earth.Forward(goal_gps.x(), goal_gps.y(), goal_gps.z(),
208 goal_ecef.x(), goal_ecef.y(), goal_ecef.z());
211 Eigen::Vector3d ecef_offset = goal_ecef - current_ecef;
216 Eigen::Quaterniond q;
218 q = Eigen::AngleAxisd(0.0, Eigen::Vector3d::UnitX())
219 * Eigen::AngleAxisd(0.0, Eigen::Vector3d::UnitY())
220 * Eigen::AngleAxisd(req->yaw, Eigen::Vector3d::UnitZ());
223 sp.translation() = current_local_pos + enu_offset;
225 sp.linear() = q.toRotationMatrix();
228 if ((req->header.stamp.toNSec() / 1000000) > old_gps_stamp) {
229 old_gps_stamp = req->header.stamp.toNSec() / 1000000;
242 current_gps = {msg->latitude, msg->longitude, msg->altitude};
253 bool set_mav_frame_cb(mavros_msgs::SetMavFrame::Request &req, mavros_msgs::SetMavFrame::Response &res)
255 mav_frame =
static_cast<MAV_FRAME>(req.mav_frame);
257 sp_nh.
setParam(
"mav_frame", mav_frame_str);
MAVROS Plugin base class.
std::shared_ptr< MAVConnInterface const > ConstPtr
ros::Subscriber setpointg_sub
GPS setpoint.
mavlink::common::MAV_FRAME mav_frame_from_str(const std::string &mav_frame)
Retreive MAV_FRAME from name.
bool set_mav_frame_cb(mavros_msgs::SetMavFrame::Request &req, mavros_msgs::SetMavFrame::Response &res)
#define ROS_WARN_THROTTLE_NAMED(period, name,...)
std::string tf_child_frame_id
void setpointg_cb(const mavros_msgs::GlobalPositionTarget::ConstPtr &req)
ros::ServiceServer mav_frame_srv
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
This mixin adds TF2 listener thread to plugin.
uint32_t old_gps_stamp
old time gps time stamp in [ms], to check if new gps msg is received
void tf2_start(const char *_thd_name, void(SetpointPositionPlugin::*cbp)(const geometry_msgs::TransformStamped &))
start tf listener
#define ROS_INFO_STREAM_NAMED(name, args)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void set_position_target_local_ned(uint32_t time_boot_ms, uint8_t coordinate_frame, uint16_t type_mask, Eigen::Vector3d p, Eigen::Vector3d v, Eigen::Vector3d af, float yaw, float yaw_rate)
Message specification: https://mavlink.io/en/messages/common.html#SET_POSITION_TARGET_LOCAL_NED.
void setpoint_cb(const geometry_msgs::PoseStamped::ConstPtr &req)
T transform_orientation_enu_ned(const T &in)
Transform from attitude represented WRT ENU frame to attitude represented WRT NED frame...
void local_cb(const geometry_msgs::PoseStamped::ConstPtr &msg)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SetpointPositionPlugin()
PluginBase()
Plugin constructor Should not do anything before initialize()
friend class TF2ListenerMixin
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::Subscriber setpoint_sub
Eigen::Vector3d current_gps
geodetic coordinates LLA
Mixin for setpoint plugins.
Subscriptions get_subscriptions()
Return vector of MAVLink message subscriptions (handlers)
std::string to_string(timesync_mode e)
ros::Subscriber gps_sub
current GPS
Eigen::Vector3d to_eigen(const geometry_msgs::Point r)
Helper to convert common ROS geometry_msgs::Point to Eigen::Vector3d.
T transform_frame_baselink_aircraft(const T &in)
Transform data expressed in Baselink frame to Aircraft frame.
friend class SetPositionTargetLocalNEDMixin
T transform_frame_enu_ned(const T &in)
Transform data expressed in ENU to NED frame.
void transformMsgToEigen(const geometry_msgs::Transform &m, Eigen::Affine3d &e)
void gps_cb(const sensor_msgs::NavSatFix::ConstPtr &msg)
void transform_cb(const geometry_msgs::TransformStamped &transform)
This mixin adds set_position_target_local_ned()
std::vector< HandlerInfo > Subscriptions
Subscriptions vector.
double quaternion_get_yaw(const Eigen::Quaterniond &q)
Get Yaw angle from quaternion.
bool getParam(const std::string &key, std::string &s) const
T transform_frame_ecef_enu(const T &in, const T &map_origin)
Transform data expressed in ECEF frame to ENU frame.
T transform_orientation_baselink_aircraft(const T &in)
Transform from attitude represented WRT baselink frame to attitude represented WRT body frame...
void send_position_target(const ros::Time &stamp, const Eigen::Affine3d &tr)
Send setpoint to FCU position controller.
Setpoint position plugin.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
void initialize(UAS &uas_)
Plugin initializer.
ros::NodeHandle spg_nh
to get local position and gps coord which are not under sp_h()
ros::Subscriber local_sub
current local ENU
constexpr std::underlying_type< _T >::type enum_value(_T e)
Eigen::Vector3d current_local_pos
Current local position in ENU.