Skip to content

A Java library to interact with hardware managed by EV3Dev using the LeJOS way.

License

Notifications You must be signed in to change notification settings

0-Kala-0/ev3dev-lang-java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ev3dev-lang-java

EV3Dev-lang-Java is a Java library designed to interact with hardware managed by EV3Dev using the LeJOS way.

ScreenShot

Execute the following statements to generate the UML diagram in local.

git clone https://github.com/jabrena/ev3dev-lang-java.git
cd library
ant -buildfile tools.xml uml

Roadmap

  • Support for PiStorm & BrickPi+
  • Support for Java 8
  • Support for more Gyro Sensors
  • Support for RPLidar
  • Create repository for navigation
  • Create repository for behaviours

Features

Getting Started.

Check if your EV3Brick with EV3Dev need some upgrade:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo echo LC_ALL="en_GB.utf8" > /etc/environment 
sudo reboot

Current development has been tested with this version:

root@ev3dev:/home# uname -a                            
Linux ev3dev 3.16.7-ckt21-9-ev3dev-ev3 #1 PREEMPT Tue Dec 15 15:16:17 CST 2015 armv5tejl GNU/Linux

If you have your OS for EV3 updated, continue with your Java project.

Create a Java Maven project:

mvn archetype:generate 
-DgroupId=ev3dev.examples.demo 
-DartifactId=Test 
-DarchetypeArtifactId=maven-archetype-quickstart 
-DinteractiveMode=false

Update the file pom.xml to add the following repository:

	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>

and add the dependency to offer Java support for EV3Dev:

	<dependency>
	    <groupId>com.github.jabrena</groupId>
	    <artifactId>ev3dev-lang-java</artifactId>
	    <version>v0.2.0</version>
	</dependency>

Create a Java Class in your Maven project:

package ev3dev.examples.demo;

import ev3dev.hardware.Battery;
import ev3dev.hardware.port.MotorPort;
import ev3dev.hardware.port.SensorPort;
import ev3dev.hardware.motor.EV3LargeRegulatedMotor;
import ev3dev.hardware.sensor.ev3.EV3IRSensor;
import lejos.robotics.SampleProvider;
import lejos.utility.Delay;

//java -cp ev3-lang-java-0.2-SNAPSHOT.jar ev3dev.examples.misc.BumperCar
public class BumperCar {
    
    //Robot Definition
    private final static EV3LargeRegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.A);
    private final static EV3LargeRegulatedMotor mB = new EV3LargeRegulatedMotor(MotorPort.B);
    private final static EV3IRSensor ir1 = new EV3IRSensor(SensorPort.S1);

    //Configuration
    private final static int motorSpeed = 500;
    
    public static void main(String[] args) {
        
        final SampleProvider sp = ir1.getDistanceMode();
        int distance = 255;

        final int distance_threshold = 35;
        
        //Robot control loop
        final int iteration_threshold = 100;
        for(int i = 0; i <= iteration_threshold; i++) {
            forward();

            float [] sample = new float[sp.sampleSize()];
            sp.fetchSample(sample, 0);
            distance = (int)sample[0];
            if(distance <= distance_threshold){
                backwardWithTurn();
            }

            System.out.println("Iteration: " + i);
            System.out.println("Battery: " + Battery.getInstance().getVoltage());
            System.out.println("Distance: " + distance);
            System.out.println();
        }

        mA.stop();
        mB.stop();
        System.exit(0);
    }
    
    private static void forward(){
        mA.setSpeed(motorSpeed);
        mB.setSpeed(motorSpeed);
        mA.forward();
        mB.forward();
    }
    
    private static void backwardWithTurn(){
        mA.backward();
        mB.backward();
        Delay.msDelay(1000);
        mA.stop();
        mB.stop();
        mA.backward();
        mB.forward();
        Delay.msDelay(1000);
        mA.stop();
        mB.stop();
    }
}

To run the example, package your project with Maven to generate a .jar file:

mvn package

upload your .jar and the library (ev3-lang-java) on your brick. In the path where you have uploaded the jar, execute the following example to run the example:

ssh root@192.168.2.3
r00tme
cd /home
java -cp Test-1.0-SNAPSHOT.jar:ev3-lang-java-0.2-SNAPSHOT.jar ev3dev.examples.demo.BumperCar

This example is included in the test examples.

Docs:

Generate Javadocs in local in a easy way:

ant -buildfile tools.xml javadocs

References:

About

A Java library to interact with hardware managed by EV3Dev using the LeJOS way.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.0%
  • Liquid 1.0%