LCOV - code coverage report
Current view: top level - AP_LandingGear - AP_LandingGear.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 7 8 87.5 %
Date: 2026-09-09 11:02:08 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /// @file   AP_LandingGear.h
       2             : /// @brief  Landing gear control library
       3             : #pragma once
       4             : 
       5             : #include "AP_LandingGear_config.h"
       6             : 
       7             : #if AP_LANDINGGEAR_ENABLED
       8             : 
       9             : #include <AP_Param/AP_Param.h>
      10             : #include <AP_Common/AP_Common.h>
      11             : #include <AP_Logger/AP_Logger_config.h>
      12             : 
      13             : /// @class  AP_LandingGear
      14             : /// @brief  Class managing the control of landing gear
      15             : class AP_LandingGear {
      16             : public:
      17        1693 :     AP_LandingGear() {
      18             :         // setup parameter defaults
      19        1693 :         AP_Param::setup_object_defaults(this, var_info);
      20             :         
      21        1693 :         if (_singleton != nullptr) {
      22           0 :             AP_HAL::panic("AP_LandingGear must be singleton");
      23             :         }
      24        1693 :         _singleton = this;
      25        1693 :     }
      26             : 
      27             :     /* Do not allow copies */
      28             :     CLASS_NO_COPY(AP_LandingGear);
      29             :     
      30             :     // get singleton instance
      31         114 :     static AP_LandingGear *get_singleton(void) {
      32         114 :         return _singleton;
      33             :     }
      34             : 
      35             :     // Gear command modes
      36             :     enum LandingGearCommand {
      37             :         LandingGear_Retract,
      38             :         LandingGear_Deploy,
      39             :     };
      40             : 
      41             :     // Gear command modes
      42             :     enum LandingGearStartupBehaviour {
      43             :         LandingGear_Startup_WaitForPilotInput = 0,
      44             :         LandingGear_Startup_Retract = 1,
      45             :         LandingGear_Startup_Deploy = 2,
      46             :     };
      47             : 
      48             :     /// initialise state of landing gear
      49             :     void init();
      50             : 
      51             :     /// returns true if the landing gear is deployed
      52             :     bool deployed();
      53             :     
      54             :     enum LG_LandingGear_State {
      55             :         LG_UNKNOWN = -1,
      56             :         LG_RETRACTED = 0,
      57             :         LG_DEPLOYED = 1,
      58             :         LG_RETRACTING = 2,
      59             :         LG_DEPLOYING = 3,
      60             :         };
      61             :     /// returns detailed state of gear
      62             :     LG_LandingGear_State get_state();
      63             :     
      64             :     enum LG_WOW_State {
      65             :         LG_WOW_UNKNOWN = -1,
      66             :         LG_NO_WOW = 0,
      67             :         LG_WOW = 1,
      68             :         };
      69             : 
      70             :     LG_WOW_State get_wow_state();
      71             : 
      72             :     /// set landing gear position to retract, deploy or deploy-and-keep-deployed
      73             :     void set_position(LandingGearCommand cmd);
      74             :     
      75             :     uint32_t get_gear_state_duration_ms() const;
      76             :     uint32_t get_wow_state_duration_ms() const;
      77             : 
      78             :     static const struct AP_Param::GroupInfo        var_info[];
      79             :     
      80             :     void update(float height_above_ground_m);
      81             :     
      82             :     bool check_before_land(void);
      83             : 
      84             :     // retract after takeoff or deploy for landing depending on the OPTIONS parameter
      85             :     void retract_after_takeoff();
      86             :     void deploy_for_landing();
      87             : 
      88             : private:
      89             :     // Parameters
      90             :     AP_Int8     _enable;
      91             :     AP_Int8     _startup_behaviour;     // start-up behaviour (see LandingGearStartupBehaviour)
      92             :     
      93             :     AP_Int8     _pin_deployed;
      94             :     AP_Int8     _pin_deployed_polarity;
      95             :     AP_Int8     _pin_weight_on_wheels;
      96             :     AP_Int8     _pin_weight_on_wheels_polarity;
      97             :     AP_Int16    _deploy_alt_m;
      98             :     AP_Int16    _retract_alt_m;
      99             :     AP_Int16    _options;
     100             : 
     101             :     // bitmask of options
     102             :     enum class Option : uint16_t {
     103             :         RETRACT_AFTER_TAKEOFF = (1U<<0),
     104             :         DEPLOY_DURING_LANDING = (1U<<1)
     105             :     };
     106             : 
     107             :     // internal variables
     108             :     bool        _deployed;              // true if the landing gear has been deployed, initialized false
     109             :     bool        _have_changed;          // have we changed the servo state?
     110             : 
     111             :     float       _last_height_above_ground_m;
     112             :     
     113             :     // debounce
     114             :     LG_WOW_State wow_state_current = LG_WOW_UNKNOWN;
     115             :     uint32_t last_wow_event_ms;
     116             :     
     117             :     LG_LandingGear_State gear_state_current = LG_UNKNOWN;
     118             :     uint32_t last_gear_event_ms;
     119             : 
     120             :     /// retract - retract landing gear
     121             :     void retract();
     122             :     
     123             :     /// deploy - deploy the landing gear
     124             :     void deploy();
     125             : 
     126             : #if HAL_LOGGING_ENABLED
     127             :     // log weight on wheels state
     128             :     void log_wow_state(LG_WOW_State state);
     129             : #else
     130             :     void log_wow_state(LG_WOW_State state) {}
     131             : #endif
     132             : 
     133             :     static AP_LandingGear *_singleton;
     134             : };
     135             : 
     136             : #endif  // AP_LANDINGGEAR_ENABLED

Generated by: LCOV version 1.14