Skip to content

Commit 3cb7200

Browse files
authored
Merge pull request #2842 from haslinghuis/fix_model_preview
Fix model preview
2 parents d9089dc + 9403782 commit 3cb7200

File tree

4 files changed

+141
-163
lines changed

4 files changed

+141
-163
lines changed

src/js/RateCurve.js

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const minRc = 1000;
44
const midRc = 1500;
55
const maxRc = 2000;
6-
76
const RateCurve = function (useLegacyCurve) {
87
this.useLegacyCurve = useLegacyCurve;
98
this.maxAngularVel = null;
@@ -150,6 +149,81 @@ const RateCurve = function (useLegacyCurve) {
150149
return angularVel;
151150
};
152151

152+
this.getCurrentRates = function () {
153+
154+
const currentRates = {
155+
roll_rate: FC.RC_TUNING.roll_rate,
156+
pitch_rate: FC.RC_TUNING.pitch_rate,
157+
yaw_rate: FC.RC_TUNING.yaw_rate,
158+
rc_rate: FC.RC_TUNING.RC_RATE,
159+
rc_rate_yaw: FC.RC_TUNING.rcYawRate,
160+
rc_expo: FC.RC_TUNING.RC_EXPO,
161+
rc_yaw_expo: FC.RC_TUNING.RC_YAW_EXPO,
162+
rc_rate_pitch: FC.RC_TUNING.rcPitchRate,
163+
rc_pitch_expo: FC.RC_TUNING.RC_PITCH_EXPO,
164+
superexpo: FC.FEATURE_CONFIG.features.isEnabled('SUPEREXPO_RATES'),
165+
deadband: FC.RC_DEADBAND_CONFIG.deadband,
166+
yawDeadband: FC.RC_DEADBAND_CONFIG.yaw_deadband,
167+
roll_rate_limit: FC.RC_TUNING.roll_rate_limit,
168+
pitch_rate_limit: FC.RC_TUNING.pitch_rate_limit,
169+
yaw_rate_limit: FC.RC_TUNING.yaw_rate_limit,
170+
};
171+
172+
if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) {
173+
currentRates.roll_rate = FC.RC_TUNING.roll_pitch_rate;
174+
currentRates.pitch_rate = FC.RC_TUNING.roll_pitch_rate;
175+
}
176+
177+
if (semver.lt(FC.CONFIG.apiVersion, "1.16.0")) {
178+
currentRates.rc_rate_yaw = currentRates.rc_rate;
179+
}
180+
181+
if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) {
182+
currentRates.superexpo = true;
183+
}
184+
185+
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_37)) {
186+
currentRates.rc_rate_pitch = currentRates.rc_rate;
187+
currentRates.rc_expo_pitch = currentRates.rc_expo;
188+
}
189+
190+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) {
191+
switch (FC.RC_TUNING.rates_type) {
192+
case FC.RATES_TYPE.RACEFLIGHT:
193+
currentRates.roll_rate *= 100;
194+
currentRates.pitch_rate *= 100;
195+
currentRates.yaw_rate *= 100;
196+
currentRates.rc_rate *= 1000;
197+
currentRates.rc_rate_yaw *= 1000;
198+
currentRates.rc_rate_pitch *= 1000;
199+
currentRates.rc_expo *= 100;
200+
currentRates.rc_yaw_expo *= 100;
201+
currentRates.rc_pitch_expo *= 100;
202+
203+
break;
204+
case FC.RATES_TYPE.ACTUAL:
205+
currentRates.roll_rate *= 1000;
206+
currentRates.pitch_rate *= 1000;
207+
currentRates.yaw_rate *= 1000;
208+
currentRates.rc_rate *= 1000;
209+
currentRates.rc_rate_yaw *= 1000;
210+
currentRates.rc_rate_pitch *= 1000;
211+
212+
break;
213+
case FC.RATES_TYPE.QUICKRATES:
214+
currentRates.roll_rate *= 1000;
215+
currentRates.pitch_rate *= 1000;
216+
currentRates.yaw_rate *= 1000;
217+
218+
break;
219+
default: // add future rates types here
220+
221+
break;
222+
}
223+
}
224+
225+
return currentRates;
226+
};
153227
};
154228

155229
RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcRate, rcExpo, superExpoActive, deadband, limit) {
@@ -165,23 +239,23 @@ RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcR
165239

166240
const rcCommandfAbs = Math.abs(rcCommandf);
167241

168-
switch(TABS.pid_tuning.currentRatesType) {
169-
case TABS.pid_tuning.RATES_TYPE.RACEFLIGHT:
242+
switch (FC.RC_TUNING.rates_type) {
243+
case FC.RATES_TYPE.RACEFLIGHT:
170244
angleRate=this.getRaceflightRates(rcCommandf, rate, rcRate, rcExpo);
171245

172246
break;
173247

174-
case TABS.pid_tuning.RATES_TYPE.KISS:
248+
case FC.RATES_TYPE.KISS:
175249
angleRate=this.getKISSRates(rcCommandf, rcCommandfAbs, rate, rcRate, rcExpo);
176250

177251
break;
178252

179-
case TABS.pid_tuning.RATES_TYPE.ACTUAL:
253+
case FC.RATES_TYPE.ACTUAL:
180254
angleRate=this.getActualRates(rcCommandf, rcCommandfAbs, rate, rcRate, rcExpo);
181255

182256
break;
183257

184-
case TABS.pid_tuning.RATES_TYPE.QUICKRATES:
258+
case FC.RATES_TYPE.QUICKRATES:
185259
angleRate=this.getQuickRates(rcCommandf, rcCommandfAbs, rate, rcRate, rcExpo);
186260

187261
break;
@@ -208,8 +282,8 @@ RateCurve.prototype.getMaxAngularVel = function (rate, rcRate, rcExpo, superExpo
208282

209283
RateCurve.prototype.setMaxAngularVel = function (value) {
210284
this.maxAngularVel = Math.ceil(value/200) * 200;
211-
return this.maxAngularVel;
212285

286+
return this.maxAngularVel;
213287
};
214288

215289
RateCurve.prototype.draw = function (rate, rcRate, rcExpo, superExpoActive, deadband, limit, maxAngularVel, context) {

src/js/fc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,4 +893,12 @@ const FC = {
893893
getSliderDefaults() {
894894
return this.DEFAULT_TUNING_SLIDERS;
895895
},
896+
897+
RATES_TYPE: {
898+
BETAFLIGHT: 0,
899+
RACEFLIGHT: 1,
900+
KISS: 2,
901+
ACTUAL: 3,
902+
QUICKRATES: 4,
903+
},
896904
};

src/js/tabs/pid_tuning.js

Lines changed: 25 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ TABS.pid_tuning = {
1111
currentRateProfile: null,
1212
currentRatesType: null,
1313
previousRatesType: null,
14-
RATES_TYPE: {
15-
BETAFLIGHT: 0,
16-
RACEFLIGHT: 1,
17-
KISS: 2,
18-
ACTUAL: 3,
19-
QUICKRATES: 4,
20-
},
2114
SETPOINT_WEIGHT_RANGE_LOW: 2.55,
2215
SETPOINT_WEIGHT_RANGE_HIGH: 20,
2316
SETPOINT_WEIGHT_RANGE_LEGACY: 2.54,
@@ -1117,8 +1110,8 @@ TABS.pid_tuning.initialize = function (callback) {
11171110
FC.RC_TUNING.RC_PITCH_EXPO = parseFloat(rc_pitch_expo_e.val());
11181111

11191112
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) {
1120-
switch(self.currentRatesType) {
1121-
case self.RATES_TYPE.RACEFLIGHT:
1113+
switch (self.currentRatesType) {
1114+
case FC.RATES_TYPE.RACEFLIGHT:
11221115
FC.RC_TUNING.pitch_rate = parseFloat(pitch_rate_e.val()) / 100;
11231116
FC.RC_TUNING.roll_rate = parseFloat(roll_rate_e.val()) / 100;
11241117
FC.RC_TUNING.yaw_rate = parseFloat(yaw_rate_e.val()) / 100;
@@ -1131,7 +1124,7 @@ TABS.pid_tuning.initialize = function (callback) {
11311124

11321125
break;
11331126

1134-
case self.RATES_TYPE.ACTUAL:
1127+
case FC.RATES_TYPE.ACTUAL:
11351128
FC.RC_TUNING.pitch_rate = parseFloat(pitch_rate_e.val()) / 1000;
11361129
FC.RC_TUNING.roll_rate = parseFloat(roll_rate_e.val()) / 1000;
11371130
FC.RC_TUNING.yaw_rate = parseFloat(yaw_rate_e.val()) / 1000;
@@ -1141,7 +1134,7 @@ TABS.pid_tuning.initialize = function (callback) {
11411134

11421135
break;
11431136

1144-
case self.RATES_TYPE.QUICKRATES:
1137+
case FC.RATES_TYPE.QUICKRATES:
11451138
FC.RC_TUNING.pitch_rate = parseFloat(pitch_rate_e.val()) / 1000;
11461139
FC.RC_TUNING.roll_rate = parseFloat(roll_rate_e.val()) / 1000;
11471140
FC.RC_TUNING.yaw_rate = parseFloat(yaw_rate_e.val()) / 1000;
@@ -1411,6 +1404,11 @@ TABS.pid_tuning.initialize = function (callback) {
14111404

14121405
self.rateCurve = new RateCurve(useLegacyCurve);
14131406

1407+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) {
1408+
$('.pid_tuning input[name="sensitivity"]').hide();
1409+
$('.pid_tuning .levelSensitivityHeader').empty();
1410+
}
1411+
14141412
function printMaxAngularVel(rate, rcRate, rcExpo, useSuperExpo, deadband, limit, maxAngularVelElement) {
14151413
const maxAngularVel = self.rateCurve.getMaxAngularVel(rate, rcRate, rcExpo, useSuperExpo, deadband, limit).toFixed(0);
14161414
maxAngularVelElement.text(maxAngularVel);
@@ -1441,86 +1439,7 @@ TABS.pid_tuning.initialize = function (callback) {
14411439
// translate to user-selected language
14421440
i18n.localizePage();
14431441

1444-
// Local cache of current rates
1445-
self.currentRates = {
1446-
roll_rate: FC.RC_TUNING.roll_rate,
1447-
pitch_rate: FC.RC_TUNING.pitch_rate,
1448-
yaw_rate: FC.RC_TUNING.yaw_rate,
1449-
rc_rate: FC.RC_TUNING.RC_RATE,
1450-
rc_rate_yaw: FC.RC_TUNING.rcYawRate,
1451-
rc_expo: FC.RC_TUNING.RC_EXPO,
1452-
rc_yaw_expo: FC.RC_TUNING.RC_YAW_EXPO,
1453-
rc_rate_pitch: FC.RC_TUNING.rcPitchRate,
1454-
rc_pitch_expo: FC.RC_TUNING.RC_PITCH_EXPO,
1455-
superexpo: FC.FEATURE_CONFIG.features.isEnabled('SUPEREXPO_RATES'),
1456-
deadband: FC.RC_DEADBAND_CONFIG.deadband,
1457-
yawDeadband: FC.RC_DEADBAND_CONFIG.yaw_deadband,
1458-
roll_rate_limit: FC.RC_TUNING.roll_rate_limit,
1459-
pitch_rate_limit: FC.RC_TUNING.pitch_rate_limit,
1460-
yaw_rate_limit: FC.RC_TUNING.yaw_rate_limit,
1461-
};
1462-
1463-
if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) {
1464-
self.currentRates.roll_rate = FC.RC_TUNING.roll_pitch_rate;
1465-
self.currentRates.pitch_rate = FC.RC_TUNING.roll_pitch_rate;
1466-
}
1467-
1468-
if (semver.lt(FC.CONFIG.apiVersion, "1.16.0")) {
1469-
self.currentRates.rc_rate_yaw = self.currentRates.rc_rate;
1470-
}
1471-
1472-
if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) {
1473-
self.currentRates.superexpo = true;
1474-
}
1475-
1476-
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) {
1477-
$('.pid_tuning input[name="sensitivity"]').hide();
1478-
$('.pid_tuning .levelSensitivityHeader').empty();
1479-
}
1480-
1481-
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_37)) {
1482-
self.currentRates.rc_rate_pitch = self.currentRates.rc_rate;
1483-
self.currentRates.rc_expo_pitch = self.currentRates.rc_expo;
1484-
}
1485-
1486-
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) {
1487-
switch(FC.RC_TUNING.rates_type) {
1488-
case self.RATES_TYPE.RACEFLIGHT:
1489-
self.currentRates.roll_rate *= 100;
1490-
self.currentRates.pitch_rate *= 100;
1491-
self.currentRates.yaw_rate *= 100;
1492-
self.currentRates.rc_rate *= 1000;
1493-
self.currentRates.rc_rate_yaw *= 1000;
1494-
self.currentRates.rc_rate_pitch *= 1000;
1495-
self.currentRates.rc_expo *= 100;
1496-
self.currentRates.rc_yaw_expo *= 100;
1497-
self.currentRates.rc_pitch_expo *= 100;
1498-
1499-
break;
1500-
1501-
case self.RATES_TYPE.ACTUAL:
1502-
self.currentRates.roll_rate *= 1000;
1503-
self.currentRates.pitch_rate *= 1000;
1504-
self.currentRates.yaw_rate *= 1000;
1505-
self.currentRates.rc_rate *= 1000;
1506-
self.currentRates.rc_rate_yaw *= 1000;
1507-
self.currentRates.rc_rate_pitch *= 1000;
1508-
1509-
break;
1510-
1511-
case self.RATES_TYPE.QUICKRATES:
1512-
self.currentRates.roll_rate *= 1000;
1513-
self.currentRates.pitch_rate *= 1000;
1514-
self.currentRates.yaw_rate *= 1000;
1515-
1516-
break;
1517-
1518-
// add future rates types here
1519-
default: // BetaFlight
1520-
1521-
break;
1522-
}
1523-
}
1442+
self.currentRates = self.rateCurve.getCurrentRates();
15241443

15251444
$('.tab-pid_tuning .tab-container .pid').on('click', () => activateSubtab('pid'));
15261445

@@ -1639,6 +1558,7 @@ TABS.pid_tuning.initialize = function (callback) {
16391558

16401559
$('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', 'false');
16411560
FC.CONFIG.rateProfile = self.currentRateProfile;
1561+
self.currentRates = self.rateCurve.getCurrentRates();
16421562

16431563
GUI.log(i18n.getMessage('pidTuningLoadedRateProfile', [self.currentRateProfile + 1]));
16441564
});
@@ -3048,6 +2968,10 @@ TABS.pid_tuning.changeRatesType = function(rateTypeID) {
30482968
self.changeRatesSystem(false);
30492969
self.previousRatesType = self.currentRatesType;
30502970
dialogRatesType.close();
2971+
2972+
FC.RC_TUNING.rates_type = self.currentRatesType;
2973+
self.currentRates = self.rateCurve.getCurrentRates();
2974+
30512975
});
30522976
}
30532977

@@ -3091,8 +3015,8 @@ TABS.pid_tuning.changeRatesSystem = function(sameType) {
30913015
rc_yaw_expo_e.val(FC.RC_TUNING.RC_YAW_EXPO.toFixed(2));
30923016
}
30933017

3094-
switch(self.currentRatesType) {
3095-
case self.RATES_TYPE.RACEFLIGHT:
3018+
switch (self.currentRatesType) {
3019+
case FC.RATES_TYPE.RACEFLIGHT:
30963020
rcRateLabel.text(i18n.getMessage("pidTuningRcRateRaceflight"));
30973021
rateLabel.text(i18n.getMessage("pidTuningRateRaceflight"));
30983022
rcExpoLabel.text(i18n.getMessage("pidTuningRcExpoRaceflight"));
@@ -3123,7 +3047,7 @@ TABS.pid_tuning.changeRatesSystem = function(sameType) {
31233047

31243048
break;
31253049

3126-
case self.RATES_TYPE.KISS:
3050+
case FC.RATES_TYPE.KISS:
31273051
rcRateLabel.text(i18n.getMessage("pidTuningRcRate"));
31283052
rateLabel.text(i18n.getMessage("pidTuningRcRateRaceflight"));
31293053
rcExpoLabel.text(i18n.getMessage("pidTuningRcExpoKISS"));
@@ -3132,7 +3056,7 @@ TABS.pid_tuning.changeRatesSystem = function(sameType) {
31323056

31333057
break;
31343058

3135-
case self.RATES_TYPE.ACTUAL:
3059+
case FC.RATES_TYPE.ACTUAL:
31363060
rcRateLabel.text(i18n.getMessage("pidTuningRcRateActual"));
31373061
rateLabel.text(i18n.getMessage("pidTuningRateQuickRates"));
31383062
rcExpoLabel.text(i18n.getMessage("pidTuningRcExpoRaceflight"));
@@ -3162,7 +3086,7 @@ TABS.pid_tuning.changeRatesSystem = function(sameType) {
31623086

31633087
break;
31643088

3165-
case self.RATES_TYPE.QUICKRATES:
3089+
case FC.RATES_TYPE.QUICKRATES:
31663090
rcRateLabel.text(i18n.getMessage("pidTuningRcRate"));
31673091
rateLabel.text(i18n.getMessage("pidTuningRateQuickRates"));
31683092
rcExpoLabel.text(i18n.getMessage("pidTuningRcExpoRaceflight"));
@@ -3213,23 +3137,23 @@ TABS.pid_tuning.changeRatesTypeLogo = function() {
32133137

32143138
const ratesLogoElement = $('.rates_type img[id="ratesLogo"]');
32153139

3216-
switch(self.currentRatesType) {
3217-
case self.RATES_TYPE.RACEFLIGHT:
3140+
switch (self.currentRatesType) {
3141+
case FC.RATES_TYPE.RACEFLIGHT:
32183142
ratesLogoElement.attr("src", "./images/rate_logos/raceflight.svg");
32193143

32203144
break;
32213145

3222-
case self.RATES_TYPE.KISS:
3146+
case FC.RATES_TYPE.KISS:
32233147
ratesLogoElement.attr("src", "./images/rate_logos/kiss.svg");
32243148

32253149
break;
32263150

3227-
case self.RATES_TYPE.ACTUAL:
3151+
case FC.RATES_TYPE.ACTUAL:
32283152
ratesLogoElement.attr("src", "./images/rate_logos/actual.svg");
32293153

32303154
break;
32313155

3232-
case self.RATES_TYPE.QUICKRATES:
3156+
case FC.RATES_TYPE.QUICKRATES:
32333157
ratesLogoElement.attr("src", "./images/rate_logos/quickrates.svg");
32343158

32353159
break;

0 commit comments

Comments
 (0)