|
One line power
I got the insane urge to eliminate if statements. Having done that, i had the urge to eliminate statements in general. The result? One line of code per track to make it flip and reverse, rescale the sticks, and ramp the speed to reduce motor wear and tear.
creepbit =creep.bit7
creep = abs(127-creep)
hold = lt
lt = (254-rt -lt *creepbit + lt)*creep/127-creep+127 min (lth-Ramp_Speed) max (lth+Ramp_Speed)
rt = (254-rt -hold *creepbit + rt)*creep/127-creep+127 min (rth-Ramp_Speed) max (rth+Ramp_Speed)
rth = rt max (254-Ramp_Speed-1) min (Ramp_Speed+1)
lth = lt max (254-Ramp_Speed-1) min (Ramp_Speed+1)
sure, it has some maintainance code before hand, but it works.
Creep is usually a wheel input. If it is full forward everything works normally. Full reverse will flip and reverse the tracks. Anything inbetween will rescale the tracks and possibly flip and reverse them too. Lastly, it will prvent motor burn. I got bored. So sue me
|