2012-07-14 23:26:17 -03:00
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
/// @file limits.cpp
2012-10-11 22:35:35 -03:00
/// @brief Imposes limits on location (geofence), altitude and other parameters
/// Each limit breach will trigger an action or set of actions to recover.
// Adapted from geofence.
2012-07-14 23:26:17 -03:00
/// @author Andrew Tridgell
/// Andreas Antonopoulos
2012-10-11 22:35:35 -03:00
# include "AP_Limit_Altitude.h"
2012-07-14 23:26:17 -03:00
2015-10-25 14:03:46 -03:00
const AP_Param : : GroupInfo AP_Limit_Altitude : : var_info [ ] = {
2012-08-17 03:20:05 -03:00
// @Param: ALT_ON
// @DisplayName: Enable altitude
2012-12-08 00:19:36 -04:00
// @Description: Setting this to Enabled(1) will enable the altitude. Setting this to Disabled(0) will disable the altitude
2012-08-17 03:20:05 -03:00
// @Values: 0:Disabled,1:Enabled
// @User: Standard
AP_GROUPINFO ( " ALT_ON " , 0 , AP_Limit_Altitude , _enabled , 0 ) ,
2012-07-14 23:26:17 -03:00
2013-01-02 05:50:03 -04:00
// @Param: ALT_REQ
2012-08-17 03:20:05 -03:00
// @DisplayName: Require altitude
2012-12-08 00:19:36 -04:00
// @Description: Setting this to Enabled(1) will make being inside the altitude a required check before arming the vehicle.
2012-08-17 03:20:05 -03:00
// @Values: 0:Disabled,1:Enabled
// @User: Standard
AP_GROUPINFO ( " ALT_REQ " , 1 , AP_Limit_Altitude , _required , 0 ) ,
2012-07-14 23:26:17 -03:00
2012-08-17 03:20:05 -03:00
// @Param: ALT_MIN
// @DisplayName: Minimum Altitude
2012-12-08 00:19:36 -04:00
// @Description: Minimum Altitude. Zero to disable. Sets a "floor" that your vehicle will try to stay above. IF the vehicle is crossing the threshold at speed, it will take a while to recover, so give yourself enough room. Caution: minimum altitude limits can cause unexpected behaviour, such as inability to land, or sudden takeoff. Read the wiki instructions before setting.
2012-08-17 03:20:05 -03:00
// @Units: Meters
// @Range: 0 250000
// @Increment: 1
// @User: Standard
AP_GROUPINFO ( " ALT_MIN " , 2 , AP_Limit_Altitude , _min_alt , 0 ) ,
2012-07-14 23:26:17 -03:00
2012-08-17 03:20:05 -03:00
// @Param: ALT_MAX
// @DisplayName: Maximum Altitude
2012-12-08 00:19:36 -04:00
// @Description: Maximum Altitude. Zero to disable. Sets a "ceiling" that your vehicle will try to stay below. IF the vehicle is crossing the threshold at speed, it will take a while to recover.
2012-08-17 03:20:05 -03:00
// @Units: Meters
// @Range: 0 250000
// @Increment: 1
// @User: Standard
AP_GROUPINFO ( " ALT_MAX " , 3 , AP_Limit_Altitude , _max_alt , 0 ) ,
2012-07-14 23:26:17 -03:00
AP_GROUPEND
} ;
2013-03-26 08:58:54 -03:00
AP_Limit_Altitude : : AP_Limit_Altitude ( const struct Location * current_loc ) :
AP_Limit_Module ( AP_LIMITS_ALTITUDE ) , // enabled and required
_current_loc ( current_loc )
2012-07-14 23:26:17 -03:00
{
2012-12-12 17:49:46 -04:00
AP_Param : : setup_object_defaults ( this , var_info ) ;
2013-03-26 08:58:54 -03:00
//_current_loc = current_loc;
2012-07-14 23:26:17 -03:00
}
bool AP_Limit_Altitude : : triggered ( )
{
2012-08-17 03:20:05 -03:00
_triggered = false ; // reset trigger before checking
2012-07-14 23:26:17 -03:00
2012-08-17 03:20:05 -03:00
// _max_alt is zero if disabled
// convert _max_alt to centimeters to compare to actual altitude
if ( _max_alt > 0 & & _current_loc - > alt > _max_alt * 100 ) {
_triggered = true ;
}
2012-07-14 23:26:17 -03:00
2012-08-17 03:20:05 -03:00
// _min_alt is zero if disabled
// convert _min_alt to centimeters to compare to actual altitude
if ( _min_alt > 0 & & _current_loc - > alt < _min_alt * 100 ) {
_triggered = true ;
}
return _triggered ;
2012-07-14 23:26:17 -03:00
}
AP_Int32 AP_Limit_Altitude : : max_alt ( ) {
2012-08-17 03:20:05 -03:00
return _max_alt ;
2012-07-14 23:26:17 -03:00
}
AP_Int32 AP_Limit_Altitude : : min_alt ( ) {
2012-08-17 03:20:05 -03:00
return _min_alt ;
2012-07-14 23:26:17 -03:00
}