LEGO Color Sensor RGB raw/scaled vs ColorRed mode [NXC]

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

LEGO Color Sensor RGB raw/scaled vs ColorRed mode [NXC]

Post by ricardocrl »

Hello everyone,

In NXC we can get from ReadSensorColorEx() a lot of parameters, including raw, normalized and scaled values of each component R, G and B. I thought the scaled values were the same as the percentage values from an exclusive Red reading in SENSOR_TYPE_COLORRED, but they are different.

How are these RGB parameters related with the stand alone color modes?

This came up to my mind because I'd like to sense color and read red reflection at the same time, without changing from type to type (which was already proven to take a long time to switch).

Cheers,
Ricardo
rghansen
Posts: 67
Joined: 12 Oct 2010, 17:44

Re: LEGO Color Sensor RGB raw/scaled vs ColorRed mode [NXC]

Post by rghansen »

If you go to the Stonehenge 3 topic under "Mindstorms projects", you can down load some software which contains an example of how to quickly get and use the RBG values from the color sensor. The routine is called "getColor". Although this version of the code turns the color sensor on and off using the setSensorColor... routines, this is not necessary. If you look at the last video posted on the topic, you can see that even under less than ideal conditions, you can very quickly identify the color of a Lego ball.
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: LEGO Color Sensor RGB raw/scaled vs ColorRed mode [NXC]

Post by ricardocrl »

I don't have a problem with the time it takes to get new sensor values, but I would like to use the Red value in percent mode, as I'm used to. Or at least I wanted to understand what the scaled and normalized values stand for or how they are calculated, comparing to the percentage, when you get "light sensor value" in the SensorColorRed mode&type.
jasonlh
Posts: 7
Joined: 12 May 2011, 05:39

Re: LEGO Color Sensor RGB raw/scaled vs ColorRed mode [NXC]

Post by jasonlh »

I just got my NXT recently and am working on my first line following bot. :roll: I've gotten it to work pretty well, and using ReadSensorColorEx have been able to read the solid color blocks on the included test pad and pause the bot (just to show it noticed the color), and still get the raw values so it can follow the line too at the same time. I don't have to do any switching of modes though? I just check the colorval parameter for when it's not black or white, and then use the raw[] parameter for red to control following the line.

But anyways, I too am curious what exactly the difference / relationship is between the raw, normalized, and scaled values are. I'm thinking raw is on a scale of 0-1023, and normalized and scaled are 0-224. Is that correct, and then what is the difference between normalized and scaled?

Also, I can't figure out what the 3rd and 4th array elements are for in the sensor arrays? 3 is listed as "Blank", and 4 is "No of Colors"? The 3rd element is all over the place, and I can't make any rhyme or reason of it? If I try to access the 4th element, the program compiles, but crashes when run on the NXT?

It's all a bit overwhelming right now, but having fun working through it. I was pretty happy when I finally got my bot to follow that stupid line the first time! lol

Thanks,
Jason
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: LEGO Color Sensor RGB raw/scaled vs ColorRed mode [NXC]

Post by ricardocrl »

Hi Jason,

I am exactly in the same circumstances as you are. And I've no idea about what the scaled/normalized values stand for, but I use them.

I've done a line follower with color detection at the same time and it's working quite well. One anoying thing I have sometimes (not that usual) is to recognize colors different than black and white along the line. That seems normal, since the sensor is between both and can get uncertain decisions. Did you encounter this "errors"?

I think it depends on the light conditions/sensor position/line and background values. Even with some kind of filters, I get long sequences of the BLUE for instance, along a curve, which makes me believe that a color was found.

To overcome that, I'm ignoring color detection while curving too much. To detect if I'm curving, I used some signal processing.

Cheers,
Ricardo
jasonlh
Posts: 7
Joined: 12 May 2011, 05:39

Re: LEGO Color Sensor RGB raw/scaled vs ColorRed mode [NXC]

Post by jasonlh »

Ricardo, it seems to work fine on the little test pad that came with the NXT, as far as following the line and distinguishing the colors at the same time. I cut out the pertinent pieces of code below:

Code: Select all

  unsigned int r[],n[],s[];
  int sv, cv;

  // set sensor type and mode
  SetSensorType(IN_3, SENSOR_TYPE_COLORFULL);
  SetSensorMode(IN_3,SENSOR_MODE_RAW);
  ResetSensor(IN_3);

   ReadSensorColorEx(IN_3,cv,r,n,s);
   sv=r[0];

 switch (cv)
      {
        case INPUT_REDCOLOR :
        {
             PlayTone(440,250);
             break;
        }......
I use sv in my actual line following routine, and then check the cv value and play a different tone as I pass each color. (really exicting, I know)

However, I tried to move beyond the test pad, and have the robot track the edge of our hardwood floor and the carpet. The carpet is a light beige color, and the hardwood a darkish oak. Seems like it should be easy enough to follow, but none of the colors sensors (red, green, or blue) pick up much difference between the two? I can get it to work sometimes, but have to tweak heavily to the lighting conditions. As the shadows change, the needed values to distinguish between the two vary a lot. I'm going to try just turning on the red sensor, which I think I read somwhere will make it brighter, and give better results?
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: LEGO Color Sensor RGB raw/scaled vs ColorRed mode [NXC]

Post by ricardocrl »

Yes, also from what I've heard, the red LED is the best choice for reflections in this kind of problems.

Well, the best is to use a calibration in the beginning of the problem. Do a reading in the floor, then in the line. Take the middle value as the offset to follow the line. :-)

I'm actually doing it with a different program and storing in a file. The line follower program just fetches that file. These way I don't have to repeat the calibration every time.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests