26 #include <condition_variable> 30 #include <mavros_msgs/WaypointList.h> 31 #include <mavros_msgs/WaypointClear.h> 32 #include <mavros_msgs/WaypointPull.h> 33 #include <mavros_msgs/WaypointPush.h> 37 using mavlink::common::MAV_CMD;
38 using mavlink::common::MAV_FRAME;
39 using MRES = mavlink::common::MAV_MISSION_RESULT;
41 using mavlink::common::MAV_FRAME;
42 using WP_ITEM = mavlink::common::msg::MISSION_ITEM;
44 using WP_TYPE = mavlink::common::MAV_MISSION_TYPE;
65 case enum_value(MAV_FRAME::GLOBAL_RELATIVE_ALT):
67 case enum_value(MAV_FRAME::GLOBAL_RELATIVE_ALT_INT):
68 case enum_value(MAV_FRAME::GLOBAL_TERRAIN_ALT):
69 case enum_value(MAV_FRAME::GLOBAL_TERRAIN_ALT_INT):
91 mavros_msgs::Waypoint ret;
112 ret.frame = mav_msg.frame;
113 ret.command = mav_msg.command;
114 ret.is_current = mav_msg.current;
115 ret.autocontinue = mav_msg.autocontinue;
116 ret.param1 = mav_msg.param1;
117 ret.param2 = mav_msg.param2;
118 ret.param3 = mav_msg.param3;
119 ret.param4 = mav_msg.param4;
120 ret.x_lat = mav_msg.x;
121 ret.y_long = mav_msg.y;
122 ret.z_alt = mav_msg.z;
131 mavros_msgs::Waypoint ret;
140 ret.frame = mav_msg.frame;
141 ret.command = mav_msg.command;
142 ret.is_current = mav_msg.current;
143 ret.autocontinue = mav_msg.autocontinue;
144 ret.param1 = mav_msg.param1;
145 ret.param2 = mav_msg.param2;
146 ret.param3 = mav_msg.param3;
147 ret.param4 = mav_msg.param4;
150 ret.z_alt = mav_msg.z;
157 template <
class ITEM>
165 ret.frame = wp.frame;
166 ret.command = wp.command;
167 ret.current = wp.is_current;
168 ret.autocontinue = wp.autocontinue;
169 ret.param1 = wp.param1;
170 ret.param2 = wp.param2;
171 ret.param3 = wp.param3;
172 ret.param4 = wp.param4;
197 ret.frame = wp.frame;
198 ret.command = wp.command;
199 ret.current = wp.is_current;
200 ret.autocontinue = wp.autocontinue;
201 ret.param1 = wp.param1;
202 ret.param2 = wp.param2;
203 ret.param3 = wp.param3;
204 ret.param4 = wp.param4;
218 template <
class ITEM>
221 std::stringstream ss;
223 ss <<
'#' << wp.seq << (wp.current ?
'*' :
' ') <<
" F:" << wp.frame <<
" C:" << std::setw(3) << wp.command;
224 ss <<
" p: " << wp.param1 <<
' ' << wp.param2 <<
' ' << wp.param3 <<
' ' << wp.param4 <<
" x: " << wp.x <<
" y: " << wp.y <<
" z: " << wp.z;
358 void handle_mission_request(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::MISSION_REQUEST &mreq);
375 void handle_mission_count(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::MISSION_COUNT &mcnt);
383 void handle_mission_ack(
const mavlink::mavlink_message_t *msg, mavlink::common::msg::MISSION_ACK &mack);
418 list_receiving.notify_all();
424 reschedule_pull =
false;
444 schedule_timer.
stop();
446 schedule_timer.
start();
450 template <
class ITEM>
452 if (seq < send_waypoints.size()) {
453 auto wp_msg = send_waypoints.at(seq);
454 auto wpi = mav_from_msg<ITEM>(wp_msg, seq,
wp_type);
466 std::unique_lock<std::mutex> lock(recv_cond_mutex);
467 return list_receiving.wait_for(lock, std::chrono::nanoseconds(LIST_TIMEOUT_DT.
toNSec()))
468 == std::cv_status::no_timeout
478 std::unique_lock<std::mutex> lock(send_cond_mutex);
480 return list_sending.wait_for(lock, std::chrono::nanoseconds(LIST_TIMEOUT_DT.
toNSec()))
481 == std::cv_status::no_timeout
489 for (
auto &it : waypoints) {
490 it.is_current = (i == seq) ?
true :
false;
512 mavlink::common::msg::MISSION_REQUEST mrq {};
524 mavlink::common::msg::MISSION_REQUEST_INT mrq {};
536 mavlink::common::msg::MISSION_SET_CURRENT msc {};
547 mavlink::common::msg::MISSION_REQUEST_LIST mrl {};
558 mavlink::common::msg::MISSION_COUNT mcnt {};
569 log_ns.c_str(),start_index, end_index);
571 mavlink::common::msg::MISSION_WRITE_PARTIAL_LIST mwpl {};
572 mwpl.start_index = start_index;
573 mwpl.end_index = end_index;
584 mavlink::common::msg::MISSION_CLEAR_ALL mclr {};
594 mavlink::common::msg::MISSION_ACK mack {};
void timeout_cb(const ros::TimerEvent &event)
Act on a timeout Resend the message that may have been lost.
std::string waypoint_to_string(const ITEM &wp)
void mission_request_list()
MAVROS Plugin base class.
void mission_request_int(uint16_t seq)
ros::Timer schedule_timer
bool sequence_mismatch(const uint16_t &seq)
checks for a sequence mismatch between a MISSION_REQUEST(_INT) sequence and the current waypoint that...
#define ROS_INFO_NAMED(name,...)
static double waypoint_encode_factor(const uint8_t &frame)
static constexpr int LIST_TIMEOUT_MS
system startup delay before start pull
#define ROS_DEBUG_STREAM_NAMED(name, args)
void scheduled_pull_cb(const ros::TimerEvent &event)
Callback for scheduled waypoint pull.
const ros::Duration BOOTUP_TIME_DT
mavlink::common::MAV_MISSION_TYPE WP_TYPE
mavros_msgs::Waypoint mav_to_msg(const ITEM &mav_msg)
void mission_request(uint16_t seq)
std::recursive_mutex mutex
void mission_send(ITEM &wp)
void restart_timeout_timer(void)
void setPeriod(const Duration &period, bool reset=true)
void handle_mission_item_int(const mavlink::mavlink_message_t *msg, WP_ITEM_INT &wpi)
handle MISSION_ITEM_INT mavlink msg handles and stores mission items when pulling waypoints ...
MissionBase(std::string _name)
void set_current_waypoint(size_t seq)
set the FCU current waypoint
void send_waypoint(size_t seq)
send a single waypoint to FCU
void msg_set_target(_T &msg)
virtual void publish_waypoints()=0
publish the updated waypoint list after operation
void handle_mission_count(const mavlink::mavlink_message_t *msg, mavlink::common::msg::MISSION_COUNT &mcnt)
handle MISSION_COUNT mavlink msg Handles a mission count from FCU in a Waypoint Pull Triggers a pull ...
std::mutex send_cond_mutex
void mission_set_current(uint16_t seq)
void request_mission_done(void)
Send ACK back to FCU after pull.
#define ROS_DEBUG_NAMED(name,...)
mavlink::common::msg::MISSION_ITEM WP_ITEM
const ros::Duration WP_TIMEOUT_DT
std::lock_guard< std::recursive_mutex > lock_guard
const ros::Duration LIST_TIMEOUT_DT
mavlink::common::msg::MISSION_ITEM_INT WP_ITEM_INT
bool mission_item_int_support_confirmed
#define UAS_FCU(uasobjptr)
helper accessor to FCU link interface
virtual void initialize(ros::NodeHandle *_wp_nh)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
bool wait_fetch_all()
wait until a waypoint pull is complete. Pull happens asynchronously, this function blocks until it is...
static constexpr int BOOTUP_TIME_MS
std::vector< mavros_msgs::Waypoint > send_waypoints
bool wait_push_all()
wait until a waypoint push is complete. Push happens asynchronously, this function blocks until it is...
void mission_write_partial_list(uint16_t start_index, uint16_t end_index)
static constexpr int WP_TIMEOUT_MS
Timeout for pull/push operations.
static constexpr int RESCHEDULE_MS
std::unique_lock< std::recursive_mutex > unique_lock
std::condition_variable list_receiving
std::condition_variable list_sending
void handle_mission_request_int(const mavlink::mavlink_message_t *msg, mavlink::common::msg::MISSION_REQUEST_INT &mreq)
handle MISSION_REQUEST_INT mavlink msg handles and acts on misison request from FCU ...
mavlink::common::MAV_MISSION_RESULT MRES
void handle_mission_item(const mavlink::mavlink_message_t *msg, WP_ITEM &wpi)
handle MISSION_ITEM mavlink msg handles and stores mission items when pulling waypoints ...
std::mutex recv_cond_mutex
ITEM mav_from_msg(const mavros_msgs::Waypoint &wp, const uint16_t seq, WP_TYPE type)
static constexpr int RETRIES_COUNT
void handle_mission_ack(const mavlink::mavlink_message_t *msg, mavlink::common::msg::MISSION_ACK &mack)
handle MISSION_ACK mavlink msg Handles a MISSION_ACK which marks the end of a push, or a failure
void schedule_pull(const ros::Duration &dt)
bool use_mission_item_int
void mission_ack(MRES type)
void restart_timeout_timer_int(void)
void handle_mission_request(const mavlink::mavlink_message_t *msg, mavlink::common::msg::MISSION_REQUEST &mreq)
handle MISSION_REQUEST mavlink msg handles and acts on misison request from FCU
std::vector< mavros_msgs::Waypoint > waypoints
static constexpr unsigned int MAV_PROTOCOL_CAPABILITY_MISSION_INT
const ros::Duration RESCHEDULE_DT
void mission_count(uint16_t cnt)
constexpr std::underlying_type< _T >::type enum_value(_T e)
std::recursive_mutex mutex