Added battery cell count based automatic PID profile switching.
[betaflight.git] / src / main / target / ALIENFLIGHTF3 / config.c
blobe2d6fe45429db9a27fb7dbfd1a58a3d28b4355ad
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
26 #ifdef USE_TARGET_CONFIG
28 #include "common/axis.h"
30 #include "config/feature.h"
32 #include "drivers/light_led.h"
33 #include "drivers/pwm_esc_detect.h"
34 #include "drivers/sound_beeper.h"
36 #include "flight/mixer.h"
37 #include "flight/pid.h"
39 #include "pg/beeper_dev.h"
40 #include "pg/gyrodev.h"
41 #include "pg/rx.h"
43 #include "rx/rx.h"
45 #include "io/serial.h"
47 #include "sensors/battery.h"
48 #include "sensors/gyro.h"
50 #include "telemetry/telemetry.h"
52 #include "hardware_revision.h"
54 #ifdef BRUSHED_MOTORS_PWM_RATE
55 #undef BRUSHED_MOTORS_PWM_RATE
56 #endif
58 #define BRUSHED_MOTORS_PWM_RATE 32000 // 32kHz
59 #define VBAT_SCALE 20
61 // alternative defaults settings for AlienFlight targets
62 void targetConfiguration(void)
64 gyroDeviceConfigMutable(0)->extiTag = selectMPUIntExtiConfigByHardwareRevision();
66 /* depending on revision ... depends on the LEDs to be utilised. */
67 if (hardwareRevision == AFF3_REV_2) {
68 statusLedConfigMutable()->inversion = 0
69 #ifdef LED0_A_INVERTED
70 | BIT(0)
71 #endif
72 #ifdef LED1_A_INVERTED
73 | BIT(1)
74 #endif
75 #ifdef LED2_A_INVERTED
76 | BIT(2)
77 #endif
80 for (int i = 0; i < STATUS_LED_NUMBER; i++) {
81 statusLedConfigMutable()->ioTags[i] = IO_TAG_NONE;
83 #ifdef LED0_A
84 statusLedConfigMutable()->ioTags[0] = IO_TAG(LED0_A);
85 #endif
86 #ifdef LED1_A
87 statusLedConfigMutable()->ioTags[1] = IO_TAG(LED1_A);
88 #endif
89 #ifdef LED2_A
90 statusLedConfigMutable()->ioTags[2] = IO_TAG(LED2_A);
91 #endif
92 } else {
93 gyroConfigMutable()->gyro_sync_denom = 2;
94 pidConfigMutable()->pid_process_denom = 2;
97 if (!haveFrSkyRX) {
98 rxConfigMutable()->serialrx_provider = SERIALRX_SPEKTRUM2048;
99 rxConfigMutable()->spektrum_sat_bind = 5;
100 rxConfigMutable()->spektrum_sat_bind_autoreset = 1;
101 parseRcChannels("TAER1234", rxConfigMutable());
102 } else {
103 rxConfigMutable()->serialrx_provider = SERIALRX_SBUS;
104 rxConfigMutable()->serialrx_inverted = true;
105 serialConfigMutable()->portConfigs[findSerialPortIndexByIdentifier(SERIALRX_UART)].functionMask = FUNCTION_TELEMETRY_FRSKY_HUB | FUNCTION_RX_SERIAL;
106 telemetryConfigMutable()->telemetry_inverted = false;
107 featureEnable(FEATURE_TELEMETRY);
108 beeperDevConfigMutable()->isOpenDrain = false;
109 beeperDevConfigMutable()->isInverted = true;
110 parseRcChannels("AETR1234", rxConfigMutable());
113 if (hardwareMotorType == MOTOR_BRUSHED) {
114 motorConfigMutable()->dev.motorPwmRate = BRUSHED_MOTORS_PWM_RATE;
115 pidConfigMutable()->pid_process_denom = 1;
118 for (uint8_t pidProfileIndex = 0; pidProfileIndex < PID_PROFILE_COUNT; pidProfileIndex++) {
119 pidProfile_t *pidProfile = pidProfilesMutable(pidProfileIndex);
121 pidProfile->pid[PID_ROLL].P = 90;
122 pidProfile->pid[PID_ROLL].I = 44;
123 pidProfile->pid[PID_ROLL].D = 60;
124 pidProfile->pid[PID_PITCH].P = 90;
125 pidProfile->pid[PID_PITCH].I = 44;
126 pidProfile->pid[PID_PITCH].D = 60;
129 *customMotorMixerMutable(0) = (motorMixer_t){ 1.0f, -0.414178f, 1.0f, -1.0f }; // REAR_R
130 *customMotorMixerMutable(1) = (motorMixer_t){ 1.0f, -0.414178f, -1.0f, 1.0f }; // FRONT_R
131 *customMotorMixerMutable(2) = (motorMixer_t){ 1.0f, 0.414178f, 1.0f, 1.0f }; // REAR_L
132 *customMotorMixerMutable(3) = (motorMixer_t){ 1.0f, 0.414178f, -1.0f, -1.0f }; // FRONT_L
133 *customMotorMixerMutable(4) = (motorMixer_t){ 1.0f, -1.0f, -0.414178f, -1.0f }; // MIDFRONT_R
134 *customMotorMixerMutable(5) = (motorMixer_t){ 1.0f, 1.0f, -0.414178f, 1.0f }; // MIDFRONT_L
135 *customMotorMixerMutable(6) = (motorMixer_t){ 1.0f, -1.0f, 0.414178f, 1.0f }; // MIDREAR_R
136 *customMotorMixerMutable(7) = (motorMixer_t){ 1.0f, 1.0f, 0.414178f, -1.0f }; // MIDREAR_L
138 #endif