No ColorLightSensor class in leJOS 0.9.1-2

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

Moderators: roger, 99jonathan, imaqine

No ColorLightSensor class in leJOS 0.9.1-2

Postby Jar0 » Mon Apr 09, 2012 11:35 pm

Hi,

I'm using leJOS 0.9.1-2 and i have small problem with color and light sensor programming. I have installed leJOS and additionaly installed Eclipse plugin to program my NXT. I Was trying to ColorSensor and LightSensor classes but my sensor wasn't working with them. Now i'm trying to use ColorLightSensor class but i can't find it in default classes.jar. Where i can find it? What should i do with this problem?

Thanks for any help.
Jar0
New User
 
Posts: 1
Joined: Mon Apr 09, 2012 11:26 pm

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby skoehler » Tue Apr 10, 2012 10:15 am

ColorLightSensor has been renamed to ColorSensor.
What sensor are you trying to use?
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby pcProfie » Thu Aug 02, 2012 5:15 pm

I've the same problems. I've got the origrinal sensor: http://www.nxt-in-der-schule.de/lego-mi ... rod_01.jpg I programmed this with the ColorLightSensor class:
while(cls.readValue()==Colors.BLACK) { [...] }
Colors from this Class: lejos.robotics.Colors
it was simple to use. in the new lejos 0.9.1-3 there is not the same method.
which method shoud I take?
(sry for the bad english. please correct my language :))
pcProfie
New User
 
Posts: 11
Joined: Thu Aug 02, 2012 4:18 pm

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby pcProfie » Thu Aug 02, 2012 5:34 pm

cs1.getColorID()
and getColor() from lejos.robotics.Color???
pcProfie
New User
 
Posts: 11
Joined: Thu Aug 02, 2012 4:18 pm

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby pcProfie » Thu Aug 02, 2012 5:37 pm

should I use this color-table?
lejos.robotics.Color
public static final int BLACK 7
public static final int BLUE 2
public static final int CYAN 12
public static final int DARK_GRAY 11
public static final int GRAY 9
public static final int GREEN 1
public static final int LIGHT_GRAY 10
public static final int MAGENTA 4
public static final int NONE -1
public static final int ORANGE 5
public static final int PINK 8
public static final int RED 0
public static final int WHITE 6
public static final int YELLOW 3
from the constant field values?
pcProfie
New User
 
Posts: 11
Joined: Thu Aug 02, 2012 4:18 pm

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby gloomyandy » Fri Aug 03, 2012 7:50 am

Yes that is the class to use. Remember you can always look at the sample code:
http://lejos.svn.sourceforge.net/viewvc ... iew=markup
This will usually help you to understand how to use the classes.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby pcProfie » Fri Aug 03, 2012 12:07 pm

thanks! and how can I activate only the red and blue or blue and green lamp?
pcProfie
New User
 
Posts: 11
Joined: Thu Aug 02, 2012 4:18 pm

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby gloomyandy » Fri Aug 03, 2012 1:17 pm

Look at the same sample...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby pcProfie » Sat Aug 04, 2012 10:24 am

no, I mean two lamps. there're only this modes: String modes[] = {"Full", "Red", "Green", "Blue", "White", "None"};
and I've got an other problem now:
here are a few lines of my programm now:

Code: Select all
import lejos.nxt.*;
import lejos.util.TextMenu;

public class allo {
   static allo allr;
   static int choice;
   String colorNames[] = { "None", "Red", "Green", "Blue", "Yellow",
         "Megenta", "Orange", "White", "Black", "Pink", "Grey",
         "Light Grey", "Dark Grey", "Cyan" };
   static String linienfarbe[] = { "Red", "Green", "Blue", "Yellow", "White",
         "Black" };
   String color;
   ColorSensor cs;

   public allo() {
      cs = new ColorSensor(SensorPort.S3);
   }

   public static void main(String[] args) {
      allr = new allo();
      TextMenu Menu2 = new TextMenu(linienfarbe, 1, "Set color");
      choice = Menu2.select();
      if (choice < 0)
         return;

      allr.method();
   }

   public void method() {
      LCD.clear();
      LCD.drawString("choice: " + linienfarbe[choice], 0, 2);
      while (true) {
         color = colorNames[cs.getColor().getColor() + 1];
         LCD.clear(3);
         LCD.drawString("current:"+color, 0, 3);
         if (color == linienfarbe[choice]) {
            LCD.clear(4, 15, 1);
            LCD.drawString("true", 11, 4);

            ;
         } else {
            LCD.drawString("false", 11, 4);

         }
      }
   }
}


simple: if the colorsensor get the same color like <linienfarbe[choice]>, the nxt tells "true"
but it always tells "false"
pcProfie
New User
 
Posts: 11
Joined: Thu Aug 02, 2012 4:18 pm

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby gloomyandy » Sat Aug 04, 2012 12:19 pm

It is not possible to have "two colors" on at the same time. There is only a single LED that can be either off, red, blue or green, White is a special case and is actually the LED changing between red, blue and green very fast.

As to your program you are comparing the object references of the strings to see if they are the same in general this is not a good idea (see below for more comments). Change the following line:
Code: Select all
         if (color == linienfarbe[choice]) {

to be:
Code: Select all
         if (color.equals(linienfarbe[choice])) {

See the following reference for more info:
http://stackoverflow.com/questions/5138 ... gs-in-java

Note: In a standard Java VM the original code would work. But it still is probably not a good idea. The reason why it would work is because both references refer to a constant string and in a standard JVM constant strings will in interned, which means that two identical strings will actual share the same object. However in leJOS constant strings are not interned to reduce the amount of memory used. This is one of the few differences between the leJOS VM and a standard JVM.

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

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby pcProfie » Sat Aug 04, 2012 2:08 pm

thanks
i thought i can use the java classes for the nxt too
(not buttons.. but sound..)
pcProfie
New User
 
Posts: 11
Joined: Thu Aug 02, 2012 4:18 pm

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby gloomyandy » Sat Aug 04, 2012 2:45 pm

I'm not sure I understand your comment, what do you mean by "i thought i can use the java classes for the nxt too"? What classes do you want to use, that you think you can't use?

Note that comparing the object references as you were doing is probably not a good idea even with a standard JVM. Also to be honest you would probably be better off comparing the color id rather than the strings...

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

Re: No ColorLightSensor class in leJOS 0.9.1-2

Postby pcProfie » Sat Aug 04, 2012 4:03 pm

ah sry i confused sth XD. thanks for your answers. i searched for a god forum sfor a long time and now i found it. XD.
can anyone german? my english is not so good and i need a translator when i have difficult questions. THANKS
pcProfie
New User
 
Posts: 11
Joined: Thu Aug 02, 2012 4:18 pm


Return to NXJ Software

Who is online

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

more stuff