2013-08-29 02:34:34 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-11-23 15:28:19 -04:00
|
|
|
/*
|
2017-02-05 22:15:33 -04:00
|
|
|
* RC_Channel.cpp - class for one RC channel input
|
2012-08-17 03:22:48 -03:00
|
|
|
*/
|
2010-11-23 15:28:19 -04:00
|
|
|
|
2012-10-26 20:59:16 -03:00
|
|
|
#include <stdlib.h>
|
2016-03-31 18:43:36 -03:00
|
|
|
#include <cmath>
|
2012-10-26 20:59:16 -03:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2012-10-26 20:59:16 -03:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2012-10-26 20:59:16 -03:00
|
|
|
|
2010-11-23 15:28:19 -04:00
|
|
|
#include "RC_Channel.h"
|
|
|
|
|
2018-04-13 23:22:14 -03:00
|
|
|
#include <GCS_MAVLink/GCS.h>
|
|
|
|
|
2018-10-25 04:36:20 -03:00
|
|
|
#include <AC_Avoidance/AC_Avoid.h>
|
2018-06-08 00:37:51 -03:00
|
|
|
#include <AC_Sprayer/AC_Sprayer.h>
|
2019-04-04 08:08:20 -03:00
|
|
|
#include <AP_Camera/AP_Camera.h>
|
2018-06-08 00:37:51 -03:00
|
|
|
#include <AP_Gripper/AP_Gripper.h>
|
2018-11-08 20:02:54 -04:00
|
|
|
#include <AP_LandingGear/AP_LandingGear.h>
|
2019-04-04 08:08:20 -03:00
|
|
|
#include <AP_ServoRelayEvents/AP_ServoRelayEvents.h>
|
2019-05-03 08:26:28 -03:00
|
|
|
#include <AP_Arming/AP_Arming.h>
|
2019-06-13 23:43:01 -03:00
|
|
|
#include <AP_GPS/AP_GPS.h>
|
2019-08-31 12:23:08 -03:00
|
|
|
#include <AC_Fence/AC_Fence.h>
|
2018-06-08 00:37:51 -03:00
|
|
|
|
2019-06-18 12:37:19 -03:00
|
|
|
#define SWITCH_DEBOUNCE_TIME_MS 200
|
|
|
|
|
2015-10-25 14:03:46 -03:00
|
|
|
const AP_Param::GroupInfo RC_Channel::var_info[] = {
|
2012-08-17 03:22:48 -03:00
|
|
|
// @Param: MIN
|
|
|
|
// @DisplayName: RC min PWM
|
2017-05-15 20:23:19 -03:00
|
|
|
// @Description: RC minimum PWM pulse width in microseconds. Typically 1000 is lower limit, 1500 is neutral and 2000 is upper limit.
|
2017-05-02 10:49:03 -03:00
|
|
|
// @Units: PWM
|
2012-08-17 03:22:48 -03:00
|
|
|
// @Range: 800 2200
|
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2016-10-22 07:27:40 -03:00
|
|
|
AP_GROUPINFO("MIN", 1, RC_Channel, radio_min, 1100),
|
2012-08-17 03:22:48 -03:00
|
|
|
|
|
|
|
// @Param: TRIM
|
|
|
|
// @DisplayName: RC trim PWM
|
2017-05-15 20:23:19 -03:00
|
|
|
// @Description: RC trim (neutral) PWM pulse width in microseconds. Typically 1000 is lower limit, 1500 is neutral and 2000 is upper limit.
|
2017-05-02 10:49:03 -03:00
|
|
|
// @Units: PWM
|
2012-08-17 03:22:48 -03:00
|
|
|
// @Range: 800 2200
|
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2016-10-22 07:27:40 -03:00
|
|
|
AP_GROUPINFO("TRIM", 2, RC_Channel, radio_trim, 1500),
|
2012-08-17 03:22:48 -03:00
|
|
|
|
|
|
|
// @Param: MAX
|
|
|
|
// @DisplayName: RC max PWM
|
2017-05-15 20:23:19 -03:00
|
|
|
// @Description: RC maximum PWM pulse width in microseconds. Typically 1000 is lower limit, 1500 is neutral and 2000 is upper limit.
|
2017-05-02 10:49:03 -03:00
|
|
|
// @Units: PWM
|
2012-08-17 03:22:48 -03:00
|
|
|
// @Range: 800 2200
|
|
|
|
// @Increment: 1
|
|
|
|
// @User: Advanced
|
2016-10-22 07:27:40 -03:00
|
|
|
AP_GROUPINFO("MAX", 3, RC_Channel, radio_max, 1900),
|
2012-08-17 03:22:48 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
// @Param: REVERSED
|
|
|
|
// @DisplayName: RC reversed
|
2017-02-07 01:32:57 -04:00
|
|
|
// @Description: Reverse channel input. Set to 0 for normal operation. Set to 1 to reverse this input channel.
|
2016-10-22 07:27:40 -03:00
|
|
|
// @Values: 0:Normal,1:Reversed
|
2012-08-17 03:22:48 -03:00
|
|
|
// @User: Advanced
|
2016-10-22 07:27:40 -03:00
|
|
|
AP_GROUPINFO("REVERSED", 4, RC_Channel, reversed, 0),
|
2013-07-13 00:18:54 -03:00
|
|
|
|
2012-08-17 03:22:48 -03:00
|
|
|
// @Param: DZ
|
|
|
|
// @DisplayName: RC dead-zone
|
2017-05-15 20:23:19 -03:00
|
|
|
// @Description: PWM dead zone in microseconds around trim or bottom
|
2017-05-02 10:49:03 -03:00
|
|
|
// @Units: PWM
|
2013-11-26 09:34:28 -04:00
|
|
|
// @Range: 0 200
|
2012-08-17 03:22:48 -03:00
|
|
|
// @User: Advanced
|
2016-10-22 07:27:40 -03:00
|
|
|
AP_GROUPINFO("DZ", 5, RC_Channel, dead_zone, 0),
|
2013-07-13 00:18:54 -03:00
|
|
|
|
2018-04-13 23:22:14 -03:00
|
|
|
// @Param: OPTION
|
|
|
|
// @DisplayName: RC input option
|
|
|
|
// @Description: Function assigned to this RC channel
|
2019-09-22 20:09:02 -03:00
|
|
|
// @Values{Copter}: 0:Do Nothing, 2:Flip, 3:Simple Mode, 4:RTL, 5:Save Trim, 7:Save WP, 9:Camera Trigger, 10:RangeFinder, 11:Fence, 13:Super Simple Mode, 14:Acro Trainer, 15:Sprayer, 16:Auto, 17:AutoTune, 18:Land, 19:Gripper, 21:Parachute Enable, 22:Parachute Release, 23:Parachute 3pos, 24:Auto Mission Reset, 25:AttCon Feed Forward, 26:AttCon Accel Limits, 27:Retract Mount, 28:Relay On/Off, 34:Relay2 On/Off, 35:Relay3 On/Off, 36:Relay4 On/Off, 29:Landing Gear, 30:Lost Copter Sound, 31:Motor Emergency Stop, 32:Motor Interlock, 33:Brake, 37:Throw, 38:ADSB-Avoidance, 39:PrecLoiter, 40:Proximity Avoidance, 41:ArmDisarm, 42:SmartRTL, 43:InvertedFlight, 44:Winch Enable, 45:WinchControl, 46:RC Override Enable, 47:User Function 1, 48:User Function 2, 49:User Function 3, 58:Clear Waypoints, 60:ZigZag, 61:ZigZag SaveWP, 62:Compass Learn, 65:GPS Disable, 66:Relay5, 67:Relay6, 68:Stabilize, 69:PosHold, 70:AltHold, 71:FlowHold, 72:Circle, 73:Drift, 100:KillIMU1, 101:KillIMU2
|
|
|
|
// @Values{Rover}: 0:Do Nothing, 4:RTL, 5:Save Trim, 7:Save WP, 9:Camera Trigger, 11:Fence, 16:Auto, 19:Gripper, 24:Auto Mission Reset, 28:Relay On/Off, 30:Lost Rover Sound, 31:Motor Emergency Stop, 34:Relay2 On/Off, 35:Relay3 On/Off, 36:Relay4 On/Off, 40:Proximity Avoidance, 41:ArmDisarm, 42:SmartRTL, 46:RC Override Enable, 50:LearnCruise, 51:Manual, 52:Acro, 53:Steering, 54:Hold, 55:Guided, 56:Loiter, 57:Follow, 58:Clear Waypoints, 59:Simple, 62:Compass Learn, 63:Sailboat Tack, 65:GPS Disable, 66:Relay5, 67:Relay6, 74:Sailboat motoring 3pos, 100:KillIMU1, 101:KillIMU2,207:MainSail
|
2019-11-16 20:29:13 -04:00
|
|
|
// @Values{Plane}: 0:Do Nothing, 4:ModeRTL, 9:Camera Trigger, 16:ModeAuto, 24:Auto Mission Reset, 28:Relay On/Off, 29:Landing Gear, 34:Relay2 On/Off, 30:Lost Plane Sound, 31:Motor Emergency Stop, 35:Relay3 On/Off, 36:Relay4 On/Off, 41:ArmDisarm, 43:InvertedFlight, 46:RC Override Enable, 51:ModeManual, 55:ModeGuided, 58:Clear Waypoints, 62:Compass Learn, 64:Reverse Throttle, 65:GPS Disable, 66:Relay5, 67:Relay6, 72:ModeCircle, 77:ModeTakeoff, 100:KillIMU1, 101:KillIMU2
|
2018-04-13 23:22:14 -03:00
|
|
|
// @User: Standard
|
2018-08-03 06:57:31 -03:00
|
|
|
AP_GROUPINFO_FRAME("OPTION", 6, RC_Channel, option, 0, AP_PARAM_FRAME_COPTER|AP_PARAM_FRAME_ROVER|AP_PARAM_FRAME_PLANE),
|
2018-04-13 23:22:14 -03:00
|
|
|
|
2012-08-17 03:22:48 -03:00
|
|
|
AP_GROUPEND
|
2012-02-11 07:54:21 -04:00
|
|
|
};
|
|
|
|
|
2012-05-31 18:59:03 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
// constructor
|
|
|
|
RC_Channel::RC_Channel(void)
|
2010-12-20 23:53:26 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2010-12-20 23:53:26 -04:00
|
|
|
}
|
|
|
|
|
2011-05-05 14:46:11 -03:00
|
|
|
void
|
2016-10-22 07:27:40 -03:00
|
|
|
RC_Channel::set_range(uint16_t high)
|
2011-05-05 14:46:11 -03:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
type_in = RC_CHANNEL_TYPE_RANGE;
|
|
|
|
high_in = high;
|
2015-12-06 17:25:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-22 07:27:40 -03:00
|
|
|
RC_Channel::set_angle(uint16_t angle)
|
2015-12-06 17:25:32 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
type_in = RC_CHANNEL_TYPE_ANGLE;
|
|
|
|
high_in = angle;
|
2015-12-06 17:25:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-22 07:27:40 -03:00
|
|
|
RC_Channel::set_default_dead_zone(int16_t dzone)
|
2015-12-06 17:25:32 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
dead_zone.set_default(abs(dzone));
|
2011-05-05 14:46:11 -03:00
|
|
|
}
|
2010-11-28 03:03:23 -04:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
bool
|
|
|
|
RC_Channel::get_reverse(void) const
|
2010-11-23 15:28:19 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
return bool(reversed.get());
|
2010-11-23 15:28:19 -04:00
|
|
|
}
|
|
|
|
|
2018-07-24 22:50:01 -03:00
|
|
|
// read input from hal.rcin or overrides
|
|
|
|
bool
|
|
|
|
RC_Channel::update(void)
|
2010-11-23 17:20:29 -04:00
|
|
|
{
|
2019-03-29 07:27:27 -03:00
|
|
|
if (has_override() && !rc().ignore_overrides()) {
|
2018-04-25 23:06:19 -03:00
|
|
|
radio_in = override_value;
|
2019-03-29 07:27:27 -03:00
|
|
|
} else if (!rc().ignore_receiver()) {
|
2018-07-24 22:50:01 -03:00
|
|
|
radio_in = hal.rcin->read(ch_in);
|
2018-04-25 23:06:19 -03:00
|
|
|
} else {
|
2018-07-24 22:50:01 -03:00
|
|
|
return false;
|
2018-04-25 23:06:19 -03:00
|
|
|
}
|
2012-08-17 03:22:48 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
if (type_in == RC_CHANNEL_TYPE_RANGE) {
|
|
|
|
control_in = pwm_to_range();
|
2012-11-05 05:49:42 -04:00
|
|
|
} else {
|
2016-10-22 07:27:40 -03:00
|
|
|
//RC_CHANNEL_TYPE_ANGLE
|
|
|
|
control_in = pwm_to_angle();
|
2012-08-17 03:22:48 -03:00
|
|
|
}
|
2018-07-24 22:50:01 -03:00
|
|
|
|
|
|
|
return true;
|
2010-11-23 15:28:19 -04:00
|
|
|
}
|
|
|
|
|
2018-04-10 19:50:16 -03:00
|
|
|
// recompute control values with no deadzone
|
|
|
|
// When done this way the control_in value can be used as servo_out
|
|
|
|
// to give the same output as input
|
2012-12-04 02:27:18 -04:00
|
|
|
void
|
2018-04-10 19:50:16 -03:00
|
|
|
RC_Channel::recompute_pwm_no_deadzone()
|
2012-12-04 02:27:18 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
if (type_in == RC_CHANNEL_TYPE_RANGE) {
|
|
|
|
control_in = pwm_to_range_dz(0);
|
2012-12-04 02:27:18 -04:00
|
|
|
} else {
|
2016-10-22 07:27:40 -03:00
|
|
|
//RC_CHANNEL_ANGLE
|
|
|
|
control_in = pwm_to_angle_dz(0);
|
2012-12-04 02:27:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-17 18:00:31 -04:00
|
|
|
/*
|
|
|
|
return the center stick position expressed as a control_in value
|
|
|
|
used for thr_mid in copter
|
|
|
|
*/
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t RC_Channel::get_control_mid() const
|
|
|
|
{
|
|
|
|
if (type_in == RC_CHANNEL_TYPE_RANGE) {
|
|
|
|
int16_t r_in = (radio_min.get() + radio_max.get())/2;
|
2014-11-17 18:00:31 -04:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
if (reversed) {
|
|
|
|
r_in = radio_max.get() - (r_in - radio_min.get());
|
2014-11-17 18:00:31 -04:00
|
|
|
}
|
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t radio_trim_low = radio_min + dead_zone;
|
2014-11-17 18:00:31 -04:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
return (((int32_t)(high_in) * (int32_t)(r_in - radio_trim_low)) / (int32_t)(radio_max - radio_trim_low));
|
2014-11-17 18:00:31 -04:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 08:37:25 -04:00
|
|
|
/*
|
|
|
|
return an "angle in centidegrees" (normally -4500 to 4500) from
|
|
|
|
the current radio_in value using the specified dead_zone
|
|
|
|
*/
|
2010-12-25 21:17:04 -04:00
|
|
|
int16_t
|
2018-10-12 19:56:44 -03:00
|
|
|
RC_Channel::pwm_to_angle_dz_trim(uint16_t _dead_zone, uint16_t _trim) const
|
2010-11-23 15:28:19 -04:00
|
|
|
{
|
2017-01-06 21:02:32 -04:00
|
|
|
int16_t radio_trim_high = _trim + _dead_zone;
|
|
|
|
int16_t radio_trim_low = _trim - _dead_zone;
|
2012-02-19 01:08:17 -04:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t reverse_mul = (reversed?-1:1);
|
2017-08-23 20:43:41 -03:00
|
|
|
if (radio_in > radio_trim_high && radio_max != radio_trim_high) {
|
2016-10-22 07:27:40 -03:00
|
|
|
return reverse_mul * ((int32_t)high_in * (int32_t)(radio_in - radio_trim_high)) / (int32_t)(radio_max - radio_trim_high);
|
2017-08-23 20:43:41 -03:00
|
|
|
} else if (radio_in < radio_trim_low && radio_trim_low != radio_min) {
|
2016-10-22 07:27:40 -03:00
|
|
|
return reverse_mul * ((int32_t)high_in * (int32_t)(radio_in - radio_trim_low)) / (int32_t)(radio_trim_low - radio_min);
|
|
|
|
} else {
|
2012-08-17 03:22:48 -03:00
|
|
|
return 0;
|
2016-10-22 07:27:40 -03:00
|
|
|
}
|
2010-12-20 23:53:26 -04:00
|
|
|
}
|
|
|
|
|
2015-12-26 06:58:26 -04:00
|
|
|
/*
|
|
|
|
return an "angle in centidegrees" (normally -4500 to 4500) from
|
|
|
|
the current radio_in value using the specified dead_zone
|
|
|
|
*/
|
|
|
|
int16_t
|
2018-10-12 19:56:44 -03:00
|
|
|
RC_Channel::pwm_to_angle_dz(uint16_t _dead_zone) const
|
2015-12-26 06:58:26 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
return pwm_to_angle_dz_trim(_dead_zone, radio_trim);
|
2015-12-26 06:58:26 -04:00
|
|
|
}
|
|
|
|
|
2012-11-05 08:37:25 -04:00
|
|
|
/*
|
|
|
|
return an "angle in centidegrees" (normally -4500 to 4500) from
|
|
|
|
the current radio_in value
|
|
|
|
*/
|
|
|
|
int16_t
|
2018-10-12 19:56:44 -03:00
|
|
|
RC_Channel::pwm_to_angle() const
|
2012-11-05 08:37:25 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
return pwm_to_angle_dz(dead_zone);
|
2012-11-05 08:37:25 -04:00
|
|
|
}
|
|
|
|
|
2010-11-23 15:28:19 -04:00
|
|
|
|
2012-12-04 02:27:18 -04:00
|
|
|
/*
|
|
|
|
convert a pulse width modulation value to a value in the configured
|
|
|
|
range, using the specified deadzone
|
|
|
|
*/
|
2010-11-23 15:28:19 -04:00
|
|
|
int16_t
|
2018-10-12 19:56:44 -03:00
|
|
|
RC_Channel::pwm_to_range_dz(uint16_t _dead_zone) const
|
2010-11-23 15:28:19 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t r_in = constrain_int16(radio_in, radio_min.get(), radio_max.get());
|
2012-05-31 18:59:03 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
if (reversed) {
|
|
|
|
r_in = radio_max.get() - (r_in - radio_min.get());
|
2012-09-16 02:05:26 -03:00
|
|
|
}
|
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t radio_trim_low = radio_min + _dead_zone;
|
2011-09-27 02:12:39 -03:00
|
|
|
|
2016-10-22 07:27:40 -03:00
|
|
|
if (r_in > radio_trim_low) {
|
|
|
|
return (((int32_t)(high_in) * (int32_t)(r_in - radio_trim_low)) / (int32_t)(radio_max - radio_trim_low));
|
|
|
|
}
|
|
|
|
return 0;
|
2010-11-23 15:28:19 -04:00
|
|
|
}
|
|
|
|
|
2012-12-04 02:27:18 -04:00
|
|
|
/*
|
|
|
|
convert a pulse width modulation value to a value in the configured
|
|
|
|
range
|
|
|
|
*/
|
|
|
|
int16_t
|
2018-10-12 19:56:44 -03:00
|
|
|
RC_Channel::pwm_to_range() const
|
2012-12-04 02:27:18 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
return pwm_to_range_dz(dead_zone);
|
2012-12-04 02:27:18 -04:00
|
|
|
}
|
|
|
|
|
2011-09-27 02:12:39 -03:00
|
|
|
|
2018-10-12 19:56:44 -03:00
|
|
|
int16_t RC_Channel::get_control_in_zero_dz(void) const
|
2010-11-23 15:28:19 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
if (type_in == RC_CHANNEL_TYPE_RANGE) {
|
|
|
|
return pwm_to_range_dz(0);
|
2014-03-26 03:38:27 -03:00
|
|
|
}
|
2016-10-22 07:27:40 -03:00
|
|
|
return pwm_to_angle_dz(0);
|
2010-11-23 15:28:19 -04:00
|
|
|
}
|
|
|
|
|
2010-12-27 19:03:26 -04:00
|
|
|
// ------------------------------------------
|
2010-12-25 21:17:04 -04:00
|
|
|
|
2011-02-14 00:43:44 -04:00
|
|
|
float
|
2018-10-12 19:56:44 -03:00
|
|
|
RC_Channel::norm_input() const
|
2010-12-27 19:03:26 -04:00
|
|
|
{
|
2014-03-15 06:43:13 -03:00
|
|
|
float ret;
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t reverse_mul = (reversed?-1:1);
|
|
|
|
if (radio_in < radio_trim) {
|
|
|
|
if (radio_min >= radio_trim) {
|
2015-11-30 06:53:54 -04:00
|
|
|
return 0.0f;
|
|
|
|
}
|
2016-10-22 07:27:40 -03:00
|
|
|
ret = reverse_mul * (float)(radio_in - radio_trim) / (float)(radio_trim - radio_min);
|
2015-02-17 21:47:56 -04:00
|
|
|
} else {
|
2016-10-22 07:27:40 -03:00
|
|
|
if (radio_max <= radio_trim) {
|
2015-11-30 06:53:54 -04:00
|
|
|
return 0.0f;
|
|
|
|
}
|
2016-10-22 07:27:40 -03:00
|
|
|
ret = reverse_mul * (float)(radio_in - radio_trim) / (float)(radio_max - radio_trim);
|
2015-02-17 21:47:56 -04:00
|
|
|
}
|
2014-03-15 06:43:13 -03:00
|
|
|
return constrain_float(ret, -1.0f, 1.0f);
|
2010-12-27 19:03:26 -04:00
|
|
|
}
|
2010-12-25 21:17:04 -04:00
|
|
|
|
2014-11-17 21:44:05 -04:00
|
|
|
float
|
2018-10-12 19:56:44 -03:00
|
|
|
RC_Channel::norm_input_dz() const
|
2014-11-17 21:44:05 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t dz_min = radio_trim - dead_zone;
|
|
|
|
int16_t dz_max = radio_trim + dead_zone;
|
2014-11-17 21:44:05 -04:00
|
|
|
float ret;
|
2016-10-22 07:27:40 -03:00
|
|
|
int16_t reverse_mul = (reversed?-1:1);
|
|
|
|
if (radio_in < dz_min && dz_min > radio_min) {
|
|
|
|
ret = reverse_mul * (float)(radio_in - dz_min) / (float)(dz_min - radio_min);
|
|
|
|
} else if (radio_in > dz_max && radio_max > dz_max) {
|
|
|
|
ret = reverse_mul * (float)(radio_in - dz_max) / (float)(radio_max - dz_max);
|
2014-11-17 21:44:05 -04:00
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return constrain_float(ret, -1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
2014-03-04 18:16:12 -04:00
|
|
|
/*
|
|
|
|
get percentage input from 0 to 100. This ignores the trim value.
|
|
|
|
*/
|
|
|
|
uint8_t
|
2018-10-12 19:56:44 -03:00
|
|
|
RC_Channel::percent_input() const
|
2014-03-04 18:16:12 -04:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
if (radio_in <= radio_min) {
|
|
|
|
return reversed?100:0;
|
2014-03-04 18:16:12 -04:00
|
|
|
}
|
2016-10-22 07:27:40 -03:00
|
|
|
if (radio_in >= radio_max) {
|
|
|
|
return reversed?0:100;
|
2014-03-04 18:16:12 -04:00
|
|
|
}
|
2016-10-22 07:27:40 -03:00
|
|
|
uint8_t ret = 100.0f * (radio_in - radio_min) / (float)(radio_max - radio_min);
|
|
|
|
if (reversed) {
|
2014-03-04 18:16:12 -04:00
|
|
|
ret = 100 - ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-30 02:46:03 -03:00
|
|
|
/*
|
2019-02-11 02:05:14 -04:00
|
|
|
return true if input is within deadzone of trim
|
2015-10-30 02:46:03 -03:00
|
|
|
*/
|
2018-10-12 19:56:44 -03:00
|
|
|
bool RC_Channel::in_trim_dz() const
|
2015-10-30 02:46:03 -03:00
|
|
|
{
|
2016-10-22 07:27:40 -03:00
|
|
|
return is_bounded_int32(radio_in, radio_trim - dead_zone, radio_trim + dead_zone);
|
2015-10-30 02:46:03 -03:00
|
|
|
}
|
2016-10-11 08:00:48 -03:00
|
|
|
|
2018-04-25 23:06:19 -03:00
|
|
|
void RC_Channel::set_override(const uint16_t v, const uint32_t timestamp_us)
|
|
|
|
{
|
2018-08-02 23:23:53 -03:00
|
|
|
if (!rc().gcs_overrides_enabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-09 17:52:47 -03:00
|
|
|
|
2018-04-25 23:06:19 -03:00
|
|
|
last_override_time = timestamp_us != 0 ? timestamp_us : AP_HAL::millis();
|
|
|
|
override_value = v;
|
2019-03-29 07:59:29 -03:00
|
|
|
rc().new_override_received();
|
2018-04-25 23:06:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void RC_Channel::clear_override()
|
|
|
|
{
|
|
|
|
last_override_time = 0;
|
|
|
|
override_value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RC_Channel::has_override() const
|
|
|
|
{
|
2018-08-27 17:03:09 -03:00
|
|
|
if (override_value <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-29 07:45:49 -03:00
|
|
|
const float override_timeout_ms = rc().override_timeout_ms();
|
2018-08-27 17:03:09 -03:00
|
|
|
return is_positive(override_timeout_ms) && ((AP_HAL::millis() - last_override_time) < (uint32_t)override_timeout_ms);
|
2018-04-25 23:06:19 -03:00
|
|
|
}
|
2018-01-08 23:41:02 -04:00
|
|
|
|
2019-05-01 17:43:27 -03:00
|
|
|
/*
|
|
|
|
perform stick mixing on one channel
|
|
|
|
This type of stick mixing reduces the influence of the auto
|
|
|
|
controller as it increases the influence of the users stick input,
|
|
|
|
allowing the user full deflection if needed
|
|
|
|
*/
|
|
|
|
int16_t RC_Channel::stick_mixing(const int16_t servo_in)
|
|
|
|
{
|
|
|
|
float ch_inf = (float)(radio_in - radio_trim);
|
|
|
|
ch_inf = fabsf(ch_inf);
|
|
|
|
ch_inf = MIN(ch_inf, 400.0f);
|
|
|
|
ch_inf = ((400.0f - ch_inf) / 400.0f);
|
|
|
|
|
|
|
|
int16_t servo_out = servo_in;
|
|
|
|
servo_out *= ch_inf;
|
|
|
|
servo_out += control_in;
|
|
|
|
|
|
|
|
return servo_out;
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:22:14 -03:00
|
|
|
//
|
|
|
|
// support for auxillary switches:
|
|
|
|
//
|
|
|
|
|
|
|
|
void RC_Channel::reset_mode_switch()
|
|
|
|
{
|
2019-06-18 12:37:19 -03:00
|
|
|
switch_state.current_position = -1;
|
|
|
|
switch_state.debounce_position = -1;
|
2018-04-13 23:22:14 -03:00
|
|
|
read_mode_switch();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RC_Channel::read_mode_switch()
|
|
|
|
{
|
|
|
|
// calculate position of flight mode switch
|
|
|
|
const uint16_t pulsewidth = get_radio_in();
|
|
|
|
if (pulsewidth <= 900 || pulsewidth >= 2200) {
|
|
|
|
return; // This is an error condition
|
|
|
|
}
|
|
|
|
|
|
|
|
modeswitch_pos_t position;
|
|
|
|
if (pulsewidth < 1231) position = 0;
|
|
|
|
else if (pulsewidth < 1361) position = 1;
|
|
|
|
else if (pulsewidth < 1491) position = 2;
|
|
|
|
else if (pulsewidth < 1621) position = 3;
|
|
|
|
else if (pulsewidth < 1750) position = 4;
|
|
|
|
else position = 5;
|
|
|
|
|
2019-06-18 12:37:19 -03:00
|
|
|
if (!debounce_completed(position)) {
|
2018-04-13 23:22:14 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set flight mode and simple mode setting
|
|
|
|
mode_switch_changed(position);
|
2019-06-18 12:37:19 -03:00
|
|
|
}
|
2018-04-13 23:22:14 -03:00
|
|
|
|
2019-06-18 12:37:19 -03:00
|
|
|
bool RC_Channel::debounce_completed(int8_t position)
|
|
|
|
{
|
|
|
|
// switch change not detected
|
|
|
|
if (switch_state.current_position == position) {
|
|
|
|
// reset debouncing
|
|
|
|
switch_state.debounce_position = position;
|
|
|
|
} else {
|
|
|
|
// switch change detected
|
|
|
|
const uint32_t tnow_ms = AP_HAL::millis();
|
|
|
|
|
|
|
|
// position not established yet
|
|
|
|
if (switch_state.debounce_position != position) {
|
|
|
|
switch_state.debounce_position = position;
|
|
|
|
switch_state.last_edge_time_ms = tnow_ms;
|
|
|
|
} else if (tnow_ms - switch_state.last_edge_time_ms >= SWITCH_DEBOUNCE_TIME_MS) {
|
|
|
|
// position estabilished; debounce completed
|
|
|
|
switch_state.current_position = position;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-04-13 23:22:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// support for auxillary switches:
|
|
|
|
//
|
|
|
|
|
|
|
|
// init_aux_switch_function - initialize aux functions
|
|
|
|
void RC_Channel::init_aux_function(const aux_func_t ch_option, const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
// init channel options
|
|
|
|
switch(ch_option) {
|
2019-08-31 12:23:08 -03:00
|
|
|
case AUX_FUNC::FENCE:
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RC_OVERRIDE_ENABLE:
|
|
|
|
case AUX_FUNC::AVOID_PROXIMITY:
|
2019-06-05 20:39:14 -03:00
|
|
|
case AUX_FUNC::MISSION_RESET:
|
2018-08-02 07:48:04 -03:00
|
|
|
do_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
2019-04-11 15:46:02 -03:00
|
|
|
// the following functions do not need to be initialised:
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RELAY:
|
|
|
|
case AUX_FUNC::RELAY2:
|
|
|
|
case AUX_FUNC::RELAY3:
|
|
|
|
case AUX_FUNC::RELAY4:
|
|
|
|
case AUX_FUNC::RELAY5:
|
|
|
|
case AUX_FUNC::RELAY6:
|
|
|
|
case AUX_FUNC::CAMERA_TRIGGER:
|
|
|
|
case AUX_FUNC::LOST_VEHICLE_SOUND:
|
|
|
|
case AUX_FUNC::DO_NOTHING:
|
|
|
|
case AUX_FUNC::CLEAR_WP:
|
|
|
|
case AUX_FUNC::COMPASS_LEARN:
|
|
|
|
case AUX_FUNC::LANDING_GEAR:
|
|
|
|
break;
|
|
|
|
case AUX_FUNC::MOTOR_ESTOP:
|
|
|
|
case AUX_FUNC::GRIPPER:
|
|
|
|
case AUX_FUNC::SPRAYER:
|
|
|
|
case AUX_FUNC::GPS_DISABLE:
|
2019-04-18 01:24:02 -03:00
|
|
|
case AUX_FUNC::KILL_IMU1:
|
|
|
|
case AUX_FUNC::KILL_IMU2:
|
2018-06-08 00:37:51 -03:00
|
|
|
do_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
2018-04-13 23:22:14 -03:00
|
|
|
default:
|
2019-04-03 18:22:02 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_WARNING, "Failed to initialise RC function (%u)", (unsigned)ch_option);
|
2018-08-03 23:12:40 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2019-04-03 18:22:02 -03:00
|
|
|
AP_HAL::panic("RC function (%u) initialisation not handled", (unsigned)ch_option);
|
2018-08-03 23:12:40 -03:00
|
|
|
#endif
|
2018-04-13 23:22:14 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 21:41:52 -03:00
|
|
|
/*
|
|
|
|
read an aux channel. Return true if a switch has changed
|
|
|
|
*/
|
|
|
|
bool RC_Channel::read_aux()
|
2018-04-13 23:22:14 -03:00
|
|
|
{
|
|
|
|
const aux_func_t _option = (aux_func_t)option.get();
|
2019-04-03 10:23:06 -03:00
|
|
|
if (_option == AUX_FUNC::DO_NOTHING) {
|
2018-04-13 23:22:14 -03:00
|
|
|
// may wish to add special cases for other "AUXSW" things
|
|
|
|
// here e.g. RCMAP_ROLL etc once they become options
|
2019-05-20 21:41:52 -03:00
|
|
|
return false;
|
2018-04-13 23:22:14 -03:00
|
|
|
}
|
2019-01-07 22:19:34 -04:00
|
|
|
aux_switch_pos_t new_position;
|
|
|
|
if (!read_3pos_switch(new_position)) {
|
2019-05-20 21:41:52 -03:00
|
|
|
return false;
|
2019-01-07 22:19:34 -04:00
|
|
|
}
|
2019-06-18 12:37:19 -03:00
|
|
|
|
|
|
|
if (!debounce_completed(new_position)) {
|
2019-05-20 21:41:52 -03:00
|
|
|
return false;
|
2018-04-13 23:22:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// debounced; undertake the action:
|
|
|
|
do_aux_function(_option, new_position);
|
2019-05-20 21:41:52 -03:00
|
|
|
return true;
|
2018-04-13 23:22:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-25 04:36:20 -03:00
|
|
|
void RC_Channel::do_aux_function_avoid_proximity(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
AC_Avoid *avoid = AP::ac_avoid();
|
|
|
|
if (avoid == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ch_flag) {
|
|
|
|
case HIGH:
|
|
|
|
avoid->proximity_avoidance_enable(true);
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case LOW:
|
|
|
|
avoid->proximity_avoidance_enable(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:22:14 -03:00
|
|
|
void RC_Channel::do_aux_function_camera_trigger(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
AP_Camera *camera = AP::camera();
|
|
|
|
if (camera == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
camera->take_picture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-31 12:23:08 -03:00
|
|
|
// enable or disable the fence
|
|
|
|
void RC_Channel::do_aux_function_fence(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
AC_Fence *fence = AP::fence();
|
|
|
|
if (fence == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AP_Logger *logger = AP_Logger::get_singleton();
|
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
fence->enable(true);
|
|
|
|
if (logger != nullptr) {
|
|
|
|
logger->Write_Event(DATA_FENCE_ENABLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fence->enable(false);
|
|
|
|
if (logger != nullptr) {
|
|
|
|
logger->Write_Event(DATA_FENCE_DISABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 23:44:15 -03:00
|
|
|
void RC_Channel::do_aux_function_clear_wp(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
AP_Mission *mission = AP::mission();
|
|
|
|
if (mission == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
mission->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:22:14 -03:00
|
|
|
void RC_Channel::do_aux_function_relay(const uint8_t relay, bool val)
|
|
|
|
{
|
|
|
|
AP_ServoRelayEvents *servorelayevents = AP::servorelayevents();
|
|
|
|
if (servorelayevents == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
servorelayevents->do_set_relay(relay, val);
|
|
|
|
}
|
|
|
|
|
2018-06-08 00:37:51 -03:00
|
|
|
void RC_Channel::do_aux_function_sprayer(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
AC_Sprayer *sprayer = AP::sprayer();
|
|
|
|
if (sprayer == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprayer->run(ch_flag == HIGH);
|
|
|
|
// if we are disarmed the pilot must want to test the pump
|
|
|
|
sprayer->test_pump((ch_flag == HIGH) && !hal.util->get_soft_armed());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RC_Channel::do_aux_function_gripper(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
AP_Gripper *gripper = AP::gripper();
|
|
|
|
if (gripper == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(ch_flag) {
|
|
|
|
case LOW:
|
|
|
|
gripper->release();
|
|
|
|
// copter.Log_Write_Event(DATA_GRIPPER_RELEASE);
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case HIGH:
|
|
|
|
gripper->grab();
|
|
|
|
// copter.Log_Write_Event(DATA_GRIPPER_GRAB);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-27 05:15:51 -03:00
|
|
|
void RC_Channel::do_aux_function_lost_vehicle_sound(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
switch (ch_flag) {
|
|
|
|
case HIGH:
|
|
|
|
AP_Notify::flags.vehicle_lost = true;
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case LOW:
|
|
|
|
AP_Notify::flags.vehicle_lost = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 07:48:04 -03:00
|
|
|
void RC_Channel::do_aux_function_rc_override_enable(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
switch (ch_flag) {
|
|
|
|
case HIGH: {
|
|
|
|
rc().set_gcs_overrides_enabled(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case LOW: {
|
|
|
|
rc().set_gcs_overrides_enabled(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 20:39:14 -03:00
|
|
|
void RC_Channel::do_aux_function_mission_reset(const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
if (ch_flag != HIGH) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AP_Mission *mission = AP::mission();
|
|
|
|
if (mission == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mission->reset();
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:22:14 -03:00
|
|
|
void RC_Channel::do_aux_function(const aux_func_t ch_option, const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
switch(ch_option) {
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::CAMERA_TRIGGER:
|
2018-04-13 23:22:14 -03:00
|
|
|
do_aux_function_camera_trigger(ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-08-31 12:23:08 -03:00
|
|
|
case AUX_FUNC::FENCE:
|
|
|
|
do_aux_function_fence(ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::GRIPPER:
|
2018-06-08 00:37:51 -03:00
|
|
|
do_aux_function_gripper(ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RC_OVERRIDE_ENABLE:
|
2018-08-02 07:48:04 -03:00
|
|
|
// Allow or disallow RC_Override
|
|
|
|
do_aux_function_rc_override_enable(ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::AVOID_PROXIMITY:
|
2018-10-25 04:36:20 -03:00
|
|
|
do_aux_function_avoid_proximity(ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RELAY:
|
2018-04-13 23:22:14 -03:00
|
|
|
do_aux_function_relay(0, ch_flag == HIGH);
|
|
|
|
break;
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RELAY2:
|
2018-04-13 23:22:14 -03:00
|
|
|
do_aux_function_relay(1, ch_flag == HIGH);
|
|
|
|
break;
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RELAY3:
|
2018-04-13 23:22:14 -03:00
|
|
|
do_aux_function_relay(2, ch_flag == HIGH);
|
|
|
|
break;
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RELAY4:
|
2018-04-13 23:22:14 -03:00
|
|
|
do_aux_function_relay(3, ch_flag == HIGH);
|
|
|
|
break;
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RELAY5:
|
2018-10-03 10:03:49 -03:00
|
|
|
do_aux_function_relay(4, ch_flag == HIGH);
|
|
|
|
break;
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::RELAY6:
|
2018-10-03 10:03:49 -03:00
|
|
|
do_aux_function_relay(5, ch_flag == HIGH);
|
|
|
|
break;
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::CLEAR_WP:
|
2018-08-16 23:44:15 -03:00
|
|
|
do_aux_function_clear_wp(ch_flag);
|
|
|
|
break;
|
2019-06-05 20:39:14 -03:00
|
|
|
case AUX_FUNC::MISSION_RESET:
|
|
|
|
do_aux_function_mission_reset(ch_flag);
|
|
|
|
break;
|
2018-04-13 23:22:14 -03:00
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::SPRAYER:
|
2018-06-08 00:37:51 -03:00
|
|
|
do_aux_function_sprayer(ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::LOST_VEHICLE_SOUND:
|
2018-08-27 05:15:51 -03:00
|
|
|
do_aux_function_lost_vehicle_sound(ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-05-03 08:26:28 -03:00
|
|
|
case AUX_FUNC::ARMDISARM:
|
|
|
|
// arm or disarm the vehicle
|
|
|
|
switch (ch_flag) {
|
|
|
|
case HIGH:
|
|
|
|
AP::arming().arm(AP_Arming::Method::AUXSWITCH, true);
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case LOW:
|
|
|
|
AP::arming().disarm();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::COMPASS_LEARN:
|
2018-10-19 21:00:04 -03:00
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
Compass &compass = AP::compass();
|
|
|
|
compass.set_learn_type(Compass::LEARN_INFLIGHT, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::LANDING_GEAR: {
|
2019-02-10 01:01:36 -04:00
|
|
|
AP_LandingGear *lg = AP_LandingGear::get_singleton();
|
2018-11-08 20:02:54 -04:00
|
|
|
if (lg == nullptr) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (ch_flag) {
|
|
|
|
case LOW:
|
|
|
|
lg->set_position(AP_LandingGear::LandingGear_Deploy);
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case HIGH:
|
|
|
|
lg->set_position(AP_LandingGear::LandingGear_Retract);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::GPS_DISABLE:
|
2018-09-04 23:37:33 -03:00
|
|
|
AP::gps().force_disable(ch_flag == HIGH);
|
|
|
|
break;
|
2019-01-20 21:36:26 -04:00
|
|
|
|
2019-04-03 10:23:06 -03:00
|
|
|
case AUX_FUNC::MOTOR_ESTOP:
|
2019-01-20 21:36:26 -04:00
|
|
|
switch (ch_flag) {
|
|
|
|
case HIGH: {
|
|
|
|
SRV_Channels::set_emergency_stop(true);
|
|
|
|
|
|
|
|
// log E-stop
|
2019-03-27 20:15:19 -03:00
|
|
|
AP_Logger *logger = AP_Logger::get_singleton();
|
|
|
|
if (logger && logger->logging_enabled()) {
|
|
|
|
logger->Write_Event(DATA_MOTORS_EMERGENCY_STOPPED);
|
2019-01-20 21:36:26 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case LOW: {
|
|
|
|
SRV_Channels::set_emergency_stop(false);
|
|
|
|
|
|
|
|
// log E-stop cleared
|
2019-03-27 20:15:19 -03:00
|
|
|
AP_Logger *logger = AP_Logger::get_singleton();
|
|
|
|
if (logger && logger->logging_enabled()) {
|
|
|
|
logger->Write_Event(DATA_MOTORS_EMERGENCY_STOP_CLEARED);
|
2019-01-20 21:36:26 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-04-18 01:24:02 -03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-07-07 05:06:02 -03:00
|
|
|
#if !HAL_MINIMIZE_FEATURES
|
2019-04-18 01:24:02 -03:00
|
|
|
case AUX_FUNC::KILL_IMU1:
|
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
AP::ins().kill_imu(0, true);
|
|
|
|
} else {
|
|
|
|
AP::ins().kill_imu(0, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::KILL_IMU2:
|
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
AP::ins().kill_imu(1, true);
|
|
|
|
} else {
|
|
|
|
AP::ins().kill_imu(1, false);
|
|
|
|
}
|
|
|
|
break;
|
2019-07-07 05:06:02 -03:00
|
|
|
#endif // HAL_MINIMIZE_FEATURES
|
2019-01-20 21:36:26 -04:00
|
|
|
|
2018-04-13 23:22:14 -03:00
|
|
|
default:
|
2019-07-26 23:09:46 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Invalid channel option (%u)", (unsigned int)ch_option);
|
2018-04-13 23:22:14 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RC_Channel::init_aux()
|
|
|
|
{
|
2019-01-07 22:19:34 -04:00
|
|
|
aux_switch_pos_t position;
|
|
|
|
if (!read_3pos_switch(position)) {
|
|
|
|
position = aux_switch_pos_t::LOW;
|
|
|
|
}
|
2018-04-13 23:22:14 -03:00
|
|
|
init_aux_function((aux_func_t)option.get(), position);
|
|
|
|
}
|
|
|
|
|
|
|
|
// read_3pos_switch
|
2019-01-07 22:19:34 -04:00
|
|
|
bool RC_Channel::read_3pos_switch(RC_Channel::aux_switch_pos_t &ret) const
|
2018-04-13 23:22:14 -03:00
|
|
|
{
|
|
|
|
const uint16_t in = get_radio_in();
|
2019-01-07 22:19:34 -04:00
|
|
|
if (in <= 900 or in >= 2200) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (in < AUX_PWM_TRIGGER_LOW) {
|
|
|
|
ret = LOW;
|
|
|
|
} else if (in > AUX_PWM_TRIGGER_HIGH) {
|
|
|
|
ret = HIGH;
|
|
|
|
} else {
|
|
|
|
ret = MIDDLE;
|
|
|
|
}
|
|
|
|
return true;
|
2018-04-13 23:22:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
RC_Channel *RC_Channels::find_channel_for_option(const RC_Channel::aux_func_t option)
|
|
|
|
{
|
|
|
|
for (uint8_t i=0; i<NUM_RC_CHANNELS; i++) {
|
|
|
|
RC_Channel *c = channel(i);
|
|
|
|
if (c == nullptr) {
|
|
|
|
// odd?
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((RC_Channel::aux_func_t)c->option.get() == option) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// duplicate_options_exist - returns true if any options are duplicated
|
|
|
|
bool RC_Channels::duplicate_options_exist()
|
|
|
|
{
|
|
|
|
uint8_t auxsw_option_counts[256] = {};
|
|
|
|
for (uint8_t i=0; i<NUM_RC_CHANNELS; i++) {
|
|
|
|
const RC_Channel *c = channel(i);
|
|
|
|
if (c == nullptr) {
|
|
|
|
// odd?
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const uint16_t option = c->option.get();
|
2018-08-06 22:59:46 -03:00
|
|
|
if (option >= sizeof(auxsw_option_counts)) {
|
2018-04-13 23:22:14 -03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auxsw_option_counts[option]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint16_t i=0; i<sizeof(auxsw_option_counts); i++) {
|
|
|
|
if (i == 0) { // MAGIC VALUE! This is AUXSW_DO_NOTHING
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (auxsw_option_counts[i] > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|