Color Sensor Problems

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

Moderators: roger, gloomyandy, skoehler

Color Sensor Problems

Postby Rkandana » Sat Oct 26, 2013 1:31 pm

So, i was getting started with using my Color Sensor on the EV3. I typed in a basic program which draws the Lightv value on my LCD. However when ever i run it i get this error.

al status is 0
Time is 3063
Init complete retry 1 time 3149
size is 60
size is 60
size is 60
size is 60
size is 60
size is 60
size is 60
size is 60
Got 6 entries time 1326
reset cnt 0
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method enableColorSensor() is undefined for the type SensorPort
The method readValues(int[]) is undefined for the type SensorPort
The method readValue() is undefined for the type SensorPort
The method readRawValues(int[]) is undefined for the type SensorPort
The method readRawValue() is undefined for the type SensorPort
The method readValues(int[]) is undefined for the type SensorPort
The method readValues(int[]) is undefined for the type SensorPort
The method readRawValues(int[]) is undefined for the type SensorPort
The method readRawValues(int[]) is undefined for the type SensorPort
The method readRawValue() is undefined for the type SensorPort
The method readRawValue() is undefined for the type SensorPort
The method readValue() is undefined for the type SensorPort
The method readValue() is undefined for the type SensorPort

at lejos.nxt.ColorSensor.<init>(ColorSensor.java:76)
at lejos.nxt.ColorSensor.<init>(ColorSensor.java:64)
at Robot.<init>(Robot.java:4)


Also when we save/compile our file, do we need to do the whole export and then copy paste before running it?

Any help would be appreciated! Thanks!
Rkandana
New User
 
Posts: 13
Joined: Sat Oct 19, 2013 1:15 pm

Re: Color Sensor Problems

Postby gloomyandy » Sat Oct 26, 2013 9:27 pm

The NXT color sensor is not support in the 0.4.0-alpha release (there are compilation errors). If you are actually trying to use the EV3 color sensor then you need to use the EV3ColorSensor driver.

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

Re: Color Sensor Problems

Postby cfin » Thu Dec 12, 2013 8:35 am

Hello,
I am still usind the 0.4.0 release and try to use the ev3-colorsensor.
Code: Select all
UARTPort uPort = new LocalUARTPort();
      if (!uPort.open(2)) {
         System.out.println("Open failed");
         return;
      }
      uPort.setMode(2);
      this.colorSensor = new EV3ColorSensor(uPort);

But somehow it always says open failed. I also saw, if I use in this port the infrared-sensor, the opening works, but the resulting color is always 0,0,0.

Does someone know, how to use the color sensor correctly?
cfin
New User
 
Posts: 15
Joined: Fri Oct 25, 2013 8:04 pm

Re: Color Sensor Problems

Postby gloomyandy » Thu Dec 12, 2013 10:57 am

Hi, are you sure you have the sensor connected to the correct port (in this case you will need the color sensor plugged into the port marked 3 on the EV3 case. Port numbers in 0.4-alpha start at 0 which is the port marked 1).
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3645
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Color Sensor Problems

Postby cfin » Thu Dec 12, 2013 1:50 pm

Hello,
I just tried again without changing anything, just restarting and it works better now.

I still see, that get Color().getRed and so on always returns 0. I then found out, that in the class color, the red, green and blue values are never set. So there is some implementation missing.

But getting the color id is working now. Are there plans to implement a possiblity to directly receive the color values instead of a single color id?

Thanks,
cfin
cfin
New User
 
Posts: 15
Joined: Fri Oct 25, 2013 8:04 pm

Re: Color Sensor Problems

Postby gloomyandy » Thu Dec 12, 2013 2:50 pm

Hi,
Glad that it seems to be working for you now. As to the RGB values, see the TODO: comments in the latest source code:
https://sourceforge.net/p/lejos/ev3/ci/ ... ensor.java

As far as I can tell this is a problem with the Lego sensor, so not a lot we can do to fix it. Interestingly the Lego block does not seem to provide access to the RGB values...

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

Re: Color Sensor Problems

Postby cfin » Thu Dec 12, 2013 3:02 pm

ok thankyou andy.
I made a Color enum:
Code: Select all
public enum ColorId {
      RED(0), GREEN(1), BLUE(2), YELLOW(3), MAGENTA(4), ORANGE(5), WHITE(6), BLACK(7), PINK(8), GRAY(9), LIGHT_GRAY(
            10), DARK_GRAY(11), CYAN(12), BROWN(13), NONE(-1);

      private int id;

      private ColorId(int id) {
         this.id = id;
      }

      public static ColorId getInstance(int id) {
         for (ColorId colorId : ColorId.values()) {
            if (colorId.id == id) {
               return colorId;
            }
         }
         return NONE;
      }
   }


This way its easer to work with the colors instead of the int values. Additionally you can directly log them in a human readable way. Perhaps it helps somebody.
cfin
New User
 
Posts: 15
Joined: Fri Oct 25, 2013 8:04 pm


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 3 guests

cron
more stuff