From: Mart Lubbers Date: Mon, 19 Oct 2015 15:00:54 +0000 (+0200) Subject: final ev3 stuff X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=657af4bec2ec8c0539231e539af4a1a991b73b06;p=des2015.git final ev3 stuff --- diff --git a/mart/ev3/.gitignore b/mart/ev3/.gitignore index d8dd753..e69de29 100644 --- a/mart/ev3/.gitignore +++ b/mart/ev3/.gitignore @@ -1 +0,0 @@ -*.wav diff --git a/mart/ev3/ex1/nl/ru/des/ButtonListener.java b/mart/ev3/ex1/nl/ru/des/ButtonListener.java index 68ae3a3..29df1ac 100644 --- a/mart/ev3/ex1/nl/ru/des/ButtonListener.java +++ b/mart/ev3/ex1/nl/ru/des/ButtonListener.java @@ -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); } diff --git a/mart/ev3/ex1/nl/ru/des/Main.java b/mart/ev3/ex1/nl/ru/des/Main.java index 805ff02..7416dd7 100644 --- a/mart/ev3/ex1/nl/ru/des/Main.java +++ b/mart/ev3/ex1/nl/ru/des/Main.java @@ -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(); } diff --git a/mart/ev3/ex1/nl/ru/des/StayInFieldBehaviour.java b/mart/ev3/ex1/nl/ru/des/StayInFieldBehaviour.java index 01ac30f..6e1b515 100644 --- a/mart/ev3/ex1/nl/ru/des/StayInFieldBehaviour.java +++ b/mart/ev3/ex1/nl/ru/des/StayInFieldBehaviour.java @@ -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(); diff --git a/mart/ev3/ex1/nl/ru/des/WandererBehaviour.java b/mart/ev3/ex1/nl/ru/des/WandererBehaviour.java index a915f4d..4912cbb 100644 --- a/mart/ev3/ex1/nl/ru/des/WandererBehaviour.java +++ b/mart/ev3/ex1/nl/ru/des/WandererBehaviour.java @@ -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(); } diff --git a/mart/ev3/ex1/nl/ru/des/WavPlayer.java b/mart/ev3/ex1/nl/ru/des/WavPlayer.java index 1a3b55e..2e0760f 100644 --- a/mart/ev3/ex1/nl/ru/des/WavPlayer.java +++ b/mart/ev3/ex1/nl/ru/des/WavPlayer.java @@ -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 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 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 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 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 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 index 0000000..823b10a Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/detect.wav differ diff --git a/mart/ev3/ex1/nl/ru/des/sounds/makeall.sh b/mart/ev3/ex1/nl/ru/des/sounds/makeall.sh index 79377df..c8da90f 100644 --- a/mart/ev3/ex1/nl/ru/des/sounds/makeall.sh +++ b/mart/ev3/ex1/nl/ru/des/sounds/makeall.sh @@ -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 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 index 0000000..0e4fcbd Binary files /dev/null and b/mart/ev3/ex1/nl/ru/des/sounds/takeoff.wav differ