├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.gradle ├── config.gradle ├── gradle ├── deploy.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lombok.config ├── settings.gradle └── src └── main ├── java └── example │ ├── MyFirstRobot.java │ ├── programming │ ├── FractalCircle.java │ ├── FractalTree.java │ ├── HelloWorld.java │ └── SimpleWebServer.java │ └── robotics │ └── ev3 │ ├── actuator │ ├── LCDShowJavaLogoExample.java │ ├── LEDPatternsExample.java │ ├── TTSDemo.java │ └── motor │ │ └── BasicMotorOperationExample.java │ └── sensor │ ├── BatteryDemo.java │ ├── DetectBlueBall.java │ ├── IRSensorRemoteControlExample.java │ ├── TouchSensorExample.java │ ├── TurnWithGyroSensorExample.java │ └── USSensorExample.java └── resources ├── META-INF └── MANIFEST.MF ├── index.html ├── logback.xml └── simplelogger.properties /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build 4 | out 5 | *.iml 6 | 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk11 4 | before_install: 5 | - chmod +x gradlew 6 | notifications: 7 | email: 8 | on_success: always 9 | on_failure: always 10 | recipients: 11 | - bren@juanantonio.info 12 | script: 13 | - ./gradlew clean classes 14 | after_success: 15 | - bash <(curl -s https://codecov.io/bash) 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Template project with Gradle 2 | 3 | ## Why 4 | 5 | Test a new technology is always a bit tedious and it requires an amount of time. 6 | So, this project try to reduce the curve of learning of any new user with `EV3Dev-lang-java`. 7 | 8 | ## Prerequisites 9 | 10 | The Prerequisites to use this project are: 11 | 12 | - Your MINDSTORMS Brick needs to have installed latest `Debian Stretch` version. https://www.ev3dev.org/docs/getting-started/ 13 | - To increase the EV3 CPU Speed, read the following article: https://lechnology.com/2018/06/overclocking-lego-mindstorms-ev3-part-2/ 14 | - Your MINDSTORMS Brick needs to be connected to the same LAN than your laptop. http://www.ev3dev.org/docs/getting-started/#step-5-set-up-a-network-connection 15 | 16 | Note: Update the EV3Dev kernel 17 | https://www.ev3dev.org/docs/tutorials/upgrading-ev3dev/ 18 | 19 | ``` 20 | sudo apt-get update 21 | sudo apt-get install linux-image-ev3dev-ev3 22 | ``` 23 | 24 | Once you have all steps done, continue with the next section. 25 | 26 | ## Getting Started 27 | 28 | This repository stores a template project about `EV3Dev-lang-java`. 29 | Once you download in your computer the project, 30 | open your favourite Java IDE ( [Eclipse](https://eclipse.org/home/index.php) or [IntelliJ](https://www.jetbrains.com/idea/)) 31 | to import this [Gradle](https://gradle.org/) project. The project includes latest dependencies and 32 | an example ready to be deployed on your Robot using the `core` library from `EV3Dev-lang-java`. 33 | 34 | The project includes some tasks to reduce the time to deploy on your robot. 35 | 36 | Review the IP of your Brick and update the file `./config.gradle`: 37 | 38 | ``` 39 | remotes { 40 | ev3dev { 41 | host = '192.168.1.180' 42 | user = 'robot' 43 | password = 'maker' 44 | } 45 | } 46 | ``` 47 | 48 | ### EV3Dev-lang-java 49 | 50 | The tasks associated to deploy on your Robot are: 51 | 52 | - testConnection (Test the connection with your Brick) 53 | - deploy (The project deliver a FatJar to your Brick) 54 | - remoteRun (Execute a Jar deployed on your Brick) 55 | - deployAndRun (Deploy & Execute from your Computer the program that you configured on the file: MANIFEST.MF) 56 | - ev3devInfo (Get technical information about your EV3 Brick) 57 | - removePreviousJar (Remove current jar remotely) 58 | - remoteBrickRun (If your program is going to use some EV3 Actuator like LCD, Buttons, use this task to execute the program) 59 | - remoteRun (Execute your jar remotely) 60 | - remoteRunClassVerbose (Execute your jar and show JVM info) 61 | - remoteProfilingRun (Execute your jar configured for Profiling activities) 62 | - deployAndBrickRun (Deploy & Execute your program with Brickrun) 63 | - deployAndProfilingRun (Deploy & Execute your jar configured for Profiling activities) 64 | - pkillJava (Kill Java processes in your Brick) 65 | 66 | You can use the Java IDE to launch the task or execute them from the terminal 67 | 68 | ``` 69 | ./gradlew deployAndBrickRun 70 | ``` 71 | 72 | ## Javadocs 73 | 74 | The project has the following technical documentation 75 | 76 | http://ev3dev-lang-java.github.io/docs/api/latest/index.html 77 | 78 | ## Examples 79 | 80 | Exist several examples ready to use here: 81 | 82 | https://github.com/ev3dev-lang-java/examples 83 | 84 | ## Issues 85 | 86 | If you have any problem or doubt, use the main project. 87 | 88 | https://github.com/ev3dev-lang-java/ev3dev-lang-java/issues 89 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | //Gradle file library ev3dev-lang-java // Template project 2 | 3 | plugins { 4 | id 'java' 5 | id 'eclipse' 6 | id 'idea' 7 | id 'org.hidetake.ssh' version '2.10.1' 8 | id "net.ossindex.audit" version "0.4.5-beta" 9 | id "com.github.johnrengelman.shadow" version "4.0.3" 10 | } 11 | 12 | version = '2.6.0' 13 | 14 | // Project definitions 15 | 16 | repositories { 17 | maven { url "https://jitpack.io" } 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation("org.slf4j:slf4j-simple:1.7.25") 23 | implementation("com.github.ev3dev-lang-java:ev3dev-lang-java:2.6.2-SNAPSHOT") 24 | } 25 | 26 | compileJava.options.encoding = 'UTF-8' 27 | 28 | //Compile 29 | compileJava { 30 | sourceCompatibility = 11 31 | targetCompatibility = 11 32 | } 33 | 34 | //Jar 35 | jar { 36 | baseName = "${rootProject.name}" 37 | manifest { 38 | from file("${projectDir}/src/main/resources/META-INF/MANIFEST.MF") 39 | } 40 | } 41 | 42 | task fatJar { 43 | doLast { 44 | } 45 | } 46 | fatJar.dependsOn shadowJar 47 | 48 | apply from: './config.gradle' 49 | apply from: './gradle/deploy.gradle' 50 | -------------------------------------------------------------------------------- /config.gradle: -------------------------------------------------------------------------------- 1 | remotes { 2 | ev3dev { 3 | host = '192.168.1.157' 4 | user = 'robot' 5 | password = 'maker' 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /gradle/deploy.gradle: -------------------------------------------------------------------------------- 1 | ssh.settings { 2 | knownHosts = allowAnyHosts 3 | } 4 | 5 | task testConnection { 6 | doLast { 7 | ssh.run { 8 | session(remotes.ev3dev) { 9 | println "ls " 10 | execute "ls " 11 | } 12 | } 13 | } 14 | } 15 | 16 | task free { 17 | doLast { 18 | ssh.run { 19 | session(remotes.ev3dev) { 20 | println "free " 21 | execute "free " 22 | } 23 | } 24 | } 25 | } 26 | 27 | task top { 28 | doLast { 29 | ssh.run { 30 | session(remotes.ev3dev) { 31 | println "top " 32 | execute "top " 33 | } 34 | } 35 | } 36 | } 37 | 38 | task ps { 39 | doLast { 40 | ssh.run { 41 | session(remotes.ev3dev) { 42 | println "ps " 43 | execute "ps aux | sort -n -k 4 " 44 | } 45 | } 46 | } 47 | } 48 | 49 | task stopBluetooth { 50 | doLast { 51 | ssh.run { 52 | session(remotes.ev3dev) { 53 | println "echo -e \"maker\" | sudo systemctl stop bluetooth" 54 | execute "echo -e \"maker\" | sudo systemctl stop bluetooth" 55 | } 56 | } 57 | } 58 | } 59 | 60 | task ev3devInfo { 61 | doLast { 62 | ssh.run { 63 | session(remotes.ev3dev) { 64 | println "ev3dev-sysinfo -m" 65 | execute "ev3dev-sysinfo -m" 66 | } 67 | } 68 | } 69 | } 70 | 71 | task pkillJava { 72 | doLast { 73 | ssh.run { 74 | session(remotes.ev3dev) { 75 | println "pkill java" 76 | execute "pkill java" 77 | } 78 | } 79 | } 80 | } 81 | 82 | task removePreviousJar { 83 | doLast { 84 | ssh.run { 85 | session(remotes.ev3dev) { 86 | println "rm /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 87 | execute "rm /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 88 | } 89 | } 90 | } 91 | } 92 | 93 | task deploy { 94 | doLast { 95 | ssh.run { 96 | session(remotes.ev3dev) { 97 | put from: "${projectDir}/build/libs/" + "${rootProject.name}" + "-" + version + ".jar", into: "/home/robot/" 98 | } 99 | } 100 | } 101 | } 102 | 103 | deploy.dependsOn clean, fatJar 104 | 105 | task remoteRun { 106 | doLast { 107 | ssh.run { 108 | session(remotes.ev3dev) { 109 | println "time java -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 110 | execute "time java -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 111 | } 112 | } 113 | } 114 | } 115 | 116 | task remoteBrickRun { 117 | doLast { 118 | ssh.run { 119 | session(remotes.ev3dev) { 120 | println "time brickrun -- java -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 121 | execute "time brickrun -- java -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 122 | } 123 | } 124 | } 125 | } 126 | 127 | task remoteRunClassVerbose { 128 | doLast { 129 | ssh.run { 130 | session(remotes.ev3dev) { 131 | println "java -verbose:class -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 132 | execute "java -verbose:class -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 133 | } 134 | } 135 | } 136 | } 137 | 138 | task remoteSudoRun { 139 | doLast { 140 | ssh.run { 141 | session(remotes.ev3dev) { 142 | println "echo -e \"maker\" | sudo -S java -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar" 143 | execute "echo -e \"maker\" | sudo -S java -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar" 144 | } 145 | } 146 | } 147 | } 148 | 149 | task remoteProfilingRun { 150 | doLast { 151 | ssh.run { 152 | session(remotes.ev3dev) { 153 | println "brickrun -- java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 154 | execute "brickrun -- java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 155 | } 156 | } 157 | } 158 | } 159 | 160 | task remoteProfilingSudoRun { 161 | doLast { 162 | ssh.run { 163 | session(remotes.ev3dev) { 164 | println "echo -e \"maker\" | sudo -S brickrun -- java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 165 | execute "echo -e \"maker\" | sudo -S brickrun -- java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar /home/robot/" + "${rootProject.name}" + "-" + version + ".jar " 166 | } 167 | } 168 | } 169 | } 170 | 171 | task deployAndRun { 172 | doLast { 173 | } 174 | } 175 | deployAndRun.dependsOn deploy, remoteRun 176 | 177 | task deployAndBrickRun { 178 | doLast { 179 | } 180 | } 181 | deployAndBrickRun.dependsOn deploy, remoteBrickRun 182 | 183 | task deployAndSudoRun { 184 | doLast { 185 | } 186 | } 187 | deployAndSudoRun.dependsOn deploy, remoteSudoRun 188 | 189 | task deployAndProfilingRun { 190 | doLast { 191 | } 192 | } 193 | deployAndProfilingRun.dependsOn deploy, remoteProfilingRun 194 | 195 | task deployAndProfilingSudoRun { 196 | doLast { 197 | } 198 | } 199 | deployAndProfilingSudoRun.dependsOn deploy, remoteProfilingSudoRun 200 | 201 | //Organize tasks in a Group 202 | def groupName = "ev3dev-lang-java" 203 | testConnection.group = groupName 204 | free.group = groupName 205 | ps.group = groupName 206 | top.group = groupName 207 | stopBluetooth.group = groupName 208 | ev3devInfo.group = groupName 209 | removePreviousJar.group = groupName 210 | deploy.group = groupName 211 | remoteBrickRun.group = groupName 212 | remoteRun.group = groupName 213 | remoteRunClassVerbose.group = groupName 214 | remoteSudoRun.group = groupName 215 | remoteProfilingRun.group = groupName 216 | remoteProfilingSudoRun.group = groupName 217 | deployAndRun.group = groupName 218 | deployAndBrickRun.group = groupName 219 | deployAndSudoRun.group = groupName 220 | deployAndProfilingRun.group = groupName 221 | deployAndProfilingSudoRun.group = groupName 222 | pkillJava.group = groupName 223 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ev3dev-lang-java/template-project-gradle/bf8f2c51c99621fe7a086eef10bd4974b1611efc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS="" 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /lombok.config: -------------------------------------------------------------------------------- 1 | lombok.nonNull.exceptionType = IllegalArgumentException 2 | lombok.log.fieldName = LOGGER 3 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | resolutionStrategy { 3 | eachPlugin { 4 | if (requested.id.namespace == "com.github.ev3dev-lang-java") { 5 | useModule("com.github.ev3dev-lang-java:${requested.id.name}:${requested.version}") 6 | } 7 | } 8 | } 9 | repositories { 10 | gradlePluginPortal() 11 | maven { url "https://jitpack.io" } 12 | jcenter() 13 | mavenCentral() 14 | } 15 | } 16 | 17 | rootProject.name = 'template_project_gradle' 18 | -------------------------------------------------------------------------------- /src/main/java/example/MyFirstRobot.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor; 4 | import ev3dev.sensors.Battery; 5 | import lejos.hardware.port.MotorPort; 6 | import lejos.utility.Delay; 7 | 8 | public class MyFirstRobot { 9 | 10 | public static void main(final String[] args){ 11 | 12 | System.out.println("Creating Motor A & B"); 13 | final EV3LargeRegulatedMotor motorLeft = new EV3LargeRegulatedMotor(MotorPort.A); 14 | final EV3LargeRegulatedMotor motorRight = new EV3LargeRegulatedMotor(MotorPort.B); 15 | 16 | //To Stop the motor in case of pkill java for example 17 | Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { 18 | public void run() { 19 | System.out.println("Emergency Stop"); 20 | motorLeft.stop(); 21 | motorRight.stop(); 22 | } 23 | })); 24 | 25 | System.out.println("Defining the Stop mode"); 26 | motorLeft.brake(); 27 | motorRight.brake(); 28 | 29 | System.out.println("Defining motor speed"); 30 | final int motorSpeed = 200; 31 | motorLeft.setSpeed(motorSpeed); 32 | motorRight.setSpeed(motorSpeed); 33 | 34 | System.out.println("Go Forward with the motors"); 35 | motorLeft.forward(); 36 | motorRight.forward(); 37 | 38 | Delay.msDelay(2000); 39 | 40 | System.out.println("Stop motors"); 41 | motorLeft.stop(); 42 | motorRight.stop(); 43 | 44 | System.out.println("Go Backward with the motors"); 45 | motorLeft.backward(); 46 | motorRight.backward(); 47 | 48 | Delay.msDelay(2000); 49 | 50 | System.out.println("Stop motors"); 51 | motorLeft.stop(); 52 | motorRight.stop(); 53 | 54 | System.out.println("Checking Battery"); 55 | System.out.println("Votage: " + Battery.getInstance().getVoltage()); 56 | 57 | System.exit(0); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/example/programming/FractalCircle.java: -------------------------------------------------------------------------------- 1 | package example.programming; 2 | 3 | import ev3dev.actuators.LCD; 4 | import ev3dev.utils.JarResource; 5 | import lejos.hardware.lcd.GraphicsLCD; 6 | import lejos.robotics.Color; 7 | import lejos.utility.Delay; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.awt.image.BufferedImage; 12 | import java.io.IOException; 13 | 14 | public class FractalCircle { 15 | 16 | public static Logger LOGGER = LoggerFactory.getLogger(FractalCircle.class); 17 | 18 | private GraphicsLCD lcd; 19 | 20 | public FractalCircle() { 21 | 22 | lcd = LCD.getInstance(); 23 | 24 | showJavaLogo(lcd); 25 | 26 | Delay.msDelay(4000); 27 | 28 | clear(lcd); 29 | fourFractalCircle( 30 | 1, 31 | 25, 32 | 0, 33 | 128, 34 | lcd); 35 | 36 | Delay.msDelay(5000); 37 | 38 | clear(lcd); 39 | fourFractalCircle( 40 | 2, 41 | 25, 42 | 0, 43 | 128, 44 | lcd); 45 | 46 | Delay.msDelay(5000); 47 | 48 | clear(lcd); 49 | fourFractalCircle( 50 | 3, 51 | 25, 52 | 0, 53 | 128, 54 | lcd); 55 | 56 | Delay.msDelay(5000); 57 | 58 | clear(lcd); 59 | fourFractalCircle( 60 | 4, 61 | 25, 62 | 0, 63 | 128, 64 | lcd); 65 | 66 | Delay.msDelay(5000); 67 | } 68 | 69 | 70 | public static void main(String[] args) { 71 | FractalCircle main = new FractalCircle(); 72 | } 73 | 74 | public static void fourFractalCircle(int interacoes, int x, int y, int tamanho, GraphicsLCD g) { 75 | if (interacoes == 0) { 76 | 77 | } else { 78 | g.setColor(Color.BLACK); 79 | g.drawOval(x, y, tamanho, tamanho); 80 | g.refresh(); 81 | fourFractalCircle(interacoes - 1, x+tamanho / 4, y, tamanho / 2, g); //chamada recurssiva para desenhar circulos na parte superior 82 | fourFractalCircle(interacoes - 1, x, y+tamanho / 4, tamanho / 2, g);//chamada recurssiva para desenhar circulos na parte esquerda 83 | fourFractalCircle(interacoes - 1, x + tamanho / 2, y+tamanho / 4, tamanho / 2, g);////chamada recurssiva para desenhar circulos na parte direita 84 | fourFractalCircle(interacoes - 1, x+ tamanho / 4, y + tamanho / 2, tamanho / 2, g);//chamada recurssiva para desenhar circulos na parte inferior 85 | } 86 | } 87 | 88 | public static void clear(GraphicsLCD g) { 89 | //lcd.setColor(Color.WHITE); 90 | g.setColor(255,255,255); 91 | g.fillRect(0,0, g.getWidth(), g.getHeight()); 92 | } 93 | 94 | public static final String JAVA_DUKE_IMAGE_NAME = "java_logo.png"; 95 | 96 | private static void showJavaLogo(GraphicsLCD lcd) { 97 | 98 | try { 99 | BufferedImage image = JarResource.loadImage(JAVA_DUKE_IMAGE_NAME); 100 | lcd.drawImage(image, 35, 10, 0); 101 | lcd.refresh(); 102 | }catch (IOException e){ 103 | LOGGER.error(e.getLocalizedMessage()); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/example/programming/FractalTree.java: -------------------------------------------------------------------------------- 1 | package example.programming; 2 | 3 | import ev3dev.actuators.LCD; 4 | import ev3dev.utils.JarResource; 5 | import lejos.hardware.lcd.GraphicsLCD; 6 | import lejos.robotics.Color; 7 | import lejos.utility.Delay; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.awt.image.BufferedImage; 12 | import java.io.IOException; 13 | 14 | public class FractalTree { 15 | 16 | public static Logger LOGGER = LoggerFactory.getLogger(FractalCircle.class); 17 | 18 | private GraphicsLCD g; 19 | 20 | public FractalTree() { 21 | g = LCD.getInstance(); 22 | 23 | showJavaLogo(g); 24 | Delay.msDelay(5000); 25 | clear(g); 26 | } 27 | 28 | public void drawTree(int x1, int y1, double angle, int depth) { 29 | if (depth == 0) return; 30 | int x2 = x1 + (int) (Math.cos(Math.toRadians(angle)) * depth * 10.0); 31 | int y2 = y1 + (int) (Math.sin(Math.toRadians(angle)) * depth * 10.0); 32 | g.setColor(Color.BLACK); 33 | g.drawLine(x1, y1, x2, y2); 34 | g.refresh(); 35 | drawTree(x2, y2, angle - 20, depth - 1); 36 | drawTree(x2, y2, angle + 20, depth - 1); 37 | } 38 | 39 | public static void clear(GraphicsLCD g) { 40 | //lcd.setColor(Color.WHITE); 41 | g.setColor(255,255,255); 42 | g.fillRect(0,0, g.getWidth(), g.getHeight()); 43 | } 44 | 45 | public static final String JAVA_DUKE_IMAGE_NAME = "java_logo.png"; 46 | 47 | private static void showJavaLogo(GraphicsLCD lcd) { 48 | 49 | try { 50 | BufferedImage image = JarResource.loadImage(JAVA_DUKE_IMAGE_NAME); 51 | lcd.drawImage(image, 35, 10, 0); 52 | lcd.refresh(); 53 | }catch (IOException e){ 54 | LOGGER.error(e.getLocalizedMessage()); 55 | } 56 | } 57 | 58 | public static void main(String[] args) { 59 | 60 | FractalTree fractal = new FractalTree(); 61 | fractal.drawTree( 178/2, 128, -90, 5); 62 | 63 | Delay.msDelay(10000); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/example/programming/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package example.programming; 2 | 3 | public class HelloWorld { 4 | 5 | public static void main(final String[] args) { 6 | System.out.println("Hello World"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/example/programming/SimpleWebServer.java: -------------------------------------------------------------------------------- 1 | package example.programming; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.*; 7 | import java.net.ServerSocket; 8 | import java.net.Socket; 9 | 10 | 11 | public class SimpleWebServer { 12 | 13 | public static Logger LOGGER = LoggerFactory.getLogger(SimpleWebServer.class); 14 | 15 | public static final int PORT = 9000; 16 | private ServerSocket ss; 17 | private Socket sock; 18 | 19 | public SimpleWebServer() throws IOException { 20 | LOGGER.info("Creating a simple API"); 21 | 22 | ss = new ServerSocket(PORT); 23 | 24 | } 25 | 26 | public void run() throws IOException { 27 | for (;;) { 28 | sock = ss.accept(); 29 | InputStream is = sock.getInputStream(); 30 | OutputStream os = sock.getOutputStream(); 31 | 32 | BufferedReader br = new BufferedReader(new InputStreamReader(is)); 33 | PrintStream ps = new PrintStream(os); 34 | 35 | for (;;) { 36 | String cmd = br.readLine(); 37 | if (cmd == null) 38 | break; 39 | String reply = execute(cmd); 40 | if (reply != null) 41 | ps.println(reply); 42 | else { 43 | br.close(); 44 | ps.close(); 45 | break; 46 | } 47 | } 48 | 49 | } 50 | } 51 | 52 | public String execute(String cmd) { 53 | String[] tokens = cmd.split(" "); 54 | 55 | if (tokens.length > 1 && tokens[0].equals("GET")) { 56 | 57 | if (tokens[1].equals("/stop")) { 58 | LOGGER.info("{}", tokens[1]); 59 | System.exit(0); 60 | } else { 61 | //Your protocol 62 | } 63 | 64 | return "HTTP/1.1 200 OK\r\n\r\n" + readFile() + "\r\n"; 65 | } 66 | return null; 67 | } 68 | 69 | private String readFile() { 70 | 71 | StringBuffer document = new StringBuffer(); 72 | 73 | try { 74 | 75 | InputStream in = this.getClass().getClassLoader().getResourceAsStream("index.html"); 76 | 77 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in), 1); 78 | String line; 79 | while ((line = bufferedReader.readLine()) != null) { 80 | document.append(line); 81 | } 82 | in.close(); 83 | 84 | }catch (IOException io) { 85 | LOGGER.error(io.getLocalizedMessage()); 86 | } 87 | 88 | return document.toString(); 89 | 90 | } 91 | 92 | } -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/actuator/LCDShowJavaLogoExample.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.actuator; 2 | 3 | import ev3dev.actuators.LCD; 4 | import ev3dev.hardware.EV3DevDistro; 5 | import ev3dev.hardware.EV3DevDistros; 6 | import ev3dev.utils.Brickman; 7 | import ev3dev.utils.JarResource; 8 | import lejos.hardware.lcd.GraphicsLCD; 9 | import lejos.utility.Delay; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import java.awt.image.BufferedImage; 14 | import java.io.IOException; 15 | 16 | public class LCDShowJavaLogoExample { 17 | 18 | public static Logger LOGGER = LoggerFactory.getLogger(LCDShowJavaLogoExample.class); 19 | 20 | public static GraphicsLCD lcd = LCD.getInstance(); 21 | 22 | public static void main(final String[] args) { 23 | 24 | if(EV3DevDistros.getInstance().getDistro().equals(EV3DevDistro.JESSIE)) { 25 | Brickman.disable(); 26 | } 27 | 28 | LOGGER.info("EV3 LCD Example"); 29 | 30 | showJavaLogo(); 31 | Delay.msDelay(5000); 32 | 33 | } 34 | 35 | public static final String JAVA_DUKE_IMAGE_NAME = "java_logo.png"; 36 | 37 | private static void showJavaLogo() { 38 | 39 | if(LOGGER.isDebugEnabled()) 40 | LOGGER.debug("Showing Java logo on EV3 Brick"); 41 | 42 | try { 43 | BufferedImage image = JarResource.loadImage(JAVA_DUKE_IMAGE_NAME); 44 | lcd.drawImage(image, 35, 10, 0); 45 | lcd.refresh(); 46 | }catch (IOException e){ 47 | LOGGER.error(e.getLocalizedMessage()); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/actuator/LEDPatternsExample.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.actuator; 2 | 3 | import ev3dev.actuators.ev3.EV3Led; 4 | import lejos.hardware.LED; 5 | import lejos.utility.Delay; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | public class LEDPatternsExample { 10 | 11 | public static Logger LOGGER = LoggerFactory.getLogger(LEDPatternsExample.class); 12 | 13 | public static void main(String[] args) { 14 | 15 | LOGGER.info("Example with EV3 Led patterns"); 16 | 17 | leftPatterns(); 18 | rightPatterns(); 19 | 20 | } 21 | 22 | public static void leftPatterns(){ 23 | 24 | LOGGER.info("Left patterns"); 25 | 26 | LED led = new EV3Led(EV3Led.LEFT); 27 | led.setPattern(0); 28 | Delay.msDelay(1000); 29 | led.setPattern(1); 30 | Delay.msDelay(1000); 31 | led.setPattern(2); 32 | Delay.msDelay(1000); 33 | led.setPattern(3); 34 | Delay.msDelay(1000); 35 | led.setPattern(0); 36 | Delay.msDelay(1000); 37 | } 38 | 39 | public static void rightPatterns(){ 40 | 41 | LOGGER.info("Right patterns"); 42 | 43 | LED led = new EV3Led(EV3Led.RIGHT); 44 | 45 | led.setPattern(0); 46 | Delay.msDelay(1000); 47 | led.setPattern(1); 48 | Delay.msDelay(1000); 49 | led.setPattern(2); 50 | Delay.msDelay(1000); 51 | led.setPattern(3); 52 | Delay.msDelay(1000); 53 | led.setPattern(0); 54 | Delay.msDelay(1000); 55 | 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/actuator/TTSDemo.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.actuator; 2 | 3 | import ev3dev.robotics.tts.Espeak; 4 | 5 | public class TTSDemo { 6 | 7 | public static void main(String[] args) { 8 | 9 | System.out.println("Testing Espeak on EV3Brick"); 10 | 11 | Espeak TTS = new Espeak(); 12 | TTS.setVolume(100); 13 | 14 | //Spanish example 15 | TTS.setVoice("es"); 16 | TTS.setSpeedReading(200); 17 | TTS.setPitch(50); 18 | TTS.setMessage("Soy un robot LEGO"); 19 | TTS.say(); 20 | 21 | //English example 22 | TTS.setVoice("en"); 23 | TTS.setSpeedReading(105); 24 | TTS.setPitch(60); 25 | TTS.setMessage("I am a LEGO robot"); 26 | TTS.say(); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/actuator/motor/BasicMotorOperationExample.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.actuator.motor; 2 | 3 | import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor; 4 | import lejos.hardware.port.MotorPort; 5 | import lejos.utility.Delay; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | class BasicMotorOperationExample { 10 | 11 | public static Logger LOGGER = LoggerFactory.getLogger(BasicMotorOperationExample.class); 12 | 13 | public static int DELAY = 2000; //2 Sedonds 14 | 15 | public static final EV3LargeRegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.A); 16 | 17 | public static void main(String[] args) { 18 | 19 | LOGGER.info("Starting motors on A"); 20 | mA.setSpeed(500); 21 | mA.brake(); 22 | 23 | LOGGER.info("Forward"); 24 | mA.forward(); 25 | LOGGER.info("Large Motor is moving: {}, at speed {}", mA.isMoving(), mA.getSpeed()); 26 | Delay.msDelay(DELAY); 27 | 28 | LOGGER.info("Stop"); 29 | mA.stop(); 30 | LOGGER.info("Large Motor is moving: {}, at speed {}", mA.isMoving(), mA.getSpeed()); 31 | Delay.msDelay(DELAY); 32 | 33 | LOGGER.info("Backward"); 34 | mA.backward(); 35 | LOGGER.info("Large Motor is moving: {}, at speed {}", mA.isMoving(), mA.getSpeed()); 36 | Delay.msDelay(2000); 37 | 38 | LOGGER.info("Stop"); 39 | mA.stop(); 40 | LOGGER.info("Large Motor is moving: {}, at speed {}", mA.isMoving(), mA.getSpeed()); 41 | Delay.msDelay(DELAY); 42 | 43 | LOGGER.info("Forward"); 44 | mA.forward(); 45 | Delay.msDelay(2000); 46 | mA.stop(); 47 | LOGGER.info("Stop"); 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/sensor/BatteryDemo.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.sensor; 2 | 3 | import ev3dev.sensors.Battery; 4 | import lejos.utility.Delay; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | public class BatteryDemo { 9 | 10 | public static Logger LOGGER = LoggerFactory.getLogger(BatteryDemo.class); 11 | 12 | public static void main(String[] args) { 13 | 14 | final Battery battery = Battery.getInstance(); 15 | 16 | for(int x = 0; x < 10; x++){ 17 | LOGGER.info("Battery Voltage: {}", battery.getVoltage()); 18 | 19 | Delay.msDelay(100); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/sensor/DetectBlueBall.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.sensor; 2 | 3 | import ev3dev.actuators.Sound; 4 | import ev3dev.sensors.ev3.EV3ColorSensor; 5 | import lejos.hardware.port.SensorPort; 6 | import lejos.robotics.Color; 7 | import lejos.robotics.SampleProvider; 8 | import lejos.utility.Delay; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | public class DetectBlueBall { 13 | 14 | public static Logger LOGGER = LoggerFactory.getLogger(DetectBlueBall.class); 15 | 16 | private static EV3ColorSensor color1 = new EV3ColorSensor(SensorPort.S1); 17 | 18 | private static int HALF_SECOND = 500; 19 | 20 | public static void main(String[] args) { 21 | 22 | //Color ID 23 | LOGGER.info("Switching to Color ID Mode"); 24 | SampleProvider sp = color1.getColorIDMode(); 25 | 26 | int sampleSize = sp.sampleSize(); 27 | float[] sample = new float[sampleSize]; 28 | 29 | int value = 0; 30 | 31 | // Takes some samples and prints them 32 | for (int i = 0; i < 100; i++) { 33 | sp.fetchSample(sample, 0); 34 | value = (int) sample[0]; 35 | 36 | LOGGER.info("N={} Sample={}", i, value); 37 | 38 | Delay.msDelay(HALF_SECOND); 39 | 40 | if(value == Color.BLUE){ 41 | Sound.getInstance().beep(); 42 | LOGGER.info("Blue ball found"); 43 | break; 44 | } 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/sensor/IRSensorRemoteControlExample.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.sensor; 2 | 3 | import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor; 4 | import ev3dev.sensors.ev3.EV3IRSensor; 5 | import lejos.hardware.port.MotorPort; 6 | import lejos.hardware.port.SensorPort; 7 | import lejos.robotics.SampleProvider; 8 | import lejos.utility.Delay; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | public class IRSensorRemoteControlExample { 13 | 14 | public static Logger LOGGER = LoggerFactory.getLogger(IRSensorRemoteControlExample.class); 15 | 16 | //Configuration 17 | private static int DELAY = 100; 18 | 19 | public static void main(String[] args) { 20 | 21 | LOGGER.info("Starting motor on A"); 22 | final EV3LargeRegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.A); 23 | LOGGER.info("Starting motor on B"); 24 | final EV3LargeRegulatedMotor mB = new EV3LargeRegulatedMotor(MotorPort.D); 25 | 26 | //To Stop the motor in case of pkill java for example 27 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 28 | System.out.println("Emergency Stop"); 29 | mA.stop(); 30 | mB.stop(); 31 | })); 32 | 33 | mA.brake(); 34 | mB.brake(); 35 | 36 | mA.setSpeed(300); 37 | mB.setSpeed(300); 38 | 39 | final EV3IRSensor ir1 = new EV3IRSensor(SensorPort.S1); 40 | 41 | final SampleProvider sp = ir1.getRemoteMode(); 42 | 43 | int beaconInfo1 = 0; 44 | int beaconInfo2 = 0; 45 | int beaconInfo3 = 0; 46 | int beaconInfo4 = 0; 47 | 48 | //Control loop 49 | final int iteration_threshold = 5000; 50 | for(int i = 0; i <= iteration_threshold; i++) { 51 | 52 | float [] sample = new float[sp.sampleSize()]; 53 | sp.fetchSample(sample, 0); 54 | 55 | beaconInfo1 = (int)sample[0]; 56 | beaconInfo2 = (int)sample[1]; 57 | beaconInfo3 = (int)sample[2]; 58 | beaconInfo4 = (int)sample[3]; 59 | 60 | LOGGER.info("Iteration: {}", i); 61 | LOGGER.info("Beacon Channel 1: Remote: " + beaconInfo1); 62 | LOGGER.info("Beacon Channel 2: Remote: " + beaconInfo2); 63 | LOGGER.info("Beacon Channel 3: Remote: " + beaconInfo3); 64 | LOGGER.info("Beacon Channel 4: Remote: " + beaconInfo4); 65 | 66 | if(beaconInfo1 == 0){ 67 | mA.stop(); 68 | mB.stop(); 69 | }else if(beaconInfo1 == 1){ 70 | mA.forward(); 71 | }else if(beaconInfo1 == 2){ 72 | mA.backward(); 73 | }else if(beaconInfo1 == 3){ 74 | mB.forward(); 75 | }else if(beaconInfo1 == 4){ 76 | mB.backward(); 77 | }else if(beaconInfo1 == 5){ 78 | mA.forward(); 79 | mB.forward(); 80 | }else if(beaconInfo1 == 6){ 81 | mA.forward(); 82 | mB.backward(); 83 | }else if(beaconInfo1 == 7){ 84 | mA.backward(); 85 | mB.forward(); 86 | }else if(beaconInfo1 == 8){ 87 | mA.backward(); 88 | mB.backward(); 89 | } 90 | 91 | Delay.msDelay(DELAY); 92 | } 93 | 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/sensor/TouchSensorExample.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.sensor; 2 | 3 | import ev3dev.sensors.Battery; 4 | import ev3dev.sensors.ev3.EV3TouchSensor; 5 | import lejos.hardware.port.SensorPort; 6 | import lejos.robotics.SampleProvider; 7 | import lejos.utility.Delay; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | public class TouchSensorExample { 12 | 13 | public static Logger LOGGER = LoggerFactory.getLogger(TouchSensorExample.class); 14 | 15 | //Robot Configuration 16 | private static EV3TouchSensor touch1 = new EV3TouchSensor(SensorPort.S1); 17 | 18 | //Configuration 19 | private static int HALF_SECOND = 500; 20 | 21 | public static void main(String[] args) { 22 | 23 | final SampleProvider sp = touch1.getTouchMode(); 24 | int touchValue = 0; 25 | 26 | //Control loop 27 | final int iteration_threshold = 20; 28 | for(int i = 0; i <= iteration_threshold; i++) { 29 | 30 | float [] sample = new float[sp.sampleSize()]; 31 | sp.fetchSample(sample, 0); 32 | touchValue = (int) sample[0]; 33 | 34 | LOGGER.info("Iteration: {}, Touch: {}", i, touchValue); 35 | 36 | Delay.msDelay(HALF_SECOND); 37 | } 38 | 39 | LOGGER.info("Battery voltage: {}", Battery.getInstance().getVoltage()); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/sensor/TurnWithGyroSensorExample.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.sensor; 2 | 3 | import ev3dev.actuators.Sound; 4 | import ev3dev.sensors.ev3.EV3GyroSensor; 5 | import lejos.hardware.port.SensorPort; 6 | import lejos.robotics.SampleProvider; 7 | import lejos.utility.Delay; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | public class TurnWithGyroSensorExample { 12 | 13 | private static final Logger LOGGER = LoggerFactory.getLogger(TurnWithGyroSensorExample.class); 14 | 15 | private static EV3GyroSensor gyroSensor = new EV3GyroSensor(SensorPort.S1); 16 | 17 | private static int HALF_SECOND = 500; 18 | private static int LOOP_LIMIT = 100; 19 | 20 | public static void main(String[] args) { 21 | 22 | gyroSensor.reset(); 23 | final SampleProvider sp = gyroSensor.getAngleMode(); 24 | int value = 0; 25 | 26 | int iterationCounter = 0; 27 | 28 | //Control loop 29 | while (true) { 30 | 31 | float [] sample = new float[sp.sampleSize()]; 32 | sp.fetchSample(sample, 0); 33 | value = (int)sample[0]; 34 | 35 | LOGGER.info("Gyro angle: {}", value); 36 | 37 | if(value >= 90){ 38 | Sound.getInstance().beep(); 39 | LOGGER.info("Rotated 90 degrees"); 40 | break; 41 | } 42 | 43 | //Avoid an infinite loop 44 | iterationCounter++; 45 | if (iterationCounter >= LOOP_LIMIT) { 46 | LOGGER.debug("Breaking the loop if you didn't rotate in 100 iterations"); 47 | break; 48 | } 49 | 50 | Delay.msDelay(HALF_SECOND); 51 | } 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/example/robotics/ev3/sensor/USSensorExample.java: -------------------------------------------------------------------------------- 1 | package example.robotics.ev3.sensor; 2 | 3 | import ev3dev.sensors.Battery; 4 | import ev3dev.sensors.ev3.EV3UltrasonicSensor; 5 | import lejos.hardware.port.SensorPort; 6 | import lejos.robotics.SampleProvider; 7 | import lejos.utility.Delay; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | public class USSensorExample { 12 | 13 | public static Logger LOGGER = LoggerFactory.getLogger(USSensorExample.class); 14 | 15 | private static EV3UltrasonicSensor us1 = new EV3UltrasonicSensor(SensorPort.S1); 16 | 17 | public static void main(String[] args) { 18 | 19 | final SampleProvider sp = us1.getDistanceMode(); 20 | int distanceValue = 0; 21 | 22 | final int iteration_threshold = 100; 23 | for(int i = 0; i <= iteration_threshold; i++) { 24 | 25 | float [] sample = new float[sp.sampleSize()]; 26 | sp.fetchSample(sample, 0); 27 | distanceValue = (int) sample[0]; 28 | 29 | LOGGER.info("Iteration: {}, Distance: {}", i, distanceValue); 30 | 31 | Delay.msDelay(500); 32 | } 33 | 34 | LOGGER.info("Battery voltage: {}", Battery.getInstance().getVoltage()); 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Implementation-Title: EV3Dev-lang-java 3 | Implementation-Version: 2.7.0-SNAPSHOT 4 | Implementation-Vendor: Juan Antonio Breña Moral 5 | Main-Class: example.programming.HelloWorld 6 | -------------------------------------------------------------------------------- /src/main/resources/index.html: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | System.err 8 | 9 | 10 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | # SLF4J's SimpleLogger configuration file 2 | # Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. 3 | 4 | org.slf4j.simpleLogger.defaultLogLevel=info 5 | 6 | #org.slf4j.simpleLogger.log.ev3dev.hardware=trace 7 | #org.slf4j.simpleLogger.log.ev3dev.utils=trace 8 | 9 | 10 | 11 | org.slf4j.simpleLogger.showDateTime=true 12 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss 13 | org.slf4j.simpleLogger.showThreadName=true 14 | org.slf4j.simpleLogger.showLogName=true 15 | org.slf4j.simpleLogger.showShortLogName=false 16 | 17 | org.slf4j.simpleLogger.logFile=System.err 18 | #org.slf4j.simpleLogger.logFile=/home/robot/java/programs/logs.log 19 | --------------------------------------------------------------------------------