Hi
What code are you using to test with on the NXT?
The following (I just pasted everything, go down to where the comment "HERE'S THE CODE" is.)
- Code: Select all
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import lejos.nxt.LCD;
import lejos.nxt.Motor;
import lejos.nxt.MotorPort;
import lejos.nxt.NXTMotor;
import lejos.nxt.SensorPort;
import lejos.nxt.Sound;
import lejos.nxt.SoundSensor;
import lejos.nxt.TouchSensor;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.addon.AccelHTSensor;
public class CPConAccel {
public static CPConAccel instance;
static String VERSION = "1.0.0";
BTConnection btc;
DataInputStream dis;
DataOutputStream dos;
NXTMotor mot;
AccelHTSensor a;
TouchSensor left;
TouchSensor right;
SoundSensor sound;
int yVal,zVal;
byte yByte,zByte;
int soundVol;
byte touch = 0;
public CPConAccel()
{
LCD.drawString("CP CONTROLLER",0,0);
LCD.drawString("Version "+VERSION, 0, 1);
LCD.drawString("YADA YADA YADA",0,2);
LCD.refresh();
SetupSensActuators();
waitForConnection();
Step();
Disconnect();
}
public void SetupSensActuators()
{
mot = new NXTMotor(MotorPort.A);
a = new AccelHTSensor(SensorPort.S1);
left = new TouchSensor(SensorPort.S2);
right = new TouchSensor(SensorPort.S3);
sound = new SoundSensor(SensorPort.S4);
}
public void waitForConnection()
{
LCD.drawString("Waiting for connection",0,4);
Sound.beepSequence();
LCD.refresh();
btc = Bluetooth.waitForConnection();
dis = btc.openDataInputStream();
dos = btc.openDataOutputStream();
LCD.clear();
LCD.drawString("Connected to PC",0,4);
Sound.twoBeeps();
LCD.refresh();
}
Byte i;
public void Step()
{
//data specification:
//in bytes: length,null,x,y,soundVol,touchSensors (7 bytes)
//TODO USE MULTI THREADING? (ONE FOR VALUE READING AND ONE FOR BLUETOOTH I/O)
while (true)
{
//UPDATE ACCEL VALUES (HERE'S THE CODE)
yVal = a.getYAccel();
yByte = (byte) (0.635*(yVal-((yVal>500) ? 1024 : 0))); //skim down values from (800..1024, 0...200) to (-127...127)
zVal = a.getZAccel();
zByte = (byte) (0.635*(zVal-((zVal>500) ? 1024 : 0)));
soundVol = sound.readValue();
if (left.isPressed()) touch+=1;
if (right.isPressed()) touch+=2;
LCD.drawInt(yByte, 0, 0);
LCD.drawInt(yVal, 5,0);
LCD.drawInt(zByte, 0 ,1);
LCD.drawInt(zVal, 5,1);
LCD.refresh();
try
{
//READ BT
if (dis.available() > 0)
{
i=dis.readByte();
if (i==1) //FEEDBACK: TURN MOTOR.
Motor.A.rotate(1000);
if (i==2) //FEEDBACK: EXIT PROGRAM
break;
dis.skipBytes(dis.available());
}
//WRITE BT
dos.writeByte(yByte);
dos.writeByte(zByte);
dos.writeByte(soundVol);
dos.writeByte(touch);
dos.flush();
}
catch (IOException e)
{
LCD.drawString("BT Exception", 0,6);
break;
}
touch = 0;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
LCD.drawString("Thread Exception", 0,6);
break;
}
}
}
public void Disconnect()
{
btc.close();
}
public static void main(String[] args)
{
instance = new CPConAccel();
}
}
What version of leJOS are you running?
0.9.0 beta
What exactly are you seeing as the output?
When I run the AccelDemo on the pc, I see nice (y and z) values in the range of 800...1000 and 0...200
When I run the CPConAccel on the NXT, the direct sensor values (variables yVal and zVal) start of just fine, but then they reach values like 9000.
How are you displaying the results?
I'm using LCD.drawInt(); to draw the sensor values directly to the LCD.
What are you doing to the sensor when you get these results?
I'm tilting it slowly over the Y and Z axes, I go down to 90 degrees and then return back.
Thanks for the response!
-Declan