2020-04-24 17:32:10 -03:00
|
|
|
/// @file AP_LandingGear.h
|
|
|
|
/// @brief Landing gear control library
|
2016-02-17 21:25:32 -04:00
|
|
|
#pragma once
|
2015-01-06 00:24:05 -04:00
|
|
|
|
2022-10-01 07:21:38 -03:00
|
|
|
#include "AP_LandingGear_config.h"
|
|
|
|
|
|
|
|
#if AP_LANDINGGEAR_ENABLED
|
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
2023-07-13 21:58:06 -03:00
|
|
|
#include <AP_Logger/AP_Logger_config.h>
|
2015-01-06 00:24:05 -04:00
|
|
|
|
2020-04-24 17:32:10 -03:00
|
|
|
/// @class AP_LandingGear
|
|
|
|
/// @brief Class managing the control of landing gear
|
2015-01-06 00:24:05 -04:00
|
|
|
class AP_LandingGear {
|
|
|
|
public:
|
2017-12-12 21:06:12 -04:00
|
|
|
AP_LandingGear() {
|
|
|
|
// setup parameter defaults
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2018-06-10 03:34:02 -03:00
|
|
|
|
|
|
|
if (_singleton != nullptr) {
|
|
|
|
AP_HAL::panic("AP_LandingGear must be singleton");
|
|
|
|
}
|
|
|
|
_singleton = this;
|
2017-12-12 21:06:12 -04:00
|
|
|
}
|
2017-08-29 20:57:36 -03:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
2022-09-30 06:50:43 -03:00
|
|
|
CLASS_NO_COPY(AP_LandingGear);
|
2018-06-10 03:34:02 -03:00
|
|
|
|
|
|
|
// get singleton instance
|
2019-02-10 14:05:37 -04:00
|
|
|
static AP_LandingGear *get_singleton(void) {
|
2018-11-08 20:03:11 -04:00
|
|
|
return _singleton;
|
2018-06-10 03:34:02 -03:00
|
|
|
}
|
2015-01-06 00:24:05 -04:00
|
|
|
|
2017-06-10 01:07:38 -03:00
|
|
|
// Gear command modes
|
|
|
|
enum LandingGearCommand {
|
|
|
|
LandingGear_Retract,
|
|
|
|
LandingGear_Deploy,
|
|
|
|
};
|
|
|
|
|
2017-08-04 03:28:33 -03:00
|
|
|
// Gear command modes
|
|
|
|
enum LandingGearStartupBehaviour {
|
|
|
|
LandingGear_Startup_WaitForPilotInput = 0,
|
|
|
|
LandingGear_Startup_Retract = 1,
|
|
|
|
LandingGear_Startup_Deploy = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// initialise state of landing gear
|
|
|
|
void init();
|
|
|
|
|
2017-06-10 01:07:38 -03:00
|
|
|
/// returns true if the landing gear is deployed
|
2018-06-10 03:34:02 -03:00
|
|
|
bool deployed();
|
|
|
|
|
|
|
|
enum LG_LandingGear_State {
|
|
|
|
LG_UNKNOWN = -1,
|
|
|
|
LG_RETRACTED = 0,
|
|
|
|
LG_DEPLOYED = 1,
|
|
|
|
LG_RETRACTING = 2,
|
|
|
|
LG_DEPLOYING = 3,
|
|
|
|
};
|
|
|
|
/// returns detailed state of gear
|
|
|
|
LG_LandingGear_State get_state();
|
|
|
|
|
|
|
|
enum LG_WOW_State {
|
|
|
|
LG_WOW_UNKNOWN = -1,
|
|
|
|
LG_NO_WOW = 0,
|
|
|
|
LG_WOW = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
LG_WOW_State get_wow_state();
|
2015-01-06 00:24:05 -04:00
|
|
|
|
2017-06-10 01:07:38 -03:00
|
|
|
/// set landing gear position to retract, deploy or deploy-and-keep-deployed
|
|
|
|
void set_position(LandingGearCommand cmd);
|
2018-06-10 03:34:02 -03:00
|
|
|
|
2021-02-01 12:26:29 -04:00
|
|
|
uint32_t get_gear_state_duration_ms() const;
|
|
|
|
uint32_t get_wow_state_duration_ms() const;
|
2015-01-06 00:24:05 -04:00
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2018-06-10 03:34:02 -03:00
|
|
|
|
2018-11-09 00:39:59 -04:00
|
|
|
void update(float height_above_ground_m);
|
2018-11-11 07:57:02 -04:00
|
|
|
|
|
|
|
bool check_before_land(void);
|
2015-01-06 00:24:05 -04:00
|
|
|
|
2020-02-20 23:08:11 -04:00
|
|
|
// retract after takeoff or deploy for landing depending on the OPTIONS parameter
|
|
|
|
void retract_after_takeoff();
|
|
|
|
void deploy_for_landing();
|
|
|
|
|
2015-01-06 00:24:05 -04:00
|
|
|
private:
|
|
|
|
// Parameters
|
2021-11-19 13:08:40 -04:00
|
|
|
AP_Int8 _enable;
|
2017-08-04 03:28:33 -03:00
|
|
|
AP_Int8 _startup_behaviour; // start-up behaviour (see LandingGearStartupBehaviour)
|
2018-06-10 03:34:02 -03:00
|
|
|
|
|
|
|
AP_Int8 _pin_deployed;
|
|
|
|
AP_Int8 _pin_deployed_polarity;
|
|
|
|
AP_Int8 _pin_weight_on_wheels;
|
|
|
|
AP_Int8 _pin_weight_on_wheels_polarity;
|
2018-11-09 00:39:59 -04:00
|
|
|
AP_Int16 _deploy_alt;
|
|
|
|
AP_Int16 _retract_alt;
|
2020-02-20 23:08:11 -04:00
|
|
|
AP_Int16 _options;
|
|
|
|
|
|
|
|
// bitmask of options
|
|
|
|
enum class Option : uint16_t {
|
|
|
|
RETRACT_AFTER_TAKEOFF = (1U<<0),
|
|
|
|
DEPLOY_DURING_LANDING = (1U<<1)
|
|
|
|
};
|
2015-01-06 00:24:05 -04:00
|
|
|
|
|
|
|
// internal variables
|
|
|
|
bool _deployed; // true if the landing gear has been deployed, initialized false
|
2018-11-09 00:39:59 -04:00
|
|
|
bool _have_changed; // have we changed the servo state?
|
2018-06-10 03:34:02 -03:00
|
|
|
|
2018-11-09 00:39:59 -04:00
|
|
|
int16_t _last_height_above_ground;
|
2018-06-10 03:34:02 -03:00
|
|
|
|
|
|
|
// debounce
|
|
|
|
LG_WOW_State wow_state_current = LG_WOW_UNKNOWN;
|
|
|
|
uint32_t last_wow_event_ms;
|
2015-01-06 00:24:05 -04:00
|
|
|
|
2018-06-10 03:34:02 -03:00
|
|
|
LG_LandingGear_State gear_state_current = LG_UNKNOWN;
|
|
|
|
uint32_t last_gear_event_ms;
|
|
|
|
|
2015-01-06 00:24:05 -04:00
|
|
|
/// retract - retract landing gear
|
|
|
|
void retract();
|
|
|
|
|
|
|
|
/// deploy - deploy the landing gear
|
|
|
|
void deploy();
|
2018-06-10 03:34:02 -03:00
|
|
|
|
2023-07-13 21:58:06 -03:00
|
|
|
#if HAL_LOGGING_ENABLED
|
2018-06-10 03:34:02 -03:00
|
|
|
// log weight on wheels state
|
|
|
|
void log_wow_state(LG_WOW_State state);
|
2023-07-13 21:58:06 -03:00
|
|
|
#else
|
|
|
|
void log_wow_state(LG_WOW_State state) {}
|
|
|
|
#endif
|
2018-06-10 03:34:02 -03:00
|
|
|
|
|
|
|
static AP_LandingGear *_singleton;
|
2015-01-06 00:24:05 -04:00
|
|
|
};
|
2022-10-01 07:21:38 -03:00
|
|
|
|
|
|
|
#endif // AP_LANDINGGEAR_ENABLED
|