Go to Post Something has gone awry this year in FIRST. I think more teams are concerned with winning and their robot that they don't even stop to think about the kids on their team, or the learning experiences of others. - Amanda Morrison [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-01-2017, 15:29
godkane godkane is offline
Registered User
FRC #3875
 
Join Date: Jan 2014
Location: Grand Rapids, MI
Posts: 12
godkane is an unknown quantity at this point
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2017, 05:07
thecitrozz thecitrozz is offline
Registered User
None #0001
 
Join Date: Jan 2017
Location: Rome - Italy
Posts: 1
thecitrozz is an unknown quantity at this point
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
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2017, 06:18
scaryone's Avatar
scaryone scaryone is online now
Registered User
FRC #0058 (The Riot Crew)
Team Role: Coach
 
Join Date: Jan 2011
Rookie Year: 2007
Location: South Portland Maine
Posts: 140
scaryone will become famous soon enough
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?
Reply With Quote
  #4   Spotlight this post!  
Unread 30-01-2017, 08:14
marshall's Avatar
marshall marshall is offline
My pants are louder than yours.
FRC #0900 (The Zebracorns)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2003
Location: North Carolina
Posts: 1,330
marshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond repute
Re: RPLIDAR with java

Quote:
Originally Posted by scaryone View Post
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
__________________
"La mejor salsa del mundo es la hambre" - Miguel de Cervantes
"The future is unwritten" - Joe Strummer
"Simplify, then add lightness" - Colin Chapman
Reply With Quote
  #5   Spotlight this post!  
Unread 30-01-2017, 12:00
scaryone's Avatar
scaryone scaryone is online now
Registered User
FRC #0058 (The Riot Crew)
Team Role: Coach
 
Join Date: Jan 2011
Rookie Year: 2007
Location: South Portland Maine
Posts: 140
scaryone will become famous soon enough
Re: RPLIDAR with java

oooo interesting. Thanks Marshall
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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