Shop OBEX P1 Docs P2 Docs Learn Events
BOE BOT jitter… Smother move? — Parallax Forums

BOE BOT jitter… Smother move?

Shane WeddleShane Weddle Posts: 4
edited 2010-06-09 19:44 in Robotics
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
circuit.jpg

BOE BOT
bot.jpg


#### 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

  • W9GFOW9GFO Posts: 4,010
    edited 2010-06-09 02:09
    Your subroutines have awful short pauses. The servos need a pulse every 20 or so milliseconds. Each command takes a short time to execute so the length of the pause will be variable depending upon what else is happening in your loop. In your case there is nothing else going on in the loop so your pause should be longer. Try PAUSE 18 for each of them, PAUSE 20 is fine too but PAUSE 3 or PAUSE 5 will likely cause your servos to respond in undesirable ways.

    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
  • Shane WeddleShane Weddle Posts: 4
    edited 2010-06-09 15:50
    I will give that a shot, I was thinking the pauses created the jitters, When I have PAUSE 20 in place its a longer forward movement but less granularity in the detection of a line.
    The hole RCTIME operation seams to be a bit consuming... Oh for the love having Analog in...

    Shane
  • W9GFOW9GFO Posts: 4,010
    edited 2010-06-09 18:44
    I would eliminate the FOR..NEXT loop so that for each time the line sensors is checked, only one pulse is sent to the servos. To get your program running smoothly you will need to get the sensor checking portion of it to take 20 milliseconds (or so) to execute. Since you only send one pulse to the servos AND the sensor checking will be taking about 20 milliseconds then you do not need pauses in the subroutines (except for the backing up one).

    ' {$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
    
      PAUSE 15                ' adjust as needed
    
      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
    RETURN
    
    Turn_Left: 
      PULSOUT 13, 850
      PULSOUT 12, 760
    RETURN
    
    Turn_Right: 
      PULSOUT 13, 760
      PULSOUT 12, 650
    RETURN
    
    Back_Up: 
      FOR pulseCount = 0 TO 40
        PULSOUT 13, 650
        PULSOUT 12, 850
        PAUSE 18
      NEXT
    RETURN
    
    END
    



    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.

    Post Edited (W9GFO) : 6/9/2010 6:53:26 PM GMT
  • Shane WeddleShane Weddle Posts: 4
    edited 2010-06-09 19:44
    Thanks W9GFO, I'll give that a shot!
Sign In or Register to comment.