64 ModuleParams(navigator)
82 if (_mission_sub.updated()) {
141 cmd.
command = vehicle_command_s::VEHICLE_CMD_DO_TRIGGER_CONTROL;
167 cmd.
command = vehicle_command_s::VEHICLE_CMD_DO_TRIGGER_CONTROL;
191 bool mission_sub_updated = _mission_sub.updated();
193 if (mission_sub_updated) {
204 mission_sub_updated =
true;
255 if (!_param_mis_mnt_yaw_ctl.get()
323 case mission_result_s::MISSION_EXECUTION_MODE_NORMAL:
324 case mission_result_s::MISSION_EXECUTION_MODE_FAST_FORWARD:
325 if (mode == mission_result_s::MISSION_EXECUTION_MODE_REVERSE) {
356 case mission_result_s::MISSION_EXECUTION_MODE_REVERSE:
357 if ((mode == mission_result_s::MISSION_EXECUTION_MODE_NORMAL) ||
358 (mode == mission_result_s::MISSION_EXECUTION_MODE_FAST_FORWARD)) {
390 const ssize_t len =
sizeof(missionitem);
391 missionitem_prev = missionitem;
393 if (
dm_read(dm_current, i, &missionitem, len) != len) {
395 PX4_ERR(
"dataman read failure");
454 return mission_valid && on_landing_stage;
514 PX4_ERR(
"mission update failed");
522 PX4_ERR(
"mission check failed");
540 switch (_mission_type) {
543 case mission_result_s::MISSION_EXECUTION_MODE_NORMAL:
544 case mission_result_s::MISSION_EXECUTION_MODE_FAST_FORWARD: {
549 case mission_result_s::MISSION_EXECUTION_MODE_REVERSE: {
555 const ssize_t len =
sizeof(missionitem);
557 if (
dm_read(dm_current, i, &missionitem, len) != len) {
559 PX4_ERR(
"dataman read failure");
593 bool user_feedback_done =
false;
597 bool has_next_position_item =
false;
606 "Executing Mission");
607 user_feedback_done =
true;
618 _mission_execution_mode == mission_result_s::MISSION_EXECUTION_MODE_REVERSE ?
"Reverse Mission finished, landed" :
619 "Mission finished, landed.");
624 _mission_execution_mode == mission_result_s::MISSION_EXECUTION_MODE_REVERSE ?
"Reverse Mission finished, loitering" :
625 "Mission finished, loitering.");
631 user_feedback_done =
true;
644 pos_sp_triplet->next.valid =
false;
653 if (!user_feedback_done) {
667 user_feedback_done =
true;
682 case mission_result_s::MISSION_EXECUTION_MODE_NORMAL:
683 case mission_result_s::MISSION_EXECUTION_MODE_FAST_FORWARD: {
705 has_next_position_item =
true;
831 has_next_position_item =
true;
835 if (pos_sp_triplet->
current.
valid && pos_sp_triplet->
current.
type == position_setpoint_s::SETPOINT_TYPE_POSITION) {
869 has_next_position_item =
true;
881 && pos_sp_triplet->
current.
type == position_setpoint_s::SETPOINT_TYPE_POSITION) {
948 case mission_result_s::MISSION_EXECUTION_MODE_REVERSE: {
966 case mission_result_s::MISSION_EXECUTION_MODE_NORMAL:
967 case mission_result_s::MISSION_EXECUTION_MODE_FAST_FORWARD: {
976 && has_next_position_item) {
1035 case mission_result_s::MISSION_EXECUTION_MODE_REVERSE: {
1055 pos_sp_triplet->
previous = current_setpoint_copy;
1062 _work_item_type = new_work_item_type;
1065 if (pos_sp_triplet->
current.
type == position_setpoint_s::SETPOINT_TYPE_LAND
1066 || pos_sp_triplet->
current.
type == position_setpoint_s::SETPOINT_TYPE_IDLE) {
1080 if (has_next_position_item) {
1177 if (setpoint->
valid && setpoint->
type == position_setpoint_s::SETPOINT_TYPE_POSITION) {
1178 mission_item->
lat = setpoint->
lat;
1179 mission_item->
lon = setpoint->
lon;
1201 mission_item_next->
lat, mission_item_next->
lon);
1237 float yaw_offset = 0.0f;
1241 case vehicle_roi_s::ROI_LOCATION: {
1250 case vehicle_roi_s::ROI_WPNEXT: {
1252 point_to_latlon[0] = pos_sp_triplet->
current.
lat;
1253 point_to_latlon[1] = pos_sp_triplet->
current.
lon;
1259 case vehicle_roi_s::ROI_NONE:
1260 case vehicle_roi_s::ROI_WPINDEX:
1261 case vehicle_roi_s::ROI_TARGET:
1262 case vehicle_roi_s::ROI_ENUM_END:
1271 point_from_latlon[1], point_to_latlon[0], point_to_latlon[1]);
1276 point_from_latlon[1], point_to_latlon[0],
1277 point_to_latlon[1]) + yaw_offset);
1301 || !(pos_sp_triplet->
previous.
type == position_setpoint_s::SETPOINT_TYPE_POSITION ||
1302 pos_sp_triplet->
previous.
type == position_setpoint_s::SETPOINT_TYPE_LOITER) ||
1311 if (pos_sp_triplet->
current.
type == position_setpoint_s::SETPOINT_TYPE_LOITER) {
1345 if (_min_current_sp_distance_xy < acc_rad) {
1412 (int)(alt_sp - alt_landing));
1426 vcmd.
command = vehicle_command_s::VEHICLE_CMD_DO_REPOSITION;
1438 mission_item_s *next_position_mission_item,
bool *has_next_position_item)
1440 *has_next_position_item =
false;
1441 bool first_res =
false;
1456 *has_next_position_item =
true;
1478 int index_to_read = current_index + offset;
1490 for (
int i = 0; i < 10; i++) {
1491 if (*mission_index_ptr < 0 || *mission_index_ptr >= (
int)
_mission.
count) {
1493 if ((*mission_index_ptr != (
int)
_mission.
count) && (*mission_index_ptr != -1)) {
1507 if (
dm_read(dm_item, *mission_index_ptr, &mission_item_tmp, len) != len) {
1540 if (offset == 0 && execute_jumps) {
1546 (*mission_index_ptr)--;
1549 (*mission_index_ptr)++;
1555 memcpy(mission_item, &mission_item_tmp,
sizeof(
struct mission_item_s));
1573 if (dm_lock_ret != 0) {
1574 PX4_ERR(
"DM_KEY_MISSION_STATE lock failed");
1591 PX4_ERR(
"Can't save mission state");
1609 PX4_ERR(
"Can't save mission state");
1614 if (dm_lock_ret == 0) {
1659 _param_mis_dist_1wp.get(),
1660 _param_mis_dist_wps.get(),
1684 if (mission.
count > 0) {
1687 for (
unsigned index = 0; index < mission.
count; index++) {
1691 if (
dm_read(dm_current, index, &item, len) != len) {
1692 PX4_WARN(
"could not read mission item during reset");
1700 PX4_WARN(
"could not save mission item during reset");
1745 &(setpoint->
lat), &(setpoint->
lon));
1746 setpoint->
type = position_setpoint_s::SETPOINT_TYPE_POSITION;
1753 int32_t min_dist_index(0);
1754 float min_dist(FLT_MAX), dist_xy(FLT_MAX), dist_z(FLT_MAX);
1760 const ssize_t len =
sizeof(missionitem);
1762 if (
dm_read(dm_current, i, &missionitem, len) != len) {
1764 PX4_ERR(
"dataman read failure");
1780 if (dist < min_dist) {
1799 if (dist < min_dist) {
1801 min_dist_index = -1;
1805 return min_dist_index;
1822 (fabs(p1->
lat - p2->
lat) < DBL_EPSILON) &&
1823 (fabs(p1->
lon - p2->
lon) < DBL_EPSILON) &&
#define VEHICLE_TYPE_FIXED_WING
#define mavlink_log_info(_pub, _text,...)
Send a mavlink info message (not printed to console).
bool home_position_valid()
Global position setpoint in WGS84 coordinates.
int32_t index_closest_mission_item() const
Return the index of the closest mission item to the current global position.
float get_distance_to_point_global_wgs84(double lat_now, double lon_now, float alt_now, double lat_next, double lon_next, float alt_next, float *dist_xy, float *dist_z)
#define mavlink_log_critical(_pub, _text,...)
Send a mavlink critical message and print to console.
enum Mission::@122 MISSION_TYPE_NONE
void copy_position_if_valid(struct mission_item_s *mission_item, struct position_setpoint_s *setpoint)
Copies position from setpoint if valid, otherwise copies current position.
void advance_mission()
Move on to next mission item or switch to loiter.
void generate_waypoint_from_heading(struct position_setpoint_s *setpoint, float yaw)
Project current location with heading to far away location and fill setpoint.
Definition of a mission consisting of mission items.
void on_inactive() override
This function is called while the mode is inactive.
Helper class to access missions.
float get_acceptance_radius()
Get the acceptance radius.
API for the uORB lightweight object broker.
Definition of geo / math functions to perform geodesic calculations.
uint8_t _mission_execution_mode
the current mode of how the mission is executed,look at mission_result.msg for the definition ...
float altitude
altitude in meters (AMSL)
bool is_planned_mission() const
Mission(Navigator *navigator)
uint16_t autocontinue
true if next waypoint should follow after this one
bool checkMissionFeasible(const mission_s &mission, float max_distance_to_1st_waypoint, float max_distance_between_waypoints, bool land_start_req)
float acceptance_radius
default radius in which the mission is accepted as reached in meters
float get_loiter_min_alt() const
__EXPORT int dm_lock(dm_item_t item)
Lock all items of a type.
float get_distance_to_next_waypoint(double lat_now, double lon_now, double lat_next, double lon_next)
Returns the distance to the next waypoint in meters.
void increment_mission_instance_count()
void set_loiter_item(struct mission_item_s *item, float min_clearance=-1.0f)
Set a loiter mission item, if possible reuse the position setpoint, otherwise take the current positi...
struct position_setpoint_s next
bool _mission_waypoints_changed
enum Mission::work_item_type WORK_ITEM_TYPE_DEFAULT
current type of work to do (sub mission item)
bool _waypoint_position_reached
struct home_position_s * get_home_position()
Getters.
void altitude_sp_foh_update()
Updates the altitude sp to follow a foh.
dm_item_t
Types of items that the data manager can store.
uint16_t vtol_back_transition
part of the vtol back transition sequence
takeoff before moving to waypoint
void set_current_mission_item()
Set the current mission item.
DEFINE_PARAMETERS((ParamFloat< px4::params::MIS_DIST_1WP >) _param_mis_dist_1wp,(ParamFloat< px4::params::MIS_DIST_WPS >) _param_mis_dist_wps,(ParamInt< px4::params::MIS_ALTMODE >) _param_mis_altmode,(ParamInt< px4::params::MIS_MNT_YAW_CTL >) _param_mis_mnt_yaw_ctl) uORB mission_s _mission
< mission subscription
uint16_t origin
how the mission item was generated
float get_absolute_altitude_for_item(const mission_item_s &mission_item) const
struct position_setpoint_s previous
void on_inactivation() override
This function is called one time when mode becomes inactive.
int32_t _current_mission_index
bool need_to_reset_mission(bool active)
Returns true if we need to reset the mission.
uint16_t do_jump_repeat_count
how many times do jump needs to be done
struct vehicle_land_detected_s * get_land_detected()
float _distance_current_previous
distance from previous to current sp in pos_sp_triplet, only use if current and previous are valid ...
uint16_t item_do_jump_remaining
void report_do_jump_mission_changed(int index, int do_jumps_remaining)
Inform about a changed mission item after a DO_JUMP.
void check_mission_valid(bool force)
Check whether a mission is ready to go.
bool get_can_loiter_at_sp()
High-resolution timer with callouts and timekeeping.
#define mavlink_and_console_log_info(_pub, _text,...)
Send a mavlink emergency message and print to console.
bool do_need_move_to_takeoff()
Returns true if we need to move to waypoint location after vtol takeoff.
double lon
longitude in degrees
void do_abort_landing()
Abort landing.
bool mission_landing_required()
bool _need_takeoff
if true, then takeoff must be performed before going to the first waypoint (if needed) ...
const vehicle_roi_s & get_vroi()
void reset_cruising_speed()
Reset cruising speed to default values.
uint16_t _land_start_index
index of DO_LAND_START, INVALID_DO_LAND_START if no planned landing
bool item_do_jump_changed
struct position_setpoint_s current
move to land waypoint before descent
uint16_t get_land_start_index() const
__EXPORT ssize_t dm_read(dm_item_t item, unsigned index, void *buf, size_t count)
Retrieve from the data manager file.
void reset_triplets()
Set triplets to invalid.
struct vehicle_global_position_s * get_global_position()
void waypoint_from_heading_and_distance(double lat_start, double lon_start, float bearing, float dist, double *lat_target, double *lon_target)
Creates a waypoint from given waypoint, distance and bearing see http://www.movable-type.co.uk/scripts/latlong.html.
float get_cruising_speed()
Get the cruising speed.
bool set_current_mission_index(uint16_t index)
mission_item_s _mission_item
void on_active() override
This function is called while the mode is active.
uint16_t nav_cmd
navigation command
void reset_mission(struct mission_s &mission)
Reset mission.
void on_activation() override
This function is called one time when mode becomes active, pos_sp_triplet must be initialized here...
uint16_t do_jump_current_count
count how many times the jump has been done
void mission_apply_limitation(mission_item_s &item)
General function used to adjust the mission item based on vehicle specific limitations.
void cruising_speed_sp_update()
Update the cruising speed setpoint.
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
float get_bearing_to_next_waypoint(double lat_now, double lon_now, double lat_next, double lon_next)
Returns the bearing to the next waypoint in radians.
bool _execution_mode_changed
void reset_mission_item_reached()
Reset all reached flags.
void heading_sp_update()
Updates the heading of the vehicle.
void set_closest_item_as_current()
void set_execution_mode(const uint8_t mode)
Set a new mission mode and handle the switching between the different modes.
float time_inside
time that the MAV should stay inside the radius before advancing in seconds
PrecLand * get_precland()
allow others, e.g.
bool _land_start_available
__EXPORT void dm_unlock(dm_item_t item)
Unlock a data Item.
bool position_setpoint_equal(const position_setpoint_s *p1, const position_setpoint_s *p2) const
void update_mission()
Update mission topic.
uint16_t land_precision
Defines if landing should be precise: 0 = normal landing, 1 = opportunistic precision landing...
constexpr _Tp min(_Tp a, _Tp b)
Type wrap_pi(Type x)
Wrap value in range [-π, π)
bool find_mission_land_start()
Find and store the index of the landing sequence (DO_LAND_START)
bool do_need_move_to_land()
Returns true if we need to move to waypoint location before starting descent.
float get_time_inside(const mission_item_s &item) const
struct position_setpoint_triplet_s * get_position_setpoint_triplet()
void on_activation() override
This function is called one time when mode becomes active, pos_sp_triplet must be initialized here...
uint16_t item_changed_index
void issue_command(const mission_item_s &item)
struct mission_result_s * get_mission_result()
int16_t do_jump_mission_index
index where the do jump will go to
constexpr _Tp max(_Tp a, _Tp b)
void save_mission_state()
Save current mission state to dataman.
bool mission_item_to_position_setpoint(const mission_item_s &item, position_setpoint_s *sp)
Convert a mission item to a position setpoint.
bool is_mission_item_reached()
Check if mission item has been reached.
bool read_mission_item(int offset, struct mission_item_s *mission_item)
Read current (offset == 0) or a specific (offset > 0) mission item from the dataman and watch out for...
bool prepare_mission_items(mission_item_s *mission_item, mission_item_s *next_position_mission_item, bool *has_next_position_item)
Read the current and the next mission item.
bool do_need_vertical_takeoff()
Returns true if we need to do a takeoff at the current state.
void publish_vehicle_cmd(vehicle_command_s *vcmd)
float calculate_takeoff_altitude(struct mission_item_s *mission_item)
Calculate takeoff height for mission item considering ground clearance.
float get_loiter_radius()
static bool item_contains_position(const mission_item_s &item)
void set_mission_item_reached()
Set a mission item as reached.
__EXPORT ssize_t dm_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf, size_t count)
Write to the data manager file.
void on_active() override
This function is called while the mode is active.
orb_advert_t * get_mavlink_log_pub()
struct vehicle_status_s * get_vstatus()
void set_mission_result_updated()
float get_takeoff_min_alt() const
bool acceleration_is_force
uint16_t force_heading
heading needs to be reached
float yaw
in radians NED -PI..+PI, NAN means don't change yaw
float loiter_radius
loiter radius in meters, 0 for a VTOL to hover, negative for counter-clockwise
void set_can_loiter_at_sp(bool can_loiter)
Setters.
void set_position_setpoint_triplet_updated()
float get_altitude_acceptance_radius()
Get the altitude acceptance radius.
virtual void on_inactivation()
This function is called one time when mode becomes inactive.
void set_align_mission_item(struct mission_item_s *mission_item, struct mission_item_s *mission_item_next)
Create mission item to align towards next waypoint.
void set_mode(PrecLandMode mode)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
float _min_current_sp_distance_xy
< true if the mission changed since the mission mode was active
uint16_t altitude_is_relative
true if altitude is relative from start point
void set_mission_items()
Set new mission items.
void set_cruising_speed(float speed=-1.0f)
Set the cruising speed.
void set_vtol_transition_item(struct mission_item_s *item, const uint8_t new_mode)
Set vtol transition item.
double lat
latitude in degrees