Shop OBEX P1 Docs P2 Docs Learn Events
GIGA Ping Roaming program — Parallax Forums

GIGA Ping Roaming program

SciTech02SciTech02 Posts: 154
edited 2006-09-27 17:59 in Robotics
I developed a Giga roaming program that uses traits from RoamingWithThePing, and FastIrRoaming.· Now, if the Boe-Bot rolls close to a wall at a tight angle, instead of doing a pan scan, it will just turn out of the way, making it much more faster.· Now it dosn't have to pan-scan at every little object it detects.· However, I has some problems.· When it would·send a pulse to turn, the weel that should turn backward, would just click and stay still.· I put the single pulses into·some subroutines, Click_Left and Click_Right.· Now it just clicks backward at least.· But for dodging small objects quickly, it's fine.· You·might have·to add your own servo pulse values for it to work properly.··

Here's the program: (Note: I could not upload the file, because it said it could not upload msword documents).

' Robotics with the Boe-Bot - GIGARoamingProgram.bs2
' Boe-Bot uses elements from FastIrRoaming and RoamingWithThePing, for an even more
' higher preformance roaming routine.
·
' {$STAMP BS2}······················································· ' Stamp directive.
' {$PBASIC 2.5}························································ ' PBASIC directive.
·
DEBUG "Program Running!"
·
Piezo············ PIN···· 4·································· ············' I/O Definitions.
Ping············· PIN···· 11
PingServo····· PIN···· 14
·
oldDistance··· VAR···· Word······································· ' Variables.
distance········ VAR···· Word
irDetectLeft···· VAR···· Bit
irDetectRight·· VAR···· Bit
counter·········· VAR···· Word
pulseCount···· VAR···· Byte
task·············· VAR···· Nib
·
FREQOUT Piezo, 2000, 3000····································· ' Signal program start.
·
DO··········································································· ' Start.
·
· FREQOUT 8, 1, 38500············································· ' Send pulse.
· irDetectLeft = IN9···················································· ' Store output.
· FREQOUT 2, 1, 38500············································· ' Send pulse.
· irDetectRight = IN0·················································· ' Store output.
·
· IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN···· ' If both sensers detect somthing.
··· GOSUB Ping_Around············································ ' Could mean a wall, so Ping around.
· ELSEIF (irDetectLeft = 0) THEN······························· ' If Left senser detects somthing.
··· GOSUB Click_Right································ ·············' Could mean a wall, so click right.
· ELSEIF (irDetectRight = 0) THEN···························· ' If Right senser detects somthing.
··· GOSUB Click_Left················································ ' Could mean a wall, so click left.
· ELSE···································································· ' If coast is clear.
··· PULSOUT PingServo, 755····································· ' Go forward.
··· PULSOUT 13, 820
··· PULSOUT 12, 650
··· PAUSE 15
· ENDIF
·
· counter = counter + 1·············································· ' Increase passive counter
·
· IF counter > 9 THEN··············································· ' Wait for nine servo pulses
··· GOSUB Ping_Out················································ ' and activate PING))).
· ENDIF
·
· IF (distance > 30) THEN········································· ' If distance is greater then 30
··· PULSOUT 13, 820··············································· ' go forward.
··· PULSOUT 12, 650
··· PAUSE 15
· ELSE·················· ·················································' If not
··· GOSUB Ping_Around·········································· ' Ping around.
· ENDIF
·
LOOP···································································· ' Repeat forever.
·
Click_Right:···························································· ' Subroutines
· FOR pulseCount = 0 TO 1
··· PULSOUT PingServo, 755
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
·
Click_Left:
· FOR pulseCount = 0 TO 1
··· PULSOUT PingServo, 755
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
·
Turn_Left:
· FOR pulseCount = 0 TO 7
··· PULSOUT PingServo, 755
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
·
Turn_Right:
· FOR pulseCount = 0 TO 7
··· PULSOUT PingServo, 755
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
·
Ping_Out:
· counter = 0
· LOW Ping
· PULSOUT Ping, 5
· PULSIN· Ping, 1, distance
· distance = distance ** 2257
· RETURN
·
Ping_Around:
· counter = 0
· oldDistance = 30
· task = 0
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 1210
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 1
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 950
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 2
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 490
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 3
· ENDIF
·
· FOR pulseCount = 0 TO 20
··· LOW Ping
··· PULSOUT PingServo, 300
··· PULSOUT Ping, 5
··· PULSIN· Ping, 1, distance
··· PAUSE 20
· NEXT
·
· distance = distance ** 2257
· IF distance > oldDistance THEN
··· oldDistance = distance
··· task = 4
· ENDIF
·
· ON task GOSUB Task0, Task1, Task2, Task3, Task4
·
· distance = 50
·
· RETURN
·
Task0:
· GOSUB Turn_Right
· GOSUB Turn_Right
· GOSUB Turn_Right
· GOSUB Turn_Right
· RETURN
·
Task1:
· GOSUB Turn_Left
· GOSUB Turn_Left
· RETURN
·
Task2:
· GOSUB Turn_Left
· RETURN
·
Task3:
· GOSUB Turn_Right
· RETURN
·
Task4:
· GOSUB Turn_Right
· GOSUB Turn_Right
· RETURN

What do you think?

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-17 17:58
    Save you programs as straight text and they will upload cleanly, and be visible in most (if not all) browsers without downloading. Embedding listing in threads is cumbersome and should be avoided. That said, congrats on your program. I find the order of things a little mysterious, but if it works, that's what counts. You could also combine the IR bits into a Nib variable and use SELECT-CASE in place of the compound IF-THEN-ELSEIF construct; but that's a style choice and not required.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-17 18:06
    The reason the RaomingWithPING does a Pan/Scan when it sees something via IR is that its original intent was to head for the most wide-open area.· So whenever it sees an obstacle it would try to find a new open heading.· In this case it is moving along a wall instead of looking for the most open path, which in a way contradicts the original intent, but if it does what you want I guess that's what counts.· The main problem with the original code was calibrating all of the servos for each set of motions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-17 21:30
    I'm sorry if it offended you, but I mainly created this program·so it could·corecct it's path so it didn't have to do another pan-scan when it didn't need to.· Also,·you can·ajust the program to·act more like the RoamingWithThePing program by ajusting the IF counter·> 9 to IF counter > 8 or less.·
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-03-17 21:50
    Here is a code (in development) that we ran yesterday- the bot went around the entire office for about 2 hours without getting stuck once. Dave A. named it the "duck code"-

    I'll post updates as I clean up the code. This code only needs the PING))) and the PING))) bracket. (Sans IR).


    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-17 22:47
    SciTech02 said...(trimmed)
    I'm sorry if it offended you, but I mainly created this program·so it could·corecct it's path so it didn't have to do another pan-scan when it didn't need to.
    No offense taken.· I was simply trying to explain the intent of the original code.· I actually wrote several PING Programs for the BOE-Bot.· In fact the one posted above is almost exactly like the first draft I have.· The one problem that crept up a few times was when the BOE-Bot came at a wall from a slight angle and the PING happened to be facing the other way.· It would roll up the wall and flip.· So I decided to change the behavior a little bit.· Tuning becomes the problem in this case though with positions of the PING Servo and left/right servo calibration.· Of course, you get that in the standard BOE-Bot code as well since there are inherent differences in servos.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 3/17/2006 10:51:20 PM GMT
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-19 22:02
    Thank you Ryan for the program.· It's verry interesting on how you got it to continuously pan scan.· There was a problem with the program, in the Get_Sonar subroutine, I had to change it where it said Turn_Left to Turn_Right and vise versa, then it worked·like it was supposed to.··If only we can get it to do it faster, it would be·even beter.· Then if we could make it run smothly not click.· Then I could intergrate it into my roaming program, and it would be fantastic. smile.gif········· -SciTech02.

    Post Edited (SciTech02) : 3/19/2006 10:05:10 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-20 03:07
    When I worked on my pan/scan routine the problem with making it go faster was that the servo would receive the new PULSOUT value before it made it to the previous one.· When this happens the servo will start stuttering all over, which is another reason I switched the way I did it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-03-20 15:06
    I have an updated version of that code, I'll clean it up and post it later. Dave liked the "duck-like" movement. I can also cut up the scan into smaller sections. The only reason you would have to change right and left would be if your servo was turned to the other side (the 'direction' you mounted the pan servo)-

    You can also work with the distance of detection by changing the value of the condition to turn.

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • DgswanerDgswaner Posts: 795
    edited 2006-09-27 05:30
    I purchased a Ping))), Works Great love it, I also downloaded the code for Romaing with Ping.
    I'm having a bit of trouble controlling the servo with the ping mounted on it. I can't get the roaming program or a program that I have written myself working right. I've been away from my BS2sx for a while and know I'm missing something easy and I can't find anything in the group that relates to my problem. here a sample:

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    PULSOUT 10, 1300 'move to position a
    PAUSE 2000 'wait 2 sec.
    PULSOUT 10, 2700 'move to position b
    PAUSE 2000 'wait 2 sec.
    END

    simple right?
    this code is working very oddly, when I delete the position b part of the code it works fine moving the servo to the desired spot. but as soon as I use the whole code the servo moves to the a position and then stops and twitches once like it wants to go to the b position but it then stops. I added some debug line to see what was going on and I get weird output. I also have to hit reset twice quickly for it to work as mentioned. I don't think it's the stamp because I can run other programs on it with no problems. I have tried other i/o lines I have had it powered from the stamp and from a battery with similar results. i have also tried a different servo. I have also verified the position for the roaming software but it behaves wierd also.

    What am I missing here? could someone send me some sample code or tell me what I'm doing wrong. I'm at a loss.

    Thanks for your help and time

    Dave
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-09-27 07:09
    Dave -

    Although I didn't stop to calculate it, it sounds like 2700 is beyond the end range of the servo.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-27 15:23
    Dave,
    ·
    ·· You should start a new post for your question.· Bruce, for the BS2sx that value is in range for the servo, since it uses .8 uS resolution rather than 2 uS resolution.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • DgswanerDgswaner Posts: 795
    edited 2006-09-27 17:59
    I thought it might be the value is out of range, so I tried lower ranges but it made no difference... nor did the lower values get the servo to work. I can move the servo to any position using one pulsout command but when I add a second command thats when it starts misbehaving. I know the values for all of the required 45, 90 and forward positions I just can't get the servo to work. I found the Ping)))Dar code after my first post it behaves the same way. but the ping portion of the code works great.. What servo does the Boe-bot use. I'll get one of those if I need to.

    thanks for the help.

    new topic... sorry meant to start a new thread.
Sign In or Register to comment.