/
controlrate_profile.c
90 lines (75 loc) · 2.59 KB
/
controlrate_profile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "common/axis.h"
#include "config/config_reset.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "fc/config.h"
#include "fc/controlrate_profile.h"
#include "fc/rc_curves.h"
const controlRateConfig_t *currentControlRateProfile;
PG_REGISTER_ARRAY_WITH_RESET_FN(controlRateConfig_t, MAX_CONTROL_RATE_PROFILE_COUNT, controlRateProfiles, PG_CONTROL_RATE_PROFILES, 3);
void pgResetFn_controlRateProfiles(controlRateConfig_t *instance)
{
for (int i = 0; i < MAX_CONTROL_RATE_PROFILE_COUNT; i++) {
RESET_CONFIG(controlRateConfig_t, &instance[i],
.throttle = {
.rcMid8 = 50,
.rcExpo8 = 0,
.dynPID = 0,
.pa_breakpoint = 1500,
.fixedWingTauMs = 0
},
.stabilized = {
.rcExpo8 = 70,
.rcYawExpo8 = 20,
.rates[FD_ROLL] = CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_DEFAULT,
.rates[FD_PITCH] = CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_DEFAULT,
.rates[FD_YAW] = CONTROL_RATE_CONFIG_YAW_RATE_DEFAULT,
},
.manual = {
.rcExpo8 = 70,
.rcYawExpo8 = 20,
.rates[FD_ROLL] = 100,
.rates[FD_PITCH] = 100,
.rates[FD_YAW] = 100
},
.misc = {
.fpvCamAngleDegrees = 0
}
);
}
}
void setControlRateProfile(uint8_t profileIndex)
{
if (profileIndex >= MAX_CONTROL_RATE_PROFILE_COUNT) {
profileIndex = 0;
}
currentControlRateProfile = controlRateProfiles(profileIndex);
}
void activateControlRateConfig(void)
{
generateThrottleCurve(currentControlRateProfile);
}
void changeControlRateProfile(uint8_t profileIndex)
{
setControlRateProfile(profileIndex);
activateControlRateConfig();
}