forked from Archive/PX4-Autopilot
LandDetector: switch land flags to properies instead of one state
This commit is contained in:
parent
1e1549a169
commit
679e4fedf5
|
@ -1,7 +1,7 @@
|
||||||
uint64 timestamp # time since system start (microseconds)
|
uint64 timestamp # time since system start (microseconds)
|
||||||
bool landed # true if vehicle is currently landed on the ground
|
|
||||||
bool freefall # true if vehicle is currently in free-fall
|
|
||||||
bool ground_contact # true if vehicle has ground contact but is not landed
|
|
||||||
bool maybe_landed # true if the vehicle might have landed
|
|
||||||
float32 alt_max # maximum altitude in [m] that can be reached
|
float32 alt_max # maximum altitude in [m] that can be reached
|
||||||
|
bool freefall # true if vehicle is currently in free-fall
|
||||||
|
bool ground_contact # true if vehicle has ground contact but is not landed (1. stage)
|
||||||
|
bool maybe_landed # true if the vehicle might have landed (2. stage)
|
||||||
|
bool landed # true if vehicle is currently landed on the ground (3. stage)
|
||||||
bool in_ground_effect # indicates if from the perspective of the landing detector the vehicle might be in ground effect (baro). This flag will become true if the vehicle is not moving horizontally and is descending (crude assumption that user is landing).
|
bool in_ground_effect # indicates if from the perspective of the landing detector the vehicle might be in ground effect (baro). This flag will become true if the vehicle is not moving horizontally and is descending (crude assumption that user is landing).
|
||||||
|
|
|
@ -48,13 +48,7 @@ namespace land_detector
|
||||||
LandDetector::LandDetector() :
|
LandDetector::LandDetector() :
|
||||||
ModuleParams(nullptr),
|
ModuleParams(nullptr),
|
||||||
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::att_pos_ctrl)
|
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::att_pos_ctrl)
|
||||||
{
|
{}
|
||||||
_land_detected.timestamp = hrt_absolute_time();
|
|
||||||
_land_detected.freefall = false;
|
|
||||||
_land_detected.landed = true;
|
|
||||||
_land_detected.ground_contact = false;
|
|
||||||
_land_detected.maybe_landed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
LandDetector::~LandDetector()
|
LandDetector::~LandDetector()
|
||||||
{
|
{
|
||||||
|
@ -76,12 +70,11 @@ void LandDetector::Run()
|
||||||
_update_topics();
|
_update_topics();
|
||||||
_update_state();
|
_update_state();
|
||||||
|
|
||||||
const bool landDetected = (_state == LandDetectionState::LANDED);
|
const bool freefallDetected = _freefall_hysteresis.get_state();
|
||||||
const bool freefallDetected = (_state == LandDetectionState::FREEFALL);
|
const bool ground_contactDetected = _ground_contact_hysteresis.get_state();
|
||||||
const bool maybe_landedDetected = (_state == LandDetectionState::MAYBE_LANDED);
|
const bool maybe_landedDetected = _maybe_landed_hysteresis.get_state();
|
||||||
const bool ground_contactDetected = (_state == LandDetectionState::GROUND_CONTACT);
|
const bool landDetected = _landed_hysteresis.get_state();
|
||||||
const float alt_max = _get_max_altitude() > 0.0f ? _get_max_altitude() : INFINITY;
|
const float alt_max = _get_max_altitude() > 0.0f ? _get_max_altitude() : INFINITY;
|
||||||
|
|
||||||
const bool in_ground_effect = _ground_effect_hysteresis.get_state();
|
const bool in_ground_effect = _ground_effect_hysteresis.get_state();
|
||||||
|
|
||||||
const hrt_abstime now = hrt_absolute_time();
|
const hrt_abstime now = hrt_absolute_time();
|
||||||
|
@ -163,22 +156,6 @@ void LandDetector::_update_state()
|
||||||
_maybe_landed_hysteresis.set_state_and_update(_get_maybe_landed_state(), now_us);
|
_maybe_landed_hysteresis.set_state_and_update(_get_maybe_landed_state(), now_us);
|
||||||
_ground_contact_hysteresis.set_state_and_update(_get_ground_contact_state(), now_us);
|
_ground_contact_hysteresis.set_state_and_update(_get_ground_contact_state(), now_us);
|
||||||
_ground_effect_hysteresis.set_state_and_update(_get_ground_effect_state(), now_us);
|
_ground_effect_hysteresis.set_state_and_update(_get_ground_effect_state(), now_us);
|
||||||
|
|
||||||
if (_freefall_hysteresis.get_state()) {
|
|
||||||
_state = LandDetectionState::FREEFALL;
|
|
||||||
|
|
||||||
} else if (_landed_hysteresis.get_state()) {
|
|
||||||
_state = LandDetectionState::LANDED;
|
|
||||||
|
|
||||||
} else if (_maybe_landed_hysteresis.get_state()) {
|
|
||||||
_state = LandDetectionState::MAYBE_LANDED;
|
|
||||||
|
|
||||||
} else if (_ground_contact_hysteresis.get_state()) {
|
|
||||||
_state = LandDetectionState::GROUND_CONTACT;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
_state = LandDetectionState::FLYING;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LandDetector::_update_topics()
|
void LandDetector::_update_topics()
|
||||||
|
|
|
@ -69,13 +69,6 @@ namespace land_detector
|
||||||
class LandDetector : public ModuleBase<LandDetector>, ModuleParams, px4::ScheduledWorkItem
|
class LandDetector : public ModuleBase<LandDetector>, ModuleParams, px4::ScheduledWorkItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class LandDetectionState {
|
|
||||||
FLYING = 0,
|
|
||||||
LANDED = 1,
|
|
||||||
FREEFALL = 2,
|
|
||||||
GROUND_CONTACT = 3,
|
|
||||||
MAYBE_LANDED = 4
|
|
||||||
};
|
|
||||||
|
|
||||||
LandDetector();
|
LandDetector();
|
||||||
virtual ~LandDetector();
|
virtual ~LandDetector();
|
||||||
|
@ -93,11 +86,6 @@ public:
|
||||||
/** @see ModuleBase::print_status() */
|
/** @see ModuleBase::print_status() */
|
||||||
int print_status() override;
|
int print_status() override;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return current state.
|
|
||||||
*/
|
|
||||||
LandDetectionState get_state() const { return _state; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the work queue going.
|
* Get the work queue going.
|
||||||
*/
|
*/
|
||||||
|
@ -151,8 +139,6 @@ protected:
|
||||||
/** Run main land detector loop at this interval. */
|
/** Run main land detector loop at this interval. */
|
||||||
static constexpr uint32_t LAND_DETECTOR_UPDATE_INTERVAL = 20_ms;
|
static constexpr uint32_t LAND_DETECTOR_UPDATE_INTERVAL = 20_ms;
|
||||||
|
|
||||||
LandDetectionState _state{LandDetectionState::LANDED};
|
|
||||||
|
|
||||||
systemlib::Hysteresis _freefall_hysteresis{false};
|
systemlib::Hysteresis _freefall_hysteresis{false};
|
||||||
systemlib::Hysteresis _landed_hysteresis{true};
|
systemlib::Hysteresis _landed_hysteresis{true};
|
||||||
systemlib::Hysteresis _maybe_landed_hysteresis{true};
|
systemlib::Hysteresis _maybe_landed_hysteresis{true};
|
||||||
|
@ -161,7 +147,14 @@ protected:
|
||||||
|
|
||||||
actuator_armed_s _actuator_armed{};
|
actuator_armed_s _actuator_armed{};
|
||||||
vehicle_acceleration_s _vehicle_acceleration{};
|
vehicle_acceleration_s _vehicle_acceleration{};
|
||||||
vehicle_land_detected_s _land_detected{};
|
vehicle_land_detected_s _land_detected = {
|
||||||
|
.timestamp = 0,
|
||||||
|
.alt_max = -1.0f,
|
||||||
|
.freefall = false,
|
||||||
|
.ground_contact = true,
|
||||||
|
.maybe_landed = true,
|
||||||
|
.landed = true,
|
||||||
|
};
|
||||||
vehicle_local_position_s _vehicle_local_position{};
|
vehicle_local_position_s _vehicle_local_position{};
|
||||||
|
|
||||||
orb_advert_t _land_detected_pub{nullptr};
|
orb_advert_t _land_detected_pub{nullptr};
|
||||||
|
|
|
@ -104,29 +104,8 @@ int LandDetector::task_spawn(int argc, char *argv[])
|
||||||
int LandDetector::print_status()
|
int LandDetector::print_status()
|
||||||
{
|
{
|
||||||
PX4_INFO("running (%s)", _currentMode);
|
PX4_INFO("running (%s)", _currentMode);
|
||||||
LandDetector::LandDetectionState state = get_state();
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case LandDetector::LandDetectionState::FLYING:
|
|
||||||
PX4_INFO("State: Flying");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LandDetector::LandDetectionState::LANDED:
|
|
||||||
PX4_INFO("State: Landed");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LandDetector::LandDetectionState::FREEFALL:
|
|
||||||
PX4_INFO("State: Freefall");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
PX4_ERR("State: unknown");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LandDetector::print_usage(const char *reason)
|
int LandDetector::print_usage(const char *reason)
|
||||||
{
|
{
|
||||||
if (reason != nullptr) {
|
if (reason != nullptr) {
|
||||||
|
|
|
@ -135,10 +135,10 @@ private:
|
||||||
vehicle_land_detected_s _vehicle_land_detected = {
|
vehicle_land_detected_s _vehicle_land_detected = {
|
||||||
.timestamp = 0,
|
.timestamp = 0,
|
||||||
.alt_max = -1.0f,
|
.alt_max = -1.0f,
|
||||||
.landed = true,
|
|
||||||
.freefall = false,
|
.freefall = false,
|
||||||
.ground_contact = false,
|
.ground_contact = true,
|
||||||
.maybe_landed = false,
|
.maybe_landed = true,
|
||||||
|
.landed = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
vehicle_attitude_setpoint_s _att_sp{}; /**< vehicle attitude setpoint */
|
vehicle_attitude_setpoint_s _att_sp{}; /**< vehicle attitude setpoint */
|
||||||
|
|
Loading…
Reference in New Issue