2020-04-24 17:33:48 -03:00
/// @file AP_Parachute.h
/// @brief Parachute release library
2016-02-17 21:25:43 -04:00
# pragma once
2014-04-01 08:57:03 -03:00
2015-08-11 03:28:45 -03:00
# include <AP_Param/AP_Param.h>
# include <AP_Common/AP_Common.h>
# include <AP_Relay/AP_Relay.h>
2014-04-01 08:57:03 -03:00
# define AP_PARACHUTE_TRIGGER_TYPE_RELAY_0 0
# define AP_PARACHUTE_TRIGGER_TYPE_RELAY_1 1
# define AP_PARACHUTE_TRIGGER_TYPE_RELAY_2 2
# define AP_PARACHUTE_TRIGGER_TYPE_RELAY_3 3
# define AP_PARACHUTE_TRIGGER_TYPE_SERVO 10
2014-04-03 11:05:41 -03:00
# 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
2015-05-12 10:08:00 -03:00
# define AP_PARACHUTE_RELEASE_DURATION_MS 2000 // when parachute is released, servo or relay stay at their released position/value for 2000ms (2seconds)
2014-04-01 08:57:03 -03:00
# define AP_PARACHUTE_SERVO_ON_PWM_DEFAULT 1300 // default PWM value to move servo to when shutter is activated
# define AP_PARACHUTE_SERVO_OFF_PWM_DEFAULT 1100 // default PWM value to move servo to when shutter is deactivated
2014-04-06 23:17:07 -03:00
# define AP_PARACHUTE_ALT_MIN_DEFAULT 10 // default min altitude the vehicle should have before parachute is released
2014-04-01 08:57:03 -03:00
2019-02-21 09:04:33 -04:00
# define AP_PARACHUTE_CRITICAL_SINK_DEFAULT 0 // default critical sink speed in m/s to trigger emergency parachute
2020-01-17 18:57:09 -04:00
# ifndef HAL_PARACHUTE_ENABLED
2020-01-17 21:09:56 -04:00
// default to parachute enabled to match previous configs
# define HAL_PARACHUTE_ENABLED 1
2020-01-17 18:57:09 -04:00
# endif
# if HAL_PARACHUTE_ENABLED
2020-04-24 17:33:48 -03:00
/// @class AP_Parachute
/// @brief Class managing the release of a parachute
2014-04-01 08:57:03 -03:00
class AP_Parachute {
public :
2017-12-12 21:06:13 -04:00
/// Constructor
AP_Parachute ( AP_Relay & relay )
: _relay ( relay )
{
// setup parameter defaults
2019-02-01 17:48:19 -04:00
# if CONFIG_HAL_BOARD == HAL_BOARD_SITL
if ( _singleton ! = nullptr ) {
2020-05-03 19:18:36 -03:00
AP_HAL : : panic ( " Parachute must be singleton " ) ;
2019-02-01 17:48:19 -04:00
}
# endif
_singleton = this ;
2017-12-12 21:06:13 -04:00
AP_Param : : setup_object_defaults ( this , var_info ) ;
2014-04-01 08:57:03 -03:00
}
2017-08-29 20:54:55 -03:00
/* Do not allow copies */
2022-09-30 06:50:43 -03:00
CLASS_NO_COPY ( AP_Parachute ) ;
2017-08-29 20:54:55 -03:00
2014-04-01 08:57:03 -03:00
/// enabled - enable or disable parachute release
2014-04-03 11:05:41 -03:00
void enabled ( bool on_off ) ;
2014-04-01 08:57:03 -03:00
/// enabled - returns true if parachute release is enabled
bool enabled ( ) const { return _enabled ; }
/// release - release parachute
void release ( ) ;
2015-10-26 20:36:04 -03:00
/// released - true if the parachute has been released (or release is in progress)
bool released ( ) const { return _released ; }
2020-09-16 02:40:26 -03:00
2016-04-05 04:39:55 -03:00
/// release_initiated - true if the parachute release sequence has been initiated (may wait before actual release)
bool release_initiated ( ) const { return _release_initiated ; }
2017-07-26 09:29:00 -03:00
/// release_in_progress - true if the parachute release sequence is in progress
bool release_in_progress ( ) const { return _release_in_progress ; }
2020-09-16 02:40:26 -03:00
2014-04-01 08:57:03 -03:00
/// update - shuts off the trigger should be called at about 10hz
void update ( ) ;
2014-04-06 23:17:07 -03:00
/// alt_min - returns the min altitude above home the vehicle should have before parachute is released
2014-04-03 05:53:45 -03:00
/// 0 = altitude check disabled
2014-04-06 23:17:07 -03:00
int16_t alt_min ( ) const { return _alt_min ; }
2014-04-01 08:57:03 -03:00
2019-02-21 09:04:33 -04:00
/// set_is_flying - accessor to the is_flying flag
void set_is_flying ( const bool is_flying ) { _is_flying = is_flying ; }
// set_sink_rate - set vehicle sink rate
2020-09-16 03:24:40 -03:00
void set_sink_rate ( float sink_rate ) ;
// trigger parachute release if sink_rate is below critical_sink_rate for 1sec
void check_sink_rate ( ) ;
2019-02-21 09:04:33 -04:00
2021-07-20 01:36:10 -03:00
// check settings are valid
bool arming_checks ( size_t buflen , char * buffer ) const ;
2014-04-01 08:57:03 -03:00
static const struct AP_Param : : GroupInfo var_info [ ] ;
2019-02-01 17:48:19 -04:00
// get singleton instance
static AP_Parachute * get_singleton ( ) { return _singleton ; }
2014-04-01 08:57:03 -03:00
private :
2019-02-01 17:48:19 -04:00
static AP_Parachute * _singleton ;
2014-04-01 08:57:03 -03:00
// Parameters
AP_Int8 _enabled ; // 1 if parachute release is enabled
AP_Int8 _release_type ; // 0:Servo,1:Relay
AP_Int16 _servo_on_pwm ; // PWM value to move servo to when shutter is activated
AP_Int16 _servo_off_pwm ; // PWM value to move servo to when shutter is deactivated
2014-04-06 23:17:07 -03:00
AP_Int16 _alt_min ; // min altitude the vehicle should have before parachute is released
2016-03-28 15:48:40 -03:00
AP_Int16 _delay_ms ; // delay before chute release for motors to stop
2019-02-21 09:04:33 -04:00
AP_Float _critical_sink ; // critical sink rate to trigger emergency parachute
2014-04-01 08:57:03 -03:00
// internal variables
2015-11-03 09:46:29 -04:00
AP_Relay & _relay ; // pointer to relay object from the base class Relay.
2014-04-03 11:05:41 -03:00
uint32_t _release_time ; // system time that parachute is ordered to be released (actual release will happen 0.5 seconds later)
2016-04-05 04:39:55 -03:00
bool _release_initiated : 1 ; // true if the parachute release initiated (may still be waiting for engine to be suppressed etc.)
2015-10-26 20:36:04 -03:00
bool _release_in_progress : 1 ; // true if the parachute release is in progress
2016-04-05 04:39:55 -03:00
bool _released : 1 ; // true if the parachute has been released
2019-02-21 09:04:33 -04:00
bool _is_flying : 1 ; // true if the vehicle is flying
2020-09-16 03:24:40 -03:00
uint32_t _sink_time_ms ; // system time that the vehicle exceeded critical sink rate
2021-01-21 21:38:59 -04:00
enum class Options : uint8_t {
HoldOpen = ( 1U < < 0 ) ,
} ;
AP_Int32 _options ;
2014-04-01 08:57:03 -03:00
} ;
2019-02-01 17:48:19 -04:00
namespace AP {
AP_Parachute * parachute ( ) ;
} ;
2020-01-17 18:57:09 -04:00
# endif // HAL_PARACHUTE_ENABLED