mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 01:53:34 +08:00
commander: internalize system status bools
Most condition bools in the commander are not used anywhere but in the commander. It therefore makes sense to move them to a different internal struct and remove them from the vehicle_status message. Also, the land_detected should be used by all the modules instead of getting it through the commander and system_status.
This commit is contained in:
@@ -144,7 +144,7 @@ Mission::on_inactive()
|
||||
check_mission_valid();
|
||||
|
||||
/* require takeoff after non-loiter or landing */
|
||||
if (!_navigator->get_can_loiter_at_sp() || _navigator->get_vstatus()->condition_landed) {
|
||||
if (!_navigator->get_can_loiter_at_sp() || _navigator->get_land_detected()->landed) {
|
||||
_need_takeoff = true;
|
||||
}
|
||||
}
|
||||
@@ -278,7 +278,7 @@ Mission::update_offboard_mission()
|
||||
_navigator->get_home_position()->alt, _navigator->home_position_valid(),
|
||||
_navigator->get_global_position()->lat, _navigator->get_global_position()->lon,
|
||||
_param_dist_1wp.get(), _navigator->get_mission_result()->warning, _navigator->get_default_acceptance_radius(),
|
||||
_navigator->get_vstatus()->condition_landed);
|
||||
_navigator->get_land_detected()->landed);
|
||||
|
||||
_navigator->get_mission_result()->valid = !failed;
|
||||
if (!failed) {
|
||||
@@ -413,7 +413,7 @@ Mission::set_mission_items()
|
||||
* https://en.wikipedia.org/wiki/Loiter_(aeronautics)
|
||||
*/
|
||||
|
||||
if (_navigator->get_vstatus()->condition_landed) {
|
||||
if (_navigator->get_land_detected()->landed) {
|
||||
/* landed, refusing to take off without a mission */
|
||||
|
||||
mavlink_log_critical(_navigator->get_mavlink_log_pub(), "no valid mission available, refusing takeoff");
|
||||
@@ -585,7 +585,7 @@ Mission::set_mission_items()
|
||||
if (_mission_item.nav_cmd == NAV_CMD_DO_VTOL_TRANSITION
|
||||
&& _work_item_type != WORK_ITEM_TYPE_ALIGN
|
||||
&& _navigator->get_vstatus()->is_rotary_wing
|
||||
&& !_navigator->get_vstatus()->condition_landed
|
||||
&& !_navigator->get_land_detected()->landed
|
||||
&& has_next_position_item) {
|
||||
|
||||
new_work_item_type = WORK_ITEM_TYPE_ALIGN;
|
||||
@@ -658,7 +658,7 @@ Mission::do_need_takeoff()
|
||||
float takeoff_alt = calculate_takeoff_altitude(&_mission_item);
|
||||
|
||||
/* force takeoff if landed (additional protection) */
|
||||
if (_navigator->get_vstatus()->condition_landed) {
|
||||
if (_navigator->get_land_detected()->landed) {
|
||||
_need_takeoff = true;
|
||||
|
||||
/* if in-air and already above takeoff height, don't do takeoff */
|
||||
@@ -752,7 +752,7 @@ Mission::calculate_takeoff_altitude(struct mission_item_s *mission_item)
|
||||
float takeoff_alt = get_absolute_altitude_for_item(*mission_item);
|
||||
|
||||
/* takeoff to at least NAV_TAKEOFF_ALT above home/ground, even if first waypoint is lower */
|
||||
if (_navigator->get_vstatus()->condition_landed) {
|
||||
if (_navigator->get_land_detected()->landed) {
|
||||
takeoff_alt = fmaxf(takeoff_alt, _navigator->get_global_position()->alt + _param_takeoff_alt.get());
|
||||
|
||||
} else {
|
||||
@@ -1118,7 +1118,7 @@ Mission::check_mission_valid()
|
||||
_navigator->get_home_position()->alt, _navigator->home_position_valid(),
|
||||
_navigator->get_global_position()->lat, _navigator->get_global_position()->lon,
|
||||
_param_dist_1wp.get(), _navigator->get_mission_result()->warning, _navigator->get_default_acceptance_radius(),
|
||||
_navigator->get_vstatus()->condition_landed);
|
||||
_navigator->get_land_detected()->landed);
|
||||
|
||||
_navigator->increment_mission_instance_count();
|
||||
_navigator->set_mission_result_updated();
|
||||
|
||||
@@ -95,7 +95,7 @@ MissionBlock::is_mission_item_reached()
|
||||
|
||||
case NAV_CMD_LAND: /* fall through */
|
||||
case NAV_CMD_VTOL_LAND:
|
||||
return _navigator->get_vstatus()->condition_landed;
|
||||
return _navigator->get_land_detected()->landed;
|
||||
|
||||
/* TODO: count turns */
|
||||
/*_mission_item.nav_cmd == NAV_CMD_LOITER_TURN_COUNT ||*/
|
||||
@@ -413,7 +413,7 @@ MissionBlock::set_previous_pos_setpoint()
|
||||
void
|
||||
MissionBlock::set_loiter_item(struct mission_item_s *item, float min_clearance)
|
||||
{
|
||||
if (_navigator->get_vstatus()->condition_landed) {
|
||||
if (_navigator->get_land_detected()->landed) {
|
||||
/* landed, don't takeoff, but switch to IDLE mode */
|
||||
item->nav_cmd = NAV_CMD_IDLE;
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
#include <uORB/topics/mission_result.h>
|
||||
#include <uORB/topics/geofence_result.h>
|
||||
#include <uORB/topics/vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/vehicle_land_detected.h>
|
||||
|
||||
#include "navigator_mode.h"
|
||||
#include "mission.h"
|
||||
@@ -133,6 +134,7 @@ public:
|
||||
* Getters
|
||||
*/
|
||||
struct vehicle_status_s* get_vstatus() { return &_vstatus; }
|
||||
struct vehicle_land_detected_s* get_land_detected() { return &_land_detected; }
|
||||
struct vehicle_control_mode_s* get_control_mode() { return &_control_mode; }
|
||||
struct vehicle_global_position_s* get_global_position() { return &_global_pos; }
|
||||
struct vehicle_gps_position_s* get_gps_position() { return &_gps_pos; }
|
||||
@@ -200,6 +202,7 @@ private:
|
||||
int _sensor_combined_sub; /**< sensor combined subscription */
|
||||
int _home_pos_sub; /**< home position subscription */
|
||||
int _vstatus_sub; /**< vehicle status subscription */
|
||||
int _land_detected_sub; /**< vehicle land detected subscription */
|
||||
int _capabilities_sub; /**< notification of vehicle capabilities updates */
|
||||
int _control_mode_sub; /**< vehicle control mode subscription */
|
||||
int _onboard_mission_sub; /**< onboard mission subscription */
|
||||
@@ -215,6 +218,7 @@ private:
|
||||
when pos control is deactivated */
|
||||
|
||||
vehicle_status_s _vstatus; /**< vehicle status */
|
||||
vehicle_land_detected_s _land_detected; /**< vehicle land_detected */
|
||||
vehicle_control_mode_s _control_mode; /**< vehicle control mode */
|
||||
vehicle_global_position_s _global_pos; /**< global vehicle position */
|
||||
vehicle_gps_position_s _gps_pos; /**< gps position */
|
||||
@@ -300,6 +304,11 @@ private:
|
||||
*/
|
||||
void vehicle_status_update();
|
||||
|
||||
/**
|
||||
* Retrieve vehicle land detected
|
||||
*/
|
||||
void vehicle_land_detected_update();
|
||||
|
||||
/**
|
||||
* Retrieve vehicle control mode
|
||||
*/
|
||||
|
||||
@@ -107,6 +107,7 @@ Navigator::Navigator() :
|
||||
_gps_pos_sub(-1),
|
||||
_home_pos_sub(-1),
|
||||
_vstatus_sub(-1),
|
||||
_land_detected_sub(-1),
|
||||
_capabilities_sub(-1),
|
||||
_control_mode_sub(-1),
|
||||
_onboard_mission_sub(-1),
|
||||
@@ -118,6 +119,7 @@ Navigator::Navigator() :
|
||||
_geofence_result_pub(nullptr),
|
||||
_att_sp_pub(nullptr),
|
||||
_vstatus{},
|
||||
_land_detected{},
|
||||
_control_mode{},
|
||||
_global_pos{},
|
||||
_gps_pos{},
|
||||
@@ -241,6 +243,12 @@ Navigator::vehicle_status_update()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Navigator::vehicle_land_detected_update()
|
||||
{
|
||||
orb_copy(ORB_ID(vehicle_land_detected), _land_detected_sub, &_land_detected);
|
||||
}
|
||||
|
||||
void
|
||||
Navigator::vehicle_control_mode_update()
|
||||
{
|
||||
@@ -290,6 +298,7 @@ Navigator::task_main()
|
||||
_sensor_combined_sub = orb_subscribe(ORB_ID(sensor_combined));
|
||||
_capabilities_sub = orb_subscribe(ORB_ID(navigation_capabilities));
|
||||
_vstatus_sub = orb_subscribe(ORB_ID(vehicle_status));
|
||||
_land_detected_sub = orb_subscribe(ORB_ID(vehicle_land_detected));
|
||||
_control_mode_sub = orb_subscribe(ORB_ID(vehicle_control_mode));
|
||||
_home_pos_sub = orb_subscribe(ORB_ID(home_position));
|
||||
_onboard_mission_sub = orb_subscribe(ORB_ID(onboard_mission));
|
||||
@@ -299,6 +308,7 @@ Navigator::task_main()
|
||||
|
||||
/* copy all topics first time */
|
||||
vehicle_status_update();
|
||||
vehicle_land_detected_update();
|
||||
vehicle_control_mode_update();
|
||||
global_position_update();
|
||||
gps_position_update();
|
||||
@@ -374,6 +384,12 @@ Navigator::task_main()
|
||||
vehicle_status_update();
|
||||
}
|
||||
|
||||
/* vehicle land detected updated */
|
||||
orb_check(_land_detected_sub, &updated);
|
||||
if (updated) {
|
||||
vehicle_land_detected_update();
|
||||
}
|
||||
|
||||
/* navigation capabilities updated */
|
||||
orb_check(_capabilities_sub, &updated);
|
||||
if (updated) {
|
||||
|
||||
@@ -94,7 +94,7 @@ RTL::on_activation()
|
||||
/* decide where to enter the RTL procedure when we switch into it */
|
||||
if (_rtl_state == RTL_STATE_NONE) {
|
||||
/* for safety reasons don't go into RTL if landed */
|
||||
if (_navigator->get_vstatus()->condition_landed) {
|
||||
if (_navigator->get_land_detected()->landed) {
|
||||
_rtl_state = RTL_STATE_LANDED;
|
||||
mavlink_log_critical(_navigator->get_mavlink_log_pub(), "no RTL when landed");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user