Lejos NXT ColorSensor

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Lejos NXT ColorSensor

Postby zatteschacht » Tue Nov 29, 2011 11:21 am

Hi,

Part of my Thesis is to make a LEGO NXT robot navigate through a world following a black line. The world also has crossroads indicated by different colors.

To follow the black line, I use 2 Light sensors and it goes well. To detect a crossroad I want to use a Color Sensor.

Reading a color however takes a lot of time.

When using Lejos NXJ 0.8.5, I used ColorLightSensor.readColor(), which returned me the color fast enough.
I switched to Lejos NXJ 0.9.0, and now I use ColorSensor.getColor(), which is far too slow. Is there any way you can still read the colorsensor without it taking so much time?

I'm getting kinda desperate..
zatteschacht
New User
 
Posts: 6
Joined: Tue Nov 29, 2011 11:13 am

Re: Lejos NXT ColorSensor

Postby skoehler » Tue Nov 29, 2011 11:42 am

Have you tried getRawColor() instead of getColor() ?
You may also try the readValues() method of the SensorPort class.

See http://lejos.svn.sourceforge.net/viewvc ... iew=markup
skoehler
leJOS Team Member
 
Posts: 1387
Joined: Thu Oct 30, 2008 4:54 pm

Re: Lejos NXT ColorSensor

Postby gloomyandy » Tue Nov 29, 2011 11:52 am

You probably need to make sure the sensor is in the correct mode before calling getColor... Try setting the floodlight to be white, at the start of your program...
setFloodlight(Color.WHITE), this should mean that when reading the sensor you will not have to get through the reset/setup code all of the time. One quick tip, it is often a good idea to look at what a call like getColor does to help you understand why something may be slow. The source code for all of the leJOS classes is provided with the leJOS and can also be accessed on line. So for instance here is the ColorSensnor code...
http://lejos.svn.sourceforge.net/viewvc ... iew=markup
As you can see a call to readColor is much more complex if the current type is not COLOR_FULL. A quick look at the code and you will see that setting the floodlight to WHITE will set the type to be COLOR_FULL...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3881
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Lejos NXT ColorSensor

Postby zatteschacht » Tue Nov 29, 2011 12:05 pm

Wow, first of all thx for the very quick response.
I tried getRawColor() and getColorID() but no change there.

I used and keep using TYPE_COLORFULL

I tested getLightValue() and it goes about 100x faster though. When looking at the code I don't understand why. getColorID() and getLightValue() are almost identical (except for a condition check). Would it be possible to get the color when using just getLightValue()?
zatteschacht
New User
 
Posts: 6
Joined: Tue Nov 29, 2011 11:13 am

Re: Lejos NXT ColorSensor

Postby zatteschacht » Tue Nov 29, 2011 12:30 pm

I have changed the int in the constructor of ColorSensor from TYPE_COLORFULL to Color.WHITE. TYPE_COLORFULL was just wrong of me to use. The getColor method now goes fast enough. Hopefully I get good readings on the colors now :D Thx all
zatteschacht
New User
 
Posts: 6
Joined: Tue Nov 29, 2011 11:13 am


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff