ok thank you for your answer !
but in fact, the author of the topic on javaspecialists.eu use the
LeJOS firmware on the NXT brick, so the LeJOSlibrary too.
I don't want to use this library, because i want my android
application running whatever the firmware is.
Anywhere i will email him, maybe he could help me!
On 19 mai, 04:12, gjs garyjamessi...@gmail.com wrote:
Hi
Have a look athttp://www.javaspecialists.eu/archive/Issue189.html
And maybe email the author.
Regards
On May 18, 7:43 pm, damienb2 damien.bruc...@gmail.com wrote:
Hello everybody!
i'm developping an android application to remote control a lego
mindstorm NXT.
The NXT let the mobile control motors, and sensors (ultrasonic, light,
temperature,...)
The android mobile is linked to the nxt by bluetooth.
I success in controling the motors, but now i've got one problem :
accessing the sensors.
I tried to get informations from the ultrasonic sensor since a long
time, but no success!
how i do it :
1) i send first the information my ultrasonic sensor is linked to the
port 1 according to instructions of the bluetooth Lego NXT developper
kit:
setUp
void initUltrasonicSensor(int sensorPort){
byte[] message = new byte[5];
message[0]= LCPMessage.DIRECT_COMMAND_NOREPLY; // DirectCommand,
byte
constant : 0x00
message[1]= LCPMessage.SET_INPUT_MODE; //
SetInputMode, byte
constant : 0x05
message[2] = (byte) sensorPort; //
Input Port, 0 1 2 or 3
message[3]= typePort ;
// Type Port, ultrasonic = 0x0B
message[4]= (byte) 0x00;
// Sensor mode
sendMessage(message);
}
/**
* Sends a message on the opened OutputStream
* @param message, the message as a byte array
*/
void sendMessage(byte[] message) throws IOException {
if (nxtOutputStream == null)
throw new IOException();
// send message length
int messageLength = message.length;
nxtOutputStream.write(messageLength);
nxtOutputStream.write(messageLength 8);
nxtOutputStream.write(message, 0, message.length);
}
2) then, i send the informtion get distance from the ultrasonic
sensor :
public void getInputValues(int sensor) {
byte[] request = new byte[3];
request[0] = LCPMessage.DIRECT_COMMAND_REPLY; // DirectCommand,
byte
constant : 0x00
request[1] = LCPMessage.GET_INPUT_VALUES; //
getInputValues, byte
constant : 0x07
request[2] = (byte) sensor;
// input port, 0 1 2 or 3
sendMessage(message);
}
3) when i reveived the reply information from the NXT, i get it :
05-18 10:33:53.652: INFO/(8885): Values received from
UltrasonicSensor : [ 2 7 0 0 1 0 B 0 0 0 0 0 0 0 0 0 ]
the expected response, according to instructions of the bluetooth Lego
NXT developper kit:
byte 0: 0x02
byte 1: 0x07
byte 2: status byte
byte 3: input port (range: 0-3)
byte 4: valid? (boolean TRUE if new data value should be seen as valid
data)
byte 5: calibrated? (boolean TRUE if calibration file found and used
for Calibrated Value field below)
byte 6: sensor type (enumerated)
byte 7: sensor mode (enumerated)
byte 8-9: Row A/D value(UWORD; device dependent)
byte 10-11: Normalized A/D value(UWORD; device dependent; Range:
0-1023)
byte 12-13: Scaled value (SWORD; mode dependent)
byte 14-15: Calibrated value (SWORD; value scaled according to
calibration. CURENTLY UNUSED.)
So i'm supposed to get the information about the distance from the 8-9
byte, but i get 0!
Could anyone help me ?
thanks for all!
(sorry for my english, i'm french!)
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en