Skip to content

Commit 9c564a4

Browse files
authored
Merge pull request #258 from betaflight/new_rc_rates
Added new rc rate calculation to rates curve. Removed SUPER_EXPO feature for >= 3.0
2 parents 20b1154 + b94f25f commit 9c564a4

File tree

6 files changed

+147
-155
lines changed

6 files changed

+147
-155
lines changed

_locales/en/messages.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,9 @@
850850
"pidTuningRcRate": {
851851
"message": "RC Rate"
852852
},
853+
"pidTuningMaxVel": {
854+
"message": "Max Vel (deg/s)"
855+
},
853856
"pidTuningRate": {
854857
"message": "Rate"
855858
},
@@ -872,19 +875,10 @@
872875
"message": "Frequency"
873876
},
874877
"pidTuningRatesCurve": {
875-
"message": "Rates"
876-
},
877-
"pidTuningMaxAngularVelRoll": {
878-
"message": "Max roll speed (deg/s):"
879-
},
880-
"pidTuningMaxAngularVelPitch": {
881-
"message": "Max pitch speed (deg/s):"
882-
},
883-
"pidTuningMaxAngularVelYaw": {
884-
"message": "Max yaw speed (deg/s):"
878+
"message": "Rates"
885879
},
886880
"throttle": {
887-
"message": "Throttle"
881+
"message": "Throttle"
888882
},
889883
"pidTuningButtonSave": {
890884
"message": "Save"
@@ -1607,6 +1601,12 @@
16071601
"pidTuningYawJumpPreventionHelp": {
16081602
"message": "Keeps the craft from jumping up at the end of yaws. Higher number gives more damping at the end of yaw moves (works like old yaw D, which was not a real D like on other axis)"
16091603
},
1604+
"pidTuningRcExpoPower": {
1605+
"message": "RC Expo Power"
1606+
},
1607+
"pidTuningRcExpoPowerHelp": {
1608+
"message": "The exponent that is used when calculating RC Expo. In Betaflight versions prior to 3.0, value is fixed at 3."
1609+
},
16101610
"pidTuningLevel": {
16111611
"message": "Angle/Horizon"
16121612
},

js/Features.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@ var Features = function (config) {
4646
);
4747
}
4848

49-
if (config.flightControllerVersion !== '' && semver.gte(config.flightControllerVersion, "3.0.0")) {
50-
features.push(
51-
{bit: 18, group: 'other', name: 'OSD', haveTip: true}
52-
);
53-
}
49+
if (config.flightControllerVersion !== '') {
50+
if (semver.gte(config.flightControllerVersion, "2.8.0")) {
51+
features.push(
52+
{bit: 22, group: 'other', name: 'AIRMODE'}
53+
);
54+
}
55+
56+
if (semver.gte(config.flightControllerVersion, "2.8.0") && !semver.gte(config.flightControllerVersion, "3.0.0")) {
57+
features.push(
58+
{bit: 23, group: 'pidTuning', name: 'SUPEREXPO_RATES'}
59+
);
60+
}
61+
62+
if (semver.gte(config.flightControllerVersion, "3.0.0")) {
63+
features.push(
64+
{bit: 18, group: 'other', name: 'OSD', haveTip: true}
65+
);
66+
}
67+
5468

55-
if (config.flightControllerVersion !== '' && semver.gte(config.flightControllerVersion, "2.8.0")) {
56-
features.push(
57-
{bit: 22, group: 'other', name: 'AIRMODE'},
58-
{bit: 23, group: 'pidTuning', name: 'SUPEREXPO_RATES'}
59-
);
6069
}
6170

6271
self._features = features;

js/RateCurve.js

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ var RateCurve = function (useLegacyCurve) {
99

1010
this.constrain = function (value, min, max) {
1111
return Math.max(min, Math.min(value, max));
12-
}
12+
};
13+
14+
this.rcCommand = function (rcData, rcRate) {
15+
var tmp = Math.min(Math.abs(rcData - midRc), 500);
16+
rcRate = rcRate;
17+
18+
if (rcRate > 2) {
19+
rcRate = rcRate + (rcRate - 2) * 14.54;
20+
}
1321

14-
this.rcCommand = function (rcData, rcRate, rcExpo) {
15-
var tmp = Math.min(Math.abs(rcData - midRc), 500) / 100;
22+
var result = tmp * rcRate;
1623

17-
var result = ((2500 + rcExpo * (tmp * tmp - 25)) * tmp * rcRate / 2500).toFixed(0);
18-
if (rcData < midRc) {
24+
if (rcData < midRc) {
1925
result = -result;
2026
}
2127

2228
return result;
23-
}
29+
};
2430

2531
this.drawRateCurve = function (rate, rcRate, rcExpo, superExpoActive, maxAngularVel, context, width, height) {
2632
var canvasHeightScale = height / (2 * maxAngularVel);
@@ -42,7 +48,7 @@ var RateCurve = function (useLegacyCurve) {
4248
context.stroke();
4349

4450
context.restore();
45-
}
51+
};
4652

4753
this.drawLegacyRateCurve = function (rate, rcRate, rcExpo, context, width, height) {
4854
// math magic by englishman
@@ -55,28 +61,41 @@ var RateCurve = function (useLegacyCurve) {
5561
context.quadraticCurveTo(width * 11 / 20, height - ((rateY / 2) * (1 - rcExpo)), width, height - rateY);
5662
context.stroke();
5763
}
58-
}
64+
};
5965

6066
RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcRate, rcExpo, superExpoActive) {
6167
var angleRate;
6268
if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined) {
63-
rate = rate * 100;
64-
rcRate = rcRate * 100;
65-
rcExpo = rcExpo * 100;
6669

67-
var inputValue = this.rcCommand(rcData, rcRate, rcExpo);
70+
var inputValue = this.rcCommand(rcData, rcRate);
71+
var maxRc = 500 * rcRate;
72+
73+
var expoPower;
74+
var rcRateConstant;
75+
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
76+
expoPower = 3;
77+
rcRateConstant = 200;
78+
} else {
79+
expoPower = 2;
80+
rcRateConstant = 205.85;
81+
}
6882

69-
if (superExpoActive) {
70-
var rcFactor = Math.abs(inputValue) / (500 * rcRate / 100);
71-
rcFactor = 1 / this.constrain(1 - rcFactor * rate / 100, 0.01, 1);
83+
if (rcExpo > 0) {
84+
var absRc = Math.abs(inputValue) / maxRc;
85+
inputValue = inputValue * Math.pow(absRc, expoPower) * rcExpo + inputValue * (1-rcExpo);
86+
}
87+
88+
var rcInput = inputValue / maxRc;
7289

73-
angleRate = rcFactor * 27 * inputValue / 16;
90+
if (superExpoActive) {
91+
var rcFactor = 1 / this.constrain(1 - Math.abs(rcInput) * rate, 0.01, 1);
92+
angleRate = rcRateConstant * rcRate * rcInput; // 200 should be variable checked on version (older versions it's 205,9)
93+
angleRate = angleRate * rcFactor;
7494
} else {
75-
angleRate = (rate + 27) * inputValue / 16;
95+
angleRate = (((rate * 100) + 27) * inputValue / 16) / 4.1; // Only applies to old versions ?
7696
}
7797

78-
angleRate = this.constrain(angleRate, -8190, 8190); // Rate limit protection
79-
angleRate = angleRate >> 2; // the shift by 2 is to counterbalance the divide by 4 that occurs on the gyro to calculate the error
98+
angleRate = this.constrain(angleRate, -1998, 1998); // Rate limit protection
8099
}
81100

82101
return angleRate;
@@ -89,7 +108,7 @@ RateCurve.prototype.getMaxAngularVel = function (rate, rcRate, rcExpo, superExpo
89108
}
90109

91110
return maxAngularVel;
92-
}
111+
};
93112

94113
RateCurve.prototype.draw = function (rate, rcRate, rcExpo, superExpoActive, maxAngularVel, context) {
95114
if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined) {
@@ -102,4 +121,4 @@ RateCurve.prototype.draw = function (rate, rcRate, rcExpo, superExpoActive, maxA
102121
this.drawRateCurve(rate, rcRate, rcExpo, superExpoActive, maxAngularVel, context, width, height);
103122
}
104123
}
105-
}
124+
};

tabs/pid_tuning.css

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@
242242
padding: 5px;
243243
text-align: left;
244244
border-right: 1px solid #ccc;
245-
width: 14%;
245+
width: 12.5%;
246246

247247
}
248248

249249
.tab-pid_tuning .pid_titlebar th:first-child {
250250
text-align: left;
251-
width: 14%;
251+
width: 12.5%;
252252
}
253253

254254
.tab-pid_tuning .pid_titlebar th:last-child {
@@ -288,7 +288,7 @@
288288

289289
.tab-pid_tuning table td {
290290
padding: 1px;
291-
width: 14%;
291+
width: 12.5%;
292292
border-right: 1px solid #ccc;
293293
}
294294

@@ -370,32 +370,8 @@
370370
border-top-right-radius: 3px;
371371
}
372372

373-
.tab-pid_tuning .name {
374-
width: 14%;
375-
}
376-
377-
.tab-pid_tuning .proportional {
378-
width: 14%;
379-
}
380-
381-
.tab-pid_tuning .integral {
382-
width: 14%;
383-
}
384-
385-
.tab-pid_tuning .derivative {
386-
width: 14%;
387-
}
388-
389-
.tab-pid_tuning .rc_rate {
390-
width: 14%;
391-
}
392-
393-
.tab-pid_tuning .rate {
394-
width: 14%;
395-
}
396-
397-
.tab-pid_tuning .rc_expo {
398-
width: 14%;
373+
.tab-pid_tuning .new_rates {
374+
text-align: left;
399375
}
400376

401377
.tab-pid_tuning .tpa {
@@ -711,7 +687,6 @@ width: 40%;
711687

712688
.tab-pid_tuning .rc_curve_bg {
713689
float: left;
714-
padding-bottom: 20px;
715690
background: #ddd;
716691
border-bottom-left-radius: 5px;
717692
border-bottom-right-radius: 5px;
@@ -757,4 +732,4 @@ width: 40%;
757732
border-bottom-left-radius: 8px;
758733
border-top: 0px solid silver;
759734
background: #f9f9f9;
760-
}
735+
}

tabs/pid_tuning.html

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<th class="derivative" i18n="pidTuningDerivative"></th>
7373
<th class="rc_rate" i18n="pidTuningRcRate"></th>
7474
<th class="rate" i18n="pidTuningRate"></th>
75+
<th class="maxVel" i18n="pidTuningMaxVel"></th>
7576
<th class="rc_expo" i18n="pidTuningRcExpo"></th>
7677
</tr>
7778
</table>
@@ -91,11 +92,12 @@
9192
<td class="pid_data"><input type="number" name="i" step="1" min="0" max="255" /></td>
9293
<td class="pid_data"><input type="number" name="d" step="1" min="0" max="255" /></td>
9394
<td rowspan="2" style="background-color:white;">
94-
<input type="number" name="rc_rate" step="0.01" min="0" max="2.5" />
95+
<input type="number" name="rc_rate" step="0.01" min="0" max="2.55" />
9596
<div class="bracket"></div>
9697
</td>
9798
<td class="roll_rate"><input type="number" name="roll_rate" step="0.01" min="0" max="1.00" /></td>
9899
<td class="roll_pitch_rate" rowspan="2"><input type="number" name="roll_pitch_rate" step="0.01" min="0" max="1.00" /></td>
100+
<td class="new_rates maxAngularVelRoll"></td>
99101
<td rowspan="2" style="background-color:white;">
100102
<input type="number" name="rc_expo" step="0.01" min="0" max="1" />
101103
<div class="bracket"></div>
@@ -108,15 +110,17 @@
108110
<td class="pid_data"><input type="number" name="i" step="1" min="0" max="255" /></td>
109111
<td class="pid_data"><input type="number" name="d" step="1" min="0" max="255" /></td>
110112
<td class="pitch_rate"><input type="number" name="pitch_rate" step="0.01" min="0" max="1.00" /></td>
113+
<td class="new_rates maxAngularVelPitch"></td>
111114
</tr>
112115
<tr class="YAW">
113116
<!-- 2 -->
114117
<td bgcolor="#8080FF"></td>
115118
<td class="pid_data"><input type="number" name="p" step="1" min="0" max="255" /></td>
116119
<td class="pid_data"><input type="number" name="i" step="1" min="0" max="255" /></td>
117120
<td></td>
118-
<td rowspan="1"><input type="number" name="rc_rate_yaw" step="0.01" min="0" max="2.5" /></td>
121+
<td rowspan="1"><input type="number" name="rc_rate_yaw" step="0.01" min="0" max="2.55" /></td>
119122
<td><input type="number" name="yaw_rate" step="0.01" min="0" max="2.55" /></td>
123+
<td class="new_rates maxAngularVelYaw"></td>
120124
<td><input type="number" name="rc_yaw_expo" step="0.01" min="0" max="1" /></td>
121125
</tr>
122126
<tr class="YAW_JUMP_PREVENTION">
@@ -127,7 +131,7 @@
127131
</div>
128132
</td>
129133
<td class="pid_data"><input type="number" name="d" step="1" min="0" max="255" /></td>
130-
<td colspan=3></td>
134+
<td colspan=4></td>
131135
</tr>
132136
</table>
133137
</div>
@@ -208,7 +212,7 @@
208212
<div id="pid_accel" class="gui_box grey topspacer pid_tuning">
209213
<table class="pid_titlebar">
210214
<tr>
211-
<th class="third" i18n="pidTuningName" style="width: 17%;"></th>
215+
<th class="third" i18n="pidTuningName" style="width: 24%;"></th>
212216
<th class="third" i18n="pidTuningStrength" style="width: 33%;"></th>
213217
<th class="third" i18n="pidTuningTransition" style="width: 33%;"></th>
214218
</tr>
@@ -371,26 +375,14 @@
371375
</thead>
372376
<tbody>
373377
<tr>
374-
<td colspan=2>
375-
<div class="spacer" style="margin-top: 10px; margin-bottom: 10px;">
378+
<td>
379+
<div class="spacer" style="margin-top: 10px;">
376380
<div class="rate_curve">
377381
<canvas height="120px" style="width: 100%; height: 100%"></canvas>
378382
</div>
379383
</div>
380384
</td>
381385
</tr>
382-
<tr class="new_rates">
383-
<td i18n="pidTuningMaxAngularVelRoll" style="width: 70%"></td>
384-
<td class="maxAngularVelRoll"></td>
385-
</tr>
386-
<tr class="new_rates">
387-
<td i18n="pidTuningMaxAngularVelPitch"></td>
388-
<td class="maxAngularVelPitch"></td>
389-
</tr>
390-
<tr class="new_rates">
391-
<td i18n="pidTuningMaxAngularVelYaw"></td>
392-
<td class="maxAngularVelYaw"></td>
393-
</tr>
394386
</tbody>
395387
</table>
396388
</div>

0 commit comments

Comments
 (0)