Pages

Showing posts with label LeJOS. Show all posts
Showing posts with label LeJOS. Show all posts

Monday, July 21, 2014

Lego Mindstorm EV3 -> Java8, LeJOS and Gradle with taste of Maven

Img.1. - Let's turn on the LegoBrick again and make remote project based on Gradle
The previous post about Lego MindStorm EV3 has been focused on its installation. I've touched how to install JavaJDK setup Wifi on LegoBrick + small sample "hello world" project.
This blog post is about setting up little more advanced project.

The simple HelloWorldGradle Remote project uses:
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.
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
            
          
        
      
    
  
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.
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();
            List tones = new ArrayList<>(asList(0,1,2,3,4,5));
            tones.forEach(tone -> {
                soundProcessor.systemSound(tone);
            });
The sample LejOS remote project HelloWorldGradle is available here (GITHub).
Enjoy !

Wednesday, July 2, 2014

Lego Mindstorm EV3 -> LeJOS installation

Img.1.: let's begin and rock (part of my toys)
I do believe that the default lego software for EV3 is pretty awesome ;) but my interest belongs to java virtual machine which implies installation of LeJOS. 

required:
1. download leJOS_EV3_0.8.1-beta.tar.gz (last available)
2. download Java for Lego Mindstorm EV3 = ejdk-8-fcs-b132-linux-arm-sflt-03_mar_2014.tar.gz
3. 6 x AA Batteries 1.5V - rechargeable -> almost green energy

Let's prepare LeJOS SD card for the mission:
1. from the manual:  card must be bigger than 2GB and FAT32 
2. unpack leJOS file -> go to the folder -> copy the lejosimage.zip file to the SD Card
3. unpack lejosimage.zip
4. copy downloaded Java SE file to the CD-Card (SD Card root)
5. put SD-CARD to the Lego Brick and finally startup

To work with LeJOS comfortably is required to have WiFi connection via dongle (Img.2.). 
Then is possible to deploy directly for the IDE (IntelliJ IDEA 13.x in my case) to Lego Brick. 

Img.2.:: supported NetGear N150 USB Wireless Adapter
Prepare Wifi Connection:
1. Boot Brick and select Control -> Wifi -> select network with WPA2 
Img.3.:set the wifi password
2. Create a sample maven program (how to will be the topic of the next blog post)
Img.4.: favorite IDE IntelliJ IDEA 13.x with Maven Lego Project inside and upload command
for those who want to use maven directly for the deployment they need to configure maven-antrun-plugin

So now we have Lego Mindstorm EV3 ready for read development and sensors usage... 

  1. HelloWolrdGradle Remote Hardware usage example project
  2. more is coming soon...