UPDATED: Need some help with alittle servo not working/jitter!
DiablodeMorte
Posts: 238
Hello everbody. I need some help with some servo jitter. I have two servos hooked up to a basicSX OEM board(the servos work fine when i run a routine that isn't computer based) and I'm getting two words of data from a serial line at 9600 baud from a VB program i built myself(yay me). Anyway. The problem is, one of the servo's jitter. I did alittle debuging and it seems that which ever servo i address first in the code to pulsout jitters. The other does not(I switched up the servos just to maintain a control). Any helpful ideas as to remedy my problem?
Here's my code:
Post Edited (DiablodeMorte) : 10/11/2007 3:43:10 AM GMT
Here's my code:
' PULSIN.bs2 ' {$STAMP BS2sx} ' {$PBASIC 2.5} 'Pin Declarations Pulse PIN 0 ' pulse input pin 'Variables pwmInput1 VAR Word ''PWM Input Variable pwmInput2 VAR Word 'Constants #SELECT $STAMP #CASE BS2, BS2E, BS2PE Scale CON $200 ' 2.0 us per unit #CASE BS2SX, BS2P Scale CON $0CC ' 0.8 us per unit #CASE BS2PX Scale CON $0CF ' 0.81 us per unit #ENDSELECT #SELECT $STAMP #CASE BS2, BS2E, BS2PE T1200 CON 813 T2400 CON 396 T9600 CON 84 T19K2 CON 32 T38K4 CON 6 #CASE BS2SX, BS2P T1200 CON 2063 T2400 CON 1021 T9600 CON 240 T19K2 CON 110 T38K4 CON 45 #CASE BS2PX T1200 CON 3313 T2400 CON 1646 T9600 CON 396 T19K2 CON 188 T38K4 CON 84 #ENDSELECT Inverted CON $4000 Open CON $8000 Baud CON T9600 + Inverted pwmInput1 = 1830 pwmInput2 = 1830 goPwm: 'Attempt to handle more than one servo: PULSOUT 6, pwmInput1 PULSOUT 5, pwmInput2 GOTO Main 'Main Program Main: DO noData = 0 'PULSIN Pulse, 1, pwmInput ' measure positive pulse SERIN 16, Baud, 20, goPwm, [noparse][[/noparse]DEC4 pwmInput1, DEC4 pwmInput2] ' receive one byte GOTO goPwm LOOP
Post Edited (DiablodeMorte) : 10/11/2007 3:43:10 AM GMT
Comments
Try shortening the timeout and speeding up the PC end of the control loop. Additionally, you could shorten the number of characters needed by sending 16 bits as two 8-bit characters for each value. That would halve the number of characters needed.
Thanks
'Main·Program
Main:
··DO
····noData·=·0
····'PULSIN·Pulse,·1,·pwmInput·'·measure·positive·pulse
····SERIN·16,·Baud,·20,time_out,·[noparse][[/noparse]WAIT("PWM"),DEC4·pwmInput1,·DEC4·pwmInput2]·'·receive·one·byte
··· time_out:
····GOSUB·goPwm
··LOOP
goPwm:
·····'Attempt·to·handle·more·than·one·servo:
·····PULSOUT·6,·pwmInput1
·····PULSOUT·5,·pwmInput2
RETURN
Adjust your VB code to send like this.........SerialPort.WriteLine("PWM" & vbCR & pwminput1 & vbCR & pwminput2)
If you still get a little jitter try a slower baud.
Jeff T.
Sadly, I have a new interesting problem:
The servo's work now w/o much jitter(the wait command helped, i hit my head on the table when i read your post unsoundcode, I already knew the wait comand but i forgot!) but the new problem is this:
When all three servos are running now every so often they just stop working at all. I have to put my joystick back in the center position and then after about 4 seconds they start to work again. If i try to move too much on the joustick the servo's stop responding again. Any help?
Here's an updated code snippit.
and the VB code i'm using:
Can you hook up an LED to a spare pin (don't forget the current limiting resistors) to use to tell where the Stamp hangs up ... turn it on just before the SERIN and turn it off just after goPWM so it's on during the SERIN.
Alter your VB code like this
MSComm1.Output·=·"PWM"·&·vbCr·&·Str(CurrentJoyR)· &·vbCr & Str(CurrentJoyZ)·&·vbCr & Str(CurrentJoyX) & vbCr
the carriage return will tell the Stamp to read into the next field.
Jeff T.
Jeff T.