Re: Ramp up down? Code ideas.
if you were to use proper complementary numbers to represent your controller power then
F(999) could be -999 and 0(345) would be 345
ie actual = -999 desired = 345
-999-345=-1344
means desired is -1344 below required
to get there in 100 x 10mS steps [1 second] just add 13.4 for the next 100 generations
to go back
345-(-999)=1344
means desired is 1344 over required
to get there in 100 x 10mS steps [1 second] just subtract 13.4 for the next 100 generations
the controller can figure if its assist or regen simply by testing bit.15
by rounding down the incrementor you will easily get within 10% will no fuss
never underestimate the beauty of unsigned subtractions with complementary numbers
to convert from pos to negative number n=~n+1
to convert from negative to pos number n=~n+1
ps never try to divide or multiply a negative number
ie.
inc = abs(difference)/100
Last edited by richard; - 25th November 2023 at 05:47.
Warning I'm not a teacher
Bookmarks