Shop OBEX P1 Docs P2 Docs Learn Events
ColorPAL — Parallax Forums

ColorPAL

colorindcolorind Posts: 4
edited 2010-10-09 03:05 in Robotics
Does someone knows how to program the ColorPAL to detect a specified colored object for example Green, from 3 objects (red green blue)?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-22 15:18
    The way I like to do this is what I call the "minimax" technique. Say you've got three known colors that you've sampled with the ColorPAL and for which you have the RGB components. Now, you present the ColorPAL with an unknown color and want to find which of the three known colors it's closest to. To compare with color 1, for example, you would do the following subtractions and absolute value computtions:

    ····|Runknown - R1|
    ····|Gunknown - G1|
    ····|Bunknown - B1|

    Then, from among these absolute differences, pick the largest one. That will be the distance from the unknown color to color 1. Repeat this procedure for color 2 and color 3. Then pick the color whose distance to the unknown color is the smallest.

    -Phil
  • BumpBump Posts: 592
    edited 2010-06-22 20:36
    Color Sorter Robot by Nikos Giannakopoulos:
    http://www.parallax.com/Resources/ApplicationsContests/Robotics/ColorSorter/tabid/870/Default.aspx

    Just posted it on our Robotics customer applications page, I'm not sure but it might be of some interest based on the subject?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • colorindcolorind Posts: 4
    edited 2010-06-23 08:33
    I've opened tcs3200_colorpal_match.exe and followed the rules, and I've adjusted 3 colors which are red green and blue like my objects. My question is, the colors are saved in the ColorPAL's memory? If they are how can I see the ColorPAL's memory with the BS editor, because I don't know where I can find the ColorPAL's source code, and how to program the robot to recognize one of the objects and deny the other 2. Thanks for your Help!
    Jimmy
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-23 16:11
    The colors are not saved in the ColorPAL's memory. When you're using the PC match program, they're saved in the PC. When you write your own PBASIC program, you will have to save the colors either in variables or in the BASIC Stamp's EEPROM.

    -Phil
  • NikosGNikosG Posts: 705
    edited 2010-10-09 03:03
    Color Sorter Robot by Nikos Giannakopoulos:
    http://www.parallax.com/Resources/ApplicationsContests/Robotics/ColorSorter/tabid/870/Default.aspx

    Just posted it on our Robotics customer applications page, I'm not sure but it might be of some interest based on the subject?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Exactly Bump,
    I agree with the formula that was given above by Phil.
    The Bs2 code for this challenge that I have used In my color sorter project is :

    SEROUT sio, PALbaud, ["= (00 $ m) !"] 'Program ColorPAL to send $ then color data.
    SERIN sio, PALbaud, [WAIT("$"), HEX3 R, HEX3 G, HEX3 B] ' Receive RGB data back.
    rgbcolorsum = R+G+B '
    the sum of the 3 variables R,G,B
    IF rgbcolorsum>190 THEN
    mycolor=4 '
    white
    ELSEIF rgbcolorsum> 5 AND rgbcolorsum<26 THEN
    mycolor=1 '
    black
    ELSEIF rgbcolorsum>26 AND rgbcolorsum<190 THEN
    IF R > G AND R > B THEN '
    find the max
    mycolor=2 '
    red
    ELSEIF G > R AND G> B THEN '
    find the max
    mycolor=5 '
    green
    ELSE
    mycolor=3 '
    blue
    ENDIF
    ELSEIF rgbcolorsum<2 THEN
    mycolor=0 '
    blank
    ELSE
    mycolor=6 '
    unknown color
    ENDIF

    In addition I calculate the sum of the 3 variables R,G,B ("rgbcolorsum = R+G+B") to identify the Black, White and Blank
  • NikosGNikosG Posts: 705
    edited 2010-10-09 03:05
    The way I like to do this is what I call the "minimax" technique. Say you've got three known colors that you've sampled with the ColorPAL and for which you have the RGB components. Now, you present the ColorPAL with an unknown color and want to find which of the three known colors it's closest to. To compare with color 1, for example, you would do the following subtractions and absolute value computtions:

    ····|Runknown - R1|
    ····|Gunknown - G1|
    ····|Bunknown - B1|

    Then, from among these absolute differences, pick the largest one. That will be the distance from the unknown color to color 1. Repeat this procedure for color 2 and color 3. Then pick the color whose distance to the unknown color is the smallest.

    -Phil

    Hi Phil,
    I absolutely agree with your formulas,
    I have done exactly this:

    SEROUT sio, PALbaud, ["= (00 $ m) !"] 'Program ColorPAL to send $ then color data.
    SERIN sio, PALbaud, [WAIT("$"), HEX3 R, HEX3 G, HEX3 B] ' Receive RGB data back.
    rgbcolorsum = R+G+B '
    the sum of the 3 variables R,G,B
    IF rgbcolorsum>190 THEN
    mycolor=4 '
    white
    ELSEIF rgbcolorsum> 5 AND rgbcolorsum<26 THEN
    mycolor=1 '
    black
    ELSEIF rgbcolorsum>26 AND rgbcolorsum<190 THEN
    IF R > G AND R > B THEN '
    find the max
    mycolor=2 '
    red
    ELSEIF G > R AND G> B THEN '
    find the max
    mycolor=5 '
    green
    ELSE
    mycolor=3 '
    blue
    ENDIF
    ELSEIF rgbcolorsum<2 THEN
    mycolor=0 '
    blank
    ELSE
    mycolor=6 '
    unknown color
    ENDIF

    In addition I calculate the sum of the 3 variables R,G,B ("rgbcolorsum = R+G+B") to identify the Black, White and Blank
Sign In or Register to comment.