Color Sensor RGB values are too low

My daughter is working on a program using an IQ color sensor as part of her science fair project. Basically she wants to read the RGB 0-255 values out and display them on the LCD, while also turning the touch LED to the sensed color.

Here is her current robotc code:
#pragma config(Sensor, port4, colorDetector, sensorVexIQ_ColorHue)
#pragma config(Sensor, port3, touchLED, sensorVexIQ_LED)
task main()

setColorMode(colorDetector, colorTypeRGB_Hue_Ambient);
setTouchLEDRGB(touchLED, 0, 255, 0);

if(getTouchLEDValue(touchLED) == 1) //Touch LED is not pressed
long redvalue = getColorRedChannel(colorDetector);
long greenvalue = getColorGreenChannel(colorDetector);
long bluevalue = getColorBlueChannel(colorDetector);
displayTextLine(1,“Red = %d”, redvalue);
displayTextLine(2,“Green = %d”, greenvalue);
displayTextLine(3,“Blue = %d”, bluevalue);
setTouchLEDRGB(touchLED, redvalue, greenvalue, bluevalue); //Set detected color



The problem we’re seeing is this: If we put black in front of the sensor, it generally does a good job and gets 0,0,0 or close to it. However, when we put white in front of it, the values are non-zero, but I expected to see close to 255,255,255. Even if it were in the 240s, I’d say it’s OK. But we are seeing values in the 30-40 range most of the time. If we put red in front, the red value is definitely the highest value, and the same with Blue or Green, but they are never above 100, much less 200.

I tried changing the color mode to the colorTypeRGB_Hue_Reflected instead of ambient, and also tried colorTypeRGB_Raw_Reflected (and ambient), but it doesn’t seem to make a difference.

I can’t seem to find a calibration routine, is there one for the color sensor?

Anyone have any ideas or experience with this? Maybe we are missing something important.

My first thought is that you could calibrate it yourself. When you hold the white in front of the detector, you can proportionally increase those values so that they are 255.

In fact, I would continually read the number for each value, and keep trying to find the max for each channel. Then, on the output, I would have it display the raw number / max * 255. You would have to calibrate it with a white sheet every time you started the code, though.

I know this is a mathematical solution, and you are looking for a way to just get it to work as it should… But this may do the trick!

Thanks for the reply, that is a good suggestion, as long as it’s giving consistent values. The only problem is it will limit the effective range of the sensor, but maybe it’s ok. I’d prefer for it to work as advertised of course! I may grab one or two of her school’s color sensors just to see if they read the same way. Could be that ours is defective.

I thought I’d update this thread in case what my daughter and I found helps anyone else. We tried 3 different color sensors, and all three performed more or less the same. RGB values were reading consistently (way) low. So we started calling the getColorAdvanced() function, which fills out a structure with all the color data, RGB and Hue/Saturation plus some others. The RGB values were still low, but what we noticed is that the Hue is very accurate, even though the RGB is way off. So my daughter ended up using Hue for her science fair project, and it worked out pretty well.

We also noticed that ambient light really impacts the sensor, which has been mentioned by many others before. But by building a cardboard housing around the the sensor, she was able to get very accurate hue readings from the sensor.

I suspect there could be something wrong with the RGB conversion in the IQ brain. It also seems to be pretty accurate with the 12 color mode, which is probably the most used mode anyways.

Did you see any documentation on getColorAdvanced() ?

The only documentation I found was the RobotC help.

Since the documentation is lacking, here is at least the mentioned TColorInfo structure:

typedef struct
        uword                   nClear;
        uword                   nRed;
        uword                   nGreen;
        uword                   nBlue;
        ubyte                   nHue;
        ubyte                   nSaturation;
        ubyte                   nAssistLED;
        ubyte                   nATime;
        ubyte                   nControl;
} TColorInfo;

Thanks for the update. I am following this.