18 #include <mavros_msgs/Trajectory.h> 19 #include <mavros_msgs/PositionTarget.h> 20 #include <nav_msgs/Path.h> 23 namespace extra_plugins {
93 x[i] = position_ned.x();
94 y[i] = position_ned.y();
95 z[i] = position_ned.z();
102 x[i] = velocity_ned.x();
103 y[i] = velocity_ned.y();
104 z[i] = velocity_ned.z();
111 x[i] = acceleration_ned.x();
112 y[i] = acceleration_ned.y();
113 z[i] = acceleration_ned.z();
120 y[i] =
wrap_pi(-yaw + (M_PI / 2.0
f));
133 y[i] =
wrap_pi(-yaw_wp + (M_PI / 2.0
f));
177 void fill_msg_position(geometry_msgs::Point &position,
const mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &t,
const size_t i)
181 position.x = position_enu.x();
182 position.y = position_enu.y();
183 position.z = position_enu.z();
186 void fill_msg_velocity(geometry_msgs::Vector3 &velocity,
const mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &t,
const size_t i)
190 velocity.x = velocity_enu.x();
191 velocity.y = velocity_enu.y();
192 velocity.z = velocity_enu.z();
195 void fill_msg_acceleration(geometry_msgs::Vector3 &acceleration,
const mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &t,
const size_t i)
199 acceleration.x = acceleration_enu.x();
200 acceleration.y = acceleration_enu.y();
201 acceleration.z = acceleration_enu.z();
215 ROS_ASSERT(NUM_POINTS == req->point_valid.size());
217 if (req->type == mavros_msgs::Trajectory::MAV_TRAJECTORY_REPRESENTATION_WAYPOINTS) {
218 mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS trajectory {};
220 auto fill_point_rep_waypoints = [&](mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &
t,
const RosPoints &rp,
const size_t i) {
221 const auto valid = req->point_valid[i];
223 auto valid_so_far = trajectory.valid_points;
229 trajectory.valid_points = valid_so_far + 1;
235 t.command[i] = UINT16_MAX;
245 fill_point_rep_waypoints(trajectory, req->point_1, 0);
246 fill_point_rep_waypoints(trajectory, req->point_2, 1);
247 fill_point_rep_waypoints(trajectory, req->point_3, 2);
248 fill_point_rep_waypoints(trajectory, req->point_4, 3);
249 fill_point_rep_waypoints(trajectory, req->point_5, 4);
252 trajectory.time_usec = req->header.stamp.toNSec() / 1000;
255 mavlink::common::msg::TRAJECTORY_REPRESENTATION_BEZIER trajectory {};
256 auto fill_point_rep_bezier = [&](mavlink::common::msg::TRAJECTORY_REPRESENTATION_BEZIER &
t,
const RosPoints &rp,
const size_t i) {
257 const auto valid = req->point_valid[i];
259 auto valid_so_far = trajectory.valid_points;
265 trajectory.valid_points = valid_so_far + 1;
277 fill_point_rep_bezier(trajectory, req->point_1, 0);
278 fill_point_rep_bezier(trajectory, req->point_2, 1);
279 fill_point_rep_bezier(trajectory, req->point_3, 2);
280 fill_point_rep_bezier(trajectory, req->point_4, 3);
281 fill_point_rep_bezier(trajectory, req->point_5, 4);
284 trajectory.time_usec = req->header.stamp.toNSec() / 1000;
300 mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS trajectory {};
302 trajectory.time_usec = req->header.stamp.toNSec() / 1000;
303 trajectory.valid_points = std::min(NUM_POINTS, req->poses.size());
305 auto fill_point = [&](mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &
t,
const size_t i) {
306 t.command[i] = UINT16_MAX;
307 if (req->poses.size() < i + 1) {
311 auto &pose = req->poses[i].pose;
324 fill_point(trajectory, 0);
325 fill_point(trajectory, 1);
326 fill_point(trajectory, 2);
327 fill_point(trajectory, 3);
328 fill_point(trajectory, 4);
334 void handle_trajectory(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &trajectory)
336 auto tr_desired = boost::make_shared<mavros_msgs::Trajectory>();
338 auto fill_msg_point = [&](
RosPoints & p,
const mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &
t,
const size_t i) {
342 p.yaw =
wrap_pi((M_PI / 2.0
f) - t.pos_yaw[i]);
343 p.yaw_rate = t.vel_yaw[i];
344 tr_desired->command[i] = t.command[i];
349 for (
int i = 0; i < trajectory.valid_points; ++i)
351 tr_desired->point_valid[i] =
true;
354 for (
int i = trajectory.valid_points; i < NUM_POINTS; ++i)
356 tr_desired->point_valid[i] =
false;
366 fill_msg_point(tr_desired->point_1, trajectory, 0);
367 fill_msg_point(tr_desired->point_2, trajectory, 1);
368 fill_msg_point(tr_desired->point_3, trajectory, 2);
369 fill_msg_point(tr_desired->point_4, trajectory, 3);
370 fill_msg_point(tr_desired->point_5, trajectory, 4);
373 trajectory_desired_pub.
publish(tr_desired);
378 if (!std::isfinite(a)) {
382 return fmod(a + M_PI, 2.0
f * M_PI) - M_PI;
std::shared_ptr< MAVConnInterface const > ConstPtr
std_msgs::Header synchronized_header(const std::string &frame_id, const T time_stamp)
void publish(const boost::shared_ptr< M > &message) const
void fill_points_velocity(MavPoints &x, MavPoints &y, MavPoints &z, const geometry_msgs::Vector3 &velocity, const size_t i)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::array< float, NUM_POINTS > MavPoints
Type matching mavlink::common::msg::TRAJECTORY::TRAJECTORY_REPRESENTATION_WAYPOINTS fields...
void fill_points_acceleration(MavPoints &x, MavPoints &y, MavPoints &z, const geometry_msgs::Vector3 &acceleration, const size_t i)
HandlerInfo make_handler(const mavlink::msgid_t id, void(_C::*fn)(const mavlink::mavlink_message_t *msg, const mavconn::Framing framing))
void fill_points_yaw_speed(MavPoints &yv, const double yaw_speed, const size_t i)
T transform_orientation_enu_ned(const T &in)
void handle_trajectory(const mavlink::mavlink_message_t *msg, mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &trajectory)
static constexpr size_t NUM_POINTS
Points count in TRAJECTORY message.
ros::Subscriber trajectory_generated_sub
void fill_points_yaw_wp(MavPoints &y, const double yaw, const size_t i)
ros::NodeHandle trajectory_nh
void fill_points_all_unused(mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &t, const size_t i)
void fill_points_position(MavPoints &x, MavPoints &y, MavPoints &z, const geometry_msgs::Point &position, const size_t i)
void fill_msg_position(geometry_msgs::Point &position, const mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &t, const size_t i)
void fill_points_all_unused_bezier(mavlink::common::msg::TRAJECTORY_REPRESENTATION_BEZIER &t, const size_t i)
#define UAS_FCU(uasobjptr)
T transform_frame_ned_enu(const T &in)
Eigen::Vector3d to_eigen(const geometry_msgs::Point r)
auto fill_points_unused_path(mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &t, const size_t i)
mavros_msgs::PositionTarget RosPoints
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
T transform_frame_enu_ned(const T &in)
void fill_points_yaw_q(MavPoints &y, const geometry_msgs::Quaternion &orientation, const size_t i)
void path_cb(const nav_msgs::Path::ConstPtr &req)
Send corrected path to the FCU.
std::vector< HandlerInfo > Subscriptions
Subscriptions get_subscriptions() override
double quaternion_get_yaw(const Eigen::Quaterniond &q)
void trajectory_cb(const mavros_msgs::Trajectory::ConstPtr &req)
Send corrected path to the FCU.
void fill_msg_acceleration(geometry_msgs::Vector3 &acceleration, const mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &t, const size_t i)
void initialize(UAS &uas_) override
ros::Publisher trajectory_desired_pub
T transform_orientation_baselink_aircraft(const T &in)
void initialize(UAS &uas_) override
void fill_msg_velocity(geometry_msgs::Vector3 &velocity, const mavlink::common::msg::TRAJECTORY_REPRESENTATION_WAYPOINTS &t, const size_t i)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void fill_points_delta(MavPoints &y, const double time_horizon, const size_t i)
constexpr std::underlying_type< _T >::type enum_value(_T e)