PropBasic Counters & Servos
Hello All!
i am trying to emulate JonnyMacs neat way of driving multiple servos with the system counter (jm_servo8_adv.spin) in PropBasic. Here is what i came up with so far, and it "kind of" works, but there is no real tourqe on the servo turn, and it chatters like a mofo when it gets to the target location.
i suspect my math for the timing is off, does anything see anything wrong with this?
thanks in advance!
i am trying to emulate JonnyMacs neat way of driving multiple servos with the system counter (jm_servo8_adv.spin) in PropBasic. Here is what i came up with so far, and it "kind of" works, but there is no real tourqe on the servo turn, and it chatters like a mofo when it gets to the target location.
i suspect my math for the timing is off, does anything see anything wrong with this?
thanks in advance!
Comments
mov tmp,_2500 ' tmp = 2500 * us001 shl tmp,#4
This basically messes up your timing.from this post:
http://forums.parallax.com/showthread.php?135098-PropBasic-Bug
So in order to check if the same bug is still present you could multiply by 80 manually (*5*16):
tmp = pos << 2 ' *4 tmp = tmp + pos ' *5 tmp = tmp << 4 ' *80
And the other location could just load 200000 (2500*80) directly.here is what is generated:
mov tmp,_2500 ' tmp = 2500 * us001 mov __temp1,tmp shl tmp,#4
tmp = us001 tmp = pos * tmp
' ----- TASK Variables (LONG only) ------------------------------------ us001 con 80 '5 '80_000_000 / 1_000_000 tick per microsecond so con 18 'servo offset start at pin 18 idx var long outpin var long slot var long pos var long tgt var long dlt var long tmp VAR long ' ----- SUB and FUNC Definitions --------------------------------------- '(2^32)/clkfreq = 4294967296/80_000_000 = 53.6870912 'clkfreq=80_000_000 53.6870912 * 65536 = 3518437.2088832 SrvStart: OUTPUT servos frqa = 1 'preset for counter phsa = 0 slot = cnt SrvMain: for idx = 0 to 7 rdlong position(idx), pos 'get chanel position value rdlong target(idx), tgt 'get channel target value rdlong delta(idx), dlt 'get speed value outpin = idx + so 'set servo pin via offset COUNTERA 32,outpin 'start counter tmp = pos * us001 phsa = -tmp if pos < tgt then 'is pos less the taget pos? pos = pos + dlt pos = pos max tgt elseif pos > tgt then pos = pos - dlt pos = pos min tgt endif tmp = 2500 * us001 'slot timing slot = slot + tmp WAITCNT slot 'wait for slot to finish ctra = 0 wrlong position(idx), pos 'put channel poition value next goto srvmain 'loop ENDTASK
if you the first set_servo you use has a speed other then 0, the servo will swing all the way to the srvmin pos at full speed, then will turn to the requested position at the requested speed. i got around it by just initiating all the servos with no speed control when i start the program.
special thanks to bean, jonnymac, and parallax.
if ya make it better please share!