- Notifications
You must be signed in to change notification settings - Fork0
A Java libraries to manage USB devices like Controllers, Arduinos, IMUs, GPS, etc...
License
NotificationsYou must be signed in to change notification settings
ev3dev-lang-java/usb-devices
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Java library to manage USB devices like LIDARs, Arduino boards, IMUs, GPS, etc...
The library supports SLAMTEC A1 & A2 models
Example using a RPLIDAR A2
packageexamples;importev3dev.sensors.slamtec.RPLidarA1;importev3dev.sensors.slamtec.RPLidarProviderListener;importev3dev.sensors.slamtec.model.Scan;importlombok.extern.slf4j.Slf4j;importjava.util.concurrent.atomic.AtomicInteger;public@Slf4jclassDemo3 {privatestaticAtomicIntegercounter;publicstaticvoidmain(String[]args)throwsException {log.info("Testing RPLidar on a EV3Dev with Java");finalStringUSBPort ="/dev/ttyUSB0";finalRPLidarA1lidar =newRPLidarA1(USBPort);lidar.init();lidar.addListener(newRPLidarProviderListener() {@OverridepublicvoidscanFinished(Scanscan) {//log.info("Iteration: {}, Measures: {}", counter.incrementAndGet(), scan.getDistances().size());log.info("Measures: {}",scan.getDistances().size());scan.getDistances() .stream() .filter((measure) ->measure.getQuality() >10) .filter((measure) -> (measure.getAngle() >=345 ||measure.getAngle() <=15)) .filter((measure) ->measure.getDistance() <=50) .forEach(System.out::println); } });for(intx =0;x <=10;x++) {lidar.scan(); }lidar.close();log.info("End");System.exit(0); }}
http://www.arduino.org/products/shields/arduino-9-axes-motion-shield
Example using the Arduino + Shield:
packageexamples;importev3dev.actuators.Sound;importev3dev.arduino.sensors.bn055.BNO055;importev3dev.arduino.sensors.bn055.BNO055Listener;importev3dev.arduino.sensors.bn055.model.BNO055Response;importev3dev.arduino.sensors.bn055.model.Euler;importev3dev.arduino.sensors.bn055.model.Euler;importev3dev.sensors.Battery;importev3dev.sensors.Button;importlombok.extern.slf4j.Slf4j;public@Slf4jclassBNO055TurnTest {publicstaticvoidmain(String[]args)throwsException {finalStringport ="/dev/ttyACM0";finalBNO055bno055 =newBNO055(port);bno055.init();log.debug("{}",Battery.getInstance().getVoltage());bno055.addListener(newBNO055Listener() {@OverridepublicvoiddataReceived(finalBNO055Responseresponse) {if(response.getEuler() !=null){finalEulereuler =response.getEuler();log.debug("Heading: {}",euler.getHeading());if( (euler.getHeading() >90.0f) &&(euler.getHeading() <=100.00f)) {//Sound.getInstance().beep();log.info("REACHED");}}}});Button.waitForAnyPress();log.debug("{}",Battery.getInstance().getVoltage());bno055.close();log.info("Closing connection with Arduino");}}
Video:
https://www.youtube.com/watch?v=OY2B7B0Qi2Y
Example connecting with a USB GPS
packageexamples;importev3dev.sensors.gps.GenericGPS;importlombok.extern.slf4j.Slf4j;@Slf4jpublicclassGenericGPSTest {publicstaticvoidmain(String[]args)throwsException {finalStringport ="/dev/ttyACM0";finalGenericGPSgps =newGenericGPS(port);gps.init();//This method block main thread 10 secondstimeCounter(10);gps.close();log.info("Closing connection with the USB GPS Device");log.info("LAT: {} {}, LAT: {} {}, ALT: {}",gps.getLatitude(),gps.getLatitudeDirection(),gps.getLongitude(),gps.getLongitudeDirection(),gps.getAltitude());log.info("DATE: {}, TIMESTAMP: {}",gps.getDate(),gps.getTimeStamp());log.info("NSTAT: {}",gps.getSatellitesTracked());}privatestaticvoidtimeCounter(finalintseconds)throwsInterruptedException {log.info("Start reading");for(intx =0;x <=seconds;x++){log.info("Iteration: {}\n\n",x);Thread.sleep(1000);}}}
About
A Java libraries to manage USB devices like Controllers, Arduinos, IMUs, GPS, etc...
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published


