20 #include <std_srvs/Trigger.h> 21 #include <mavros_msgs/CommandLong.h> 22 #include <mavros_msgs/HomePosition.h> 26 namespace std_plugins {
35 hp_nh(
"~home_position"),
41 PluginBase::initialize(uas_);
73 using mavlink::common::MAV_CMD;
79 auto client = pnh.
serviceClient<mavros_msgs::CommandLong>(
"cmd/command");
81 mavros_msgs::CommandLong
cmd{};
85 ret = client.call(
cmd);
86 ret =
cmd.response.success;
95 void handle_home_position(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::HOME_POSITION &home_position)
99 auto hp = boost::make_shared<mavros_msgs::HomePosition>();
103 auto hp_approach_enu =
ftf::transform_frame_ned_enu(Eigen::Vector3d(home_position.approach_x, home_position.approach_y, home_position.approach_z));
106 hp->geo.latitude = home_position.latitude / 1E7;
107 hp->geo.longitude = home_position.longitude / 1E7;
113 ROS_DEBUG_NAMED(
"home_position",
"HP: Home lat %f, long %f, alt %f", hp->geo.latitude, hp->geo.longitude, hp->geo.altitude);
119 mavlink::common::msg::SET_HOME_POSITION hp {};
121 Eigen::Vector3d
pos, approach;
122 Eigen::Quaterniond q;
144 hp.latitude = req->geo.latitude * 1e7;
145 hp.longitude = req->geo.longitude * 1e7;
149 hp.approach_x = approach.x();
150 hp.approach_y = approach.y();
151 hp.approach_z = approach.z();
157 bool req_update_cb(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)
MAVROS Plugin base class.
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
std::shared_ptr< MAVConnInterface const > ConstPtr
#define ROS_INFO_NAMED(name,...)
double ellipsoid_to_geoid_height(T lla)
Conversion from height above ellipsoid (WGS-84) to height above geoid (AMSL)
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())
ros::ServiceServer update_srv
HandlerInfo make_handler(const mavlink::msgid_t id, void(_C::*fn)(const mavlink::mavlink_message_t *msg, const mavconn::Framing framing))
Subscriptions get_subscriptions()
Return vector of MAVLink message subscriptions (handlers)
Eigen::Quaterniond mavlink_to_quaternion(const std::array< float, 4 > &q)
Convert Mavlink float[4] quaternion to Eigen.
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
T transform_orientation_enu_ned(const T &in)
Transform from attitude represented WRT ENU frame to attitude represented WRT NED frame...
void handle_home_position(const mavlink::mavlink_message_t *msg, mavlink::common::msg::HOME_POSITION &home_position)
#define ROS_DEBUG_NAMED(name,...)
uint8_t get_tgt_system()
Return communication target system.
void vectorMsgToEigen(const geometry_msgs::Vector3 &m, Eigen::Vector3d &e)
const ros::Duration REQUEST_POLL_TIME_DT
position refresh poll interval
void vectorEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Vector3 &m)
#define UAS_FCU(uasobjptr)
helper accessor to FCU link interface
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
void initialize(UAS &uas_)
Plugin initializer.
void home_position_cb(const mavros_msgs::HomePosition::ConstPtr &req)
void pointMsgToEigen(const geometry_msgs::Point &m, Eigen::Vector3d &e)
T transform_frame_ned_enu(const T &in)
Transform data expressed in NED to ENU frame.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void timeout_cb(const ros::TimerEvent &event)
void connection_cb(bool connected) override
void pointEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Point &m)
T transform_frame_enu_ned(const T &in)
Transform data expressed in ENU to NED frame.
void enable_connection_cb()
std::vector< HandlerInfo > Subscriptions
Subscriptions vector.
T transform_orientation_ned_enu(const T &in)
Transform from attitude represented WRT NED frame to attitude represented WRT ENU frame...
void quaternionMsgToEigen(const geometry_msgs::Quaternion &m, Eigen::Quaterniond &e)
#define ROS_ERROR_NAMED(name,...)
void quaternion_to_mavlink(const Eigen::Quaterniond &q, std::array< float, 4 > &qmsg)
Store Quaternion to MAVLink float[4] format.
static constexpr int REQUEST_POLL_TIME_MS
bool req_update_cb(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)
bool call_get_home_position(void)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
double geoid_to_ellipsoid_height(T lla)
Conversion from height above geoid (AMSL) to height above ellipsoid (WGS-84)
constexpr std::underlying_type< _T >::type enum_value(_T e)