mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 04:53:33 +08:00
navigator: audio messages about what is happening, RTL during mission not triggered but after mission
This commit is contained in:
@@ -1296,7 +1296,6 @@ int commander_thread_main(int argc, char *argv[])
|
|||||||
status.rc_signal_lost = true;
|
status.rc_signal_lost = true;
|
||||||
status_changed = true;
|
status_changed = true;
|
||||||
|
|
||||||
|
|
||||||
if (!(status.set_nav_state == NAVIGATION_STATE_AUTO_MISSION && !mission_result.mission_finished)) {
|
if (!(status.set_nav_state == NAVIGATION_STATE_AUTO_MISSION && !mission_result.mission_finished)) {
|
||||||
|
|
||||||
/* if we have a global position, we can switch to RTL, if not, we can try to land */
|
/* if we have a global position, we can switch to RTL, if not, we can try to land */
|
||||||
@@ -1306,10 +1305,26 @@ int commander_thread_main(int argc, char *argv[])
|
|||||||
status.failsafe_state = FAILSAFE_STATE_LAND;
|
status.failsafe_state = FAILSAFE_STATE_LAND;
|
||||||
}
|
}
|
||||||
failsafe_state_changed = true;
|
failsafe_state_changed = true;
|
||||||
|
} else {
|
||||||
|
mavlink_log_info(mavlink_fd, "#audio: no RTL during Mission");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* hack to detect if we finished a mission after we lost RC, so that we can trigger RTL now */
|
||||||
|
if (status.rc_signal_lost && status.set_nav_state == NAVIGATION_STATE_AUTO_MISSION &&
|
||||||
|
mission_result.mission_finished && status.failsafe_state != FAILSAFE_STATE_RTL_RC) {
|
||||||
|
/* if we have a global position, we can switch to RTL, if not, we can try to land */
|
||||||
|
if (status.condition_global_position_valid) {
|
||||||
|
status.failsafe_state = FAILSAFE_STATE_RTL_RC;
|
||||||
|
mavlink_log_info(mavlink_fd, "#audio: RTL after Mission is finished");
|
||||||
|
} else {
|
||||||
|
/* this probably doesn't make sense since we are in mission and have global position */
|
||||||
|
status.failsafe_state = FAILSAFE_STATE_LAND;
|
||||||
|
}
|
||||||
|
failsafe_state_changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
/* handle commands last, as the system needs to be updated to handle them */
|
/* handle commands last, as the system needs to be updated to handle them */
|
||||||
orb_check(cmd_sub, &updated);
|
orb_check(cmd_sub, &updated);
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
|
|
||||||
#include <dataman/dataman.h>
|
#include <dataman/dataman.h>
|
||||||
|
#include <mavlink/mavlink_log.h>
|
||||||
#include <systemlib/err.h>
|
#include <systemlib/err.h>
|
||||||
#include <geo/geo.h>
|
#include <geo/geo.h>
|
||||||
|
|
||||||
@@ -210,20 +211,39 @@ Mission::set_mission_items(struct position_setpoint_triplet_s *pos_sp_triplet)
|
|||||||
{
|
{
|
||||||
set_previous_pos_setpoint(&pos_sp_triplet->current, &pos_sp_triplet->previous);
|
set_previous_pos_setpoint(&pos_sp_triplet->current, &pos_sp_triplet->previous);
|
||||||
|
|
||||||
|
/* try setting onboard mission item */
|
||||||
if (is_current_onboard_mission_item_set(&pos_sp_triplet->current)) {
|
if (is_current_onboard_mission_item_set(&pos_sp_triplet->current)) {
|
||||||
/* try setting onboard mission item */
|
/* if mission type changed, notify */
|
||||||
|
if (_mission_type != MISSION_TYPE_ONBOARD) {
|
||||||
|
mavlink_log_info(_navigator->get_mavlink_fd(),
|
||||||
|
"#audio: onboard mission running");
|
||||||
|
}
|
||||||
_mission_type = MISSION_TYPE_ONBOARD;
|
_mission_type = MISSION_TYPE_ONBOARD;
|
||||||
_navigator->set_is_in_loiter(false);
|
_navigator->set_is_in_loiter(false);
|
||||||
|
|
||||||
|
/* try setting offboard mission item */
|
||||||
} else if (is_current_offboard_mission_item_set(&pos_sp_triplet->current)) {
|
} else if (is_current_offboard_mission_item_set(&pos_sp_triplet->current)) {
|
||||||
/* try setting offboard mission item */
|
/* if mission type changed, notify */
|
||||||
|
if (_mission_type != MISSION_TYPE_OFFBOARD) {
|
||||||
|
mavlink_log_info(_navigator->get_mavlink_fd(),
|
||||||
|
"#audio: offboard mission running");
|
||||||
|
}
|
||||||
_mission_type = MISSION_TYPE_OFFBOARD;
|
_mission_type = MISSION_TYPE_OFFBOARD;
|
||||||
_navigator->set_is_in_loiter(false);
|
_navigator->set_is_in_loiter(false);
|
||||||
} else {
|
} else {
|
||||||
|
if (_mission_type != MISSION_TYPE_NONE) {
|
||||||
|
mavlink_log_info(_navigator->get_mavlink_fd(),
|
||||||
|
"#audio: mission finished");
|
||||||
|
} else {
|
||||||
|
mavlink_log_info(_navigator->get_mavlink_fd(),
|
||||||
|
"#audio: no mission available");
|
||||||
|
}
|
||||||
_mission_type = MISSION_TYPE_NONE;
|
_mission_type = MISSION_TYPE_NONE;
|
||||||
|
|
||||||
bool use_current_pos_sp = pos_sp_triplet->current.valid && _waypoint_position_reached;
|
bool use_current_pos_sp = pos_sp_triplet->current.valid && _waypoint_position_reached;
|
||||||
set_loiter_item(use_current_pos_sp, pos_sp_triplet);
|
set_loiter_item(use_current_pos_sp, pos_sp_triplet);
|
||||||
|
reset_mission_item_reached();
|
||||||
|
report_mission_finished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,8 +262,9 @@ Mission::is_current_onboard_mission_item_set(struct position_setpoint_s *current
|
|||||||
{
|
{
|
||||||
/* make sure param is up to date */
|
/* make sure param is up to date */
|
||||||
updateParams();
|
updateParams();
|
||||||
if (_param_onboard_enabled.get() > 0
|
if (_param_onboard_enabled.get() > 0 &&
|
||||||
&& _current_onboard_mission_index < (int)_onboard_mission.count) {
|
_current_onboard_mission_index >= 0&&
|
||||||
|
_current_onboard_mission_index < (int)_onboard_mission.count) {
|
||||||
struct mission_item_s new_mission_item;
|
struct mission_item_s new_mission_item;
|
||||||
if (read_mission_item(DM_KEY_WAYPOINTS_ONBOARD, true, &_current_onboard_mission_index,
|
if (read_mission_item(DM_KEY_WAYPOINTS_ONBOARD, true, &_current_onboard_mission_index,
|
||||||
&new_mission_item)) {
|
&new_mission_item)) {
|
||||||
@@ -264,7 +285,8 @@ Mission::is_current_onboard_mission_item_set(struct position_setpoint_s *current
|
|||||||
bool
|
bool
|
||||||
Mission::is_current_offboard_mission_item_set(struct position_setpoint_s *current_pos_sp)
|
Mission::is_current_offboard_mission_item_set(struct position_setpoint_s *current_pos_sp)
|
||||||
{
|
{
|
||||||
if (_current_offboard_mission_index < (int)_offboard_mission.count) {
|
if (_current_offboard_mission_index >= 0 &&
|
||||||
|
_current_offboard_mission_index < (int)_offboard_mission.count) {
|
||||||
dm_item_t dm_current;
|
dm_item_t dm_current;
|
||||||
if (_offboard_mission.dataman_id == 0) {
|
if (_offboard_mission.dataman_id == 0) {
|
||||||
dm_current = DM_KEY_WAYPOINTS_OFFBOARD_0;
|
dm_current = DM_KEY_WAYPOINTS_OFFBOARD_0;
|
||||||
@@ -282,8 +304,6 @@ Mission::is_current_offboard_mission_item_set(struct position_setpoint_s *curren
|
|||||||
report_current_offboard_mission_item();
|
report_current_offboard_mission_item();
|
||||||
memcpy(&_mission_item, &new_mission_item, sizeof(struct mission_item_s));
|
memcpy(&_mission_item, &new_mission_item, sizeof(struct mission_item_s));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
warnx("ERROR: WP read fail");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -295,7 +315,8 @@ Mission::get_next_onboard_mission_item(struct position_setpoint_s *next_pos_sp)
|
|||||||
int next_temp_mission_index = _onboard_mission.current_index + 1;
|
int next_temp_mission_index = _onboard_mission.current_index + 1;
|
||||||
|
|
||||||
/* try if there is a next onboard mission */
|
/* try if there is a next onboard mission */
|
||||||
if (next_temp_mission_index < (int)_onboard_mission.count) {
|
if (_onboard_mission.current_index >= 0 &&
|
||||||
|
next_temp_mission_index < (int)_onboard_mission.count) {
|
||||||
struct mission_item_s new_mission_item;
|
struct mission_item_s new_mission_item;
|
||||||
if (read_mission_item(DM_KEY_WAYPOINTS_ONBOARD, false, &next_temp_mission_index, &new_mission_item)) {
|
if (read_mission_item(DM_KEY_WAYPOINTS_ONBOARD, false, &next_temp_mission_index, &new_mission_item)) {
|
||||||
/* convert next mission item to position setpoint */
|
/* convert next mission item to position setpoint */
|
||||||
@@ -315,7 +336,9 @@ Mission::get_next_offboard_mission_item(struct position_setpoint_s *next_pos_sp)
|
|||||||
{
|
{
|
||||||
/* try if there is a next offboard mission */
|
/* try if there is a next offboard mission */
|
||||||
int next_temp_mission_index = _offboard_mission.current_index + 1;
|
int next_temp_mission_index = _offboard_mission.current_index + 1;
|
||||||
if (next_temp_mission_index < (int)_offboard_mission.count) {
|
warnx("next index: %d, count; %d", next_temp_mission_index, _offboard_mission.count);
|
||||||
|
if (_offboard_mission.current_index >= 0 &&
|
||||||
|
next_temp_mission_index < (int)_offboard_mission.count) {
|
||||||
dm_item_t dm_current;
|
dm_item_t dm_current;
|
||||||
if (_offboard_mission.dataman_id == 0) {
|
if (_offboard_mission.dataman_id == 0) {
|
||||||
dm_current = DM_KEY_WAYPOINTS_OFFBOARD_0;
|
dm_current = DM_KEY_WAYPOINTS_OFFBOARD_0;
|
||||||
@@ -346,14 +369,17 @@ Mission::read_mission_item(const dm_item_t dm_item, bool is_current, int *missio
|
|||||||
/* read mission item from datamanager */
|
/* read mission item from datamanager */
|
||||||
if (dm_read(dm_item, *mission_index, new_mission_item, len) != len) {
|
if (dm_read(dm_item, *mission_index, new_mission_item, len) != len) {
|
||||||
/* not supposed to happen unless the datamanager can't access the SD card, etc. */
|
/* not supposed to happen unless the datamanager can't access the SD card, etc. */
|
||||||
|
mavlink_log_critical(_navigator->get_mavlink_fd(),
|
||||||
|
"#audio: ERROR waypoint could not be read");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for DO_JUMP item, and whether it hasn't not already been repeated enough times */
|
/* check for DO_JUMP item, and whether it hasn't not already been repeated enough times */
|
||||||
if (new_mission_item->nav_cmd == NAV_CMD_DO_JUMP) {
|
if (new_mission_item->nav_cmd == NAV_CMD_DO_JUMP) {
|
||||||
|
|
||||||
/* TODO: do this check more gracefully since it is not a serious error */
|
|
||||||
if (new_mission_item->do_jump_current_count >= new_mission_item->do_jump_repeat_count) {
|
if (new_mission_item->do_jump_current_count >= new_mission_item->do_jump_repeat_count) {
|
||||||
|
mavlink_log_info(_navigator->get_mavlink_fd(),
|
||||||
|
"#audio: DO JUMP repetitions completed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,9 +392,10 @@ Mission::read_mission_item(const dm_item_t dm_item, bool is_current, int *missio
|
|||||||
if (dm_write(dm_item, *mission_index, DM_PERSIST_IN_FLIGHT_RESET,
|
if (dm_write(dm_item, *mission_index, DM_PERSIST_IN_FLIGHT_RESET,
|
||||||
new_mission_item, len) != len) {
|
new_mission_item, len) != len) {
|
||||||
/* not supposed to happen unless the datamanager can't access the dataman */
|
/* not supposed to happen unless the datamanager can't access the dataman */
|
||||||
|
mavlink_log_critical(_navigator->get_mavlink_fd(),
|
||||||
|
"#audio: ERROR DO JUMP waypoint could not be written");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* TODO: report about DO JUMP count */
|
|
||||||
}
|
}
|
||||||
/* set new mission item index and repeat
|
/* set new mission item index and repeat
|
||||||
* we don't have to validate here, if it's invalid, we should realize this later .*/
|
* we don't have to validate here, if it's invalid, we should realize this later .*/
|
||||||
@@ -381,7 +408,8 @@ Mission::read_mission_item(const dm_item_t dm_item, bool is_current, int *missio
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* we have given up, we don't want to cycle forever */
|
/* we have given up, we don't want to cycle forever */
|
||||||
warnx("ERROR: cycling through mission items without success");
|
mavlink_log_critical(_navigator->get_mavlink_fd(),
|
||||||
|
"#audio: ERROR DO JUMP is cycling, giving up");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,6 +430,13 @@ Mission::report_current_offboard_mission_item()
|
|||||||
publish_mission_result();
|
publish_mission_result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Mission::report_mission_finished()
|
||||||
|
{
|
||||||
|
_mission_result.mission_finished = true;
|
||||||
|
publish_mission_result();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Mission::publish_mission_result()
|
Mission::publish_mission_result()
|
||||||
{
|
{
|
||||||
@@ -416,4 +451,5 @@ Mission::publish_mission_result()
|
|||||||
}
|
}
|
||||||
/* reset reached bool */
|
/* reset reached bool */
|
||||||
_mission_result.mission_reached = false;
|
_mission_result.mission_reached = false;
|
||||||
|
_mission_result.mission_finished = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,6 +151,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
void report_current_offboard_mission_item();
|
void report_current_offboard_mission_item();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report that the mission is finished if one exists or that none exists
|
||||||
|
*/
|
||||||
|
void report_mission_finished();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish the mission result so commander and mavlink know what is going on
|
* Publish the mission result so commander and mavlink know what is going on
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ RTL::set_rtl_item(position_setpoint_triplet_s *pos_sp_triplet)
|
|||||||
/* for safety reasons don't go into RTL if landed */
|
/* for safety reasons don't go into RTL if landed */
|
||||||
if (_navigator->get_vstatus()->condition_landed) {
|
if (_navigator->get_vstatus()->condition_landed) {
|
||||||
_rtl_state = RTL_STATE_FINISHED;
|
_rtl_state = RTL_STATE_FINISHED;
|
||||||
|
mavlink_log_info(_navigator->get_mavlink_fd(), "#audio: no RTL when landed");
|
||||||
/* if lower than return altitude, climb up first */
|
/* if lower than return altitude, climb up first */
|
||||||
} else if (_navigator->get_global_position()->alt < _navigator->get_home_position()->alt
|
} else if (_navigator->get_global_position()->alt < _navigator->get_home_position()->alt
|
||||||
+ _param_return_alt.get()) {
|
+ _param_return_alt.get()) {
|
||||||
@@ -133,11 +134,6 @@ RTL::set_rtl_item(position_setpoint_triplet_s *pos_sp_triplet)
|
|||||||
|
|
||||||
float climb_alt = _navigator->get_home_position()->alt + _param_return_alt.get();
|
float climb_alt = _navigator->get_home_position()->alt + _param_return_alt.get();
|
||||||
|
|
||||||
/* TODO understand and fix this */
|
|
||||||
// if (_vstatus.condition_landed) {
|
|
||||||
// climb_alt = fmaxf(climb_alt, _global_pos.alt + _parameters.rtl_alt);
|
|
||||||
// }
|
|
||||||
|
|
||||||
_mission_item.lat = _navigator->get_global_position()->lat;
|
_mission_item.lat = _navigator->get_global_position()->lat;
|
||||||
_mission_item.lon = _navigator->get_global_position()->lon;
|
_mission_item.lon = _navigator->get_global_position()->lon;
|
||||||
_mission_item.altitude_is_relative = false;
|
_mission_item.altitude_is_relative = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user