Problems with the ColorLightSensor

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: 99jonathan, roger, imaqine

Problems with the ColorLightSensor

Postby michaeljoswig » Wed Mar 31, 2010 4:52 pm

Hello -- I am new in this forum (yes, the newest member) and English is not my mother language, so please don’t be to hard if my terminology is a little “strange”. I have bought a NXT 2.0 and I “play” with this toy since some weeks (with a lot of fun :D ) – I use a java editor, the lejos vers. is 0.85 (rev. 3303) and the colour sensor is the type 64892. I have exact the problems described in a former topic: I only get 0 or -1 back if I ask for …getRedComponent() or Green or Blue … I tried with the new classes.jar in the lib directory – but the problem is as before. Can somebody help me? Some more information: the result is on port 1 to 4 the same; the Ultrasonic sensor works perfect

Thanks, Michael
michaeljoswig
New User
 
Posts: 4
Joined: Wed Mar 31, 2010 2:23 pm

Postby gloomyandy » Wed Mar 31, 2010 5:18 pm

Have you tried the sample program ColorSensorTest that is supplied with leJOS (it is located in your home directory in eJOSNXJProjects\samples\ColorSensorTest)?

Also if you have downloaded the updated classes.jar you may need to replace more than one copy (I think there is one in your program files directory and there is also one in the leJOSNXJProjects dirs, you should probably search your system for classes.jar).

If you are still having problems please post your code. Also please post a link to which updated classes.jar you have been using (there is more than one...). I would recommend that you use the one I posted in this thread:
viewtopic.php?t=1883&highlight=download

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

Postby michaeljoswig » Thu Apr 01, 2010 5:44 am

Hello,

I took the classes.jar from your source. I also tried the "ColorSensorTest" after reading your answer: it seams to work fine: different colours can be switched on/off and I see also the values for the colours changing (depending on the colour between 200 and 1000). So, the not working program is "ColorDetector" and I used it (instaed of the ColorSensorTest) to understand how the different parts are working -- it was easy to understand. Now I will check, if I find some other places where the classes.jar have to be replaced.

Thansk a lot -- I will inform you as fast as possible

Michael
michaeljoswig
New User
 
Posts: 4
Joined: Wed Mar 31, 2010 2:23 pm

Postby gloomyandy » Thu Apr 01, 2010 9:55 am

ColorDetector is really a test program for the HiTechnics sensor not for the Lego one... In 0.85 I don't think you can use the two interchangeably, so it is probably safer (and more efficient) to use the mechanisms in the ColorSensor test program to read the various component values. The interface for this sensor has changed a lot in the current development builds (to improve interchangeability) , but I would not recommend that you use this (due to changes in other parts of the system)....

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

Postby michaeljoswig » Thu Apr 01, 2010 8:09 pm

Hello -- Ok, I understand. But, now, it is not so easy to understand, how the sensor works: in detail: there are SensorConstants -- and I can´t find a description, what do they do !? In the example ColorSensorTest the int type is "TYPE_COLORNONE"-- but what does it mean ? What does the type TYPE_COLORGREEN means ? Do you have a link to a page with some more information ? Thanks, Michael
michaeljoswig
New User
 
Posts: 4
Joined: Wed Mar 31, 2010 2:23 pm

Ups, I understand

Postby michaeljoswig » Thu Apr 01, 2010 9:08 pm

Hello -- I think I understand now :P ! You use "TYPE_COLORFULL + mode" -- +1 is red, +2 is green OK ok. Forget the question before !

Michael
michaeljoswig
New User
 
Posts: 4
Joined: Wed Mar 31, 2010 2:23 pm

Postby gloomyandy » Thu Apr 01, 2010 9:16 pm

The code for the color sensor was all done in a bit of a rush to get it out for the 0.85 release. So there is not as much documentation as we would like. Much of the API has been revised and will be different in the next leJOS release. The TYPE_* constants are basically the operating mode of the sensor. The color sensor is really 4 sensors in one...

TYPE_COLORNONE: No light is generated by the sensor, so the sensor returns a passive value of ambient light.
TYPE_COLORRED, TYPE_COLORGREEN, TYPE_COLORBLUE, the sensor will emit light of the specified color and so will typically return a light reading that measures the reflected light.
TYPE_COLORFULL The sensor operates in full color sensing mode. It samples all three colors (plus ambient), very rapidly, and then uses internal calibration values to identify the color of the an illuminated object.

The above constants can be passed into the constructor to set the operating mode of the sensor, or passed to the setType method to change the operating mode dynamically.

Remember that you always have the source of the leJOS classes so if there is something you do not understand, try taking a look at the source code...

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

Re: Problems with the ColorLightSensor

Postby mrnogues » Mon Mar 07, 2011 4:53 pm

Hi, I have test the code "ColorSensorTest" from projects/samples/ColorSensor/Test. No matter where do I point, or which color do I choose, the result it is always "-1".

What can i do to make it work properly?

Thanks,
MRN
mrnogues
New User
 
Posts: 4
Joined: Mon Mar 07, 2011 4:43 pm

Re: Problems with the ColorLightSensor

Postby gloomyandy » Mon Mar 07, 2011 6:03 pm

Which color sensor do you you have? There are two different types. Where did you get the sensor from?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3947
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Problems with the ColorLightSensor

Postby mrnogues » Mon Mar 07, 2011 7:00 pm

I bought the Lego NXT box online on July.

My sensor i think is the 64892 one, but i am not sure. Is the RGB one.

Thanks,
MRN
mrnogues
New User
 
Posts: 4
Joined: Mon Mar 07, 2011 4:43 pm

Re: Problems with the ColorLightSensor

Postby gloomyandy » Mon Mar 07, 2011 9:52 pm

Have you replaced your classes.jar file as described in the earlier post? Note you must replace all of the leJOS classes.jar files on your system. If you are using any of the plug-ins there may be more than one. I would suggest that you build the test program using the command line tools, to be sure...

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

Re: Problems with the ColorLightSensor

Postby s.frings » Tue Mar 08, 2011 9:06 am

Sometimes, the Lego Color Ligth Sensor does not work in Sensorport 4. I upgraded my Lejos and the NXT firmware in November 2010, since then that problem did not re-occur on my device.
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm

Re: Problems with the ColorLightSensor

Postby mrnogues » Tue Mar 08, 2011 5:58 pm

Thanks very much gloomyandy and s.frings, solved!!

The solution was to replace the classes.jar file, I am very sorry for asking when the solution was in the previous post. I will read better next time.

Thanks.
mrnogues
New User
 
Posts: 4
Joined: Mon Mar 07, 2011 4:43 pm

Re: Problems with the ColorLightSensor

Postby gloomyandy » Tue Mar 08, 2011 8:07 pm

Hi,
good to hear that you have solved your problem...

All the best

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


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff