Img.1. - Let's turn on the LegoBrick again and make remote project based on Gradle |
This blog post is about setting up little more advanced project.
The simple HelloWorldGradle Remote project uses:
- Java 8
- local maven repository
- Gradle 2.0 (automation )
- LejOS 0.8.0-alpha
The legoBrick, connected to the WiFi, is possible to access remotely without problem using Java Remote Method Invocation, shortly RMI.
RemoteEV3 ev3Brick = new RemoteEV3(EV3BRICK_IP); ev3Brick.setDefault();Before we start working on the sample source code we create Gradle project. We can randomly choose the project as HelloWorldGradle. Important is to setup 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.
This library can be created by maven with usage of maven-assembly-plugin. The final *.jar file can then easily imported into the local maven cache.lejos ev3classes jar 1.0-SNAPSHOT lejos dbusjava 1.0-SNAPSHOT net.java.dev.jna jna 3.2.7 ${basedir}/src ev3classes install maven-compiler-plugin ${maven.compiler.version} ${java.version} ${java.version} org.apache.maven.plugins maven-jar-plugin ${maven.jar.version} maven-assembly-plugin ${maven.assembly.version} ${project.build.finalName}-${project.version}.jar jar-with-dependencies make-assembly package single
Now we are ready to remotely access our Lego MindStorm robot and in our case let him to play some short song.
RemoteEV3 ev3Brick = new RemoteEV3(EV3BRICK_IP); ev3Brick.setDefault(); Audio soundProcessor = ev3Brick.getAudio(); ListThe sample LejOS remote project HelloWorldGradle is available here (GITHub).tones = new ArrayList<>(asList(0,1,2,3,4,5)); tones.forEach(tone -> { soundProcessor.systemSound(tone); });
Enjoy !
No comments:
Post a Comment