Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   RPLIDAR with java (http://www.chiefdelphi.com/forums/showthread.php?t=153712)

godkane 15-01-2017 15:29

RPLIDAR with java
 
I'm having issues getting the RPLILDAR v2 working with the default serial driver in java with the RoboRIO. I have no issues communicating when connected to a PC with my own C# code or provided C libraries.

Here is the webpage with the lidar including SDK documentation and code:
http://www.robotshop.com/en/rplidar-...r-scanner.html

Here is a simple command to have the LIDAR spin.
SerialPort sp = new SerialPort(115200, SerialPort.Port.kUSB1, 8, Parity.kNone);
byte[] b = new byte[5];
b[0] = (byte)0xa5;
b[1] = (byte)0xf0;
b[2] = (byte)0x90;
b[3] = (byte)0x01;
b[4] = (byte)0xc5;
sp.write(b, b.length);
sp.flush();

I do seem to be able to get basic health commands to work, just the more advanced commands such as spin and get reading do not work.

I have also connected V5 power to the power connector on the RPLidar board.

Any help would be appreciated.

thecitrozz 30-01-2017 05:07

Re: RPLIDAR with java
 
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

scaryone 30-01-2017 06:18

Re: RPLIDAR with java
 
I assume you are not using this on an FRC bot? It's listed over the $400 limit. Or does the volume discount price count?

marshall 30-01-2017 08:14

Re: RPLIDAR with java
 
Quote:

Originally Posted by scaryone (Post 1638014)
I assume you are not using this on an FRC bot? It's listed over the $400 limit. Or does the volume discount price count?

About that...

https://www.chiefdelphi.com/forums/s...d.php?t=154127

scaryone 30-01-2017 12:00

Re: RPLIDAR with java
 
oooo interesting. Thanks Marshall


All times are GMT -5. The time now is 21:34.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi