Shop OBEX P1 Docs P2 Docs Learn Events
I need help with my boe-bot project for class — Parallax Forums

I need help with my boe-bot project for class

StatzStatz Posts: 28
edited 2008-11-17 22:34 in BASIC Stamp
So I have a boe-bot project due i think 6 or 8 weeks for class and I've decided to make the boe-bot draw out a room while roaming around it and calculate the area and the perimeter as well. I just starting learning programming this semester as well, so I know I'm going to have a lot of trouble in this class. Also! We're supposed to work in groups of two for this class, but I'm partnerless since my partner dropped out. I'm eager to try this and failing or passing isn't a main concern, because I'm taking this class for personal experience, because robots is my dream. So here's my code so far, Its just a really really rough sketch of the program.

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

'====================Declare Variables=====================
W VAR Word        'Boe-Bot Going West
S VAR Word          'Boe-Bot Going South
N VAR Word          'Boe-Bot Going North
E VAR Word          'Boe-Bot Going East
pulseCount VAR Word
forwardCount VAR Byte        'Times Moved Forward
turnCount VAR Byte           'Record Turning
lineDirection VAR Word       'Either the "-" or "|"

'===================Initialize Variables====================
W = 1
E = 1
S = 0
N = 0



'===================Main Routine======================

DO

IF (IN5 = 0) AND (IN7 = 0) THEN  'Both whiskers are hit
  GOSUB Turn_Right

ELSEIF {Laser Activated} THEN    'When Laser sees no object
 GOSUB Turn_Left

ELSE               'Keep Driving Forward
  forwardCount = forwardCount + 1         'Count How Many Times Moved Forward
  PULSOUT 13, 850
  PULSOUT 12, 650
  PAUSE 20

ENDIF

lineDirection = turnCount%2               'To make the following case Statement 0 or 1


SELECT (lineDirection)
  CASE 0
    DEBUG "-"
  CASE ELSE
    DEBUG "|"
ENDSELECT


LOOP






'===================Sub Routines===================



'----------Turn Right Routine--------
Turn_Right:
  '---Move Backwards---
  turnCount = turnCount + 1
  FOR pulseCount = 0 TO 20
    PULSOUT 13, 650
    PULSOUT 12, 850
    PAUSE 20
  NEXT

  '---Turn Right---
  FOR pulseCount = 0 TO 20
    PULSOUT 13, 850
    PULSOUT 12, 850
    PAUSE 20
  PAUSE 20
  NEXT

RETURN



'----------Turn Left Routine---------
Turn_Left:
'---Turn Left---
  turnCount = turnCount - 1
  FOR pulseCount = 0 TO 20
    PULSOUT 13, 850
    PULSOUT 12, 850
    PAUSE 20
  NEXT

RETURN

'-----------Debugging the East "-"--------------
'**Still In Progress**
debug_East:
FOR E = 0 TO forwardCount
DEBUG "-"
NEXT
RETURN


'-----------Debugging the South "|"-----------
'**Still in Progress**
debug_South:
FOR S = 0 TO forwardCount
DEBUG CR, " "
NEXT
DEBUG "|"
RETURN





I dont really want anyone to do my project for me, I just need a little advice on how I should go about writing my code. So here are the goals:

1.Make The Boe-bot Move around the room. When it bumps into the wall, the bump sensor will make it turn right. When The laser sees that there isn't a wall to the left, The Boe-bot Turns left.
2.After the boe-bot is done moving around the confined area, it is plugged into the computer and draws out the room with "-" and "|' on the debug screen.
3.The robot also finds a way to calculate the area and the perimeter of the room it roamed around


I know this is hard, but I just need ideas on how I should go about writing the program. Thanks a lot btw. I'm really excited about this project roll.gif

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-10-22 20:16
    The way that you have it set up right now is not going to work. You have measurements given in #number of commands to the servos. What you need is a pair of encoders. With the method that you have currently, you might get a 50% accuracy. With encoders, you'll get something more like >90%. If you have the parts, you can build your own, or parallax sells a kit.

    For now, you should just have the BOE Bot measure the length of each side, and display that. You can save the drawing until later when everything else works.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-22 20:18
    A couple of questions:

    Which dirrection are you going? Clockwise or anit-clockwise?
    What are your sensors and where are they positioned?
    How exactly do you plan to stay close to a wall?
    What defines a "corner" in your program?
  • StatzStatz Posts: 28
    edited 2008-10-23 01:34
    Alright THanks SRLM

    So here are the answers to your questions.

    The Boe-bot is going to be going Clockwise, so the bump sensors will be in the front. Whenever the bump sensors are hit, the robot will 90 degree turn to the right.

    The boe-bot will also have a laser pointing to the left, which will be scanning the wall the whole time. When it sees that there is no more wall, it will turn to the left and continue.

    I'll have the boe-bot start off going east against the wall and to make sure it stays close to the wall, I'll have the laser make sure it isn't too far from the wall.

    I actually don't know yet what is going to be a corner, but I will definately look into that. The ping sensors will help with that rite?

    Thanks again.
  • StatzStatz Posts: 28
    edited 2008-10-23 01:40
    Do you thinnk I should just use the ping sensors for all of it?
  • SRLMSRLM Posts: 5,045
    edited 2008-10-23 02:17
    Where did you get a laser and how are you planning on using it? You can't just point a laser and hope that it gives you useful data...

    Anyway, some IR would probably be the best tool to use (cheap mostly). The ping might work, but it's overkill. Plus you'd need to stay minimum distance away from the wall (something like 2 or 3 inches) due to the ping limitations.

    Why are you turning left? I envision a box that the BOE goes around in, and since it's going clockwise it can only turn right.
  • StatzStatz Posts: 28
    edited 2008-10-23 03:36
    So I'm in class right now and am learning how to use the infrared Laser. I decided to use them instead of the ping sensor or the bump sensor. The BOE isnt going to be in a box, its going to be in room with possible corners anywhere, though the box is a good really good Idea. In Case I run out of time i'll definately use the box.

    So yeah, I plan to use the IR. I'm going to write the code with the IR in a couple of days, do you mind looking over it?
  • SRLMSRLM Posts: 5,045
    edited 2008-10-23 04:36
    What exactly do you mean by "infrared Laser"? Did you buy one, or do you really mean infrared LED? An IRLED is a clear bulb shaped device with two legs.

    You may want to define what sort of room you plan to run in. It sounds like something that is, at the worst, a random shape where all the corners are 90 degrees. True? If so, then you will have a very difficult time calculating the area. My recomendation is that you create a system that tells you length of a straight piece, then the dirrection of turn, length, turn, and so on. Like this:

    22, R, 3, L, 45, L, 22, R, ...

    Then, output that into a PC program that will graphically display it for you.
  • StatzStatz Posts: 28
    edited 2008-10-23 19:01
    Yeah I mean the IRLED, sorry I'm bad with remembering terms.

    So yeah that makes sense. Having a random room is probably too difficult for me right now. I have a big tendancy to try to do the most.

    Also, yeah, I'll start off trying to find the length of 1 straight piece.

    Thanks for helping me mellow down my goals for this project. I have a bad habit of trying to start off with the impossible that I forget I don't know enough yet.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-23 20:40
    A good design principle that I follow is to design the project (in general terms) to do everything that you possibly want it to do (the ideal situation). Then, build it in such a way that you always have something that works. Aka, get the wheels to roll, then get it measure a distance, then figure out corners, then figure out rooms. You can always drop the last step if it doesn't work out, and you still have a good project.
  • StatzStatz Posts: 28
    edited 2008-10-27 15:59
    I got the whole functionality working now.

    irDetectLeft VAR Bit
    pulseCount VAR Byte
    pulseLeft VAR Word
    pulseRight VAR Word
    loopCount VAR Byte
    
    
    
    
    
    DO
    
      FREQOUT 8, 1, 38500
      irDetectLeft = IN9
    
      IF (irDetectLeft = 0) THEN
      pulseCount = 24
      pulseLeft = 850
      pulseRight = 850
      measure = 0
      ELSE
      pulseCount = 1
      pulseLeft = 850
      pulseRight = 650
      ENDIF
    
      FOR loopCount = 1 TO pulseCount
        PULSOUT 13, pulseLeft
        PULSOUT 12, pulseRight
        PAUSE 20
      NEXT
    LOOP
    



    Guess I just needed to know how to use the IR, now I do. So next would be being able to make it record how far its going rite?


    So I'm laying down a ruler and calculating the speed itself. Seems like a good idea?
  • StatzStatz Posts: 28
    edited 2008-10-27 16:31
    Ha so I found the distance for every inch now. this is so much fun.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '{1 to 6 with a pause 20 is equivalant to 1 inch
    
    irDetectLeft VAR Bit
    pulseCount VAR Byte
    pulseLeft VAR Word
    pulseRight VAR Word
    loopCount VAR Byte
    'measure VAR Byte      'Variable for distance in inches
    
    
    
    
    
    DO
    
      FREQOUT 8, 1, 38500
      irDetectLeft = IN9
    
      IF (irDetectLeft = 0) THEN
      pulseCount = 24
      pulseLeft = 850
      pulseRight = 850
     ' measure = 0                  'Reset Recorded Distance
      ELSE
      pulseCount = 6
      'measure = measure + 1     'To count how many inches are travelled
      pulseLeft = 850
      pulseRight = 650
      ENDIF
    
      FOR loopCount = 1 TO pulseCount
        PULSOUT 13, pulseLeft
        PULSOUT 12, pulseRight
        PAUSE 20
      NEXT
    
      '  DEBUG DEC measure   'Will debug the distance in inches
    
    
    LOOP
    
    
    
    
    



    I'm excited. I'll try to make see if the resetting actually works when its supposed to.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-27 19:54
    I'm not quite sure exactly how you are calculating distance, but it sounds like you are doing it by counting how many times you pulse the servos. Beware! As you battery voltage drops, your servos will go slower (if they are unregulated). Also, the more load that you have on them the slower that they will go. So, you'll have a high error rate when using you bot in various circumstances: like showing it to your teacher. A better way would be to use encoders. Parallax sells some, or you can make your own with some IR LEDs and recievers. Counting servo pulses may be fine just get the project up and running, but it is not a very good solution. Also, one servo will undoubtedly turn faster than another, so you'll need to correct by changing the pulse width, which changes the speed, ...

    In short: use IR encoders for distance tracking.
  • StatzStatz Posts: 28
    edited 2008-10-28 04:18
    Ahh makes sense, I'll definately look into it. lol Obstacles are always being thrown in the way, but I guess it makes the learning process better.

    I'll have to learn what IR encoders are too.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-28 05:55
    Here's some links...
  • StatzStatz Posts: 28
    edited 2008-11-17 22:34
    So I finished my code. I've yet to test it because my boe-bot is trippin with it's left led sensor. But so far from me reading the code it seems like it'll do almost exactly what I want it to do. I will just have to test the movement. It should draw out the path it is taking, and also at the end calculate everything. I'm pretty proud of myself, and thanks for the help. So the goal was this.


    -Move around a square or a rectangle
    -Draw out the direction its going
    -Calculate the perimeter and area of what it measured




    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '{1 to 6 with a pause 20 is equivalant to 1 inch)
    
    irDetectLeft VAR Bit
    pulseCount VAR Byte
    pulseLeft VAR Word
    pulseRight VAR Word
    loopCount VAR Byte
    irDetectMiddle VAR Bit
    hit VAR Nib
    FINISH CON 4            'Just a constant of if a square is made
    turn VAR Nib            'Will increase if a full corner turn is predicted
    measure VAR Byte
    
    '===debug variables===
    horiz VAR Byte
    vert VAR Byte
    firstWidth VAR Byte
    firstLength VAR Byte
    secondWidth VAR Byte
    secondLength VAR Byte
    
    
    
    
    
    
    DO
    
      FREQOUT 8, 1, 41500
      irDetectLeft = IN10
      FREQOUT 2, 1, 41500
      irDetectMiddle = IN0
    
      IF (irDetectMiddle = 0)  THEN   'If the front eye sees something, boe-bot will turn to the right
      DO
        FREQOUT 8, 1, 41500
        irDetectLeft = IN10
        FREQOUT 2, 1, 41500
        irDetectMiddle = IN0
        PULSOUT 13, 850
        PULSOUT 12, 800
        hit = hit + 1                       'When hit equals 4, the boe-bot should have turned long enough to make 90 degrees
        PAUSE 20
       LOOP UNTIL ((irDetectLeft = 0) AND (irDetectMiddle = 1)) 'Repeat the loop until the left eye sees a wall and the front doesn't
    
      '===If hit is more than 4 then the boe-bot is most likely turning a long enough turn to hit 90 degrees===
       IF hit = 4 THEN
       turn = turn+1   'Add one to the turn variable to tell how many times it turned
       measure = 0    'The measuring resets
       ENDIF
    
    
    
      ELSEIF (irDetectLeft = 0) THEN 'If the left eye sees a wall, boe-bot goes straight
      pulseCount = 5
      pulseLeft = 850
      pulseRight = 650
    
    
      ELSE 'Should turn slightly to the left if both eyes don't see anything, just until the left sees a wall
      pulseCount = 5
      pulseLeft = 780
      pulseRight = 650
      ENDIF
    
      FOR loopCount = 1 TO pulseCount
        PULSOUT 13, pulseLeft
        PULSOUT 12, pulseRight
        measure = measure + 1   'Counts how many inches is traveled
        PAUSE 20
    
      NEXT
    
      GOSUB debug_Rectangle
    
      '=====Check if Boe-Bot made a square or rectangle====
       IF (turn = FINISH) THEN
       EXIT
       ENDIF
    
    
    LOOP
    
    
    END
    
    
    '===Statement for printing out the drawing and calculating measurement===
    debug_Rectangle:
    SELECT turn
    CASE 0
    vert = measure
    firstLength = measure
    DEBUG CRSRXY, 0,vert, "|"
    CASE 1
    horiz = measure
    firstWidth = measure
    DEBUG CRSRXY, horiz,0,"-"
    CASE 2
    vert = measure
    secondLength = measure
    DEBUG CRSRXY, horiz, vert,"|"
    
    CASE 3
    horiz = measure
    secondWidth = measure
    DEBUG CRSRXY, horiz, vert,"-"
    
    CASE ELSE
    'When turn = 4, the debug prints out the info
    DEBUG CRSRXY, horiz+2, vert+2,"Area is between : ",DEC (firstWidth*firstLength), " and ", DEC (secondWidth*secondLength)
    DEBUG CRSRXY, horiz+2, vert+3,"Perimeter is between ",DEC ((2*firstWidth)+(2*firstLength)), " and", DEC ((2*secondWidth)+(2*secondLength))
    
    ENDSELECT
    
    END
    
    




    After I test this out at school on wednesday, I'm going to have to learn how to use the transceiever, so I can send the data back to another breadboard to display on the debug terminal. I'm so excited ^_^
Sign In or Register to comment.