Misfittech / nano_stepper

Stepper feedback controller
423 stars 179 forks source link

setpos to negative number error #62

Open brianmichalk1 opened 1 year ago

brianmichalk1 commented 1 year ago

If a setpos command is issued with a negative value, a resulting readpos value will be the abs() of the negative.

move -124.00 400
:>
 deg
:>
readpos
encoder -124.10
:>
setpos -10
:>
readpos
encoder 10.08

The current implementation:

static int setpos_cmd(sCmdUart *ptrUart,int argc, char * argv[])
{
    if (argc>=1)
    {
        int64_t a;
        float x;
        x=fabs(atof(argv[0]));
        a=ANGLE_FROM_DEGREES(x);
        stepperCtrl.setAngle(a);
        return 0;
    }
    return 1;
}

Is there a reason why the fabs() is used?