I found the same problem with my new RPLidar v2.
Using the C++ example from the SDK, I found out that it's necessary to start the motor before sending the scan command.
Based on the Java implementation found in
https://github.com/lessthanoptimal/j...eption/rplidar
I added
/**
* Sends a command with data payload
*/
protected void sendPayLoad(byte command, byte[] payLoad) {
if (verbose) {
System.out.printf("Sending command 0x%02x\n", command & 0xFF);
}
dataOut[0] = SYNC_BYTE0;
dataOut[1] = command;
//add payLoad and calculate checksum
dataOut[2] = (byte) payLoad.length;
int checksum = 0 ^ dataOut[0] ^ dataOut[1] ^ (dataOut[2] & 0xFF);
for(int i=0; i<payLoad.length; i++){
dataOut[3 + i] = payLoad[i];
checksum ^= dataOut[3 + i];
}
//add checksum - now total length is 3 + payLoad.length + 1
dataOut[3 + payLoad.length] = (byte) checksum;
try {
out.write(dataOut, 0, 3 + payLoad.length + 1);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Sends a command with data payload - int
*/
protected void sendPayLoad(byte command, int payLoadInt) {
byte[] payLoad = new byte[2];
//load payload little Endian
payLoad[0] = (byte) payLoadInt;
payLoad[1] = (byte) (payLoadInt >> 8);
sendPayLoad(command, payLoad);
}
/**
* Sends a start motor command
*/
public void sendStartMotor(int speed) {
sendPayLoad(START_MOTOR, speed);
}
In order to start scan, simply invoke
driver.sendStartMotor(660);
driver.sendScan(500);
Just created a pull request on the Java implementation above.
bye
Francesco