AP_Parachute.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /// @file AP_Parachute.h
  2. /// @brief Parachute release library
  3. #pragma once
  4. #include <AP_Param/AP_Param.h>
  5. #include <AP_Common/AP_Common.h>
  6. #include <AP_Relay/AP_Relay.h>
  7. #define AP_PARACHUTE_TRIGGER_TYPE_RELAY_0 0
  8. #define AP_PARACHUTE_TRIGGER_TYPE_RELAY_1 1
  9. #define AP_PARACHUTE_TRIGGER_TYPE_RELAY_2 2
  10. #define AP_PARACHUTE_TRIGGER_TYPE_RELAY_3 3
  11. #define AP_PARACHUTE_TRIGGER_TYPE_SERVO 10
  12. #define AP_PARACHUTE_RELEASE_DELAY_MS 500 // delay in milliseconds between call to release() and when servo or relay actually moves. Allows for warning to user
  13. #define AP_PARACHUTE_RELEASE_DURATION_MS 2000 // when parachute is released, servo or relay stay at their released position/value for 2000ms (2seconds)
  14. #define AP_PARACHUTE_SERVO_ON_PWM_DEFAULT 1300 // default PWM value to move servo to when shutter is activated
  15. #define AP_PARACHUTE_SERVO_OFF_PWM_DEFAULT 1100 // default PWM value to move servo to when shutter is deactivated
  16. #define AP_PARACHUTE_ALT_MIN_DEFAULT 10 // default min altitude the vehicle should have before parachute is released
  17. #define AP_PARACHUTE_CRITICAL_SINK_DEFAULT 0 // default critical sink speed in m/s to trigger emergency parachute
  18. /// @class AP_Parachute
  19. /// @brief Class managing the release of a parachute
  20. class AP_Parachute {
  21. public:
  22. /// Constructor
  23. AP_Parachute(AP_Relay &relay)
  24. : _relay(relay)
  25. {
  26. // setup parameter defaults
  27. #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
  28. if (_singleton != nullptr) {
  29. AP_HAL::panic("Rally must be singleton");
  30. }
  31. #endif
  32. _singleton = this;
  33. AP_Param::setup_object_defaults(this, var_info);
  34. }
  35. /* Do not allow copies */
  36. AP_Parachute(const AP_Parachute &other) = delete;
  37. AP_Parachute &operator=(const AP_Parachute&) = delete;
  38. /// enabled - enable or disable parachute release
  39. void enabled(bool on_off);
  40. /// enabled - returns true if parachute release is enabled
  41. bool enabled() const { return _enabled; }
  42. /// release - release parachute
  43. void release();
  44. /// released - true if the parachute has been released (or release is in progress)
  45. bool released() const { return _released; }
  46. /// release_initiated - true if the parachute release sequence has been initiated (may wait before actual release)
  47. bool release_initiated() const { return _release_initiated; }
  48. /// release_in_progress - true if the parachute release sequence is in progress
  49. bool release_in_progress() const { return _release_in_progress; }
  50. /// update - shuts off the trigger should be called at about 10hz
  51. void update();
  52. /// critical_sink - returns the configured maximum sink rate to trigger emergency release
  53. float critical_sink() const { return _critical_sink; }
  54. /// alt_min - returns the min altitude above home the vehicle should have before parachute is released
  55. /// 0 = altitude check disabled
  56. int16_t alt_min() const { return _alt_min; }
  57. /// set_is_flying - accessor to the is_flying flag
  58. void set_is_flying(const bool is_flying) { _is_flying = is_flying; }
  59. // set_sink_rate - set vehicle sink rate
  60. void set_sink_rate(float sink_rate) { _sink_rate = sink_rate; }
  61. static const struct AP_Param::GroupInfo var_info[];
  62. // get singleton instance
  63. static AP_Parachute *get_singleton() { return _singleton; }
  64. private:
  65. static AP_Parachute *_singleton;
  66. // Parameters
  67. AP_Int8 _enabled; // 1 if parachute release is enabled
  68. AP_Int8 _release_type; // 0:Servo,1:Relay
  69. AP_Int16 _servo_on_pwm; // PWM value to move servo to when shutter is activated
  70. AP_Int16 _servo_off_pwm; // PWM value to move servo to when shutter is deactivated
  71. AP_Int16 _alt_min; // min altitude the vehicle should have before parachute is released
  72. AP_Int16 _delay_ms; // delay before chute release for motors to stop
  73. AP_Float _critical_sink; // critical sink rate to trigger emergency parachute
  74. // internal variables
  75. AP_Relay &_relay; // pointer to relay object from the base class Relay.
  76. uint32_t _release_time; // system time that parachute is ordered to be released (actual release will happen 0.5 seconds later)
  77. bool _release_initiated:1; // true if the parachute release initiated (may still be waiting for engine to be suppressed etc.)
  78. bool _release_in_progress:1; // true if the parachute release is in progress
  79. bool _released:1; // true if the parachute has been released
  80. bool _is_flying:1; // true if the vehicle is flying
  81. float _sink_rate; // vehicle sink rate in m/s
  82. uint32_t _sink_time; // time that the vehicle exceeded critical sink rate
  83. };
  84. namespace AP {
  85. AP_Parachute *parachute();
  86. };