ColorLightSensor battery voltange dependency

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

Moderators: roger, 99jonathan, imaqine

ColorLightSensor battery voltange dependency

Postby s.frings » Mon Jul 26, 2010 4:37 pm

Hello all,

I noticed that the ColorLightSensor seems to depend much on the battery voltage. With fresh alcaline batteries, it always detect all four colors of the balls (from the Mindstorms 2.0 set) properly.

With rechargeable nickel batteries (7.8 Volt), the green color is often detected as black. After some time (7.4 Volt), green cannot be detected anymore at all and yellow balls are often detected as red. If tried different angles and istanced and I eliminted ambient light without any success.

This is really strange to me, because

a) Independently of the battery type, the device should work down to 1 Volt per Cell (6 Volts in total) because both alcaline and nickel batteries are empty below that level.

b) The hardware developer kit says that the four input connectors provide 4.3 Volt, so why does it depend on the battery voltage?

Any Ideas how to fix this?

Debugging Info, collected with 7.4 Volt battery Voltage using four balls with a distance of about 8mm:

Blue ball:
raw r/g/b/n: 133,150,273,97
cal r/g/b/n: 23,44,127,32
Color: 2, BLUE

Green ball:
raw r/g/b/n: 119,162,134,89
cal r/g/b/n: 19,61,32,22
Color: 1, BLACK

Yellow ball:
raw r/g/b/n: 376,252,176,114
cal r/g/b/n: 175,113,43,54
Color: 4, YELLOW

Red ball:
raw r/g/b/n: 347,135,140,114
cal r/g/b/n: 154,14,16,55
Color: 5, RED
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm

Postby s.frings » Mon Jul 26, 2010 4:52 pm

Ooops, I played around a little more and now I cannot detect the green ball anymore even with fresh alcaline batteries.

So it might not be related to the batteries. But anyway - my main problem is still there: I cannot detect the green ball!

More debugging data, taken with fresh alcaline batteries at 9.1 Volts:

Blue ball:
raw r/g/b/n: 122,132,244,88
cal r/g/b/n: 24,36,112,21
Color: 2, BLUE

Green ball:
raw r/g/b/n: 118,150,126,88
cal r/g/b/n: 20,51,27,21
Color: 1, BLACK

Yellow ball:
raw r/g/b/n: 337,229,167,115
cal r/g/b/n: 149,94,38,61
Color: 4, YELLOW

Red ball:
raw r/g/b/n: 299,125,125,104
cal r/g/b/n: 131,18,15,43
Color: 5, RED
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm

Postby s.frings » Mon Jul 26, 2010 6:56 pm

I did a simple visual test.

If I switch the ColorLightSensor to expose green light, and let it shine on the green ball, I see visually only few reflection. The ball appears nearly black to my eyes. So it is no wonder that the "cal green" value is only 50.

If I do the same with the red or blue ball, I see a great difference. The blue ball reflects the red light very good, and also the blue ball reflects blue light very good. In both cases, the "cal red" and "cal blue" values are above 100.

It seems that the color of the green ball does not match the color of the green Led. To check this further, I used a piece of green paper, but noticeable lighter color than the ball has.

This paper can be detected cleary as green, and also the measured value is much better ("cal green" is greater than 100).

Is there anbody who could tell post his values for a green ball (Using the ColorSensor Test" sample program and using the corrected classes.jar).
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm

Postby gloomyandy » Mon Jul 26, 2010 7:43 pm

Hi,
Before going too far down this road you may be better to wait for the next release of leJOS (coming soon now I hope). This has an updated color recognition algorithm (as used by the latest Lego firmware). If you understand how to use a developer snapshot you could try it out now. Otherwise if you want to take a look at the new code it is here...
http://lejos.svn.sourceforge.net/viewvc ... iew=markup
Take a look at the readValue method...

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

Postby s.frings » Mon Jul 26, 2010 8:15 pm

I found a workaround, by replacing the ColorLightSensor.readColor() by the following method:

public static Color getFarbe() {
int[] raw=new int[4];
farbSensor.readRawValues(raw);
//LCD.drawInt(raw[0]-raw[3],3,0,7);
//LCD.drawInt(raw[1]-raw[3],3,4,7);
//LCD.drawInt(raw[2]-raw[3],3,8,7);
boolean rot=(raw[0]-raw[3]) > 100;
boolean gruen=(raw[1]-raw[3]) > 50;
boolean blau=(raw[2]-raw[3]) > 100;
Color farbe;
if (rot && gruen)
farbe=Color.YELLOW;
else if (rot)
farbe=Color.RED;
else if (blau)
farbe=Color.BLUE;
else if (gruen)
farbe=Color.GREEN;
else
farbe=Color.BLACK;
//LCD.drawString(farbe.name()+" ", 12, 7);
return farbe;
}

It detects only the four colors that I am interested in. The trick is, to define lower threshold for green, than for the other colors.

Anyway, I think the green LED should have a darker color or the green ball should have a brighter color, so that both match. Then the ColorLightSensor.readColor() would work as it should.

If the color detection code part of the hardware, or can we change it in Lejos?
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm

Postby gloomyandy » Mon Jul 26, 2010 8:16 pm

Did you see my previous reply?

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

Postby gloomyandy » Mon Jul 26, 2010 8:18 pm

Oh and using the raw values is probably not a good idea for any general code. The values returned from one sensor to the next will vary. That is why Lego supply each sensor with individual calibration data...

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

Postby s.frings » Sat Jul 31, 2010 7:18 pm

Oh, yes. I can see that my problem will be solved in the new class source. I never noticed the problem with the Lego Firmware because I started with version 1.29.

I found snapshots in the SVN repository, which I will use now. Thanks for your help.
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm

Postby s.frings » Sat Jul 31, 2010 8:30 pm

It works fine with the new classes.jar snapshot from today.

The ColorLightSensor class has been renamed to ColorSensor. The Color class does not support the name() function anymore, so I need to rewrite my programs a litte - but that's not a problem.

I also updated the VM and the menu application using the snapshot files, just to ensure compatibility.
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm

Postby gloomyandy » Sat Jul 31, 2010 8:43 pm

Make sure you also use the linker (jtools.jar) from the snapshot... In general you are best to use all of the files in lib along with the new firmware and menu code...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby s.frings » Tue Aug 03, 2010 2:21 pm

Sure, I replaced all jar files and binaries that are in the snapshot directory.
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm

Re: ColorLightSensor battery voltange dependency

Postby Coppola » Mon Oct 17, 2011 1:08 pm

This paper can be detected cleary as green, and also the measured value is much better ("cal green" is greater than 100). Is there anbody who could tell post his values for a green ball (Using the ColorSensor Test" sample program and using the corrected classes.jar).
Coppola
New User
 
Posts: 2
Joined: Mon Oct 17, 2011 12:53 pm


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff