By Miroslav Kopecky
Img.1: Let’s turn on the LegoBrick again and make remote project based on Gradle
The previous post about Lego MindStorm EV3  focused on its installation. I’ve also touched how to install JavaJDK setup Wi-Fi on LegoBrick + small sample “hello world” project. This blog post is about setting up little more advanced project.

The simple HelloWorldGradle Remote project uses:

With the LegoBrick connected to Wi-Fi, it’s possible to access it remotely without problem using the Java Remote Method Invocation, or RMI for short.
RemoteEV3 ev3Brick = new RemoteEV3(EV3BRICK_IP);  
ev3Brick.setDefault();  

Before we start working on the sample source code we create a Gradle project. Let’s randomly title the project as HelloWorldGradle. It’s important to setup the Gradle property file “build.gradle” correctly.

apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
version = '1.0'
repositories {
    mavenCentral()
    mavenLocal()
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'lejos:ev3classes:1.0-SNAPSHOT'
    compile ('log4j:log4j:1.2.17'){
        exclude group: "com.sun.jdmk", module: "jmxtools"
        exclude group: "javax.jms", module: "jms"
        exclude group: "com.sun.jmx", module: "jmxri"
    }
    compile 'org.slf4j:slf4j-log4j12:1.7.5'
}

jar library “ev3classes” is very important! This library creates the gateway into the Lego hardware by using RMI because EV3 acts as the RMI Registry. You need to create it by yourself.

<groupid>lejos</groupid>
  <artifactid>ev3classes</artifactid>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupid>lejos</groupid>
      <artifactid>dbusjava</artifactid>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupid>net.java.dev.jna</groupid>
      <artifactid>jna</artifactid>
      <version>3.2.7</version>
    </dependency>
  </dependencies>
  <build>
    <sourcedirectory>${basedir}/src</sourcedirectory>
    <finalname>ev3classes</finalname>
    <defaultgoal>install</defaultgoal>
    <plugins>
      <plugin>
        <artifactid>maven-compiler-plugin</artifactid>
        <version>${maven.compiler.version}</version>
        <configuration>
          <source>${java.version}
          <target>${java.version}</target>
        </configuration>
      </plugin>
      <plugin>
        <groupid>org.apache.maven.plugins</groupid>
        <artifactid>maven-jar-plugin</artifactid>
        <version>${maven.jar.version}</version>
      </plugin>
      <plugin>
        <artifactid>maven-assembly-plugin</artifactid>
        <version>${maven.assembly.version}</version>
        <configuration>
          <finalname>${project.build.finalName}-${project.version}.jar</finalname>
          <descriptorrefs>
            <descriptorref>jar-with-dependencies</descriptorref>
          </descriptorrefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

This library can be created with Maven with the usage of maven-assembly-plugin. The final *.jar file can then easily imported into the local maven cache.

Now we are ready to remotely access our Lego MindStorm robot and in our case let him to play a short song.

RemoteEV3 ev3Brick = new RemoteEV3(EV3BRICK_IP);
            ev3Brick.setDefault();
            Audio soundProcessor = ev3Brick.getAudio();
            List<integer> tones = new ArrayList<>(asList(0,1,2,3,4,5));
            tones.forEach(tone -> {
                soundProcessor.systemSound(tone);
            });
</integer>

The sample LejOS remote project HelloWorldGradle is available here (GITHub).

Enjoy!

Lego Mindstorm EV3: Java8, LeJOS and Gradle with a Taste of Maven

| Mind the Geek| 667 views | 0 Comments
About The Author
-

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>