/* * This file is part of Cleanflight. * * Cleanflight 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. * * Cleanflight 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 Cleanflight. If not, see . */ #pragma once #include #include "config/parameter_group.h" typedef enum { BOXARM = 0, BOXANGLE, BOXHORIZON, BOXBARO, // BOXVARIO, BOXMAG, BOXHEADFREE, BOXHEADADJ, BOXCAMSTAB, BOXCAMTRIG, BOXGPSHOME, BOXGPSHOLD, BOXPASSTHRU, BOXBEEPERON, BOXLEDMAX, BOXLEDLOW, BOXLLIGHTS, BOXCALIB, BOXGOV, BOXOSD, BOXTELEMETRY, BOXGTUNE, BOXSONAR, BOXSERVO1, BOXSERVO2, BOXSERVO3, BOXBLACKBOX, BOXFAILSAFE, BOXAIRMODE, BOX3DDISABLESWITCH, BOXFPVANGLEMIX, BOXBLACKBOXERASE, CHECKBOX_ITEM_COUNT } boxId_e; extern uint32_t rcModeActivationMask; #define IS_RC_MODE_ACTIVE(modeId) ((1 << (modeId)) & rcModeActivationMask) #define ACTIVATE_RC_MODE(modeId) (rcModeActivationMask |= (1 << modeId)) typedef enum rc_alias { ROLL = 0, PITCH, YAW, THROTTLE, AUX1, AUX2, AUX3, AUX4, AUX5, AUX6, AUX7, AUX8 } rc_alias_e; typedef enum { THROTTLE_LOW = 0, THROTTLE_HIGH } throttleStatus_e; #define AIRMODEDEADBAND 12 typedef enum { NOT_CENTERED = 0, CENTERED } rollPitchStatus_e; typedef enum { RC_SMOOTHING_OFF = 0, RC_SMOOTHING_DEFAULT, RC_SMOOTHING_AUTO, RC_SMOOTHING_MANUAL } rcSmoothing_t; #define ROL_LO (1 << (2 * ROLL)) #define ROL_CE (3 << (2 * ROLL)) #define ROL_HI (2 << (2 * ROLL)) #define PIT_LO (1 << (2 * PITCH)) #define PIT_CE (3 << (2 * PITCH)) #define PIT_HI (2 << (2 * PITCH)) #define YAW_LO (1 << (2 * YAW)) #define YAW_CE (3 << (2 * YAW)) #define YAW_HI (2 << (2 * YAW)) #define THR_LO (1 << (2 * THROTTLE)) #define THR_CE (3 << (2 * THROTTLE)) #define THR_HI (2 << (2 * THROTTLE)) #define MAX_MODE_ACTIVATION_CONDITION_COUNT 20 #define CHANNEL_RANGE_MIN 900 #define CHANNEL_RANGE_MAX 2100 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step) #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25) #define MIN_MODE_RANGE_STEP 0 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25) // Roll/pitch rates are a proportion used for mixing, so it tops out at 1.0: #define CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX 100 /* Meaningful yaw rates are effectively unbounded because they are treated as a rotation rate multiplier: */ #define CONTROL_RATE_CONFIG_YAW_RATE_MAX 255 #define CONTROL_RATE_CONFIG_TPA_MAX 100 // steps are 25 apart // a value of 0 corresponds to a channel value of 900 or less // a value of 48 corresponds to a channel value of 2100 or more // 48 steps between 900 and 1200 typedef struct channelRange_s { uint8_t startStep; uint8_t endStep; } channelRange_t; typedef struct modeActivationCondition_s { boxId_e modeId; uint8_t auxChannelIndex; channelRange_t range; } modeActivationCondition_t; PG_DECLARE_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions); typedef struct modeActivationProfile_s { modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT]; } modeActivationProfile_t; #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep) extern int16_t rcCommand[4]; typedef struct rcControlsConfig_s { uint8_t deadband; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero. uint8_t yaw_deadband; // introduce a deadband around the stick center for yaw axis. Must be greater than zero. uint8_t alt_hold_deadband; // defines the neutral zone of throttle stick during altitude hold, default setting is +/-40 uint8_t alt_hold_fast_change; // when disabled, turn off the althold when throttle stick is out of deadband defined with alt_hold_deadband; when enabled, altitude changes slowly proportional to stick movement int8_t yaw_control_direction; // change control direction of yaw (inverted, normal) } rcControlsConfig_t; PG_DECLARE(rcControlsConfig_t, rcControlsConfig); typedef struct flight3DConfig_s { uint16_t deadband3d_low; // min 3d value uint16_t deadband3d_high; // max 3d value uint16_t neutral3d; // center 3d value uint16_t deadband3d_throttle; // default throttle deadband from MIDRC } flight3DConfig_t; PG_DECLARE(flight3DConfig_t, flight3DConfig); typedef struct armingConfig_s { uint8_t gyro_cal_on_first_arm; // allow disarm/arm on throttle down + roll left/right uint8_t disarm_kill_switch; // allow disarm via AUX switch regardless of throttle value uint8_t auto_disarm_delay; // allow automatically disarming multicopters after auto_disarm_delay seconds of zero throttle. Disabled when 0 } armingConfig_t; PG_DECLARE(armingConfig_t, armingConfig); bool areUsingSticksToArm(void); bool areSticksInApModePosition(uint16_t ap_mode); throttleStatus_e calculateThrottleStatus(void); void processRcStickPositions(throttleStatus_e throttleStatus); bool isRangeActive(uint8_t auxChannelIndex, const channelRange_t *range); void updateActivatedModes(void); bool isAirmodeActive(void); bool isUsingSticksForArming(void); int32_t getRcStickDeflection(int32_t axis, uint16_t midrc); bool isModeActivationConditionPresent(const modeActivationCondition_t *modeActivationConditions, boxId_e modeId); struct pidProfile_s; void useRcControlsConfig(const modeActivationCondition_t *modeActivationConditions, struct pidProfile_s *pidProfileToUse);