I'm currently facing some issues with the PC API when using Color and / or Ultrasonic Sensor.
Attached the very simple source code and the sysouts. Have I forgotten something or is there a bug?
- Code: Select all
import java.io.InputStream;
import java.io.OutputStream;
import lejos.nxt.ColorLightSensor;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.pc.comm.NXTComm;
import lejos.pc.comm.NXTCommFactory;
import lejos.pc.comm.NXTInfo;
public class HelloWorld {
/**
* @param args
*/
public static void main(String [] args) throws Exception {
try{
NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.USB);
NXTInfo[] nxtInfo = nxtComm.search("NXT",NXTCommFactory.USB);
System.out.println(nxtInfo.length);
if(nxtInfo.length>0)
{
NXTInfo nxt = nxtInfo[0];
//nxtComm.open(nxt);
System.out.println("COnnected");
int[] b;
ColorLightSensor a = new ColorLightSensor(SensorPort.S2, ColorLightSensor.TYPE_COLORFULL);
UltrasonicSensor c = new UltrasonicSensor(SensorPort.S4);
System.out.println(c.getDistance());
for(int i=0;i<100;i++)
{
System.out.println("Check" + i);
System.out.println("Blue: " + a.getBlueComponent());
System.out.println("Green: " + a.getGreenComponent());
System.out.println("Red: " + a.getRedComponent());
System.out.println("Floodlight: " + a.getFloodlight());
System.out.println("Normalized Light: " + a.getNormalizedLightValue());
b = a.getColor();
for (int j : b) {
System.out.println(j);
}
System.out.println("Color: " + a.getColor());
System.out.println("RAW " + SensorPort.S1.readRawValue());
Thread.sleep(1000);
}
}
else
{
System.out.println("No NXT Found");
}
}
catch (Exception e) {
// TODO: handle exception
}
}
}
Sysout:
Found NXT: NXT 0016530CEBC4
1
COnnected
Found NXT: NXT 0016530CEBC4
255
Check0
Blue: 16335
Green: 16335
Red: 16335
Floodlight: NONE
Normalized Light: 65535
0
0
0
Color: [I@1389e4
RAW 65535
EDIT:
I just tried the sensor test:
Found NXT: NXT 0016530CEBC4
light = 100
distance = 255
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 8
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
light = 100
distance = 7
So the Ultrasonic is here working, but the light sensor always returns 100.
What is the correct class? I have the RGB Color Sensor with 3 holes in the front:
- RGB LEDs
- a black one (IR?)
- a white one (maybe light)
Thanks & Kind regards
Dominik
