View Full Version : Project help, ColorPAL code integration
I am working on my final project using a BS2, Propeller Servo Controller and ColorPAL. I found a piece of starter code that is exactly what I am trying to do, but it's designed for a different color sensor (Taos). I have been trying to rewrite the code so that it will use the ColorPAL instead but I am having no luck. I was hoping that someone who knows more about this could tell me what I am doing wrong. I am attaching the code that I am using. Props to the people who originally wrote it.
Also, slightly disappointed with the ColorPAL's sensor range, only about half an inch... but we work with what we have right?
Anyway, thanks in advance!
EDIT: Forgot to say what the code does. It's supposed to control a robotic arm that picks up colored blocks from one location and sorts them by color into cups.
EDIT2: Posted code updated thanks to PhiPi's recommendation. TY!
Post Edited (M.W.) : 3/4/2010 5:44:39 AM GMT
Phil Pilgrim (PhiPi)
02-28-2010, 04:47 AM
Since this is a school project, I'm not going to write your code for you. But let's discuss this block of code from your program:
SEROUT sio, baud, ["= (00 $ m) !"] 'Program ColorPAL to send $ then color data.
SERIN sio, baud, [WAIT("$"), HEX3 RED, HEX3 GREEN, HEX3 BLUE] ' Receive RGB data back
'DEBUG "RGB: "
'DEBUG DEC3 RED, " "
'DEBUG DEC3 GREEN," "
'DEBUG DEC3 BLUE, CR
First, the SEROUT part only needs to be done once, at the beginning of your program. This programs the ColorPAL to send color data continuously, so it doesn't need to be repeated each time you want to get a sample.
Next, your DO .. LOOP construct will never exit, so your subroutine will never return. You don't need the loop there at all.
'Hope this helps. Good luck with your project!
Ah, good, thank you for your reply. That's something I think I never would have noticed. So I have made some changes that I feel are appropriate thanks to the reply I have gotten. I do have a direct question though; does the ColorPAL need a place to store the color information or does it do that automatically as it continuously scans for color?
Ok, so I have tried the code out with all the working parts. Some of it works and some does not. I have re-attached the changed code to my first post.
Here's the problem I think I'm having, I think the ColorPAL is not coming on at all. I have tried putting the SEROUT command in multiple places, but the LED never turns on inside as it tries to sample the color. The servo controller seems to work, as do the servos. I think right now the only thing holding me up is that ColorPAL. I am going to search for more documentation but if anyone has any pointers that would be great.
Also, I don't see a command that lets me step through my code [to see if I am ending up in an endless loop or something] for the stamp editor that Parallax provides. Is it there and I don't see it or should I try a different compiler?
Phil Pilgrim (PhiPi)
03-04-2010, 01:56 PM
When the ColorPAL is sampling colors, the RGB LED barely appears to light up, since it's pulsing on so briefly and quickly. In a darkened room do you see any LED activity at all? Does your GetColor routine return when you call it? (If it does, that means it's getting color data from the ColorPAL.) How about the ColorPAL demo program: does it work correctly?
Hey, the demo programs work. I will hook it all up again tonight and see if I can see the activity in the LED and run a debug on my GetColor routine. I am fairly confident that I am just one or two mistakes away from making this work right.
Thank you for your continued help Phil, seems you're the resident expert on ColorPAL. I noticed your name in some of the sample code that Parallax provides, pretty cool :) So I will post results tonight. TY again.
Final update, the code worked great with a few more modifications. Unfortunately my teammates had taken the ColorPAL home to machine a bracket for it so I didn't get a chance to test again until the due date. I made a few adjustments to the code and it worked fine.
Did have a little problem with the weight of the arm vs. servo torque though, but that is something of a different matter.
Thanks for your help! Attached is my final code, some of it has been simply rerouted to make it function more succinctly.