Program Differances and too much Servo Rotation BS1
Dunedon
Posts: 13
Hi ... I've got two projects that I've tried on my servo's (continuous rotation) and they both produce differant results in the amount of the rotation ... I assume it's due to the extra code travelled in the one project and I'm wondering if there is anything I can do about it.
If I use this code as the entire program I get a nice small rotation (maybe 1 degree or less)·with each step (the behaviour I want):
But if I use a larger program I get a swing of about 10·degrees (maybe more) using the exact same code to send the pulse each step·(without the for-next loop). Ignore the Button code, I've removed it from this program for now and am just using the auto-movement code.
Q1) Is this a problem with the BS1 due to the instruction processing speed?
Q2) Can anything be done to allow me to get the small step increasements I want? (ie: code change, or change to BS2)
Q3) And unrelated ... since I have continuious rotation servo's, is there any way to have to reset to the same beginning position when powered up?· Will normal servo's reset to a "center" position if sent a pulse of 150?
Thanks in advance for any help you can give - I really appreciated it [noparse]:)[/noparse] - Keith
·
If I use this code as the entire program I get a nice small rotation (maybe 1 degree or less)·with each step (the behaviour I want):
FOR X = 0 TO 200 PULSEOUT 6, 151 PAUSE 20 NEXT
But if I use a larger program I get a swing of about 10·degrees (maybe more) using the exact same code to send the pulse each step·(without the for-next loop). Ignore the Button code, I've removed it from this program for now and am just using the auto-movement code.
' PUPPET2.BS1 ' ------------------------ ' PIN 0: Head Up Button ' PIN 1: Head Left Button ' PIN 2: Head Right Button ' PIN 3: Head Down Button ' PIN 6: Head Up/Down Servo ' PIN 7: Head Left/Right Servo ' {$STAMP BS1} ' {$PBASIC 1.0} Init: 'Button PINS SYMBOL btn_U = 0 SYMBOL btn_D = 3 SYMBOL btn_L = 1 SYMBOL btn_R = 2 'Button WorkSpaces SYMBOL btn_U_Wrk = B2 SYMBOL btn_D_Wrk = B3 SYMBOL btn_L_Wrk = B4 SYMBOL btn_R_Wrk = B5 'Head Location Variables SYMBOL headUD = 6 SYMBOL headLR = 7 SYMBOL headUD_Wrk = B6 SYMBOL headLR_Wrk = B7 'Temp Variable SYMBOL UseAuto = B8 SYMBOL AutoTemp = B9 SYMBOL UPLEFT = B10 SYMBOL DOWNRIGHT = B11 SYMBOL RandValue = W5 'Initialze Servo LET PINS = 0 LET DIRS = %00000011 LET UPLEFT = 151 LET DOWNRIGHT = 149 LET headUD_Wrk = 90 LET headLR_Wrk = 90 Main: LET UseAuto = 1 RANDOM RandValue Do_Auto: 'Enter the Automovement code here AutoTemp = RandValue / 6550 MIN 0 DEBUG AutoTemp BRANCH AutoTemp, (AutoMove_1,AutoMove_2,AutoMove_3,AutoMove_4,AutoMove_5,AutoMove_6,AutoMove_7,AutoMove_8) PAUSE 20 GOTO Main 'Up AutoMove_1: DEBUG "1", headUD_Wrk, headLR_Wrk LET headUD_Wrk = headUD_Wrk + 1 MAX 180 PULSOUT headUD, UPLEFT PAUSE 20 GOTO Main 'Down AutoMove_2: DEBUG "2", headUD_Wrk, headLR_Wrk LET headUD_Wrk = headUD_Wrk - 1 MIN 0 PULSOUT headUD, DOWNRIGHT PAUSE 20 GOTO Main 'Left AutoMove_3: DEBUG "3", headUD_Wrk, headLR_Wrk LET headLR_Wrk = headLR_Wrk + 1 MAX 180 PULSOUT headLR, UPLEFT PAUSE 20 GOTO Main 'Right AutoMove_4: DEBUG "4", headUD_Wrk, headLR_Wrk LET headLR_Wrk = headLR_Wrk - 1 MIN 0 PULSOUT headLR, DOWNRIGHT PAUSE 20 GOTO Main 'Up/Left AutoMove_5: DEBUG "5", headUD_Wrk, headLR_Wrk LET headUD_Wrk = headUD_Wrk + 1 MAX 180 PULSOUT headUD, UPLEFT PAUSE 20 LET headLR_Wrk = headLR_Wrk + 1 MAX 180 PULSOUT headLR, UPLEFT PAUSE 20 GOTO Main 'Up/Right AutoMove_6: DEBUG "6", headUD_Wrk, headLR_Wrk LET headUD_Wrk = headUD_Wrk + 1 MAX 180 PULSOUT headUD, UPLEFT PAUSE 20 LET headLR_Wrk = headLR_Wrk - 1 MIN 0 PULSOUT headLR, DOWNRIGHT PAUSE 20 GOTO Main 'Down/Right AutoMove_7: DEBUG "7", headUD_Wrk, headLR_Wrk LET headUD_Wrk = headUD_Wrk - 1 MIN 0 PULSOUT headUD, DOWNRIGHT PAUSE 20 LET headLR_Wrk = headLR_Wrk - 1 MIN 0 PULSOUT headLR, DOWNRIGHT PAUSE 20 GOTO Main 'Down/Left AutoMove_8: DEBUG "8", headUD_Wrk, headLR_Wrk LET headUD_Wrk = headUD_Wrk - 1 MIN 0 PULSOUT headUD, DOWNRIGHT PAUSE 20 LET headLR_Wrk = headLR_Wrk + 1 MAX 180 PULSOUT headLR, UPLEFT PAUSE 20 GOTO Main
Q1) Is this a problem with the BS1 due to the instruction processing speed?
Q2) Can anything be done to allow me to get the small step increasements I want? (ie: code change, or change to BS2)
Q3) And unrelated ... since I have continuious rotation servo's, is there any way to have to reset to the same beginning position when powered up?· Will normal servo's reset to a "center" position if sent a pulse of 150?
Thanks in advance for any help you can give - I really appreciated it [noparse]:)[/noparse] - Keith
·
Comments
One solution would be to have a routine "Servo_Refresh:" which you call every 20 mSec, to 'refresh' the current commanded settings of all your servo's. One problem with this solution is you'll need a "word" value for each servo to hold it's desired setting.· For that I think you'll need a BS2.
The other problem is, "Modified" servo's have been "Modified" to REMOVE the explicit positioning ability. This allows them to be used as "wheel" motors, but does remove their "center" position ability.
2) Depends on what you mean by "step increments". Servos are not that accurate and the speed is not closely reproducible over time using the same pulse width.
3) No. The only way you can do that is to have some external position sensor. For a wheel, often this is done by having a hole in one position on the opaque wheel and having an LED positioned to shine through that hole. A phototransistor is on the other side to sense when the hole is present and the Stamp moves the wheel until the phototransistor indicates that the hole is there. Normal servos will move to whatever absolute position you specify (by sending a specific pulse width).
If you want to measure position, I have been successful using an absolute encoder from usdigital.com. (http://www.usdigital.com/news/press-releases/introducing-the-ma2) It gives 0-5 volts and using an ADC chip it gives pretty reliable information.