View unanswered posts | View active topics It is currently Thu Sep 18, 2014 5:49 pm






Reply to topic  [ 9 posts ] 
NXT Color Sensor 2.0 
Author Message
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 37
Location: Saint Paul, MN
Post NXT Color Sensor 2.0
I recently purchased 2 color sensors since the ambient light sensor has a red light and cant differentiate the blue line with the ground, but I purchased them seeing that the color also has an ambient light sensor. I know how to use the rgb values perfectly well, I just haven't seen any resources showing how to utilize the part of the sensor, and I need that function to tell the difference between the ground and the black platform. Any help is appreciated, thanks!

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Thu Oct 10, 2013 9:30 pm
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: NXT Color Sensor 2.0
How close are you mounting the sensors to the ground? Are these LEGO sensors or HiTechnic sensors?

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Thu Oct 10, 2013 9:39 pm
Profile
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 37
Location: Saint Paul, MN
Post Re: NXT Color Sensor 2.0
They are about an inch off the ground (pointed down of course) and they are lego sensors

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Fri Oct 11, 2013 8:22 am
Profile WWW
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 37
Location: Saint Paul, MN
Post Re: NXT Color Sensor 2.0
This is from the Lego site itself: "The NXT Color Sensor is able to perform three unique functions. It acts as a color sensor, distinguishing among six colors; it works as a light sensor, detecting light intensities – both reflected light and ambient light; and it works as a color lamp, emitting red, green, or blue light."

So I don't know how RobotC handles those two other functions.

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Fri Oct 11, 2013 6:02 pm
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: NXT Color Sensor 2.0
I see what you mean. You can detect ambient light intensity simply by adding up the RGB values and dividing by 3. As to the "color lamp" functionality, you'll have to find drivers for the sensor. I don't think Xander has written drivers for the NXT color sensor yet (there's one for the light sensor though).

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Fri Oct 11, 2013 9:53 pm
Profile
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 37
Location: Saint Paul, MN
Post Re: NXT Color Sensor 2.0
Thanks, for the RGB values would I use SensorRaw? I can figure out how to use it but I dont know if that is what I would use, I just do SensorValue right now.

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Fri Oct 11, 2013 10:41 pm
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: NXT Color Sensor 2.0
That's what I would think. Having never used it before, I now realize it might be really tricky. :P
It'd be nice if a dev or Xander could lend some help here.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Fri Oct 11, 2013 10:58 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: NXT Color Sensor 2.0
There's a sample program in the, well, err, sample program folder, called, you guessed it, "ColorSensor.c". It has code that shows you how to get the RGB values from the LEGO Colour Sensor.

I've attached it for your convenience and pasted a small snippet, so you know what to look for:
Code:
void displayRGBColorValues()
{
   short nAtoDValues[4];
   short nRawValues[4];
   short nColorValues[4];
   string sTemp;

  getColorSensorData(colorPort, colorAtoD,   &nAtoDValues[0]);
  getColorSensorData(colorPort, colorRaw,    &nRawValues[0]);
  getColorSensorData(colorPort, colorValue,  &nColorValues[0]);

  displayColorIndex();

  nxtDisplayTextLine(3, "   AtoD  Raw   %%");
  StringFormat(sTemp, "R  %4i%5i", nAtoDValues[0], nRawValues[0]);      nxtDisplayTextLine(4, "%s%4i", sTemp, nColorValues[0]);
  StringFormat(sTemp, "G  %4i%5i", nAtoDValues[1], nRawValues[1]);      nxtDisplayTextLine(5, "%s%4i", sTemp, nColorValues[1]);
  StringFormat(sTemp, "B  %4i%5i", nAtoDValues[2], nRawValues[2]);      nxtDisplayTextLine(6, "%s%4i", sTemp, nColorValues[2]);
  StringFormat(sTemp, "Amb%4i%5i", nAtoDValues[3], nRawValues[3]);      nxtDisplayTextLine(7, "%s%4i", sTemp, nColorValues[3]);
}


I've never really done a lot with the LEGO colour sensors but hopefully the raw values will be able to help you. There's some RGB to HSV conversion code in my driver suite, I think it might be in the common-light.h file. From what I have gathered is that HSV is much easier to map to actual colour ranges than RGB.

= Xander


Attachments:
ColorSensor.c [11.18 KiB]
Downloaded 321 times

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]
Sat Oct 12, 2013 2:00 am
Profile WWW
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 37
Location: Saint Paul, MN
Post Re: NXT Color Sensor 2.0
Thanks so much, got my autonomous working!

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Sat Oct 12, 2013 10:47 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.