Floating point conversion, How I do
micman2
Posts: 18
Hi all,
i've a question:
I've a PID algorithmic ,
the result "outputL " is floating point algorithmic , The result is floating point ? how to convert in long ?
The next code limit -100 < outputL < 100 and send in PWM
The constant is:
work but When I change in :
1.2 (.2) (.1;.3;.4 ecc ecc ) send in over limit the "outputL"
Why?
i've a question:
I've a PID algorithmic ,
encL := Enco.ReadEncoderLeft cur_posL := encL - prevVL prevVL := encL cur_errorL := set_posL - cur_posL PL := f.FMul(f.FFloat(cur_errorL),constKp) IL := f.FAdd(f.FFloat(IL),(f.FMul(f.FMul(f.FFloat(cur_errorL),cstdt),constKi))) eL := cur_errorL - pre_errorL DL := f.FDiv(f.FMul(f.FFloat(eL),constKd),cstdt) outputL := f.FAdd(f.FAdd(PL,IL),DL)
the result "outputL " is floating point algorithmic , The result is floating point ? how to convert in long ?
The next code limit -100 < outputL < 100 and send in PWM
if outputL > 100 outputL := 100 if outputL < -100 outputL := -100 PWMg.setpwmDuty1(outputL,frequenzaPWM)
The constant is:
constKp = 1.0 constKi = 0.0 constKd = 0.0
work but When I change in :
constKp = 1.2 <------ constKi = 0.0 constKd = 0.0
1.2 (.2) (.1;.3;.4 ecc ecc ) send in over limit the "outputL"
Why?
Comments
and outputL will now be a normal integer .
debugLout = 10
The result is Ok ! ( I see with viewPort v4.1.504)
But when I change constKp with 1.8
constKp = 1.8
The result is wrong
debugLout = 1 !!!!!! Why???
Post Edited (micman2) : 5/13/2009 12:01:48 PM GMT
The answer is quite simple, in fact, so simple that it took me awhile to see it . You have entered cur_errorL as a floating point constant. However, you then try and convert it to a floating point as if it were an integer. Change the code above to this
and you should have more luck.