Shop OBEX P1 Docs P2 Docs Learn Events
programming ping))) on a boe bot — Parallax Forums

programming ping))) on a boe bot

respective98respective98 Posts: 4
edited 2012-12-05 19:52 in Accessories
I have been trying to program a boe bot with ping in it but every time it works it has a very shaky n a very slow movement.
Please help!
below is my code!
' {$STAMP BS2}
' {$PBASIC 2.5}


Ping PIN 15
PingServo PIN 14
LeftServo PIN 13
RightServo PIN 12


rawDist VAR Word
sweepcount VAR Word
x VAR Byte
pulseCount VAR Byte




Main:
FOR sweepcount = 350 TO 1150 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 0
NEXT
GOSUB GetSonar
NEXT


FOR sweepcount = 950 TO 550 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 0
NEXT
GOSUB GetSonar
NEXT
GOTO Main


GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist


IF (rawDist < 600) THEN
IF (sweepcount < 750) THEN
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Turn_Right
ELSE
GOSUB Back_Up
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF


RETURN


Forward_Pulse:
FOR pulsecount = 0 TO 5
PULSOUT LeftServo, 850
PULSOUT RightServo, 650
PAUSE 0
NEXT
RETURN


Turn_Left:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 650
PULSOUT RightServo, 650
PAUSE 0
NEXT
RETURN


Turn_Right:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 850
PULSOUT RightServo, 850
PAUSE 0
NEXT
RETURN


Back_Up:
FOR pulseCount = 0 TO 3
PULSOUT LeftServo, 750
PULSOUT RightServo, 750
PAUSE 0
NEXT


FOR pulseCount = 0 TO 7
PULSOUT LeftServo, 650
PULSOUT RightServo, 850
PAUSE 0
NEXT
RETURN

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-05 07:22
    Why are all your "PAUSE" statements zero? They should be about 20ms. Use "PAUSE 20" instead of "PAUSE 0"
  • respective98respective98 Posts: 4
    edited 2012-12-05 07:28
    Already tried it was still very jerky so changed it to 0 !
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-05 07:42
    Already tried it was still very jerky so changed it to 0 !

    Zero is wrong! Servo need a 1ms to 2ms (with some latitude) pulse every 20ms. The PAUSE 20 gives the needed pause between pulses.

    Are you looking at some example code? It seems like your sweeps may be too large (but not outrageous). I think you should try to keep your sweeps between 500 and 1000 (1ms and 2ms).

    Are your batteries fresh or freshly charged? A lot of servo problems are the result on batteries not providing enough current.

    What do you mean by "jerky"? Is just the Ping servo jerky or are the drive servos also jerky? The Ping servo moves in rather large jumps. You can make it change by smaller abouts by using smaller steps. To change the step change
    step 200
    

    to
    step 20
    

    or some other number. This will make the Ping servo turn in smaller amounts.
  • respective98respective98 Posts: 4
    edited 2012-12-05 19:04
    i changed the step 200 to step 200 and also pause to 20. When it moves forward it pauses for a few milliseconds m then continues. N with time it slows down.
  • respective98respective98 Posts: 4
    edited 2012-12-05 19:11
    Here is my current code.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    Ping PIN 15
    PingServo PIN 14
    LeftServo PIN 13
    RightServo PIN 12


    rawDist VAR Word
    sweepcount VAR Word
    x VAR Byte
    pulseCount VAR Byte




    Main:
    FOR sweepcount = 350 TO 1000 STEP 20
    FOR x = 0 TO 5
    PULSOUT 14, sweepcount
    PAUSE 20
    NEXT
    GOSUB GetSonar
    NEXT


    FOR sweepcount = 950 TO 1000 STEP 20
    FOR x = 0 TO 5
    PULSOUT 14, sweepcount
    PAUSE 20
    NEXT
    GOSUB GetSonar
    NEXT
    GOTO Main


    GetSonar:
    LOW Ping
    PULSOUT Ping, 5
    PULSIN Ping, 1, rawDist


    IF (rawDist < 600) THEN
    IF (sweepcount < 750) THEN
    GOSUB Turn_Left
    ELSEIF (sweepcount > 750) THEN
    GOSUB Turn_Right
    ELSE
    GOSUB Back_Up
    ENDIF
    ELSE
    GOSUB Forward_Pulse
    ENDIF


    RETURN


    Forward_Pulse:
    FOR pulsecount = 0 TO 5
    PULSOUT LeftServo, 850
    PULSOUT RightServo, 650
    PAUSE 20
    NEXT
    RETURN


    Turn_Left:
    FOR pulseCount = 0 TO 10
    PULSOUT LeftServo, 650
    PULSOUT RightServo, 650
    PAUSE 20
    NEXT
    RETURN


    Turn_Right:
    FOR pulseCount = 0 TO 10
    PULSOUT LeftServo, 850
    PULSOUT RightServo, 850
    PAUSE 20
    NEXT
    RETURN


    Back_Up:
    FOR pulseCount = 0 TO 3
    PULSOUT LeftServo, 750
    PULSOUT RightServo, 750
    PAUSE 20
    NEXT


    FOR pulseCount = 0 TO 7
    PULSOUT LeftServo, 650
    PULSOUT RightServo, 850
    PAUSE 20
    NEXT
    RETURN
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-05 19:52
    The main problem is that, for smooth movement, you have to issue servo control pulses roughly every 20ms. If you miss one of these, the servo will stutter as it shuts itself off, then turns itself on again. For Turn_Left and Turn_Right, you've got 10 of these pulses (200ms) before you go back and do something else (like sweep the PING and look at the distance). Forward_Pulse only lasts 100ms and Back_Up, although it lasts 200ms, involves a very short backup and then a short turn.

    Have a look at the Roaming with the PING example. This uses a number of techniques to keep the pulses flowing.

    Another option is to use a servo controller like the Propeller Servo Controller to handle the generation of the pulses. There used to be another controller called the ServoPAL, but it's discontinued at this time.
Sign In or Register to comment.