Using latest version of leJOS, eclipse and all JAVA updates. Running Windows 7 x64.
Using Bluetooth, I am currently sending sensor data from my NXT to an Android phone. The Android phone sends data to the NXT, which the NXT then uses to decide which direction to move the robot in. All's fine when I do one or the other, ie. Either do receive data from Android for movements, or send sensor data to Android.
If I try do both of these, the response time for movement is almost unusable - while the sensor data is still fine with close to zero delay. Any Idea's on why I would see a delay on the DataInputStream side of things?
I've tried putting them on separate threads, but the delay remains.
On main thread...
- Code: Select all
public void Start() throws IOException {
//Sets up the MovementManager - hands over the mode (100 = manual mode) and the DataOutputStream.
mm.Setup(100, _dis);
//start a new thread to read movement commands.
Thread movement_Thread = new Thread(new Runnable(){
@Override
public void run() {
try {
mm.ManualMovement();
} catch (IOException e) {
}
}
});
movement_Thread.start();
//Sets up the DataSender - hands over the sensors and the DataOutputStream.
sendData.Setup(sensors, _dos);
//start a new thread to send the sensor data.
Thread sendSensorData_thread = new Thread(new Runnable(){
@Override
public void run() {
sendData.Start();
}
});
sendSensorData_thread.start();
}
On separate thread... for receiving movement commands
- Code: Select all
public void ManualMovement() throws IOException {
while (true) {
int direction = dis.readInt();
int speed = dis.readInt();
Move(direction, speed);
LCDDrawData(direction, speed);
}
}
On another thread... for sending the sensor data
- Code: Select all
public void Start() {
while (true) {
try {
value = (int) sensors.GetComapssAngle();
dos.writeInt(value);
dos.flush();
} catch (IOException e) {
}
}
}
It all works, just like I mentioned, the receiving commands part is slow - delay of like 2 or 3 seconds...
I even tried introducing a delay into how often it sends sensor data, thinking that maybe it was sending data too frequently and thus blocking the network, but it made no difference.
Any ideas?

