LandDetector: switch land flags to properies instead of one state

This commit is contained in:
Matthias Grob 2019-10-12 21:52:52 +02:00 committed by Daniel Agar
parent 1e1549a169
commit 679e4fedf5
5 changed files with 20 additions and 71 deletions

View File

@ -1,7 +1,7 @@
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
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).

View File

@ -48,13 +48,7 @@ namespace land_detector
LandDetector::LandDetector() :
ModuleParams(nullptr),
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()
{
@ -76,12 +70,11 @@ void LandDetector::Run()
_update_topics();
_update_state();
const bool landDetected = (_state == LandDetectionState::LANDED);
const bool freefallDetected = (_state == LandDetectionState::FREEFALL);
const bool maybe_landedDetected = (_state == LandDetectionState::MAYBE_LANDED);
const bool ground_contactDetected = (_state == LandDetectionState::GROUND_CONTACT);
const bool freefallDetected = _freefall_hysteresis.get_state();
const bool ground_contactDetected = _ground_contact_hysteresis.get_state();
const bool maybe_landedDetected = _maybe_landed_hysteresis.get_state();
const bool landDetected = _landed_hysteresis.get_state();
const float alt_max = _get_max_altitude() > 0.0f ? _get_max_altitude() : INFINITY;
const bool in_ground_effect = _ground_effect_hysteresis.get_state();
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);
_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);
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()

View File

@ -69,13 +69,6 @@ namespace land_detector
class LandDetector : public ModuleBase<LandDetector>, ModuleParams, px4::ScheduledWorkItem
{
public:
enum class LandDetectionState {
FLYING = 0,
LANDED = 1,
FREEFALL = 2,
GROUND_CONTACT = 3,
MAYBE_LANDED = 4
};
LandDetector();
virtual ~LandDetector();
@ -93,11 +86,6 @@ public:
/** @see ModuleBase::print_status() */
int print_status() override;
/**
* @return current state.
*/
LandDetectionState get_state() const { return _state; }
/**
* Get the work queue going.
*/
@ -151,8 +139,6 @@ protected:
/** Run main land detector loop at this interval. */
static constexpr uint32_t LAND_DETECTOR_UPDATE_INTERVAL = 20_ms;
LandDetectionState _state{LandDetectionState::LANDED};
systemlib::Hysteresis _freefall_hysteresis{false};
systemlib::Hysteresis _landed_hysteresis{true};
systemlib::Hysteresis _maybe_landed_hysteresis{true};
@ -161,7 +147,14 @@ protected:
actuator_armed_s _actuator_armed{};
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{};
orb_advert_t _land_detected_pub{nullptr};

View File

@ -104,29 +104,8 @@ int LandDetector::task_spawn(int argc, char *argv[])
int LandDetector::print_status()
{
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;
}
int LandDetector::print_usage(const char *reason)
{
if (reason != nullptr) {

View File

@ -135,10 +135,10 @@ private:
vehicle_land_detected_s _vehicle_land_detected = {
.timestamp = 0,
.alt_max = -1.0f,
.landed = true,
.freefall = false,
.ground_contact = false,
.maybe_landed = false,
.ground_contact = true,
.maybe_landed = true,
.landed = true,
};
vehicle_attitude_setpoint_s _att_sp{}; /**< vehicle attitude setpoint */