Trouble setting color sensor lamp to white

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

Moderators: 99jonathan, roger, imaqine

Trouble setting color sensor lamp to white

Postby clintonb » Mon Nov 21, 2011 5:15 pm

Greetings.

I am having difficulty setting the the lamp on a LEGO color sensor to white, with a slighty-modified version of Enchanting 0.0.9. [The modifications should not have any effect on the color sensor].

When I run the ColorSensorTest.java sample, it works fine, and I can set the lamp white (and red, green, blue, and off).

Here is the simplest test code I can come up with:

Code: Select all
import lejos.nxt.*;
import lejos.robotics.Color;

public class SimpleColorTest
{   
    public static final void delay(float seconds) {
       Sound.pause( (int)(1000.0f * seconds) );  // time in milliseconds
    }

    public static void main(String [] args) throws Exception
    {
        ColorSensor S1 = new ColorSensor(SensorPort.S1);
   
        while (true) {
            S1.setFloodlight(Color.NONE);   delay(1.0f);
            S1.setFloodlight(Color.RED);    delay(1.0f);
            S1.setFloodlight(Color.GREEN);  delay(1.0f);
            S1.setFloodlight(Color.BLUE);   delay(1.0f);
            S1.setFloodlight(Color.WHITE);  delay(2.0f);   
        }
    }
}


What I find is that the lamp does not turn on white when I tell it to. (It does blink on white for an instant before I set the next color. Changing how long it is supposed to be white has no effect). Every other color works fine.

This seems so simple. Does anyone else get the unexpected result? What am I doing wrong?

Thanks,
Clinton
clintonb
Active User
 
Posts: 121
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Trouble setting color sensor lamp to white

Postby gloomyandy » Mon Nov 21, 2011 6:27 pm

Hi,
There is no actual white flood light, it is white only because the NXt rapidly switches between red/blue/green, it will only do this when actually reading the sensor....

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

Re: Trouble setting color sensor lamp to white

Postby clintonb » Mon Nov 21, 2011 10:54 pm

Ah, thank you Andy. That makes a lot of sense!

Clinton
clintonb
Active User
 
Posts: 121
Joined: Fri May 28, 2010 1:44 am
Location: Cardston, Alberta, Canada

Re: Trouble setting color sensor lamp to white

Postby marvin » Thu Aug 01, 2013 9:54 pm

Hello Andy,

gloomyandy wrote:There is no actual white flood light, it is white only because the NXt rapidly switches between red/blue/green, it will only do this when actually reading the sensor....


This is right. The original firmware supports white floodlight by dummy measurements. I tried this with leJOS but it does not work - the sensor flashes white for a short time then it remains one second black until the next white flash and so on. How to speed up this to get a white "Floodlight"?

Thank you :-)

Bye Marvin
--
I am feeling very depressed...
marvin
Novice
 
Posts: 26
Joined: Mon Mar 19, 2012 12:47 am

Re: Trouble setting color sensor lamp to white

Postby gloomyandy » Thu Aug 01, 2013 10:34 pm

How did you try doing dummy measurements?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4119
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Trouble setting color sensor lamp to white

Postby marvin » Sat Aug 03, 2013 1:44 pm

Hello Andy,

I tried it like this:

Code: Select all
ColorSensor Lamp = new (ColorSensor(SensorPort.S3));
Lamp.SetColor(Color.WHITE);
while (0)
{
  Lamp.getColor();
}


But this only flashes...

If you have an idea to get it faster - you are welcome :-)

Thank you,
Bye Marvin
--
I am feeling very depressed...
marvin
Novice
 
Posts: 26
Joined: Mon Mar 19, 2012 12:47 am

Re: Trouble setting color sensor lamp to white

Postby gloomyandy » Sat Aug 03, 2013 1:56 pm

Is this code running on the NXT or on a PC? Are any other threads running at the same time. I'm struggling to see how it would flash at a rate of 1Hz if it runs on the NXT with no other Threads running. Have you tried using the sample program that ships with leJOS? ColorSensorTest, it runs on the NXT and I'm pretty sure that the sensor stays on most of the time then. If your code is running on a PC then all bets are off!

Actually your code is not even legal Java I'm pretty sure that while (0) will give an error... Also While (0) would never execute the contents of the loop (assuming your language is C like).
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4119
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Trouble setting color sensor lamp to white

Postby marvin » Sat Aug 03, 2013 9:00 pm

Hello Andy,

of course I should have written "true" instead of "0". The "0" was totally bullshit.

And I am sorry because the program works as expected - the sensor LED is now white. The program runs on the NXT and I had some more code around it - for reading the distance sensor... That one needs the time - mea culpa.

Thank you very much for your help :-)

Bye marvin
--
I am feeling very depressed...
marvin
Novice
 
Posts: 26
Joined: Mon Mar 19, 2012 12:47 am


Return to NXJ Software

Who is online

Users browsing this forum: Google [Bot] and 3 guests

more stuff