You are here

Maybe a typo in the code

4 posts / 0 new
Last post
Ackmaniac
Offline
Last seen: 5 years 11 months ago
Joined: 2017-09-04 23:17
Posts: 10
Maybe a typo in the code

Is the 1e-20 in the second line a typo? In the old version this was 1e-10.
float utils_fast_atan2(float y, float x) {
    float abs_y = fabsf(y) + 1e-20; // kludge to prevent 0/0 condition
    float angle;

    if (x >= 0) {
        float r = (x - abs_y) / (x + abs_y);
        float rsq = r * r;
        angle = ((0.1963 * rsq) - 0.9817) * r + (M_PI / 4.0);
    } else {
        float r = (x + abs_y) / (abs_y - x);
        float rsq = r * r;
        angle = ((0.1963 * rsq) - 0.9817) * r + (3.0 * M_PI / 4.0);
    }

    if (y < 0) {
        return(-angle);
    } else {
        return(angle);
    }
}

Danny Bokma
Offline
Last seen: 3 months 1 week ago
VESC Original
Joined: 2017-05-24 12:11
Posts: 53

I guess the 10^-20 is only to prevent divide by zero. The smaller the amount the closer you get to infinity hence a smaller number is better ( 10^-20 < 10^-10 ).

frank
Offline
Last seen: 6 days 23 hours ago
VESC BronzeVESC FreeVESC GoldVESC OriginalVESC PlatinumVESC Silver
Joined: 2016-12-27 20:19
Posts: 847
Thx Ackmaniac for your close look! I still owe you a call, the last weeks were to busy and I often fell asleep with my kids. Frank
Dimitri
Offline
Last seen: 5 years 10 months ago
VESC Original
Joined: 2017-06-21 09:03
Posts: 5

In File: rf.c

// Enable dynamic payload length
void rf_enable_pipe_dlp(int pipes)

i think you meant to write "rf_enable_pipe_dpl" instead of "rf_enable_pipe_dlp" ?
i could be wrong, idk..
but either way no big deal...
;-)

Dimitri.