You are here

Limiting of throttle curves has no effect

2 posts / 0 new
Last post
Ackmaniac
Offline
Last seen: 6 years 6 months ago
Joined: 2017-09-04 23:17
Posts: 10
Limiting of throttle curves has no effect

The truncation of the val for the throttle curve has no effect because the absolute of it (val_a) is defined previously. So the truncation should be done before val_a is created.

float throttle_curve(float val, float curve_acc, float curve_brake, int mode) {
    float ret = 0.0;
    float val_a = fabsf(val); <-WRONG HERE

    if (val < -1.0) {
        val = -1.0;
    }

    if (val > 1.0) {
        val = 1.0;
    }

    <-BETTER HERE

    float curve;
    if (val >= 0.0) {
        curve = curve_acc;
    } else {
        curve = curve_brake;
    }

    // See
    // http://math.stackexchange.com/questions/297768/how-would-i-create-a-expo...
    if (mode == 0) { // Power
        if (curve >= 0.0) {
            ret = 1.0 - powf(1.0 - val_a, 1.0 + curve);
        } else {
            ret = powf(val_a, 1.0 - curve);
        }
    } else if (mode == 1) { // Exponential
        if (fabsf(curve) < 1e-10) {
            ret = val_a;
        } else {
            if (curve >= 0.0) {
                ret = 1.0 - ((expf(curve * (1.0 - val_a)) - 1.0) / (expf(curve) - 1.0));
            } else {
                ret = (expf(-curve * val_a) - 1.0) / (expf(-curve) - 1.0);
            }
        }
    } else if (mode == 2) { // Polynomial
        if (curve >= 0.0) {
            ret = 1.0 - ((1.0 - val_a) / (1.0 + curve * val_a));
        } else {
            ret = val_a / (1.0 - curve * (1.0 - val_a));
        }
    } else { // Linear
        ret = val_a;
    }

    if (val < 0.0) {
        ret = -ret;
    }

    return ret;
}

 

 

frank
Offline
Last seen: 1 week 21 hours ago
VESC BronzeVESC FreeVESC GoldVESC OriginalVESC PlatinumVESC Silver
Joined: 2016-12-27 20:19
Posts: 847
Nico, I will go through all the matters with Benjamin when we meet the coming weekend. Thx for all your feedback! As debated already, we will have a look at the brakes as well, doing some test rides. Frank