Shop OBEX P1 Docs P2 Docs Learn Events
Please, Help with RCTIME!! — Parallax Forums

Please, Help with RCTIME!!

EduardEduard Posts: 21
edited 2009-02-20 14:57 in BASIC Stamp
Hi!

I want to differ between three cubes of differents colors (Black, Purple and Yellow) using a LDR.
I've three different LEDs (blue, green and red) to create three differents values in the LDR for each color of the cube.

I do this :

'Sensor
'{$STAMP BS2}
'{$PORT COM1}
'{$PBASIC 2.5}

' -----[noparse][[/noparse] Programa ]----------------------------------------------------
Green VAR Word
Red VAR Word
Blue VAR Word
leds:

HIGH 4
PAUSE 3000
HIGH 7
PAUSE 1
RCTIME 7, 1, Green
DEBUG HOME, DEC5 ? Green
LOW 4

HIGH 2
PAUSE 3000
HIGH 7
PAUSE 1
RCTIME 7, 1, Red
DEBUG HOME, DEC5 ? Red
LOW 2

HIGH 0
PAUSE 3000
HIGH 7
PAUSE 1
RCTIME 7, 1, Blue
DEBUG HOME, DEC5 ? Blue
LOW 0

IF Green >10000  <13000 AND Red <00030 >00002 AND Blue >14000 <15500 THEN GOTO yellow:

IF Green <19500 >17500 AND Red <00029 >00002 AND Blue <14000 >12000 THEN GOTO purple:

IF Green >50000 AND Red <17000 AND Blue >50000 THEN GOTO black:

yellow:
DEBUG "This cube is yellow"

purple:
DEBUG "This cube is purple"

black:
DEBUG "This cube is black"


GOTO leds
END



Boe-Bot always says "This cube is yellow","This cube is purple","This cube is black" at the same time.

When I DEBUG the RCTIME value, I often see that the value is more bigger (have mor decimals) than the value that I can put in the program, so I've to quit the three last decimals.

What I'm doing wrong ?

Sorry if my English isn't very good.
Regards from Barcelona!

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-02-08 21:25
    You're using GOTOS to call the debug statements. When it finishes with the method, it falls through to the next line (whatever it is). Solution: put a return after each statement, then change the GOTO Yellow (or other) to GOSUB. In addition, you'll probably want to move the GOTO LEDs before the three debug blocks.
  • EduardEduard Posts: 21
    edited 2009-02-08 22:14
    Hi!
    I've done this:

    'Sensor
    '{$STAMP BS2}
    '{$PORT COM1}
    '{$PBASIC 2.5}
    
    ' -----[noparse][[/noparse] Programa ]----------------------------------------------------
    Green VAR Word
    Red VAR Word
    Blue VAR Word
    leds:
    
    HIGH 4
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Green
    DEBUG HOME, DEC5 ? Green
    LOW 4
    
    HIGH 2
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Red
    DEBUG HOME, DEC5 ? Red
    LOW 2
    
    HIGH 0
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Blue
    DEBUG HOME, DEC5 ? Blue
    LOW 0
    
    IF Green >10000  <13000 AND Red <00030 >00002 AND Blue >14000 <15500 THEN GOSUB yellow:
    
    IF Green <19500 >17500 AND Red <00029 >00002 AND Blue <14000 >12000 THEN GOSUB purple:
    
    IF Green >50000 AND Red <17000 AND Blue >50000 THEN GOSUB black:
    
    yellow:
    DEBUG "This cube is yellow"
    RETURN
    
    purple:
    DEBUG "This cube is purple"
    RETURN
    
    black:
    DEBUG "This cube is black"
    RETURN
    
    GOTO leds
    
    END
    



    But still doesn't work.
    It always says yellow. confused.gif
  • MrBi11MrBi11 Posts: 117
    edited 2009-02-08 22:23
    After your last "IF" and before "Yellow:" you need to END or loop back to the start. it's falling through into the YELLOW routine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Smile ... It increases your face value!
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-08 22:35
    IF·Green·>10000··<13000·AND·Red·<00030·>00002·AND·Blue·>14000·<15500·THEN·GOSUB·yellow

    needs to be re-written:

    IF Green>10000 AND Green<13000 AND Red>2 AND Red<30 AND Blue>14000 AND Blue<15500 THEN GOSUB Yellow

    Likewise the other IF...THEN statements

    I think that GOSUB...RETURN isn't the way to go.· You should GOTO the Yellow, Purple, Black subroutines and end each with "GOTO Leds" --

    black:
    DEBUG·"This·cube·is·black"
    GOTO Leds

    Post Edit -- attached slightly updated .BS2

    Post Edited (PJ Allen) : 2/8/2009 10:42:49 PM GMT
  • EduardEduard Posts: 21
    edited 2009-02-08 22:39
    Hi.

    If I put a "END" after the last IF and before yellow, it always says "purple". [noparse]:([/noparse]
  • EduardEduard Posts: 21
    edited 2009-02-08 22:50
    PJ Allen said...
    IF Green >10000 <13000 AND Red <00030 >00002 AND Blue >14000 <15500 THEN GOSUB yellow


    needs to be re-written:



    IF Green>10000 AND Green<13000 AND Red>2 AND Red<30 AND Blue>14000 AND Blue<15500 THEN GOSUB Yellow



    Likewise the other IF...THEN statements



    I think that GOSUB...RETURN isn't the way to go. You should GOTO the Yellow, Purple, Black subroutines and end each with "GOTO Leds" --



    black:
    DEBUG "This cube is black"
    GOTO Leds




    Post Edit -- attached slightly updated .BS2

    Thanks a lot!!, but still doesn't work.

    With eduard.bs2 it says that the cube is always black.
    With eduard_2.bs2 it says that the test failed or that the cube is black.
    confused.gif

    Post Edit, attached some photos of the Debug Terminal.

    When the DEBUG terminal shows the LDR value, it shows this:

    my.php?image=85447161rc9.jpg

    my.php?image=66842695rl1.jpg

    my.php?image=91424587av0.jpg

    But I can't introduce the same numbers that the DEBUG Terminal says because they're too big (like the Red value).
    Can be there , the problem ?

    Post Edited (Eduard) : 2/8/2009 11:01:36 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-08 22:58
    I did not check the ranges' validity, I just re-wrote them.· That the second version's Results are inconsistent (Fail or Black) is telling you something.·

    Are the DEBUG values coming back from the RCTIME routines within the ranges?·

    What if you plugged in values for Red, Green, Black (with the RCTIME routines commented out)?
  • EduardEduard Posts: 21
    edited 2009-02-08 23:01
    When the DEBUG terminal shows the LDR value, it shows this:



    img23.imageshack.us/my.php?image=85447161rc9.jpg

    img23.imageshack.us/my.php?image=66842695rl1.jpg

    img22.imageshack.us/my.php?image=91424587av0.jpg



    But I can't introduce the same numbers that the DEBUG Terminal says because they're too big (like the Red value).
    Can be there , the problem ?

    I haven't understand this :
    PJ Allen said...

    Are the DEBUG values coming back from the RCTIME routines within the ranges?

    What if you plugged in values for Red, Green, Black (with the RCTIME routines commented out)?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-08 23:08
    OK

    I have attached a version of your program with values appropriate for Yellow and it responds with "This cube is Yellow"

    Try changing the R,G,B values yourself.
  • EduardEduard Posts: 21
    edited 2009-02-09 00:26
    Hi, thanks a lot again!!

    I've tested your new file, and it always says "This cube is yellow" and the leds doesn't work.
    If I change the Plug-in Values it says "This test failed".

    What do you mean with changing the RGB values ? Am I putting well in the programm the LDR values that the DEBUG Terminal shows me?

    Sorry, but I don't know why is not working. Months ago it was working perfectly in another place and conditions; the LEDS, the LDR, the Boe... all components were the same, and it was working with a program that was quite similar as the first program that I posted here in this post. You can see a video of it:

    www.youtube.com/watch?v=R3nCRU3TwCg
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-09 02:13
    "I've tested your new file, and it always says "This cube is yellow" and the leds doesn't work.
    What do you mean with changing the RGB values ?"


    Well, it is a simulation.· The LEDs do not turn on.· I made it so that it has Red, Green, and Blue (R.G.B) values appropriate for a "Yellow" result, to test the validity of Color Test ranges / arguments.· I made a similar test, attached, that tests all 3.· So, that seems right.·

    You need to look at your RCTIME results·and·check that they are within the ranges given for Yellow or Purple or Black.
  • EduardEduard Posts: 21
    edited 2009-02-09 19:51
    Hi!

    Thanks again for the test!

    I don't know how to put the good RCTIME value in the program.
    When I see the DEBUG Terminal it says, with every colour, the RCTIME value.
    But I don't know well how to put these values in the program.

    These are the RCTIME results that I see on the Debug Terminal:

    Yellow cube:

    Green = 10638
    Red = 0204919
    Blue = 144745

    Purple Cube:

    Green = 19137
    Red = 0290655
    Blue = 164388

    Black cube:

    Green = 00000
    Red = 1547200
    Blue = 00000

    For example, when I want to put in the program the Red value of the Black cube (Red=1547200), I can't. It says me that "Constant exeeds 16 bits", so I've to quit the last two zeros, like this: 15472.

    I supose that there's the problem, but how I can resolve it ?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-09 23:29
    For Yellow and Purple, your Red values are supposed to be in the range of 2-30, so 204000 is a little bit high.· It seems that·that is indicating·poor Red response.

    I think you need to get that sensor situation right.· Optimize your sensor or change your color testing ranges to accomodate.

    In the test, the values are Words, so nothing > 65,535.
  • EduardEduard Posts: 21
    edited 2009-02-10 19:40
    OK!

    In general, all Red values are lower tha the Red and Blue ones... but they're constant.

    I don't know how to put well in the program the RCTIME data:

    58203675dt4.jpg
    w813.png


    confused.gifconfused.gif
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-11 00:03
    Since the VARiable "Red" is declared as a Work Word I do not see how it can be a value greater than 65535.

    Please run the attached program and post a screen-shot of the Results.

    Post Edit -- typo.

    Post Edited (PJ Allen) : 2/11/2009 12:42:42 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-02-11 16:55
    The reason your number looks so large is that you are printing over parts of it that aren’t being cleared from what was previously displayed. So if you printed:

    Some Numbr = 1234

    …then printed…

    Results = 98

    …your display could look like:

    Results = 981234 because you didn’t erase to the end of line. After printing the value add the following to your DEBUG…

    DEBUG “Results = “, DEC value, CLREOL

    I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-11 18:29
    That's my surmise, too, Chris.· My last program just knocks out a list, 10 trials, to confirm.· No word back yet.
  • EduardEduard Posts: 21
    edited 2009-02-11 19:07
    Hi!!

    Thanks a lot again.

    I've screen-shoted the results of the new attached program.

    These are the results for the Yellow Cube:

    2grochc8.png
    w591.png

    These are the results for the Purple Cube:

    2lilais0.png
    w595.png

    And these are the results for the Black Cube:

    2negreqd4.png
    w593.png
  • EduardEduard Posts: 21
    edited 2009-02-11 19:40
    Hi, I think that I'm starting to get the correct program... smile.gif

    'Sensor
    '{$STAMP BS2}
    '{$PORT COM1}
    '{$PBASIC 2.5}
    
    ' -----[noparse][[/noparse] Programa ]----------------------------------------------------
    Green VAR Word
    Blue VAR Word
    Red VAR Word
    
    leds:
    
    
    HIGH 4
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Green
    DEBUG DEC HOME, " Green = ", DEC Green, CR
    LOW 4
    PAUSE 1000
    
    
    
    HIGH 2
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Red
    DEBUG DEC HOME, " Red = ", DEC Red, CR
    LOW 2
    PAUSE 1000
    
    
    
    HIGH 0
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Blue
    DEBUG DEC HOME, " Blue = ", DEC Blue, CR
    LOW 0
    PAUSE 1000
    
    
    
    
    IF ((Green > 10000) AND (Green < 13000)) AND ((Red > 1500) AND (Red < 2500)) AND((Blue >18000) AND (Blue <23000 )) THEN GOTO yellow
    
    IF ((Green > 22500) AND (Green < 24000))  AND ((Red > 2000) AND (Red < 3500)) AND((Blue >13500) AND (Blue < 16000)) THEN GOTO purple
    
    IF (Green < 10)  AND (Red > 13000) AND (Blue < 10) THEN GOTO black
    
    
    
    yellow:
    DEBUG "This cube is yellow"
    
    GOTO leds
    
    purple:
    DEBUG "This cube is purple"
    
    GOTO leds
    
    black:
    DEBUG "This cube is black"
    
    GOTO leds
    
    
    GOTO leds
    
    END
    



    It works SOMETIMES. With BLACK works OK, but sometimes confuses purple and yellow.


    confused.gif
  • EduardEduard Posts: 21
    edited 2009-02-11 19:51
    It works a little bit better if I do this... but why ??

    It continues confusing YELLOW and PURPLE. What can I do to solve this ?


    'Sensor
    '{$STAMP BS2}
    '{$PORT COM1}
    '{$PBASIC 2.5}
    
    ' -----[noparse][[/noparse] Programa ]----------------------------------------------------
    Green VAR Word
    Blue VAR Word
    Red VAR Word
    
    leds:
    
    PAUSE 2000
    HIGH 4
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Green
    DEBUG DEC HOME, " Green = ", DEC Green, CR
    LOW 4
    PAUSE 1000
    
    
    
    HIGH 2
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Red
    DEBUG DEC HOME, " Red = ", DEC Red, CR
    LOW 2
    PAUSE 1000
    
    
    
    HIGH 0
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Blue
    DEBUG DEC HOME, " Blue = ", DEC Blue, CR
    LOW 0
    PAUSE 1000
    
    
    
    
    IF (Green < 13000) AND (Red < 2500) AND (Blue > 17001)THEN GOTO yellow
    
    IF (Green > 20500) AND (Red < 3500) AND (Blue < 17000) THEN GOTO purple
    
    IF (Green < 10)  AND (Red > 13000) AND ((Blue < 10) OR (Blue > 60000))  THEN GOTO black
    
    
    
    yellow:
    DEBUG "This cube is yellow"
    
    GOTO leds
    
    purple:
    DEBUG "This cube is purple"
    
    GOTO leds
    
    black:
    DEBUG "This cube is black"
    
    
    
    GOTO leds
    
    
    GOTO leds
    
    END
    
    




    I'm feeding the Boe-Bot with a simple homemade power supply (4 diodes, 2 condensators and a 7806). Can this be a problem for the Boe-Bot?

    Post Edit:

    Hi again! I've changed some values of the program. There's no Red color check in the detection of the Yellow Cube.
    It seems that it works better, saying good the color of the cube the 95% of times.

    'Sensor
    '{$STAMP BS2}
    '{$PORT COM1}
    '{$PBASIC 2.5}
    
    ' -----[noparse][[/noparse] Programa ]----------------------------------------------------
    Green VAR Word
    Blue VAR Word
    Red VAR Word
    
    leds:
    
    PAUSE 5000
    
    HIGH 4
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Green
    DEBUG DEC HOME, " Green = ", DEC Green, CR
    LOW 4
    PAUSE 1000
    
    
    
    HIGH 2
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Red
    DEBUG DEC HOME, " Red = ", DEC Red, CR
    LOW 2
    PAUSE 1000
    
    
    
    HIGH 0
    PAUSE 3000
    HIGH 7
    PAUSE 1
    RCTIME 7, 1, Blue
    DEBUG DEC HOME, " Blue = ", DEC Blue, CR
    LOW 0
    PAUSE 1000
    
    
    
    
    IF ((Green > 10000) AND (Green < 16000)) AND ((Blue >14500) AND (Blue <24000 )) THEN GOTO yellow
    
    IF ((Green > 16001) AND (Green < 24000))  AND ((Red > 2000) AND (Red < 3500)) AND((Blue >12500) AND (Blue < 15499)) THEN GOTO purple
    
    IF ((Green < 10) OR (Green > 60000))  AND (Red > 11000) AND ((Blue < 10) OR (Blue > 60000))  THEN GOTO black
    
    
    
    
    
    purple:
    DEBUG "This cube is purple"
    
    GOTO leds
    
    black:
    DEBUG "This cube is black"
     GOTO leds
    
     yellow:
    DEBUG "This cube is yellow"
    
    
    
    GOTO leds
    
    
    GOTO leds
    
    END
    

    Post Edited (Eduard) : 2/11/2009 8:35:45 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-12 02:59
    OK.· You're the designer, so you get to determine the test parameters.

    It seems like you're on the right track.·
  • EduardEduard Posts: 21
    edited 2009-02-20 14:57
    OK!! smilewinkgrin.gif

    Thanks to all, specially to PJ Allen !

    You can see a video of the project here:




    Thanks again!!! hop.gif
Sign In or Register to comment.