Switch off the colorsensor

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

Moderators: roger, gloomyandy, skoehler

Switch off the colorsensor

Postby LastSamurai » Thu Jan 02, 2014 10:15 pm

Hey,

I am using the Ev3 + ColorSensor + USB Connection and Control Center to debug. Now I was experimenting with the different colors of the sensors led (any docu somewhere which colors are possible? Full rgb?). I used setFloodlight fron eV3ColorSensor to change colors. This one only works with (well thats in the source code) blue white and red. But when I want to switch the sensor back off I used setFloodlight (boolean) with false. Crashed. This methode calles the other setFloodlight with Color.none but that's not supported (at least I think so):

Code: Select all
@Override
    public boolean setFloodlight(int color)
    {
        int mode;
        switch (color)
        {
        case Color.BLUE:
            mode = COL_AMBIENT;
            break;
        case Color.WHITE:
            mode = COL_COLOR;
            break;
        case Color.RED:
            mode = COL_REFLECT;
            break;
        default:
            // TODO: Should we ignore a wrong color or throw an exception?
            throw new IllegalArgumentException("Invalid color specified");
        }
        switchMode(mode, SWITCH_DELAY);
        // TODO Auto-generated method stub
        return true;
    }


I gues this is a bug. Or did I miss something?
LastSamurai
New User
 
Posts: 9
Joined: Thu Dec 26, 2013 8:22 pm

Re: Switch off the colorsensor

Postby gloomyandy » Fri Jan 03, 2014 12:21 am

Hmm,
I'm not sure if this a bug or not. If I remember correctly there is no mode for the color sensor that has the light turned off. The only possibility is probably to reset it, but I have a feeling if you do that it will flash red. If I get chance I'll take a look at it but at the moment I'm pretty busy with some motor control stuff. Arguably it does not make sense to support the floodlight method if you can't actually turn it off...

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

Re: Switch off the colorsensor

Postby Aswin » Fri Jan 03, 2014 12:55 am

Hi,

assuming you are using 0.5.0-alpha.

The preferred way to enable or disable the floodlight is to use the different modes and not to use the setFloodLight method directly.

The Method getAmbientMode returns a SampleProvider that utilises the sensor without its LEDs on, the method getRedMode returns a sample provider that utilises the sensor with a red floodlight on. As far as I know it is not possible to turn other LEDs on. Not even sure if the sensor has them.

Each of the SampleProviders/Modes makes sure that the sensor is properly configured for the mode before taking a measurement. if not it will configure the sensor first. This means that a fetchSample call to the AmbientMode SampleProvider always results in the floodlight being off. The RedMode SampleProvider will switch the floodlight on if needed. The good thing is that you do not have to bother with configuring the sensor, you just use the mode you want to. if you mix modes in a program you have to be aware that switching from one mode to another takes some time. In case of the color sensor this is 250 msec.

All sensors that support different modes now work this way. For each mode there is a different SampleProvider. You do not have to switch from one mode to another, this is done implicitly.

Aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Switch off the colorsensor

Postby gloomyandy » Fri Jan 03, 2014 11:16 am

Hi Aswin,
I'm pretty sure that in ambient mode the sensor turns on the blue led. not totally sure why but I think that is what happens!

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

Re: Switch off the colorsensor

Postby Aswin » Fri Jan 03, 2014 2:09 pm

I'll check it out.
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Switch off the colorsensor

Postby LastSamurai » Fri Jan 03, 2014 5:12 pm

Ok, after some playing around I get good results now with my robot (key was to have the sensor as near to the floor and as vertical as possible).
Standard mode seems to be rgb (at least thats what I get using getColorID()).
Code: Select all
@Override
    public int getColorID()
    {
        setFloodlight(Color.WHITE);
        return colorMap[port.getByte()];
    }


Anyways... I am trying to build a line following robot and I only got one color sensor (standard kit). If I dont want him to go from one side of the line to the other (like a drunk) I need to find the edge of the line and therefore need an excact value of the sensor. Is that possible with this sensor? How do I do that? As far as I have seen there is no method for that in the code?!

And sorry for all these questions guys, but I am having fun with this, so I really wanna learn more about it. If I could help with the code I'd do it (although I am no pro, and I am new to that project).
LastSamurai
New User
 
Posts: 9
Joined: Thu Dec 26, 2013 8:22 pm

Re: Switch off the colorsensor

Postby Aswin » Fri Jan 03, 2014 10:31 pm

Andy,

I stand corrected.
The ambient mode of the EV3 color sensor has the blue LED on. There is no way to get the LED light off with this sensor. Also not with the modes that are not implemented: REF-RAW and COL-CAL.

Aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: Switch off the colorsensor

Postby stijn.van.bael » Sun Jan 05, 2014 6:07 pm

Using following code on 0.5.0-alpha I can read a color and turn off the floodlight again. Repeating the code correctly re-initializes the sensor. Note that this did not work for port 1 (red flashing light).

Code: Select all
EV3ColorSensor sensor = new EV3ColorSensor(SensorPort.S3);
int colorID = sensor.getColorID();
sensor.close();
stijn.van.bael
New User
 
Posts: 1
Joined: Sun Jan 05, 2014 6:02 pm

Re: Switch off the colorsensor

Postby gloomyandy » Sun Jan 05, 2014 7:20 pm

When you say you get a red flashing light, can you be clear when you get the flashing light? If you simply use the sensor in color id mode do you get this flashing light or does the sensor work correctly. If you get the flashing light in this simple mode then please try the same thing on the same port using the Lego software and report back.

Thanks

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


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff