Skip to content

Max Vel (deg/s) in Rates Screen #38

Open
@GarryPlays

Description

@GarryPlays

Not sure how that number is created, but if that would be available, would be great.

capture

Activity

beeb

beeb commented on Sep 6, 2017

@beeb

For reference, this is how it's computed by betaflight configurator (with getMaxAngularVel):

var minRc = 1000;
var midRc = 1500;
var maxRc = 2000;

this.rcCommand = function (rcData, rcRate, deadband) {
        var tmp = Math.min(Math.max(Math.abs(rcData - midRc) - deadband, 0), 500);

        var result = tmp * rcRate;

        if (rcData < midRc) {
            result = -result;
        }

        return result;
    };

RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcRate, rcExpo, superExpoActive, deadband) {
    var angleRate;
    if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined) {
        if (rcRate > 2) {
            rcRate = rcRate + (rcRate - 2) * 14.54;
        }

        var inputValue = this.rcCommand(rcData, rcRate, deadband);
        var maxRc = 500 * rcRate;
        
        var expoPower;
        var rcRateConstant;
        if (semver.gte(CONFIG.apiVersion, "1.20.0")) {
            expoPower = 3;
            rcRateConstant = 200;
        } else {
            expoPower = 2;
            rcRateConstant = 205.85;
        }

        if (rcExpo > 0) {
            var absRc = Math.abs(inputValue) / maxRc;
            inputValue =  inputValue * Math.pow(absRc, expoPower) * rcExpo + inputValue * (1-rcExpo);
        }

        var rcInput = inputValue / maxRc;

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

        angleRate = this.constrain(angleRate, -1998, 1998); // Rate limit protection
    }

    return angleRate;
};

RateCurve.prototype.getMaxAngularVel = function (rate, rcRate, rcExpo, superExpoActive, deadband) {
    var maxAngularVel;
    if (!this.useLegacyCurve) {
        maxAngularVel = this.rcCommandRawToDegreesPerSecond(maxRc, rate, rcRate, rcExpo, superExpoActive, deadband);
    }

    return maxAngularVel;
};
mikeller

mikeller commented on Sep 6, 2017

@mikeller
Member

@beeb: For reference, the implementation in the configurator was originally created by hand-translating the calculations that are done in the firmware into JavaScript. Since the firmware has been updated a number of time since then, and configurator not, it's not really accurate any more. Probably better create a fresh lua translation from the firmware.

beeb

beeb commented on Sep 7, 2017

@beeb

@mikeller good to know! That would indeed be a nice thing to do.

added 2 commits that reference this issue on Nov 11, 2017

Merge pull request #38 from ethomas997/etsaveSettingsMods

86c2e56

Minified: Merge pull request #38 from ethomas997/etsaveSettingsMods [8…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Max Vel (deg/s) in Rates Screen · Issue #38 · betaflight/betaflight-tx-lua-scripts