final ev3 stuff
authorMart Lubbers <mart@martlubbers.net>
Mon, 19 Oct 2015 15:00:54 +0000 (17:00 +0200)
committerMart Lubbers <mart@martlubbers.net>
Mon, 19 Oct 2015 15:00:54 +0000 (17:00 +0200)
15 files changed:
mart/ev3/.gitignore
mart/ev3/ex1/nl/ru/des/ButtonListener.java
mart/ev3/ex1/nl/ru/des/Main.java
mart/ev3/ex1/nl/ru/des/StayInFieldBehaviour.java
mart/ev3/ex1/nl/ru/des/WandererBehaviour.java
mart/ev3/ex1/nl/ru/des/WavPlayer.java
mart/ev3/ex1/nl/ru/des/sounds/bootaudio.wav [new file with mode: 0644]
mart/ev3/ex1/nl/ru/des/sounds/bootsystem.wav [new file with mode: 0644]
mart/ev3/ex1/nl/ru/des/sounds/bounds.wav [new file with mode: 0644]
mart/ev3/ex1/nl/ru/des/sounds/bump.wav [new file with mode: 0644]
mart/ev3/ex1/nl/ru/des/sounds/calibrate.wav [new file with mode: 0644]
mart/ev3/ex1/nl/ru/des/sounds/detect.wav [new file with mode: 0644]
mart/ev3/ex1/nl/ru/des/sounds/makeall.sh
mart/ev3/ex1/nl/ru/des/sounds/rick.wav [new file with mode: 0644]
mart/ev3/ex1/nl/ru/des/sounds/takeoff.wav [new file with mode: 0644]

index 68ae3a3..29df1ac 100644 (file)
@@ -4,8 +4,10 @@ import lejos.hardware.Key;
 import lejos.hardware.KeyListener;
 
 class ButtonListener implements KeyListener {
+       
        @Override
        public void keyPressed(Key k) {
+               LCDPrinter.print("Bye");
                System.exit(0);
        }
 
index 805ff02..7416dd7 100644 (file)
@@ -14,8 +14,21 @@ import lejos.robotics.subsumption.Behavior;
 import lejos.utility.Delay;
 
 public class Main {
+       public static Arbitrator arbitrator;
 
        public static void main(String[] args) {
+               String[] sounds = new String[]{
+                               "bootaudio.wav",
+                               "bootsystem.wav",
+                               "bounds.wav",
+                               "bump.wav",
+                               "calibrate.wav",
+                               "detect.wav",
+                               "takeoff.wav",
+                               "rick.wav"
+               };
+
+               
                EV3 brick = LocalEV3.get();
                LCDPrinter lcdprinter = new LCDPrinter(brick.getGraphicsLCD(), Font.getSmallFont());
                LCDPrinter.print("Starting up systems");
@@ -24,8 +37,9 @@ public class Main {
                LCDPrinter.print("Loading audio...");
                Audio audio = brick.getAudio();
                WavPlayer wavplayer = new WavPlayer(audio);
+               wavplayer.preLoad(sounds);
                wavplayer.start();
-               WavPlayer.playWav("boot.wav");
+               WavPlayer.playWav("bootaudio.wav");
                
                LCDPrinter.print("Loading keylistener...");
                brick.getKey("Escape").addKeyListener(new ButtonListener());
@@ -59,12 +73,12 @@ public class Main {
                WavPlayer.playWav("calibrate.wav");
                
                LCDPrinter.print("Initializing arbitrator...");
-               Arbitrator arb = new Arbitrator(behaviorList);
+               Main.arbitrator = new Arbitrator(behaviorList);
                
                WavPlayer.playWav("takeoff.wav");
-               Delay.msDelay(1850);
+               Delay.msDelay(2000);
                LCDPrinter.print("Takeoff!");
-               arb.start();
+               Main.arbitrator.start();
                lightSensor.close();
                ultraSensor.close();
        }
index 01ac30f..6e1b515 100644 (file)
@@ -11,7 +11,7 @@ public class StayInFieldBehaviour extends AvoidBehaviour{
        private float black, white, dist;
        
        public StayInFieldBehaviour(NXTLightSensor lightSensor, EV3LargeRegulatedMotor leftMotor, EV3LargeRegulatedMotor rightMotor) {
-               super(rightMotor, leftMotor, "bound.wav");
+               super(rightMotor, leftMotor, "bounds.wav");
                light = lightSensor.getRedMode();
                samples = new float[light.sampleSize()];
                calibrate();
index a915f4d..4912cbb 100644 (file)
@@ -5,6 +5,7 @@ import lejos.robotics.subsumption.Behavior;
 
 public class WandererBehaviour implements Behavior {
        private EV3LargeRegulatedMotor leftMotor, rightMotor;
+       private long play = 0;
        
        public WandererBehaviour(EV3LargeRegulatedMotor leftMotor, EV3LargeRegulatedMotor rightMotor){
                this.leftMotor = leftMotor;
@@ -18,6 +19,10 @@ public class WandererBehaviour implements Behavior {
 
        @Override
        public void action() {
+               if(System.currentTimeMillis() - play > 30000){
+                       WavPlayer.playWav("rick.wav");
+                       play = System.currentTimeMillis();
+               }
                leftMotor.forward();
                rightMotor.forward();
        }
index 1a3b55e..2e0760f 100644 (file)
@@ -1,6 +1,10 @@
 package nl.ru.des;
 
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 
 import lejos.hardware.Audio;
 import lejos.utility.Delay;
@@ -15,20 +19,49 @@ public class WavPlayer extends Thread{
        
        public WavPlayer(Audio audio){
                this.audio = audio;
-               audio.setVolume(100);
+               audio.setVolume(Audio.VOL_MAX);
+       }
+       
+       public void preLoad(String[] files){
+               LCDPrinter.print("Preloading audiofiles...");
+               for(String sound : files){
+                       try {
+                               LCDPrinter.print("Preloading: " + sound);
+                               InputStream inp = new BufferedInputStream(Class.class.getResourceAsStream("/nl/ru/des/sounds/" + sound));
+                               File f = new File(sound);
+                               if(f.exists()){
+                                       inp.close();
+                                       LCDPrinter.print(sound + " already exists, skipping...");
+                                       continue;
+                               }
+                               FileOutputStream outp = new FileOutputStream(sound);
+                               byte[] buffer = new byte[1024];
+                               int length;
+                               while ((length = inp.read(buffer)) > 0){
+                                       outp.write(buffer, 0, length);
+                               }
+                               outp.close();
+                               LCDPrinter.print("Done...");
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
+               }
        }
        
        @Override
        public void run(){
+               File c;
                while(true){
                        if(current != null){
-                               File c = new File(current);
+                               c = new File(current);
                                if(c.canRead()){
                                        audio.playSample(new File(current));
+                               } else {
+                                       LCDPrinter.print("can't load: " + current);
                                }
                                current = null;
                        }
-                       Delay.msDelay(200);
+                       Delay.msDelay(00);
                }
        }
 }
\ No newline at end of file
diff --git a/mart/ev3/ex1/nl/ru/des/sounds/bootaudio.wav b/mart/ev3/ex1/nl/ru/des/sounds/bootaudio.wav
new file mode 100644 (file)
index 0000000..fd3daf0
Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/bootaudio.wav differ
diff --git a/mart/ev3/ex1/nl/ru/des/sounds/bootsystem.wav b/mart/ev3/ex1/nl/ru/des/sounds/bootsystem.wav
new file mode 100644 (file)
index 0000000..9eaa4a1
Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/bootsystem.wav differ
diff --git a/mart/ev3/ex1/nl/ru/des/sounds/bounds.wav b/mart/ev3/ex1/nl/ru/des/sounds/bounds.wav
new file mode 100644 (file)
index 0000000..efebe32
Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/bounds.wav differ
diff --git a/mart/ev3/ex1/nl/ru/des/sounds/bump.wav b/mart/ev3/ex1/nl/ru/des/sounds/bump.wav
new file mode 100644 (file)
index 0000000..c81de2d
Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/bump.wav differ
diff --git a/mart/ev3/ex1/nl/ru/des/sounds/calibrate.wav b/mart/ev3/ex1/nl/ru/des/sounds/calibrate.wav
new file mode 100644 (file)
index 0000000..6b35b1a
Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/calibrate.wav differ
diff --git a/mart/ev3/ex1/nl/ru/des/sounds/detect.wav b/mart/ev3/ex1/nl/ru/des/sounds/detect.wav
new file mode 100644 (file)
index 0000000..823b10a
Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/detect.wav differ
index 79377df..c8da90f 100644 (file)
@@ -1,7 +1,7 @@
-echo "Audio system loaded" | espeak --stdout | sox - -r 8000 -b 8  bootaudio.wav
-echo "Ready for calibration" | espeak --stdout | sox - -r 8000 -b 8  bootsystem.wav
-echo "Succesfull calibration" | espeak --stdout | sox - -r 8000 -b 8  calibrate.wav
-echo "Takeoff in 3 2 1 go" | espeak --stdout | sox - -r 8000 -b 8  takeoff.wav
-echo "Almost out of bounds" | espeak --stdout | sox - -r 8000 -b 8  bounds.wav
-echo "Bumped against low object" | espeak --stdout | sox - -r 8000 -b 8  bump.wav
-echo "Detected big object" | espeak --stdout | sox - -r 8000 -b 8  detect.wav
+echo "Audio system loaded" | espeak --stdout           | sox -V - -c 1 -r 8k -b 8 bootaudio.wav
+echo "Ready for calibration" | espeak --stdout                 | sox -V - -c 1 -r 8k -b 8 bootsystem.wav
+echo "Succesfull calibration" | espeak --stdout        | sox -V - -c 1 -r 8k -b 8 calibrate.wav
+echo "Takeoff in 3 2 1 go" | espeak --stdout           | sox -V - -c 1 -r 8k -b 8 takeoff.wav
+echo "Almost out of bounds" | espeak --stdout          | sox -V - -c 1 -r 8k -b 8 bounds.wav
+echo "Bumped against low object" | espeak --stdout     | sox -V - -c 1 -r 8k -b 8 bump.wav
+echo "Detected big object" | espeak --stdout           | sox -V - -c 1 -r 8k -b 8 detect.wav
diff --git a/mart/ev3/ex1/nl/ru/des/sounds/rick.wav b/mart/ev3/ex1/nl/ru/des/sounds/rick.wav
new file mode 100644 (file)
index 0000000..9e46ce1
Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/rick.wav differ
diff --git a/mart/ev3/ex1/nl/ru/des/sounds/takeoff.wav b/mart/ev3/ex1/nl/ru/des/sounds/takeoff.wav
new file mode 100644 (file)
index 0000000..0e4fcbd
Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/takeoff.wav differ