Shop OBEX P1 Docs P2 Docs Learn Events
Please post source code for smooth roaming with Ping))) — Parallax Forums

Please post source code for smooth roaming with Ping)))

jason777jason777 Posts: 11
edited 2014-04-20 20:35 in BASIC Stamp
Hello,
I just·got my boe-bot and am new to programming this thing.· I'm trying to figure out how to have the boe-bot roam with ping, but not stop to take measurements.· There is an example code file I tried, but the robot moves forward in a jerky manner.· Is there a way to keep the robot rolling smoothly, while the ping servo scans around. Or is that just too much for the basic stamp?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-22 19:33
    The problem is that, when the BoeBot is moving, you're trying to do PING distance sensing with a moving platform and all the readings have to be adjusted for the "true" position of the PING and the BoeBot. The other piece is that, when the BoeBot is waiting for a response from the PING, it can't command the servos. When the distances are long, that'll make for jerky movement. You could off-load the servo control to eliminate this part of the jerkiness. A PWMPAL is the simplest way to do this since it mounts under the Stamp chip. You'll need to rewrite the programs since the servo control works differently. You could also use a PSC (Parallax Servo Controller) to control the two wheel servos and the PING servo, but that requires its own mounting and would also need program modifications. Last choice would be to switch to a Propeller using the Protoboard. In the Object Exchange there's even a version of Basic designed for this configuration (BoeBot Basic - for BoeBot / PING / IR sensors / PING servo / Compass). There are some pictures and a description in the Completed Projects forum (http://forums.parallax.com/showthread.php?p=635533).
  • MightorMightor Posts: 338
    edited 2007-07-22 19:50
    jason777 said...
    Hello,
    I just got my boe-bot and am new to programming this thing. I'm trying to figure out how to have the boe-bot roam with ping, but not stop to take measurements. There is an example code file I tried, but the robot moves forward in a jerky manner. Is there a way to keep the robot rolling smoothly, while the ping servo scans around. Or is that just too much for the basic stamp?
    Jason,

    I had the same problem with my Boe-Bot. I tried to write a program that rotates the ping and keep the servos going at the same time. The trick is to keep the time between your wheel servos to about 20-30ms. Anything more than that and your bot will be slow and quick to stall. It is not hard to keep the wheel servos going and taking ping measurements and perhaps just stopping swivelling around the sensor only when it detects something.

    What code are you using?

    Gr,
    Mightor

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    | What the world needs is more geniuses with humility, there are so few of us left.
  • MightorMightor Posts: 338
    edited 2007-07-22 20:05
    Jason,

    I am working on some code right now that will lunge towards targets when it detects them within a certain range. It's for a SumoBot that I intend to implement on a Prop, as soon as I get the parts for it. I will post you the code when I have it finished. It is written for the BoeBot in with the BS2.

    If you are new to the BasicStamp, I cannot emphasise enough to go through the Boe-Bot book that came with the package. The sensor stuff can be a little daunting if you don't fully grasp the basics yet. There are also some other PING))) experiments in the Smart Sensors book. You can download it here: http://www.parallax.com/dl/docs/prod/sic/SmartSensors-v1.0.pdf . It's a great read. The code for the book can be found here: http://www.parallax.com/dl/sw/SmartSensorsv1.0code-v1.zip

    Remember Jason-san, you must learn to walk before fly!

    Mightor Myagi

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    | What the world needs is more geniuses with humility, there are so few of us left.

    Post Edited (Mightor) : 7/22/2007 8:10:36 PM GMT
  • jason777jason777 Posts: 11
    edited 2007-07-22 20:08
    I started out with the simple roaming from the ping sensor web page and tried changing·it to be more smooth. I dont know enough about how the servos need to be programmed yet.

    ' {$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 20
      NEXT
      GOSUB GetSonar
     NEXT
     FOR sweepcount = 950 TO 550 STEP 200
      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
    

    ·
  • jason777jason777 Posts: 11
    edited 2007-07-22 20:09
    thanks guys
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-07-23 09:17
    Jason -

    If you don't stop when you take a measurement with the PING))) every measurement taken that way will be inaccurate. What's the point of having the PING))) then?

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonathanJonathan Posts: 1,023
    edited 2007-07-23 16:18
    Bruce,

    It can be very handy to know if there is an object while moving, for example if I detect an object with 20 cm in front of my 'bot, I stop and take a more accurate reading. It can also be usefull for room mapping and tracking. Sometimes just knowing that the object is there is important.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-07-23 17:41
    Jonathan -

    As I remember the following phrase was mising from Jason's post:

    "I stop and take a more accurate reading"

    OTOH, I'm not sure that the following is going to happen accurately and repeatably if you're moving:

    "if I detect an object with 20 cm in front of my 'bot"

    'Nuf said -

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • walice_drelwalice_drel Posts: 81
    edited 2007-08-15 18:10
    This code should work for you.

    ' =========================================================================
    '
    ' File...... RoamingWithPING.bs2
    ' Purpose... Roam And Scan Using PING))) Mounting Bracket
    ' Author.... Parallax, Inc.
    ' E-mail.... support@parallax.com
    ' Started...
    ' Updated... 12-21-2005
    '
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    ' =========================================================================


    '
    [noparse][[/noparse] Program Description ]

    ' This programs demonstrates roaming with the Parallax PING))) Mounting
    ' Bracket, which allows you to pan-scan with your Parallax PING))) sensor.
    '
    ' This program assumes you have already set your BOE-Bot up for roaming
    ' with IR sensors. You must also have the PING))) Mounting bracket
    ' installed as per the instructions, with the servo connected to P14 and
    ' the PING))) sensor connected to P15.
    '
    ' Due to the way the PING))) bracket mounts you may have to trim your IR
    ' detectors down so that they don't stick up in the way of the moving
    ' PING))) bracket as it rotates. It's best to angle them off at 45
    ' degree angles so that the BOE-Bot doesn't run into anything while
    ' moving along a wall at a narrow angle.
    '
    ' The BOE-Bot will now roam around and when it senses an object, it will
    ' scan within a 180 degree field of view for the clearest path, which it
    ' will then navigate scanning for an object again. The IR Sensors prevent
    ' hitting a wall when coming at it from a narrow angle where the PING)))
    ' might have trouble seeing it due to the lack of reflection of sound.
    '
    ' Calibration is important to this code working properly. If you do not
    ' have the correct values for your servos then you may get strange results
    ' from your BOE-Bot. The necessary calibration information is listed in
    ' each section of the code where it is required.

    '
    [noparse][[/noparse] Revision History ]

    ' This code is basically a modified version of the Roaming With IR code
    ' from the Robotics With The BOE-Bot Manual, written by Andy Lindsay.
    ' Much of the original code was left untouched so you can see how it was
    ' altered.


    '
    [noparse][[/noparse] I/O Definitions ]

    Piezo PIN 4 ' Piezo Speaker
    RightServo PIN 12 ' Right Servo
    LeftServo PIN 13 ' Left Servo
    PingServo PIN 14 ' PING))) Servo
    Ping PIN 15 ' PING))) Sensor


    '
    [noparse][[/noparse] Variables ]

    irDetectLeft VAR Bit ' Variable For Left IR Input
    irDetectRight VAR Bit ' Variable For Right IR Input
    pulseCount VAR Byte ' Used For Measuring Turns
    distance VAR Word ' Current Distance Of Object
    oldDistance VAR Word ' Old Distance Value
    counter VAR Word ' PING))) Cycle Counter
    task VAR Nib ' Current Task


    '
    [noparse][[/noparse] Initialization ]

    FREQOUT Piezo, 2000, 3000 ' Signal Program Start/Reset


    '
    [noparse][[/noparse] Program Code ]

    Main:
    DO

    FREQOUT 8, 1, 38500 ' Emit 38.5 kHz IR To Left
    irDetectLeft = IN9 ' Store IR Detection Values

    FREQOUT 2, 1, 38500 ' Emit 38.5 kHz IR To Right
    irDetectRight = IN0 ' Store IR Detection Values

    IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
    GOSUB Ping_Around ' Object Detected via IR Forward
    ELSEIF (irDetectLeft = 0) THEN
    GOSUB Ping_Around ' Object Detected via IR Left
    ELSEIF (irDetectRight = 0) THEN
    GOSUB Ping_Around ' Object Detected via IR Right
    ENDIF

    counter = counter + 1 ' Increment Passive Counter

    IF counter > 10 THEN ' Wait For 10 Servo Pulses
    GOSUB Ping_Out ' Activate PING)))
    ENDIF

    IF (distance > 30) THEN ' Is Object Farther Than 30 cm?
    GOSUB Forward_Pulse ' If Yes Go Forward
    ELSE
    GOSUB Ping_Around ' Otherwise Scan For Clear Path
    ENDIF

    LOOP


    '
    [noparse][[/noparse] Subroutines ]

    ' *************************************************************************
    ' * USE THE APPROPRIATE PULSOUT VALUES TO MAKE YOUR BOE-BOT MOVE FORWARD *
    ' * WHILE THE PING))) IS FACING FORWARD. *
    ' *************************************************************************

    Forward_Pulse: ' Send A Single Forward Pulse
    PULSOUT PingServo, 750 ' Ping Servo Forward Pulse Value
    PULSOUT LeftServo, 850 ' Left Servo Forward Pulse Value
    PULSOUT RightServo, 650 ' Right Servo Forward Pulse Value
    PAUSE 20 ' Refresh Delay
    RETURN

    ' *************************************************************************
    ' * USE THE APPROPRIATE PULSOUT VALUES TO MAKE YOUR BOE-BOT TURN LEFT 90 *
    ' * DEGREES. USE THE SAME VALUE AS ABOVE FOR THE PING))) BRACKET SERVO. *
    ' *************************************************************************

    Turn_Left: ' Left Turn, About 45 Degrees
    FOR pulseCount = 0 TO 7 ' Number Of Pulses To Turn
    PULSOUT PingServo, 750 ' Ping Servo Forward Pulse Value
    PULSOUT LeftServo, 650 ' Left Servo Left Pulse Value
    PULSOUT RightServo, 650 ' Right Servo Left Pulse Value
    PAUSE 20 ' Refresh Delay
    NEXT
    RETURN

    ' *************************************************************************
    ' * USE THE APPROPRIATE PULSOUT VALUES TO MAKE YOUR BOE-BOT TURN RIGHT 90 *
    ' * DEGREES. USE THE SAME VALUE AS ABOVE FOR THE PING))) BRACKET SERVO. *
    ' *************************************************************************

    Turn_Right: ' Right Turn, About 45 Degrees
    FOR pulseCount = 0 TO 7 ' Number Of Pulses To Turn
    PULSOUT PingServo, 750 ' Ping Servo Forward Pulse Value
    PULSOUT LeftServo, 850 ' Left Servo Right Pulse Value
    PULSOUT RightServo, 850 ' Right Servo Right Pulse Value
    PAUSE 20 ' Refresh Delay
    NEXT
    RETURN

    ' *************************************************************************
    ' * USE THE APPROPRIATE PULSOUT VALUES TO MAKE YOUR BOE-BOT MOVE BACKWARD *
    ' * WHILE THE PING))) IS FACING FORWARD. *
    ' *************************************************************************

    Back_Up: ' Back Up
    FOR pulseCount = 0 TO 40 ' Number Of Pulses To Backup
    PULSOUT PingServo, 750 ' Ping Servo Forward Pulse Value
    PULSOUT LeftServo, 650 ' Left Servo Backup Pulse Value
    PULSOUT RightServo, 850 ' Right Servo Backup Pulse Value
    PAUSE 20 ' Refresh Delay
    NEXT
    RETURN

    Ping_Out: ' PING)))
    counter = 0 ' Reset Passive Delay Counter
    LOW Ping ' Force PING))) Line Low
    PULSOUT Ping, 5 ' Activate PING))) Pulse
    PULSIN Ping, 1, distance ' Receive Return Pulse
    distance = distance ** 2257 ' Calculate Distance
    RETURN

    Ping_Around: ' Start 180 Degree Pan-Scan
    counter = 0 ' Reset Passive Delay Counter
    oldDistance = 30 ' Current Old Distance Values
    task = 0 ' Current Task Priority

    ' *************************************************************************
    ' * USE THE APPROPRIATE PULSOUT VALUE TO MAKE YOUR PING))) *
    ' * TURN 90 DEGREES LEFT. *
    ' *************************************************************************

    FOR pulseCount = 0 TO 20 ' Number Of Pulses To Spin
    LOW Ping ' Force PING))) Line Low
    PULSOUT PingServo, 1085 ' Ping Servo 90 Left Pulse Value
    PULSOUT Ping, 5 ' Activate PING)))
    PULSIN Ping, 1, distance ' Receive Distance Value
    PAUSE 20 ' Refresh Delay
    NEXT

    distance = distance ** 2257 ' Calculate Distance In cm
    IF distance > oldDistance THEN ' Is distance > Last Clear Path
    oldDistance = distance ' Update oldDistance Value
    task = 1
    ENDIF

    ' *************************************************************************
    ' * USE THE APPROPRIATE PULSOUT VALUE TO MAKE YOUR PING))) *
    ' * TURN 45 DEGREES LEFT. *
    ' *************************************************************************

    FOR pulseCount = 0 TO 20 ' Number Of Pulses To Spin
    LOW Ping ' Force PING))) Line Low
    PULSOUT PingServo, 850 ' Ping Servo 45 Left Pulse Value
    PULSOUT Ping, 5 ' Activate PING)))
    PULSIN Ping, 1, distance ' Receive Distance Value
    PAUSE 20 ' Refresh Delay
    NEXT

    distance = distance ** 2257 ' Calculate Distance In cm
    IF distance > oldDistance THEN ' Is distance > Last Clear Path
    oldDistance = distance ' Update oldDistance Value
    task = 2
    ENDIF

    ' *************************************************************************
    ' * USE THE APPROPRIATE PULSOUT VALUE TO MAKE YOUR PING))) *
    ' * TURN 45 DEGREES RIGHT. *
    ' *************************************************************************

    FOR pulseCount = 0 TO 20 ' Number Of Pulses To Spin
    LOW Ping ' Force PING))) Line Low
    PULSOUT PingServo, 400 ' Ping Servo 45 Right Pulse Value
    PULSOUT Ping, 5 ' Activate PING)))
    PULSIN Ping, 1, distance ' Receive Distance Value
    PAUSE 20 ' Refresh Delay
    NEXT

    distance = distance ** 2257 ' Calculate Distance In cm
    IF distance > oldDistance THEN ' Is distance > Last Clear Path
    oldDistance = distance ' Update oldDistance Value
    task = 3
    ENDIF

    ' *************************************************************************
    ' * USE THE APPROPRIATE PULSOUT VALUE TO MAKE YOUR PING))) *
    ' * TURN 90 DEGREES RIGHT. *
    ' *************************************************************************

    FOR pulseCount = 0 TO 20 ' Number Of Pulses To Spin
    LOW Ping ' Force PING))) Line Low
    PULSOUT PingServo, 225 ' Ping Servo 90 Right Pulse Value
    PULSOUT Ping, 5 ' Activate PING)))
    PULSIN Ping, 1, distance ' Receive Distance Value
    PAUSE 20 ' Refresh Delay
    NEXT

    distance = distance ** 2257 ' Calculate Distance In cm
    IF distance > oldDistance THEN ' Is distance > Last Clear Path
    oldDistance = distance ' Update oldDistance Value
    task = 4
    ENDIF

    ON task GOSUB Task0, Task1, Task2, Task3, Task4

    distance = 50 ' Prevent Scan From Looping

    RETURN

    Task0: ' Forward Was Clearest Path
    GOSUB Turn_Right ' This Could Mean Narrow Path
    GOSUB Turn_Right ' So We'll Turn Around
    GOSUB Turn_Right ' You Can Change The Behavior
    GOSUB Turn_Right ' Of Any Of The Tasks
    RETURN

    Task1: ' 90 Degrees Left Was Clearest
    GOSUB Turn_Left
    GOSUB Turn_Left
    RETURN

    Task2: ' 45 Degrees Left Was Clearest
    GOSUB Turn_Left
    RETURN

    Task3: ' 45 Degrees Right Was Clearest
    GOSUB Turn_Right
    RETURN

    Task4: ' 90 Degrees Right Was Clearest
    GOSUB Turn_Right
    GOSUB Turn_Right
    RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    boe-bot001.jpg
  • EleutherEleuther Posts: 20
    edited 2012-10-11 15:55
    I was looking at this program and I thought it was pretty legit so I tried it. But My robot only scans around for a second then turns a random direction and keeps repeating this help.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-12 02:47
    Eleuther, on the Ping))) product page http://www.parallax.com/tabid/768/ProductID/92/Default.aspx in the downloads and resources section are a set of demo programs. The zip Roaming with Ping))) should give you what you need.

    Here's a link.

    http://www.parallax.com/Portals/0/Downloads/src/prod/RoamingWithPING-V1.0.zip
  • ajwardajward Posts: 1,130
    edited 2012-10-12 06:33
    Eleuther wrote: »
    I was looking at this program and I thought it was pretty legit so I tried it. But My robot only scans around for a second then turns a random direction and keeps repeating this help.

    Make sure your batteries are fresh. Weak batteries can cause the Boe Bot to behave erratically.

    @
  • wperkowperko Posts: 66
    edited 2014-04-20 20:35
    Hi,

    I'm approaching the problem a little differently ... I'm including the concept of the TableBot 1 Challange ... that is not just to roam, but to roam around on a table top and not fall off the table ...

    I have my new robot design set and it works pretty good;
    http://www.brainless.org/lrobotorium/Products/BOE-Bot/IMG_1886-20140418-PING-HeadBOE-Bot-c.jpg

    The 3D CAD Model;
    http://www.brainless.org/lrobotorium/Products/BOE-Bot/PingHead-BOE-Bot3-c.jpg

    Here I am running a fundamental program to test the PING, LEDs, Piezo speakers, neck and head servos and wheel servo motors ...
    https://www.youtube.com/watch?v=Gx-N6vRkfAQ

    Eventually I will write a roaming program for all this and maybe one or two other types of roaming programs with a menu selection through the IR sensor ... for now, here is the code I've started with for the video test;

    ' PING-HeadBOE-Bot-v02.bs2
    ' by Walt Perko the SolidWorksMagi

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    LED0 PIN 0
    LED1 PIN 1
    LED2 PIN 2

    IR PIN 7

    PIEZOL PIN 8
    PIEZOR PIN 9

    srvohd PIN 11
    srvonk PIN 15

    wheelL PIN 12
    wheelR PIN 13


    i VAR Word
    j VAR Word

    ' PING Conversion constants for room temperature measurements.

    PINGR PIN 14

    DistanceF VAR Word
    DistanceD VAR Word
    DistanceL VAR Word
    DistanceR VAR Word


    ' Default Settings
    CmConstant CON 2260
    InConstant CON 890

    cmDistance VAR Word
    inDistance VAR Word
    time VAR Word
    ' PING Conversion constants for room temperature measurements.

    ' Variable Assignments
    DistanceF = 10
    DistanceD = 10
    DistanceL = 10
    DistanceR = 10


    ' START Main Program Body * * * * * * * * * * * * * * * * * * * * * * * * * *
    DO
    ' R we near a tables edge?
    GOSUB tabletest

    GOSUB fwrd
    GOSUB PING
    GOSUB flash

    GOSUB lookL
    GOSUB PING
    GOSUB flash

    GOSUB lookR
    GOSUB PING
    GOSUB flash

    GOSUB closest

    'PAUSE 500
    LOOP
    ' END Main Program Body * * * * * * * * * * * * * * * * * * * * * * * * * * *

    ' Subroutines * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    ' Flash the LEDs
    flash:
    FOR i = 0 TO 1
    HIGH LED0
    PAUSE 30
    LOW LED0
    HIGH LED1
    PAUSE 30
    LOW LED1
    HIGH LED2
    PAUSE 30
    LOW LED2
    PAUSE 25
    HIGH LED2
    PAUSE 30
    LOW LED2
    HIGH LED1
    PAUSE 30
    LOW LED1
    HIGH LED0
    PAUSE 30
    LOW LED0
    NEXT
    RETURN

    ' START TableTopTest * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    tabletest:
    GOSUB lookdn
    GOSUB PING
    'GOSUB flash
    IF DistanceD > 5 THEN GOSUB backup
    RETURN
    ' END TableTopTest * * * * * * * * * * * * * * * * * * * * * * * * * * * * **


    backup:
    ' Tables Edge has been Detected ... BackUp and Turn about 30°
    GOSUB warning
    GOSUB stepB
    GOSUB warning
    GOSUB stepB
    RETURN
    END

    warning:
    GOSUB lookU
    FOR i = 0 TO 1
    PULSOUT srvonk, 375
    HIGH LED0
    LOW LED1
    HIGH LED2
    FREQOUT PIEZOL, 100, 3200
    FREQOUT PIEZOR, 100, 2500
    PULSOUT srvonk, 1000
    LOW LED0
    HIGH LED1
    LOW LED2
    FREQOUT PIEZOL, 100, 3200
    FREQOUT PIEZOR, 100, 2500
    PULSOUT srvonk, 750
    NEXT
    RETURN


    lookdn:
    DEBUG CLS, "Look Down"
    FOR j = 0 TO 50
    PULSOUT srvonk, 750
    PULSOUT srvohd, 1200
    PAUSE 20
    NEXT

    GOSUB PING
    DistanceD = cmDistance
    RETURN

    lookU:
    DEBUG CLS, "Look UP"
    FOR j = 0 TO 50
    PULSOUT srvonk, 750
    PULSOUT srvohd, 350
    PAUSE 20
    NEXT
    RETURN


    fwrd:
    DEBUG CLS, "Look Forward"
    FOR j = 0 TO 50
    PULSOUT srvonk, 750
    PULSOUT srvohd, 650
    PAUSE 20
    NEXT

    GOSUB PING
    DistanceF = cmDistance
    RETURN


    lookL:
    DEBUG CLS, "Look Left"
    FOR j = 0 TO 50
    PULSOUT srvonk, 1200
    PULSOUT srvohd, 1200
    PAUSE 20
    NEXT

    GOSUB PING
    DistanceL = cmDistance
    RETURN


    lookR:
    DEBUG CLS, "Look Right"
    FOR j = 0 TO 50
    PULSOUT srvonk, 325
    PULSOUT srvohd, 1200
    PAUSE 20
    NEXT

    GOSUB PING
    DistanceR = cmDistance
    RETURN

    ' START Drive the Wheels * * * * * * * * * * * * * * * * * * * * * * * * * **
    stepF:
    DEBUG CLS, CR, "Step Foward ... ", DEC distanceF
    IF distanceF < 10 THEN GOSUB stepR2
    FOR j = 0 TO 89
    PULSOUT wheelL, 800
    PULSOUT wheelR, 700
    NEXT
    RETURN

    stepB:
    DEBUG CLS, CR, "Step Back ... ", DEC distanceF
    FOR j = 0 TO 199
    PULSOUT wheelL, 800
    PULSOUT wheelR, 700
    NEXT
    RETURN

    stepL:
    DEBUG CLS, CR, "Step Left ... ", DEC distanceL
    'IF distanceL < 10 THEN GOSUB stepR
    FOR j = 0 TO 89
    PULSOUT wheelL, 700
    PULSOUT wheelR, 700
    NEXT
    RETURN

    stepR:
    DEBUG CLS, CR, "Step Right ... ", DEC distanceR
    'IF distanceR < 10 THEN GOSUB stepL
    FOR j = 0 TO 89
    PULSOUT wheelL, 800
    PULSOUT wheelR, 800
    NEXT
    RETURN

    stepR2:
    DEBUG CLS, CR, "Step Right2 ..."
    'IF distanceR < 10 THEN GOSUB stepL
    FOR j = 0 TO 89
    PULSOUT wheelL, 800
    PULSOUT wheelR, 800
    NEXT

    FOR j = 0 TO (3 * distanceF)
    GOSUB stepF
    NEXT
    RETURN
    ' END Drive the Wheels * * * * * * * * * * * * * * * * * * * * * * * * * * **

    ' START Closest Object to Move Towards Until TOO Close. * * * * * * * * * * *
    closest:
    DEBUG CLS, "CLOSEST", DEC cmDistance
    IF distanceF < 10 THEN GOSUB stepR2
    IF (distanceF < distanceR) AND (distanceF < distanceL) THEN stepR
    IF (distanceR < distanceF) AND (distanceR < distanceL)THEN stepR
    IF distanceL < distanceF AND (distanceL < distanceR)THEN stepL

    RETURN
    ' END Closest Object to Move Towards Until TOO Close. * * * * * * * * * * * *

    ' END Drive the Wheels * * * * * * * * * * * * * * * * * * * * * * * * * * **

    ' PING Conversion constants for room temperature measurements.
    PING:
    'DO
    FOR i = 0 TO 9
    PULSOUT PINGR, 5
    PULSIN PINGR, 1, time

    cmDistance = cmConstant ** time
    inDistance = inConstant ** time

    DEBUG HOME, CR, CR, DEC3 cmDistance, " cm"
    DEBUG CR, DEC3 inDistance, " in"

    PAUSE 100
    NEXT
    'LOOP
    RETURN
    ' PING Conversion constants for room temperature measurements.


    END


    ' START SONY TV IR remote variables * * * * * * * * * * * * * * * * * * * * *

    irPulse VAR Word ' Stores pulse widths
    remoteCode VAR Byte ' Stores remote code

    'IR PIN 7

    DEBUG "Press/release remote buttons..."

    DO ' Main DO...LOOP

    remoteCode = 0

    DO ' Wait for end of resting state.
    RCTIME IR, 1, irPulse
    LOOP UNTIL irPulse > 1000

    PULSIN IR, 0, irPulse ' Get data pulses.
    IF irPulse > 500 THEN remoteCode.BIT0 = 1
    RCTIME IR, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT1 = 1
    RCTIME IR, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT2 = 1
    RCTIME IR, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT3 = 1
    RCTIME IR, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT4 = 1
    RCTIME IR, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT5 = 1
    RCTIME IR, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT6 = 1

    ' Map digit keys to actual values.
    IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
    IF (remoteCode = 10) THEN remoteCode = 0

    DEBUG CLS, ? remoteCode

    LOOP ' Repeat main DO...LOOP
    ' END SONY TV IR remote variables * * * * * * * * * * * * * * * * * * * * * *

    END


    C U L8r, ...
Sign In or Register to comment.