vedderb / bldc

The VESC motor control firmware
2.16k stars 1.35k forks source link

`utils_norm_angle_rad()` API contract doesn't agree with the code #439

Closed kubark42 closed 2 years ago

kubark42 commented 2 years ago

The contract stipulates -pi <= angle < pi, but the code delivers -pi <= angle <= pi

/**
 * Make sure that -pi <= angle < pi,
 *
 * @param angle
 * The angle to normalize in radians.
 * WARNING: Don't use too large angles.
 */
void utils_norm_angle_rad(float *angle) {
    while (*angle < -M_PI) {
        *angle += 2.0 * M_PI;
    }

    while (*angle >  M_PI) {
        *angle -= 2.0 * M_PI;
    }
}

It would make sense to fix this, either by adjusting the contract or the deliverable.

C.f. https://github.com/vedderb/bldc/blob/master/utils.c#L73