Shop OBEX P1 Docs P2 Docs Learn Events
Need Help With A Program — Parallax Forums

Need Help With A Program

Link2TimeLink2Time Posts: 5
edited 2008-04-03 16:42 in BASIC Stamp
What I'm trying to do is confine my Boe-Bot within a Circle colored Black with the edge of the circle in white. I want my boe-bot to reverse when the two Photoresistors see white. I'm having trouble getting it to work. If you have problems understand what I'm asking please reply and I'll try my best to answer.

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

'----[noparse][[/noparse]Variables]-----
timeLeft   VAR  Word
timeRight  VAR  Word
timeLeftB  VAR  Word
timeRightB VAR  Word
timeLeftW  VAR  Word
timeRightW VAR  Word
counter    VAR  Word

counter = 0

'----[noparse][[/noparse]Main Routine]----

DO
  IF (IN1 = 0) THEN
    counter = counter + 1
    PAUSE 200
  ENDIF
  IF (counter = 0) THEN
    GOSUB Read_Black
  ELSEIF (counter = 1) THEN
    GOSUB Read_White
  ELSEIF (counter > 2) THEN
    GOSUB Navigate
  ENDIF
LOOP

'-----[noparse][[/noparse]SubRoutines]-----
Read_Black:
  timeLeftB = timeLeft
  timeRightB = timeRight
RETURN

Read_White:
  timeLeftW = timeLeft
  timeRightW = timeRight
RETURN

Navigate:
  IF (timeLeft > timeLeftW) AND (timeRight > timeRightW) THEN
    PULSOUT 13, 650
    PULSOUT 12, 850
  ELSEIF (timeLeft > timeLeftW) THEN
    PULSOUT 13, 850
    PULSOUT 12, 850
  ELSEIF (timeRight > timeRightW) THEN
    PULSOUT 13, 650
    PULSOUT 12, 650
  ELSE
    PULSOUT 13, 850
    PULSOUT 12, 650
    PAUSE 20
  ENDIF
RETURN

Comments

  • Link2TimeLink2Time Posts: 5
    edited 2008-04-02 06:04
    Anyone?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-04-02 06:33
    Link2Time -

    If there were some comments, including definitions of what the pin ports were, and a schematic to show what external parts were being used, and where, you might get some answers.

    Just by way of example, where are the photo-resistors being "read"? The only pin port that's being used is pin port 1, and one would expect more in an ordinary ring-sensing set-up.

    Another odd part of your program is when you check the "counter" variable. You check for 0, 1, and greather than 2. What is supposed to happen if counter is equal to 2? If you want to check for equal to 2 and greater than 2, you can use both comparison operators " => " to indicate the two conditions.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Involvement and committment can be best understood by looking at a plate of ham and eggs. The chicken was involved, but the pig was committed. ANON
  • Link2TimeLink2Time Posts: 5
    edited 2008-04-02 15:05
    Hey

    Yeah I didn't know how to include my PhotoResistors in this but the pins I'm using are Pin3 and Pin6. I also changed the counter to what you have suggested. I don't know about the rest of the stuff because I'm a noob with at working with this.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-02 15:21
    You need to put some effort into describing what you have, what you want it to do, and what actually happens. I suggest a schematic drawing of some kind. In addition to the general description of what you want to accomplish, how about a prose "flowchart" that outlines the logic of your program? What happens when you turn it on? How does it behave?

    If you took some sample program as a starting point, how about giving us that background?

    This has nothing to do with whether you have Stamp or Robotics experience or not. It's about how to ask for help. If you're paying someone to help you, they'll generally be accommodating ... after all, you're paying for their time and you can use it well or waste it. If you're asking someone to volunteer their time and effort (as is true here), you need to provide lots of information including your intentions, observations, assumptions, etc. You'll get faster and better answers and people will be more interested in helping.
  • Link2TimeLink2Time Posts: 5
    edited 2008-04-02 15:37
    MikeGreen...if I knew how to do any of that don't you think I would have posted in the beginning? I also changed my code up a bit but I'm still having problems. Here's what I want it to do and here's what it does:

    What I want:

    I'm using a button to record black and white for me and in the code the Boe-Bot is supposed to avoid white but move on black.

    Button Press 1: Record Black Color With Photo Resistors
    Button Press 2: Record White Color With Photo Resistors
    Button Press 3: Navigates

    When both Resistors see White the reverse 180
    When left sees White it turns left
    When right sees White it turns right

    -none of that is happening for me.

    When it Navigates I want it to avoid white but move on black, but what really happens is that it keeps moving no matter what color is under my photo resistors.

    Here are some images:

    boebot_diagram348.jpg

    surface229.jpg
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-02 16:36
    You're assuming (from your description) that magically the photoresistors will tell you whether there's black or white under them. There's nothing in what you've posted that does anything like that. Even if you had working photoresistors, getting the sensitivity just right takes some work. I suggest you work on that first until it's working well, then tackle movement and navigation.
  • Link2TimeLink2Time Posts: 5
    edited 2008-04-02 18:11
    I figured it out. My photoresistors weren't plugged in correctly. Thanks for nothing guys. Anyway here's my new code:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    '---------[noparse][[/noparse]Variables]------------------------------------
    
    timeLeft   VAR  Word
    timeRight  VAR  Word
    timeLeftB  VAR  Word
    timeRightB VAR  Word
    timeLeftW  VAR  Word
    timeRightW VAR  Word
    counter    VAR  Word
    
    counter = 0
    
    '------------[noparse][[/noparse]Initialization]-----------------------------
    
    FREQOUT 4, 2000, 3000
    
    '------------[noparse][[/noparse]Main Routine]--------------------------------
    
    DO
      IF (IN1 = 0) THEN
        counter = counter + 1
      ENDIF
      IF (counter = 1) THEN
        GOSUB Test_Resistors
        GOSUB On_LED
      ELSEIF (counter = 2) THEN
        GOSUB Test_Resistors
        GOSUB Off_LED
      ELSEIF (counter > 2) THEN
        GOSUB Test_Resistors
        GOSUB Navigate
      ENDIF
    LOOP
    
    '-------------[noparse][[/noparse]SubRoutines]-----------------------------------
    
    On_LED:
      timeLeftB = timeLeft
      timeRightB = timeRight
    RETURN
    
    Off_LED:
      timeLeftW = timeLeft
      timeRightW = timeRight
    RETURN
    
    Test_Resistors:
      HIGH 6
      RCTIME 6, 1, timeLeft
      RCTIME 3, 1, timeRight
    
    Navigate:
      IF (timeLeft < timeLeftB) AND (timeRight < timeRightB) THEN
        PULSOUT 13, 650
        PULSOUT 12, 850
      ELSEIF (timeLeft < timeLeftB) THEN
        PULSOUT 13, 850
        PULSOUT 12, 850
      ELSEIF (timeRight < timeRightW ) THEN
        PULSOUT 13, 650
        PULSOUT 12, 650
      ELSE
        PULSOUT 13, 850
        PULSOUT 12, 650
        PAUSE 20
      ENDIF
    RETURN
    



    Darn photoresistors
  • FranklinFranklin Posts: 4,747
    edited 2008-04-02 23:09
    link2time said...
    I figured it out. My photoresistors weren't plugged in correctly. Thanks for nothing guys.
    So, you screw up and it's their (our) fault? Next time maybe you won't get any help with an attitude like that. I may be wrong, others here aren't as bitter as I. [noparse];)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-04-03 16:42
    Link2Time

    I send you a PM· nono.gif

    ·

    Franklin

    So, you screw up and it's their (our) fault? Next time maybe you won't get any help with an attitude like that. I may be wrong, others here aren't as bitter as I. [noparse];)[/noparse]



    You could not have said it any better than that·· smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 4/3/2008 4:48:26 PM GMT
Sign In or Register to comment.