BOE BOT jitter Smother move?
Shane Weddle
Posts: 4
Hello,
I have added 2 Photoreflectors to my BOE BOT to perform line fallowing. It works but it has jittery movement do to my code and I think it could be done better but not sure how. I have used code from the TestBothPhotoresistors.bs2 and RoamingWithWhiskers.bs2 to make it work…
CIRCUIT
BOE BOT
#### THE CODE ####
' {$Stamp bs2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
'
[noparse][[/noparse] Variables ]
irDetectLeft VAR Bit
irDetectRight VAR Bit
timeLeft VAR Word
timeRight VAR Word
pulseCount VAR Byte
DO
FREQOUT 8, 1, 38500
HIGH 6
HIGH 5
PAUSE 2
RCTIME 6,1,timeLeft
RCTIME 5,1,timeRight
IF (timeLeft > 1300) AND (timeRight > 1300) THEN
'SEEING ALL BLACK, BACK UP.
GOSUB Back_Up
ELSEIF timeLeft > 1300 THEN
'TURN RIGHT.. SEEING BLACK ON LEFT
GOSUB Turn_Right
ELSEIF timeRight > 1300 THEN
'TURN LEFT... SEEING BLACK ON RIGHT
GOSUB Turn_Left
ELSE
'GO FORWARD... SEEING WIGHT ON BOTH
GOSUB Forward_Pulse
ENDIF
LOOP
'
[noparse][[/noparse] Subroutines ]
'STOP = 760
Forward_Pulse:
PULSOUT 13,850 'LEFT
PULSOUT 12,650 'RIGHT
'PAUSE 5
RETURN
Turn_Left:
FOR pulseCount = 0 TO 3
PULSOUT 13, 850
PULSOUT 12, 760
'PAUSE 3
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 3
PULSOUT 13, 760
PULSOUT 12, 650
'PAUSE 3
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
'PAUSE 20
NEXT
RETURN
#### END THE CODE ####
Thanks for any help!
Shane
I have added 2 Photoreflectors to my BOE BOT to perform line fallowing. It works but it has jittery movement do to my code and I think it could be done better but not sure how. I have used code from the TestBothPhotoresistors.bs2 and RoamingWithWhiskers.bs2 to make it work…
CIRCUIT
BOE BOT
#### THE CODE ####
' {$Stamp bs2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
'
[noparse][[/noparse] Variables ]
irDetectLeft VAR Bit
irDetectRight VAR Bit
timeLeft VAR Word
timeRight VAR Word
pulseCount VAR Byte
DO
FREQOUT 8, 1, 38500
HIGH 6
HIGH 5
PAUSE 2
RCTIME 6,1,timeLeft
RCTIME 5,1,timeRight
IF (timeLeft > 1300) AND (timeRight > 1300) THEN
'SEEING ALL BLACK, BACK UP.
GOSUB Back_Up
ELSEIF timeLeft > 1300 THEN
'TURN RIGHT.. SEEING BLACK ON LEFT
GOSUB Turn_Right
ELSEIF timeRight > 1300 THEN
'TURN LEFT... SEEING BLACK ON RIGHT
GOSUB Turn_Left
ELSE
'GO FORWARD... SEEING WIGHT ON BOTH
GOSUB Forward_Pulse
ENDIF
LOOP
'
[noparse][[/noparse] Subroutines ]
'STOP = 760
Forward_Pulse:
PULSOUT 13,850 'LEFT
PULSOUT 12,650 'RIGHT
'PAUSE 5
RETURN
Turn_Left:
FOR pulseCount = 0 TO 3
PULSOUT 13, 850
PULSOUT 12, 760
'PAUSE 3
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 3
PULSOUT 13, 760
PULSOUT 12, 650
'PAUSE 3
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
'PAUSE 20
NEXT
RETURN
#### END THE CODE ####
Thanks for any help!
Shane
Comments
Eek! I just noticed that you have commented out your pauses. So what is happening is you are sending three pulses, each only a couple milliseconds apart. Your servos aren't going to be liking that.
If after changing the pause times you still do not get smooth movement it would be because RCTIME is taking too long. You could either try a smaller capacitor or read only one of the ir detectors each time through the loop. If you did that you could also change your movement subroutines so that the pulses are sent only once each time.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Post Edited (W9GFO) : 6/9/2010 2:22:14 AM GMT
The hole RCTIME operation seams to be a bit consuming... Oh for the love having Analog in...
Shane
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Post Edited (W9GFO) : 6/9/2010 6:53:26 PM GMT