Skip to content

Commit

Permalink
Add Acro center sensitivity to Betaflight Rates (#3927)
Browse files Browse the repository at this point in the history
* Add Acro center sensitivity to Betaflight Rates

* Remove Acro from pid titlebar header
  • Loading branch information
haslinghuis authored May 21, 2024
1 parent 3b088d7 commit 48526f2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
3 changes: 3 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -7042,6 +7042,9 @@
"pidTuningRcRateActual": {
"message": "Center Sensitivity"
},
"pidTuningAcroCenterSensitiviy": {
"message": "Center-Max Sensitivity"
},
"dialogRatesTypeTitle": {
"message": "Rates type change"
},
Expand Down
2 changes: 1 addition & 1 deletion src/css/tabs/pid_tuning.less
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
.pid_titlebar {
th {
padding: 5px;
text-align: left;
text-align: center;
border-right: 1px solid var(--subtleAccent);
&:first-child {
text-align: left;
Expand Down
60 changes: 46 additions & 14 deletions src/js/tabs/pid_tuning.js
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,11 @@ pid_tuning.initialize = function (callback) {
self.maxAngularVelPitchElement = $('.pid_tuning .maxAngularVelPitch');
self.maxAngularVelYawElement = $('.pid_tuning .maxAngularVelYaw');

// Only used with Betaflight Rates
self.acroCenterSensitivityRollElement = $('.pid_tuning .acroCenterSensitivityRoll');
self.acroCenterSensitivityPitchElement = $('.pid_tuning .acroCenterSensitivityPitch');
self.acroCenterSensitivityYawElement = $('.pid_tuning .acroCenterSensitivityYaw');

rcCurveElement.width = 1000;
rcCurveElement.height = 1000;

Expand Down Expand Up @@ -2697,13 +2702,31 @@ pid_tuning.updateRatesLabels = function() {
);
}

// Add labels for angleCenterSensitivity
// Only show Acro Center - Max Sensitivity for betaflight rates
const centerSensitivyLabel = $('#pid-tuning .pid_titlebar .centerSensitivity');

const isBetaflightRates = self.currentRatesType === FC.RATES_TYPE.BETAFLIGHT;

centerSensitivyLabel.toggle(isBetaflightRates);

self.acroCenterSensitivityRollElement.toggle(isBetaflightRates);
self.acroCenterSensitivityPitchElement.toggle(isBetaflightRates);
self.acroCenterSensitivityYawElement.toggle(isBetaflightRates);

$('#pid-tuning .pid_titlebar .maxVel').toggle(!isBetaflightRates);
self.maxAngularVelRollElement.toggle(!isBetaflightRates);
self.maxAngularVelPitchElement.toggle(!isBetaflightRates);
self.maxAngularVelYawElement.toggle(!isBetaflightRates);

// Add labels for Angle Center Sensitivity
const angleLimit = FC.ADVANCED_TUNING.levelAngleLimit;
const maxAngleRollRate = parseInt(maxAngularVelRoll);
const maxAnglePitchRate = parseInt(maxAngularVelPitch);
const maxAngleYawRate = parseInt(maxAngularVelYaw);

const rcRate = self.currentRates.rc_rate;
const rcRatePitch = self.currentRates.rc_rate_pitch;
const rcRateYaw = self.currentRates.rc_rate_yaw;

function getOffsetForBalloon(value) {
return curveWidth - (Math.ceil(stickContext.measureText(value).width) / (stickContext.canvas.clientWidth / stickContext.canvas.clientHeight)) - 40;
Expand Down Expand Up @@ -2734,24 +2757,32 @@ pid_tuning.updateRatesLabels = function() {

const RC_RATE_INCREMENTAL = 14.54;

const getRcRateModified = rate => rate > 2.0 ? (rate - 2.0) * RC_RATE_INCREMENTAL + 2.0: rate;
const getAcroSensitivityFraction = (exponent, rate) => ((1 - exponent) * getRcRateModified(rate) * 200).toFixed(0);
const getAngleSensitivityFraction = (exponent, rate) => (angleLimit * ((1 - exponent) * getRcRateModified(rate) * 200 / maxAngleRollRate)).toFixed(1);

// ROLL
const expo = self.currentRates.rc_expo;
const rcRateModified = rcRate > 2.0 ? (rcRate - 2.0) * RC_RATE_INCREMENTAL + 2.0: rcRate;
const sensitivityFractionRoll = (angleLimit * ((1 - expo) * rcRateModified * 200 / maxAngleRollRate)).toFixed(1);

const sensitivityFractionRollText = `${sensitivityFractionRoll}...${angleLimit}`;
const sensitivityFractionRollOffset = getOffsetForBalloon(sensitivityFractionRollText);
const angleCenterSensitivityFractionRoll = getAngleSensitivityFraction(expo, rcRate);
const angleCenterSensitivityFractionRollText = `${angleCenterSensitivityFractionRoll} - ${angleLimit}`;
const angleCenterSensitivityFractionRollOffset = getOffsetForBalloon(angleCenterSensitivityFractionRollText);
const acroCenterSensitivityFractionRoll = getAcroSensitivityFraction(expo, rcRate);
self.acroCenterSensitivityRollElement.text(`${acroCenterSensitivityFractionRoll} - ${maxAngleRollRate}`);
// PITCH
const expoPitch = self.currentRates.rc_pitch_expo;
const rcRateModifiedPitch = rcRatePitch > 2.0 ? (rcRatePitch - 2.0) * RC_RATE_INCREMENTAL + 2.0: rcRatePitch;
const sensitivityFractionPitch = (angleLimit * ((1 - expoPitch) * rcRateModifiedPitch * 200 / maxAnglePitchRate)).toFixed(1);

const sensitivityFractionPitchText = `${sensitivityFractionPitch}...${angleLimit}`;
const sensitivityFractionPitchOffset = getOffsetForBalloon(sensitivityFractionPitchText);
const angleCenterSensitivityFractionPitch = getAngleSensitivityFraction(expoPitch, rcRatePitch);
const angleCenterSensitivityFractionPitchText = `${angleCenterSensitivityFractionPitch} - ${angleLimit}`;
const angleCenterSensitivityFractionPitchOffset = getOffsetForBalloon(angleCenterSensitivityFractionPitchText);
const acroCenterSensitivityFractionPitch = getAcroSensitivityFraction(expoPitch, rcRatePitch);
self.acroCenterSensitivityPitchElement.text(`${acroCenterSensitivityFractionPitch} - ${maxAnglePitchRate}`);
// YAW
const expoYaw = self.currentRates.rc_yaw_expo;
const acroCenterSensitivityFractionYaw = getAcroSensitivityFraction(expoYaw, rcRateYaw);
self.acroCenterSensitivityYawElement.text(`${acroCenterSensitivityFractionYaw} - ${maxAngleYawRate}`);

balloons.push(
{value: parseInt(sensitivityFractionRoll), balloon: function() {drawBalloonLabel(stickContext, sensitivityFractionRollText, sensitivityFractionRollOffset, curveHeight - 150, 'none', BALLOON_COLORS.roll, balloonsDirty);}},
{value: parseInt(sensitivityFractionPitch), balloon: function() {drawBalloonLabel(stickContext, sensitivityFractionPitchText, sensitivityFractionPitchOffset, curveHeight - 50, 'none', BALLOON_COLORS.pitch, balloonsDirty);}},
{value: parseInt(angleCenterSensitivityFractionRoll), balloon: function() {drawBalloonLabel(stickContext, angleCenterSensitivityFractionRollText, angleCenterSensitivityFractionRollOffset, curveHeight - 150, 'none', BALLOON_COLORS.roll, balloonsDirty);}},
{value: parseInt(angleCenterSensitivityFractionPitch), balloon: function() {drawBalloonLabel(stickContext, angleCenterSensitivityFractionPitchText, angleCenterSensitivityFractionPitchOffset, curveHeight - 50, 'none', BALLOON_COLORS.pitch, balloonsDirty);}},
);
}

Expand Down Expand Up @@ -2894,6 +2925,7 @@ pid_tuning.changeRatesSystem = function(sameType) {
const rcRateLabel = $('#pid-tuning .pid_titlebar .rc_rate');
const rateLabel = $('#pid-tuning .pid_titlebar .rate');
const rcExpoLabel = $('#pid-tuning .pid_titlebar .rc_expo');
const centerSensitivyLabel = $('#pid-tuning .pid_titlebar .centerSensitivity');

// default values for betaflight curve. all the default values produce the same betaflight default curve (or at least near enough)
let rcRateDefault = (1).toFixed(2), rateDefault = (0.7).toFixed(2), expoDefault = (0).toFixed(2);
Expand Down Expand Up @@ -3006,7 +3038,7 @@ pid_tuning.changeRatesSystem = function(sameType) {
rcRateLabel.text(i18n.getMessage("pidTuningRcRate"));
rateLabel.text(i18n.getMessage("pidTuningRate"));
rcExpoLabel.text(i18n.getMessage("pidTuningRcExpo"));

centerSensitivyLabel.text(i18n.getMessage("pidTuningAcroCenterSensitiviy"));
break;
}

Expand Down
4 changes: 4 additions & 0 deletions src/tabs/pid_tuning.html
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@
<th class="rc_rate" i18n="pidTuningRcRate"></th>
<th class="rate" i18n="pidTuningRate"></th>
<th class="rc_expo" i18n="pidTuningRcExpo"></th>
<th class="new_rates centerSensitivity" i18n="pidTuningRcRateActual"></th>
<th class="new_rates maxVel" i18n="pidTuningMaxVel"></th>
</tr>
<tr class="pid_titlebar2">
Expand All @@ -1001,6 +1002,7 @@
<input type="number" class="expo_input" name="rc_expo" step="0.01" min="0" max="1" />
<div class="bracket"></div>
</td>
<td class="new_rates acroCenterSensitivityRoll"></td>
<td class="new_rates maxAngularVelRoll"></td>
</tr>
<tr class="PITCH">
Expand All @@ -1014,6 +1016,7 @@
<td>
<input type="number" class="expo_input" name="rc_pitch_expo" step="0.01" min="0" max="1" />
</td>
<td class="new_rates acroCenterSensitivityPitch"></td>
<td class="new_rates maxAngularVelPitch"></td>
</tr>
<tr class="YAW">
Expand All @@ -1027,6 +1030,7 @@
<td>
<input type="number" class="expo_input" name="rc_yaw_expo" step="0.01" min="0" max="1" />
</td>
<td class="new_rates acroCenterSensitivityYaw"></td>
<td class="new_rates maxAngularVelYaw"></td>
</tr>
</table>
Expand Down

0 comments on commit 48526f2

Please sign in to comment.