21 #include <nav_msgs/Path.h> 22 #include <mavros_msgs/PositionTarget.h> 23 #include <mavros_msgs/SetMavFrame.h> 24 #include <trajectory_msgs/MultiDOFJointTrajectory.h> 25 #include <trajectory_msgs/MultiDOFJointTrajectoryPoint.h> 26 #include <std_srvs/Trigger.h> 29 namespace std_plugins {
30 using mavlink::common::MAV_FRAME;
41 sp_nh(
"~setpoint_trajectory")
46 PluginBase::initialize(uas_);
59 std::string mav_frame_str;
88 std::vector<trajectory_msgs::MultiDOFJointTrajectoryPoint>::const_iterator
setpoint_target;
106 for (
const auto &p : req->points) {
107 if (p.transforms.empty())
110 geometry_msgs::PoseStamped pose_msg;
111 pose_msg.pose.position.x = p.transforms[0].translation.x;
112 pose_msg.pose.position.y = p.transforms[0].translation.y;
113 pose_msg.pose.position.z = p.transforms[0].translation.z;
114 pose_msg.pose.orientation = p.transforms[0].rotation;
115 msg.poses.emplace_back(pose_msg);
126 if(static_cast<MAV_FRAME>(mav_frame) == MAV_FRAME::BODY_NED || static_cast<MAV_FRAME>(mav_frame) == MAV_FRAME::BODY_OFFSET_NED){
132 trajectory_target_msg = req;
135 setpoint_target = req->points.cbegin();
142 using mavlink::common::POSITION_TARGET_TYPEMASK;
145 if(!trajectory_target_msg)
148 Eigen::Vector3d position, velocity, af;
149 Eigen::Quaterniond attitude;
151 uint16_t type_mask = 0;
152 if(!setpoint_target->transforms.empty()){
157 type_mask = type_mask | uint16_t(POSITION_TARGET_TYPEMASK::X_IGNORE)
158 | uint16_t(POSITION_TARGET_TYPEMASK::Y_IGNORE)
159 | uint16_t(POSITION_TARGET_TYPEMASK::Z_IGNORE)
160 | uint16_t(POSITION_TARGET_TYPEMASK::YAW_IGNORE);
164 if(!setpoint_target->velocities.empty()){
166 yaw_rate = setpoint_target->velocities[0].angular.z;
169 type_mask = type_mask | uint16_t(POSITION_TARGET_TYPEMASK::VX_IGNORE)
170 | uint16_t(POSITION_TARGET_TYPEMASK::VY_IGNORE)
171 | uint16_t(POSITION_TARGET_TYPEMASK::VZ_IGNORE)
172 | uint16_t(POSITION_TARGET_TYPEMASK::YAW_RATE_IGNORE);
176 if(!setpoint_target->accelerations.empty()){
180 type_mask = type_mask | uint16_t(POSITION_TARGET_TYPEMASK::AX_IGNORE)
181 | uint16_t(POSITION_TARGET_TYPEMASK::AY_IGNORE)
182 | uint16_t(POSITION_TARGET_TYPEMASK::AZ_IGNORE);
196 next_setpoint_target = setpoint_target + 1;
197 if (next_setpoint_target != trajectory_target_msg->points.cend()) {
201 trajectory_target_msg.reset();
207 bool reset_cb(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)
209 if(trajectory_target_msg){
210 trajectory_target_msg.reset();
214 res.message =
"Trajectory reset denied: Empty trajectory";
220 bool set_mav_frame_cb(mavros_msgs::SetMavFrame::Request &req, mavros_msgs::SetMavFrame::Response &res)
222 mav_frame =
static_cast<MAV_FRAME>(req.mav_frame);
224 sp_nh.
setParam(
"mav_frame", mav_frame_str);
MAVROS Plugin base class.
ros::Subscriber local_sub
void local_cb(const trajectory_msgs::MultiDOFJointTrajectory::ConstPtr &req)
std::shared_ptr< MAVConnInterface const > ConstPtr
Setpoint TRAJECTORY plugin.
mavlink::common::MAV_FRAME mav_frame_from_str(const std::string &mav_frame)
Retreive MAV_FRAME from name.
void publish(const boost::shared_ptr< M > &message) const
trajectory_msgs::MultiDOFJointTrajectory::ConstPtr trajectory_target_msg
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool set_mav_frame_cb(mavros_msgs::SetMavFrame::Request &req, mavros_msgs::SetMavFrame::Response &res)
void setPeriod(const Duration &period, bool reset=true)
StaticTF
Orientation transform options when applying rotations to data.
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void reference_cb(const ros::TimerEvent &event)
Eigen::Quaterniond transform_orientation(const Eigen::Quaterniond &q, const StaticTF transform)
Transform representation of attitude from 1 frame to another (e.g. transfrom attitude from representi...
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.
Eigen::Vector3d transform_static_frame(const Eigen::Vector3d &vec, const StaticTF transform)
Transform data expressed in one frame to another frame.
ros::ServiceServer mav_frame_srv
PluginBase()
Plugin constructor Should not do anything before initialize()
std::vector< trajectory_msgs::MultiDOFJointTrajectoryPoint >::const_iterator setpoint_target
void publish_path(const trajectory_msgs::MultiDOFJointTrajectory::ConstPtr &req)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Mixin for setpoint plugins.
std::string to_string(timesync_mode e)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Eigen::Vector3d to_eigen(const geometry_msgs::Point r)
Helper to convert common ROS geometry_msgs::Point to Eigen::Vector3d.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Subscriptions get_subscriptions() override
Return vector of MAVLink message subscriptions (handlers)
friend class SetPositionTargetLocalNEDMixin
std::vector< trajectory_msgs::MultiDOFJointTrajectoryPoint >::const_iterator next_setpoint_target
bool reset_cb(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)
SetpointTrajectoryPlugin()
This mixin adds set_position_target_local_ned()
change from expressed WRT baselnk to WRT aircraft
std::vector< HandlerInfo > Subscriptions
Subscriptions vector.
void reset_timer(ros::Duration duration)
double quaternion_get_yaw(const Eigen::Quaterniond &q)
Get Yaw angle from quaternion.
bool getParam(const std::string &key, std::string &s) const
ros::ServiceServer trajectory_reset_srv
std::lock_guard< std::mutex > lock_guard
ros::Publisher desired_pub
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
change from expressed WRT ENU frame to WRT NED frame
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
void initialize(UAS &uas_) override
Plugin initializer.
constexpr std::underlying_type< _T >::type enum_value(_T e)
std::recursive_mutex mutex