diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..612f84d --- /dev/null +++ b/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project JavaLibrary6. + + + diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties new file mode 100644 index 0000000..8c8ab62 --- /dev/null +++ b/lib/nblibraries.properties @@ -0,0 +1,10 @@ +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..55720ab --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,721 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..90ae97c --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=a8056d46 +build.xml.script.CRC32=3a7a628a +build.xml.stylesheet.CRC32=958a1d3e +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=afb4810b +nbproject/build-impl.xml.script.CRC32=7668b6e9 +nbproject/build-impl.xml.stylesheet.CRC32=5c621a33@1.26.1.45 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..cfeabca --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,70 @@ +application.title=wiigee-lib +application.vendor=bepo +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8 +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80 +auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=default +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/wiigee-lib.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jnlp.codebase.type=local +jnlp.codebase.url=file:/Users/bepo/develop/java/wiigee/trunk/wiigee-lib/dist +jnlp.descriptor=application +jnlp.enabled=false +jnlp.offline-allowed=false +jnlp.signed=false +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..2d55e43 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,19 @@ + + + org.netbeans.modules.java.j2seproject + + + wiigee-lib + 1.6.5 + + + + + + + + + lib/nblibraries.properties + + + diff --git a/src/org/wiigee/control/Wiigee.java b/src/org/wiigee/control/Wiigee.java new file mode 100644 index 0000000..fff9e7e --- /dev/null +++ b/src/org/wiigee/control/Wiigee.java @@ -0,0 +1,46 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.control; + +import org.wiigee.util.Log; + +/** + * The mother of all classes. :-) It's just used as parent class + * to print version information and later on maybe dynamic configuring + * of the whole wiimote system... detecting plugins and devices automatically + * maybe. :) + * + * @author Benjamin 'BePo' Poppinga + */ +public class Wiigee { + + protected static String version = "1.5.5 alpha"; + protected static String releasedate = "20090714"; + + protected Wiigee() { + Log.write("This is wiigee version "+version+" ("+releasedate+")"); + } + +} diff --git a/src/org/wiigee/device/Device.java b/src/org/wiigee/device/Device.java new file mode 100644 index 0000000..796b952 --- /dev/null +++ b/src/org/wiigee/device/Device.java @@ -0,0 +1,234 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.wiigee.device; + +import java.io.IOException; +import java.util.Vector; + +import org.wiigee.logic.*; +import org.wiigee.event.*; +import org.wiigee.filter.*; + +/** + * Abstract representation of a device with very basic functionalities. This + * class should be derived from, if anybody plans to add a new class of devices, + * like Wiimote or AndroidDevice does. This class mainly consist of filter + * management, recognition control and core event control. + * + * @author Benjamin 'BePo' Poppinga + */ +public class Device { + + // Fixed number values. + public static final int MOTION = 0; + + // Buttons for action coordination + protected int recognitionbutton; + protected int trainbutton; + protected int closegesturebutton; + + // Functional + protected boolean accelerationEnabled; + + // Filters, can filter the data stream + protected Vector accfilters = new Vector(); + + // Listeners, receive generated events + protected Vector accelerationlistener = new Vector(); + protected Vector buttonlistener = new Vector(); + + // Processing unit to analyze the data + protected ProcessingUnit processingunit = new TriggeredProcessingUnit(); + + public Device(boolean autofiltering) { + if (autofiltering) { + this.addAccelerationFilter(new IdleStateFilter()); + this.addAccelerationFilter(new MotionDetectFilter(this)); + this.addAccelerationFilter(new DirectionalEquivalenceFilter()); + } + this.addAccelerationListener(this.processingunit); + this.addButtonListener(this.processingunit); + } + + /** + * Adds a Filter for processing the acceleration values. + * @param filter The Filter instance. + */ + public void addAccelerationFilter(Filter filter) { + this.accfilters.add(filter); + } + + /** + * Resets all the accfilters, which are resetable. + * Sometimes they have to be resettet if a new gesture starts. + */ + public void resetAccelerationFilters() { + for (int i = 0; i < this.accfilters.size(); i++) { + this.accfilters.elementAt(i).reset(); + } + } + + /** + * Adds an AccelerationListener to the Device. Everytime an acceleration + * on the Device is performed the AccelerationListener would receive + * an event of this action. + * + * @param listener The Listener. + */ + public void addAccelerationListener(AccelerationListener listener) { + this.accelerationlistener.add(listener); + } + + /** + * Adds a ButtonListener to the Device. Everytime a Button has been + * pressed or released, the Listener would be notified about this via + * the corresponding Events. + * + * @param listener The Listener. + */ + public void addButtonListener(ButtonListener listener) { + this.buttonlistener.add(listener); + } + + /** + * Adds a GestureListener to the Device. Everytime a gesture + * is performed the GestureListener would receive an event of + * this gesture. + * + * @param listener The Listener. + */ + public void addGestureListener(GestureListener listener) { + this.processingunit.addGestureListener(listener); + } + + public int getRecognitionButton() { + return this.recognitionbutton; + } + + public void setRecognitionButton(int b) { + this.recognitionbutton = b; + } + + public int getTrainButton() { + return this.trainbutton; + } + + public void setTrainButton(int b) { + this.trainbutton = b; + } + + public int getCloseGestureButton() { + return this.closegesturebutton; + } + + public void setCloseGestureButton(int b) { + this.closegesturebutton = b; + } + + public ProcessingUnit getProcessingUnit() { + return this.processingunit; + } + + public void setAccelerationEnabled(boolean enabled) throws IOException { + this.accelerationEnabled = enabled; + } + + public void loadGesture(String filename) { + this.processingunit.loadGesture(filename); + } + + public void saveGesture(int id, String filename) { + this.processingunit.saveGesture(id, filename); + } + + // ###### Event-Methoden + /** Fires an acceleration event. + * @param vector Consists of three values: + * acceleration on X, Y and Z axis. + */ + public void fireAccelerationEvent(double[] vector) { + for (int i = 0; i < this.accfilters.size(); i++) { + vector = this.accfilters.get(i).filter(vector); + // cannot return here if null, because of time-dependent accfilters + } + + // don't need to create an event if filtered away + if (vector != null) { + // calculate the absolute value for the accelerationevent + double absvalue = Math.sqrt((vector[0] * vector[0]) + + (vector[1] * vector[1]) + (vector[2] * vector[2])); + + AccelerationEvent w = new AccelerationEvent(this, + vector[0], vector[1], vector[2], absvalue); + for (int i = 0; i < this.accelerationlistener.size(); i++) { + this.accelerationlistener.get(i).accelerationReceived(w); + } + } + + } // fireaccelerationevent + + /** Fires a button pressed event. + * @param button + * Integer value of the pressed button. + */ + public void fireButtonPressedEvent(int button) { + ButtonPressedEvent w = new ButtonPressedEvent(this, button); + for (int i = 0; i < this.buttonlistener.size(); i++) { + this.buttonlistener.get(i).buttonPressReceived(w); + } + + if (w.isRecognitionInitEvent() || w.isTrainInitEvent()) { + this.resetAccelerationFilters(); + } + } + + /** Fires a button released event. + */ + public void fireButtonReleasedEvent(int button) { + ButtonReleasedEvent w = new ButtonReleasedEvent(this, button); + for (int i = 0; i < this.buttonlistener.size(); i++) { + this.buttonlistener.get(i).buttonReleaseReceived(w); + } + } + + /** + * Fires a motion start event. + */ + public void fireMotionStartEvent() { + MotionStartEvent w = new MotionStartEvent(this); + for (int i = 0; i < this.accelerationlistener.size(); i++) { + this.accelerationlistener.get(i).motionStartReceived(w); + } + } + + /** + * Fires a motion stop event. + */ + public void fireMotionStopEvent() { + MotionStopEvent w = new MotionStopEvent(this); + for (int i = 0; i < this.accelerationlistener.size(); i++) { + this.accelerationlistener.get(i).motionStopReceived(w); + } + } +} diff --git a/src/org/wiigee/event/AccelerationEvent.java b/src/org/wiigee/event/AccelerationEvent.java new file mode 100755 index 0000000..2f54741 --- /dev/null +++ b/src/org/wiigee/event/AccelerationEvent.java @@ -0,0 +1,79 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import java.util.EventObject; + +import org.wiigee.device.*; + +/** + * This Event would be generated if an acceleration has been detected. + * It contains information about the force applied to the device in each + * direction (x, y, z). Further it contains the absolute value of this + * vector and the source which generated this event (Device). + * + * @author Benjamin 'BePo' Poppinga + * + */ +public class AccelerationEvent extends EventObject { + + double X, Y, Z; + double absvalue; + + /** + * Create an AccelerationEvent with a specific source, + * all the three acceleration values and the calculated absolute + * value. + * + * @param source The source which has been accelerated (Wiimote). + * @param X The value of acceleration in the x direction. + * @param Y The value of acceleration in the y direction. + * @param Z The value of acceleration in the z direction. + * @param absvalue The absolute value of this acceleration vector. + */ + public AccelerationEvent(Device source, double X, double Y, double Z, double absvalue) { + super(source); + this.X=X; + this.Y=Y; + this.Z=Z; + this.absvalue=absvalue; + } + + public double getX() { + return X; + } + + public double getY() { + return Y; + } + + public double getZ() { + return Z; + } + + public double getAbsValue() { + return absvalue; + } +} diff --git a/src/org/wiigee/event/AccelerationListener.java b/src/org/wiigee/event/AccelerationListener.java new file mode 100755 index 0000000..e70707a --- /dev/null +++ b/src/org/wiigee/event/AccelerationListener.java @@ -0,0 +1,65 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import java.util.EventListener; + +/** + * This interface has to be implemented if the application should react + * to pure acceleration data. This could be useful if you want to e.g. + * graphically display the acceleration data in your application. + * + * @author Benjamin 'BePo' Poppinga + */ +public interface AccelerationListener extends EventListener { + + /** + * This method would be called if a Device source has been accelerated. + * + * @param event The acceleration representation as an event. + */ + public abstract void accelerationReceived(AccelerationEvent event); + + /** + * This method would be called if a Device is in idle state and then a + * motion starts or if a Device is in motion and then the motion stops and + * the Device is in idle state. + * + * @param event This is the event which contains if the Wiimote is now + * in motion or not. + */ + public abstract void motionStartReceived(MotionStartEvent event); + + /** + * This method would be called if a Device is in motion and then the motion + * stops and the Device is in idle state. + * + * @param event This is the event which contains if the Device is now + * in motion or not. + */ + public abstract void motionStopReceived(MotionStopEvent event); + + +} diff --git a/src/org/wiigee/event/ActionStartEvent.java b/src/org/wiigee/event/ActionStartEvent.java new file mode 100755 index 0000000..9cdfab8 --- /dev/null +++ b/src/org/wiigee/event/ActionStartEvent.java @@ -0,0 +1,84 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import java.util.EventObject; + +import org.wiigee.device.Device; + +/** + * An ActionStartEvent is an Event where other different events can + * be derived from, if they can be considered as an event actually starting + * a process like e.g. Training, Recognition, ... + * + * @author Benjamin 'BePo' Poppinga + */ +public class ActionStartEvent extends EventObject { + + protected boolean trainbutton; + protected boolean recognitionbutton; + protected boolean closegesturebutton; + + public ActionStartEvent(Device source) { + super(source); + } + + /** + * Is true if this button press has been done by the + * individual defined RecognitionButton which has to be + * set during initialization of a Wiimote. + * + * @return Is this button press initiated by the recognition button. + * @see device.Wiimote#setRecognitionButton(int) setRecognitionButton() + */ + public boolean isRecognitionInitEvent() { + return this.recognitionbutton; + } + + /** + * Is true if this button press has been done by the + * individual defined TrainButton which has to be + * set during initialization of a Wiimote. + * + * @return Is this button pres initiated by the training button. + * @see device.Wiimote#setTrainButton(int) setTrainButton() + */ + public boolean isTrainInitEvent() { + return this.trainbutton; + } + + /** + * Is true if this button press has been done by the + * individual defined CloseGestureButton which has to be + * set during initialization of a Wiimote. + * + * @return Is this button press initiated by the close gesture button. + * @see device.Wiimote#setCloseGestureButton(int) setCloseGestureButton() + */ + public boolean isCloseGestureInitEvent() { + return this.closegesturebutton; + } + +} diff --git a/src/org/wiigee/event/ActionStopEvent.java b/src/org/wiigee/event/ActionStopEvent.java new file mode 100755 index 0000000..c4379e2 --- /dev/null +++ b/src/org/wiigee/event/ActionStopEvent.java @@ -0,0 +1,43 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import java.util.EventObject; +import org.wiigee.device.Device; + +/** + * An ActionStopEvent is an Event where other different events can + * be derived from, if they can be considered as an event actually stopping + * a process like e.g. Training, Recognition, ... + * + * @author Benjamin 'BePo' Poppinga + */ +public class ActionStopEvent extends EventObject { + + public ActionStopEvent(Device source) { + super(source); + } + +} diff --git a/src/org/wiigee/event/ButtonListener.java b/src/org/wiigee/event/ButtonListener.java new file mode 100644 index 0000000..296c6ae --- /dev/null +++ b/src/org/wiigee/event/ButtonListener.java @@ -0,0 +1,54 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import java.util.EventListener; + +/** + * This interface has to be implemented if the application should react + * to button press/releases. + * + * @author Benjamin 'BePo' Poppinga + */ +public interface ButtonListener extends EventListener { + + + /** + * This method would be called if a Device button has been pressed. + * + * @param event The button representation as an event. + */ + public abstract void buttonPressReceived(ButtonPressedEvent event); + + /** + * This method would be called if a Device button has been released. + * + * @param event This is actually a meta-event NOT containing which button + * has been released. + */ + public abstract void buttonReleaseReceived(ButtonReleasedEvent event); + + +} diff --git a/src/org/wiigee/event/ButtonPressedEvent.java b/src/org/wiigee/event/ButtonPressedEvent.java new file mode 100755 index 0000000..36d54a4 --- /dev/null +++ b/src/org/wiigee/event/ButtonPressedEvent.java @@ -0,0 +1,80 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import org.wiigee.device.*; + +/** + * + * This Event would be generated if a button on a wiimote has been + * pressed by user. It contains the source (wiimote) and an integer + * representation of which button has been pressed. Please note that + * there exist enumeration constants in the class, so you don't + * have to use this integer values directly. + * + * @author Benjamin 'BePo' Poppinga + */ +public class ButtonPressedEvent extends ActionStartEvent { + + // Fixed number values. + public static final int BUTTON_2 = 1; + public static final int BUTTON_1 = 2; + public static final int BUTTON_B = 3; + public static final int BUTTON_A = 4; + public static final int BUTTON_MINUS = 5; + public static final int BUTTON_HOME = 8; + public static final int BUTTON_LEFT = 9; + public static final int BUTTON_RIGHT = 10; + public static final int BUTTON_DOWN = 11; + public static final int BUTTON_UP = 12; + public static final int BUTTON_PLUS = 13; + + int button; + + /** + * Create a WiimoteButtonPressedEvent with the Wiimote source whose + * Button has been pressed and the integer representation of the button. + * + * @param source + * @param button + */ + public ButtonPressedEvent(Device source, int button) { + super(source); + this.button=button; + + if(source.getRecognitionButton()==button) { + this.recognitionbutton=true; + } else if(source.getTrainButton()==button) { + this.trainbutton=true; + } else if(source.getCloseGestureButton()==button) { + this.closegesturebutton=true; + } + } + + public int getButton() { + return this.button; + } + +} diff --git a/src/org/wiigee/event/ButtonReleasedEvent.java b/src/org/wiigee/event/ButtonReleasedEvent.java new file mode 100755 index 0000000..45de43b --- /dev/null +++ b/src/org/wiigee/event/ButtonReleasedEvent.java @@ -0,0 +1,49 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import org.wiigee.device.*; + +/** + * + * This event would be generated if a button was released. + * contains: source (wiimote). + * + * @author Benjamin 'BePo' Poppinga + */ +public class ButtonReleasedEvent extends ActionStopEvent { + + int button; + + public ButtonReleasedEvent(Device source, int button) { + super(source); + this.button = button; + } + + public int getButton() { + return this.button; + } + +} diff --git a/src/org/wiigee/event/GestureEvent.java b/src/org/wiigee/event/GestureEvent.java new file mode 100755 index 0000000..e3465a7 --- /dev/null +++ b/src/org/wiigee/event/GestureEvent.java @@ -0,0 +1,71 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.wiigee.event; + +import org.wiigee.logic.ProcessingUnit; + +/** + * This event would be generated if a gesture has been detected. + * It contains information about the gesture "name" or type, + * the accelerationstreamanalyzer which generated the event (source) + * and the probability calculated from the bayes classifier. + * + * @author Benjamin 'BePo' Poppinga + */ +public class GestureEvent { + + int id; + boolean valid; + double probability; + ProcessingUnit analyzer; + + /** Create a GestureEvent + * + * @param source The Source, which detected the gesture. + * @param id A gesture ID for identifying a gesture. + * @param probability The Bayes-Classifier calculated probability. + */ + public GestureEvent(ProcessingUnit source, boolean valid, int id, double probability) { + this.analyzer = source; + this.valid = valid; + this.id = id; + this.probability = probability; + } + + public int getId() { + return this.id; + } + + public boolean isValid() { + return this.valid; + } + + public double getProbability() { + return this.probability; + } + + public ProcessingUnit getSource() { + return this.analyzer; + } +} diff --git a/src/org/wiigee/event/GestureListener.java b/src/org/wiigee/event/GestureListener.java new file mode 100755 index 0000000..f076ed9 --- /dev/null +++ b/src/org/wiigee/event/GestureListener.java @@ -0,0 +1,47 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import java.util.EventListener; + +/** + * + * This is the GestureListener interface which has to be implemented + * by any application which should receive recognized gestures. + * + * @author Benjamin 'BePo' Poppinga + * + */ +public interface GestureListener extends EventListener { + + /** + * This method would be called if a gesture has been recognized. + * + * @param event The GestureEvent containing information about + * the recognized gesture. + */ + public abstract void gestureReceived(GestureEvent event); + +} diff --git a/src/org/wiigee/event/MotionStartEvent.java b/src/org/wiigee/event/MotionStartEvent.java new file mode 100755 index 0000000..e669ba6 --- /dev/null +++ b/src/org/wiigee/event/MotionStartEvent.java @@ -0,0 +1,63 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import org.wiigee.device.Device; + +/** + * This Event gets fired, if the Device starts to move. + * + * @author Benjamin 'BePo' Poppinga + */ +public class MotionStartEvent extends ActionStartEvent { + + public MotionStartEvent(Device source) { + super(source); + + if(source.getRecognitionButton()==Device.MOTION) { + this.recognitionbutton=true; + } else if(source.getTrainButton()==Device.MOTION) { + this.trainbutton=true; + } else if(source.getCloseGestureButton()==Device.MOTION) { + this.closegesturebutton=true; + } + } + + @Override + public boolean isTrainInitEvent() { + return this.trainbutton; + } + + @Override + public boolean isCloseGestureInitEvent() { + return this.closegesturebutton; + } + + @Override + public boolean isRecognitionInitEvent() { + return this.recognitionbutton; + } + +} diff --git a/src/org/wiigee/event/MotionStopEvent.java b/src/org/wiigee/event/MotionStopEvent.java new file mode 100755 index 0000000..d5f8747 --- /dev/null +++ b/src/org/wiigee/event/MotionStopEvent.java @@ -0,0 +1,42 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.event; + +import org.wiigee.device.Device; + +/** +* +* This event would be generated if a motion stops. +* contains: source. +* +* @author Benjamin 'BePo' Poppinga +*/ +public class MotionStopEvent extends ActionStopEvent { + + public MotionStopEvent(Device source) { + super(source); + } + +} diff --git a/src/org/wiigee/filter/DirectionalEquivalenceFilter.java b/src/org/wiigee/filter/DirectionalEquivalenceFilter.java new file mode 100755 index 0000000..e5098dd --- /dev/null +++ b/src/org/wiigee/filter/DirectionalEquivalenceFilter.java @@ -0,0 +1,70 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.filter; + +/** + * This filter removes a vector, if it doesn't differ enough from + * the previously retrieved filter. + * + * @author Benjamin 'BePo' Poppinga + */ +public class DirectionalEquivalenceFilter extends Filter { + + private double sensivity; + private double[] reference; + + public DirectionalEquivalenceFilter() { + super(); + this.reset(); + } + + public void reset() { + this.sensivity=0.2; + this.reference = new double[] {0.0, 0.0, 0.0}; + } + + public double[] filterAlgorithm(double[] vector) { + if(vector[0]reference[0]+this.sensivity || + vector[1]reference[1]+this.sensivity || + vector[2]reference[2]+this.sensivity) { + this.reference=vector; + return vector; + } else { + return null; + } + } + + public void setSensivity(double sensivity) { + this.sensivity=sensivity; + } + + public double getSensivity() { + return this.sensivity; + } + +} diff --git a/src/org/wiigee/filter/Filter.java b/src/org/wiigee/filter/Filter.java new file mode 100755 index 0000000..e97d4a9 --- /dev/null +++ b/src/org/wiigee/filter/Filter.java @@ -0,0 +1,62 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.filter; + +/** + * Abstract class to give a definition for a general filter. + * + * @author Benjamin 'BePo' Poppinga + */ +public abstract class Filter { + + /*** + * The actual called method to filter anything. It checks if the vector is + * already set to NULL by another filter and won't process it anymore. If it's + * not NULL it would be forwarded to the actual implemented method - filterAlgorithm(). + * @param vector The acceleration vector, encoding: 0/x, 1/y, 2/z + * @return a new, filtered acceleration vector, encoded the same way + */ + public double[] filter(double[] vector) { + if(vector==null) { + return null; + } else { + return filterAlgorithm(vector); + } + } + + /*** + * A filter receives a triple of acceleration values within the variable 'vector'. + * It's encoded as vector[0]=x, vector[1]=y, vector[2]=z. This is not an object since the + * processing of the filter should be really fast, since every acceleration of the wiimote + * passes the filter. + * @param vector + * @param absvalue + * @return + */ + abstract public double[] filterAlgorithm(double[] vector); + + abstract public void reset(); + +} diff --git a/src/org/wiigee/filter/HighPassFilter.java b/src/org/wiigee/filter/HighPassFilter.java new file mode 100644 index 0000000..54a6946 --- /dev/null +++ b/src/org/wiigee/filter/HighPassFilter.java @@ -0,0 +1,71 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.filter; + +/** + * + * This filter removes every acceleration that happens slowly or + * steadily (like e.g. gravity). Remember: It _passes_ acceleration + * with a big variety. + * + * @author Benjamin 'BePo' Poppinga + */ +public class HighPassFilter extends Filter { + + private double factor; + private double[] prevAcc; + + public HighPassFilter() { + super(); + this.factor = 0.1; + this.reset(); + } + + public HighPassFilter(double factor) { + super(); + this.factor = factor; + this.reset(); + } + + @Override + public void reset() { + this.prevAcc = new double[] {0.0, 0.0, 0.0}; + } + + @Override + public double[] filterAlgorithm(double[] vector) { + double[] retVal = new double[3]; + prevAcc[0] = vector[0] * this.factor + this.prevAcc[0] * (1.0 - this.factor); + prevAcc[1] = vector[1] * this.factor + this.prevAcc[1] * (1.0 - this.factor); + prevAcc[2] = vector[2] * this.factor + this.prevAcc[2] * (1.0 - this.factor); + + retVal[0] = vector[0] - prevAcc[0]; + retVal[1] = vector[1] - prevAcc[1]; + retVal[2] = vector[2] - prevAcc[2]; + + return retVal; + } + +} diff --git a/src/org/wiigee/filter/IdleStateFilter.java b/src/org/wiigee/filter/IdleStateFilter.java new file mode 100755 index 0000000..b816e0b --- /dev/null +++ b/src/org/wiigee/filter/IdleStateFilter.java @@ -0,0 +1,86 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.filter; + +/** + * Filters if the wiimote is not moved in any way. Be careful in using + * this filter together with a HighPassFilter. + * + * @author Benjamin 'BePo' Poppinga + */ +public class IdleStateFilter extends Filter { + + private double sensivity; + + /** + * Since an acceleration sensor usually provides information even + * if it doesn't move, this filter removes the data if it's in the + * idle state. + */ + public IdleStateFilter() { + super(); + this.sensivity = 0.1; + } + + @Override + public void reset() { + // not needed + } + + @Override + public double[] filterAlgorithm(double[] vector) { + // calculate values needed for filtering: + // absolute value + double absvalue = Math.sqrt((vector[0]*vector[0])+ + (vector[1]*vector[1])+(vector[2]*vector[2])); + + // filter formulaes and return values + if(absvalue > 1+this.sensivity || + absvalue < 1-this.sensivity) { + return vector; + } else { + return null; + } + } + + /** + * Defines the absolute value when the wiimote should react to acceleration. + * This is a parameter for the first of the two filters: idle state + * filter. For example: sensivity=0.2 makes the wiimote react to acceleration + * where the absolute value is equal or greater than 1.2g. The default value 0.1 + * should work well. Only change if you are sure what you're doing. + * + * @param sensivity + * acceleration data values smaller than this value wouldn't be detected. + */ + public void setSensivity(double sensivity) { + this.sensivity = sensivity; + } + + public double getSensivity() { + return this.sensivity; + } + +} diff --git a/src/org/wiigee/filter/LowPassFilter.java b/src/org/wiigee/filter/LowPassFilter.java new file mode 100644 index 0000000..2c3e012 --- /dev/null +++ b/src/org/wiigee/filter/LowPassFilter.java @@ -0,0 +1,67 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.filter; + +/** + * + * This filter removes every acceleration that happens fast or + * suddenly (like e.g. a short hit). Remember: It _passes_ acceleration + * with a slight variety. + * + * @author Benjamin 'BePo' Poppinga + */ +public class LowPassFilter extends Filter { + + private double factor; + private double[] prevAcc; + + public LowPassFilter() { + super(); + this.factor = 0.01; + this.reset(); + } + + public LowPassFilter(double factor) { + super(); + this.factor = factor; + this.reset(); + } + + @Override + public void reset() { + this.prevAcc = new double[] {0.0, 0.0, 0.0}; + } + + @Override + public double[] filterAlgorithm(double[] vector) { + double[] retVal = new double[3]; + retVal[0] = vector[0] * this.factor + this.prevAcc[0] * (1.0 - this.factor); + retVal[1] = vector[1] * this.factor + this.prevAcc[1] * (1.0 - this.factor); + retVal[2] = vector[2] * this.factor + this.prevAcc[2] * (1.0 - this.factor); + this.prevAcc = retVal; + return retVal; + } + +} diff --git a/src/org/wiigee/filter/MotionDetectFilter.java b/src/org/wiigee/filter/MotionDetectFilter.java new file mode 100755 index 0000000..b13124a --- /dev/null +++ b/src/org/wiigee/filter/MotionDetectFilter.java @@ -0,0 +1,102 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.filter; + +import org.wiigee.device.Device; + +/** + * This filter uses time to determine if the wiimote actually is in motion + * or not. This filter only works together with the IdleStateFilter. + * + * @author Benjamin 'BePo' Poppinga + */ +public class MotionDetectFilter extends Filter { + + private int motionchangetime; + private boolean nowinmotion; + private long motionstartstamp; + private Device device; + + /*** + * Detects wheather the wiimote receives acceleration or not and + * raises an event, if the device starts or stops. This is actual a + * null filter, not manipulating anything. But looks pretty good in + * this datatype since it could be removed easily. + * + * @param wiimote The Wiimote object which is controlled by the filter. + */ + public MotionDetectFilter(Device device) { + super(); + this.device=device; + this.reset(); + } + + public void reset() { + this.motionstartstamp=System.currentTimeMillis(); + this.nowinmotion=false; + this.motionchangetime=190; + } + + @Override + public double[] filter(double[] vector) { + + if(this.nowinmotion && + (System.currentTimeMillis()-this.motionstartstamp)>= + this.motionchangetime) { + this.nowinmotion=false; + this.device.fireMotionStopEvent(); + } // fi + + return filterAlgorithm(vector); + } + + public double[] filterAlgorithm(double[] vector) { + if(vector!=null) { + this.motionstartstamp=System.currentTimeMillis(); + if(!this.nowinmotion) { + this.nowinmotion=true; + this.motionstartstamp=System.currentTimeMillis(); + this.device.fireMotionStartEvent(); + } + } + + return vector; + } + + /** + * Defines the time the wiimote has to be in idle state before a new motion change + * event appears. The default value 500ms should work well, only change it if you are sure + * about what you're doing. + * @param time Time in ms + */ + public void setMotionChangeTime(int time) { + this.motionchangetime=time; + } + + public int getMotionChangeTime() { + return this.motionchangetime; + } + +} diff --git a/src/org/wiigee/logic/Classifier.java b/src/org/wiigee/logic/Classifier.java new file mode 100644 index 0000000..a8f1b5a --- /dev/null +++ b/src/org/wiigee/logic/Classifier.java @@ -0,0 +1,109 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.logic; + +import java.util.Vector; + +public class Classifier { + + private Vector gesturemodel; // each gesturetype got its own + // gesturemodel in this vector + private double lastprob; + + public Classifier() { + this.gesturemodel=new Vector(); + this.lastprob=0.0; + } + + /** + * This method recognize a specific gesture, given to the procedure. + * For classification a bayes classification algorithm is used. + * + * @param g gesture to classify + */ + public int classifyGesture(Gesture g) { + //Log.write("Recognizing gesture..."); + + // Wert im Nenner berechnen, nach Bayes + double sum = 0; + for(int i=0; irecogprob) { + probgesture=tmpgesture; + probmodel=tmpmodel; + recogprob=((tmpmodel*tmpgesture)/sum); + recognized=i; + } + } + + // a gesture could be recognized + if(recogprob>0 && probmodel>0 && probgesture>0 && sum>0) { + this.lastprob=recogprob; + return recognized; + } else { + // no gesture could be recognized + return -1; + } + + } + + public double getLastProbability() { + return this.lastprob; + } + + public void addGestureModel(GestureModel gm) { + this.gesturemodel.add(gm); + } + + public GestureModel getGestureModel(int id) { + return this.gesturemodel.elementAt(id); + } + + public Vector getGestureModels() { + return this.gesturemodel; + } + + public int getCountOfGestures() { + return this.gesturemodel.size(); + } + + public void clear() { + this.gesturemodel = new Vector(); + } + + +} diff --git a/src/org/wiigee/logic/Gesture.java b/src/org/wiigee/logic/Gesture.java new file mode 100755 index 0000000..2d1976a --- /dev/null +++ b/src/org/wiigee/logic/Gesture.java @@ -0,0 +1,155 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: wiigee@benjaminpoppinga.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.logic; + +import java.util.Vector; +import org.wiigee.event.AccelerationEvent; + +/** + * This class represents ONE movement trajectory in a + * concrete instance. + * + * @author Benjamin 'BePo' Poppinga + */ + +public class Gesture implements Cloneable { + + /** Min/MaxAcceleration setup manually? */ + private boolean minmaxmanual; + private double minacc; + private double maxacc; + + /** The complete trajectory as WiimoteAccelerationEvents + * as a vector. It's a vector because we don't want to + * loose the chronology of the stored events. + */ + private Vector data; + + /** + * Create an empty Gesture. + */ + public Gesture() { + this.data = new Vector(); + } + + /** + * Make a deep copy of another Gesture object. + * + * @param original Another Gesture object + */ + public Gesture(Gesture original) { + this.data = new Vector(); + Vector origin = original.getData(); + for (int i = 0; i < origin.size(); i++) { + this.add((AccelerationEvent) origin.get(i)); + } + } + + + /** + * Adds a new acceleration event to this gesture. + * + * @param event The WiimoteAccelerationEvent to add. + */ + public void add(AccelerationEvent event) { + this.data.add(event); + } + + /** + * Returns the last acceleration added to this gesture. + * + * @return the last acceleration event added. + */ + public AccelerationEvent getLastData() { + return (AccelerationEvent) this.data.get(this.data.size() - 1); + } + + /** + * Returns the whole chronological sequence of accelerations as + * a vector. + * + * @return chronological sequence of accelerations. + */ + public Vector getData() { + return this.data; + } + + /** + * Removes the first element of the acceleration queue of a gesture + */ + public void removeFirstData() { + this.data.remove(0); + } + + public int getCountOfData() { + return this.data.size(); + } + + public void setMaxAndMinAcceleration(double max, double min) { + this.maxacc = max; + this.minacc = min; + this.minmaxmanual = true; + } + + public double getMaxAcceleration() { + if(!this.minmaxmanual) { + double maxacc = Double.MIN_VALUE; + for(int i=0; i maxacc) { + maxacc=Math.abs(this.data.get(i).getX()); + } + if(Math.abs(this.data.get(i).getY()) > maxacc) { + maxacc=Math.abs(this.data.get(i).getY()); + } + if(Math.abs(this.data.get(i).getZ()) > maxacc) { + maxacc=Math.abs(this.data.get(i).getZ()); + } + } + return maxacc; + } else { + return this.maxacc; + } + } + + public double getMinAcceleration() { + if(!this.minmaxmanual) { + double minacc = Double.MAX_VALUE; + for(int i=0; i