Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
GarryPlays opened this issue Aug 31, 2017 · 3 comments
Open

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

GarryPlays opened this issue Aug 31, 2017 · 3 comments

Comments

@GarryPlays
Copy link

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

capture

@beeb
Copy link

beeb commented Sep 6, 2017

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
Copy link
Member

mikeller commented Sep 6, 2017

@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
Copy link

beeb commented Sep 7, 2017

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

mikeller pushed a commit that referenced this issue Nov 11, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants