Changed every System.out.print[ln] to Log.write, thus logging can be changed depending on the used platform.

git-svn-id: svn://svn.code.sf.net/p/wiigee/code/trunk@73 c7eff9ee-dd40-0410-8832-91a4d88773cf
This commit is contained in:
bepo23
2009-05-29 06:24:45 +00:00
parent 3a31bcafdc
commit 3b30923460
10 changed files with 74 additions and 65 deletions

View File

@@ -33,6 +33,7 @@ import filter.DirectionalEquivalenceFilter;
import filter.Filter;
import filter.IdleStateFilter;
import filter.MotionDetectFilter;
import util.Log;
public class Device {
@@ -52,7 +53,7 @@ public class Device {
// Listeners, receive generated events
protected Vector<DeviceListener> devicelistener = new Vector<DeviceListener>();
protected ProcessingUnit processingunit = new TriggeredProcessingUnit();
protected ProcessingUnit processingunit = new ContinuousProcessingUnit();//new TriggeredProcessingUnit();
public Device() {
this.addFilter(new IdleStateFilter());
@@ -67,7 +68,7 @@ public class Device {
*/
public void addFilter(Filter filter) {
this.filters.add(filter);
System.out.println("Filter added...");
Log.write("Filter added...");
}
/**
@@ -88,7 +89,7 @@ public class Device {
*/
public void addDeviceListener(DeviceListener listener) {
this.devicelistener.add(listener);
System.out.println("WiimoteListener added...");
Log.write("WiimoteListener added...");
}
/**
@@ -98,7 +99,7 @@ public class Device {
*/
public void addGestureListener(GestureListener listener) {
this.processingunit.addGestureListener(listener);
System.out.println("GestureListener added...");
Log.write("GestureListener added...");
}
public int getRecognitionButton() {

View File

@@ -29,6 +29,7 @@ import java.util.Random;
import javax.bluetooth.L2CAPConnection;
import javax.microedition.io.Connector;
import event.*;
import util.Log;
/**
* @author Benjamin 'BePo' Poppinga
@@ -70,7 +71,7 @@ public class Wiimote extends Device {
// LED encoded as byte
byte ledencoding;
// control connection, send commands to wiimote
private L2CAPConnection controlCon;
@@ -125,9 +126,9 @@ public class Wiimote extends Device {
try {
this.controlCon.close();
this.receiveCon.close();
System.out.println("Disconnected wiimote.");
Log.write("Disconnected wiimote.");
} catch(Exception e) {
System.out.println("Failure during disconnect of wiimote.");
Log.write("Failure during disconnect of wiimote.");
}
}

View File

@@ -31,6 +31,7 @@ import javax.bluetooth.L2CAPConnection;
import event.ButtonPressedEvent;
import event.ButtonReleasedEvent;
import util.Log;
/**
* This class listens to data sended by the wiimote and generates specific
@@ -86,7 +87,7 @@ public class WiimoteStreamer extends Thread {
this.x1 = b[11] & 0xFF;
this.y1 = b[12] & 0xFF;
this.z1 = b[13] & 0xFF;
System.out.println("Autocalibration successful!");
Log.write("Autocalibration successful!");
continue;
}
@@ -258,7 +259,7 @@ public class WiimoteStreamer extends Thread {
} // while(running)
} catch (IOException e) {
System.out.println("Streamer: Connection to Wiimote lost.");
Log.write("Streamer: Connection to Wiimote lost.");
this.running = false;
}
}

View File

@@ -44,7 +44,7 @@ public class Classifier {
* @param g gesture to classify
*/
public int classifyGesture(Gesture g) {
//System.out.println("Recognizing gesture...");
//Log.write("Recognizing gesture...");
// Wert im Nenner berechnen, nach Bayes
double sum = 0;

View File

@@ -26,6 +26,7 @@ package logic;
import java.util.Vector;
import event.AccelerationEvent;
import util.Log;
/**
* This Class units a Quantizer-Component and an Model-Component.
@@ -129,7 +130,7 @@ public class GestureModel {
* For debug purposes or very technical interested people. :)
*/
public void printMap() {
System.out.println("Gesture Quantizer-Map:");
Log.write("Gesture Quantizer-Map:");
this.quantizer.printMap();
}
@@ -138,9 +139,9 @@ public class GestureModel {
* @return
*/
public void print() {
System.out.println("HMM-Print:");
Log.write("HMM-Print:");
this.markovmodell.print();
System.out.println("Quanzizer-Print:");
Log.write("Quanzizer-Print:");
this.quantizer.printMap();
}
@@ -182,7 +183,7 @@ public class GestureModel {
public void setDefaultProbability(double prob) {
this.defaultprobability = prob;
System.out.println("def-prob. set to = "+this.defaultprobability);
Log.write("def-prob. set to = "+this.defaultprobability);
}
public Quantizer getQuantizer() {

View File

@@ -23,8 +23,9 @@
*/
package logic;
import java.text.*;
import java.text.DecimalFormat;
import java.util.Vector;
import util.Log;
/**
* This is a Hidden Markov Model implementation which internally provides
@@ -272,20 +273,20 @@ public class HMM {
fmt.setMinimumFractionDigits(5);
fmt.setMaximumFractionDigits(5);
for (int i = 0; i < numStates; i++)
System.out.println("pi(" + i + ") = " + fmt.format(pi[i]));
System.out.println();
Log.write("pi(" + i + ") = " + fmt.format(pi[i]));
Log.write("");
for (int i = 0; i < numStates; i++) {
for (int j = 0; j < numStates; j++)
System.out.print("a(" + i + "," + j + ") = "
Log.write("a(" + i + "," + j + ") = "
+ fmt.format(a[i][j]) + " ");
System.out.println();
Log.write("");
}
System.out.println();
Log.write("");
for (int i = 0; i < numStates; i++) {
for (int k = 0; k < numObservations; k++)
System.out.print("b(" + i + "," + k + ") = "
Log.write("b(" + i + "," + k + ") = "
+ fmt.format(b[i][k]) + " ");
System.out.println();
Log.write("");
}
}

View File

@@ -26,6 +26,7 @@ package logic;
import java.text.*;
import java.util.Vector;
import java.lang.Math;
import util.Log;
/**
* This is a Hidden Markov Model implementation which internally provides
@@ -345,10 +346,10 @@ public class PreciseHMM {
}
}
//System.out.println("log p = "+lp);
//Log.write("log p = "+lp);
//return lp;
// we now have log10(p) calculated, transform to p.
System.out.println("prob = "+Math.exp(lp));
Log.write("prob = "+Math.exp(lp));
return Math.exp(lp);
//return Math.pow(10, lp);
}
@@ -413,20 +414,20 @@ public class PreciseHMM {
fmt.setMinimumFractionDigits(10);
fmt.setMaximumFractionDigits(10);
for (int i = 0; i < numStates; i++)
System.out.println("pi(" + i + ") = " + fmt.format(pi[i]));
System.out.println();
Log.write("pi(" + i + ") = " + fmt.format(pi[i]));
Log.write("");
for (int i = 0; i < numStates; i++) {
for (int j = 0; j < numStates; j++)
System.out.print("a(" + i + "," + j + ") = "
Log.write("a(" + i + "," + j + ") = "
+ fmt.format(a[i][j]) + " ");
System.out.println();
Log.write("");
}
System.out.println();
Log.write("");
for (int i = 0; i < numStates; i++) {
for (int k = 0; k < sigmaSize; k++)
System.out.print("b(" + i + "," + k + ") = "
Log.write("b(" + i + "," + k + ") = "
+ fmt.format(b[i][k]) + " ");
System.out.println();
Log.write("");
}
}

View File

@@ -12,6 +12,7 @@ import event.InfraredEvent;
import event.MotionStartEvent;
import event.MotionStopEvent;
import event.StateEvent;
import util.Log;
public abstract class ProcessingUnit implements DeviceListener {
@@ -69,9 +70,9 @@ public abstract class ProcessingUnit implements DeviceListener {
public void reset() {
if(this.classifier.getCountOfGestures()>0) {
this.classifier.clear();
System.out.println("### Model reset ###");
Log.write("### Model reset ###");
} else {
System.out.println("There doesn't exist any data to reset.");
Log.write("There doesn't exist any data to reset.");
}
}

View File

@@ -26,6 +26,7 @@ package logic;
import java.util.Vector;
import event.AccelerationEvent;
import util.Log;
/**
* This class implements a quantization component. In this case a
@@ -77,7 +78,7 @@ public class Quantizer {
double pi = Math.PI;
this.radius = (gesture.getMaxAcceleration() + gesture
.getMinAcceleration()) / 2;
System.out.println("Using radius: " + this.radius);
Log.write("Using radius: " + this.radius);
// x , z , y
if (!this.maptrained) {
@@ -135,11 +136,11 @@ public class Quantizer {
if (nenner > 1) { // nur wenn der nenner>0 oder >1??? ist muss
// was
// geaendert werden
// System.out.println("Setze neuen Centeroid!");
// Log.write("Setze neuen Centeroid!");
this.map[i] = new double[] {(zaehlerX / (double) nenner),
(zaehlerY / (double) nenner),
(zaehlerZ / (double) nenner) };
// System.out.println("Centeroid: "+i+": "+newcenteroid[0]+":"+newcenteroid[1]);
// Log.write("Centeroid: "+i+": "+newcenteroid[0]+":"+newcenteroid[1]);
}
} // new centeroids
@@ -148,7 +149,7 @@ public class Quantizer {
// Debug: Printout groups
/*
* for (int i = 0; i < n; i++) { for (int j = 0; j < this.data.size();
* j++) { System.out.print(g[i][j] + "|"); } System.out.println(""); }
* j++) { Log.write(g[i][j] + "|"); } Log.write(""); }
*/
}
@@ -181,9 +182,9 @@ public class Quantizer {
vector[2] = ref[2] - curr[2];
d[i][j] = Math.sqrt((vector[0] * vector[0])
+ (vector[1] * vector[1]) + (vector[2] * vector[2]));
// System.out.print(d[i][j] + "|");
// Log.write(d[i][j] + "|");
}
// System.out.println("");
// Log.write("");
}
// look, to which group a value belongs
@@ -203,8 +204,8 @@ public class Quantizer {
// Debug output
/*
* for (int i = 0; i < groups.length; i++) { // zeilen for (int j = 0; j
* < groups[i].length; j++) { System.out.print(groups[i][j] + "|"); }
* System.out.println(""); }
* < groups[i].length; j++) { Log.write(groups[i][j] + "|"); }
* Log.write(""); }
*/
return groups;
@@ -222,12 +223,12 @@ public class Quantizer {
int[][] groups = this.deriveGroups(gesture);
Vector<Integer> sequence = new Vector<Integer>();
// System.out.print("Visible symbol sequence: ");
// Log.write("Visible symbol sequence: ");
for (int j = 0; j < groups[0].length; j++) { // spalten
for (int i = 0; i < groups.length; i++) { // zeilen
if (groups[i][j] == 1) {
// System.out.print(" "+ i);
// Log.write(" "+ i);
sequence.add(i);
break;
}
@@ -241,10 +242,10 @@ public class Quantizer {
// better resolution than copying the old value a few time.
while (sequence.size() < this.numStates) {
sequence.add(sequence.elementAt(sequence.size() - 1));
// System.out.print(" "+sequence.elementAt(sequence.size()-1));
// Log.write(" "+sequence.elementAt(sequence.size()-1));
}
// System.out.println("");
// Log.write("");
int[] out = new int[sequence.size()];
for (int i = 0; i < sequence.size(); i++) {
@@ -259,9 +260,9 @@ public class Quantizer {
* interests.
*/
public void printMap() {
System.out.println("Centeroids:");
Log.write("Centeroids:");
for (int i = 0; i < this.map.length; i++) {
System.out.println(i + ". :" + this.map[i][0] + ":"
Log.write(i + ". :" + this.map[i][0] + ":"
+ this.map[i][1] + ":" + this.map[i][2]);
}
}

View File

@@ -26,6 +26,7 @@ package logic;
import java.util.Vector;
import event.*;
import util.Log;
/**
* This class analyzes the WiimoteAccelerationEvents emitted from a Wiimote
@@ -99,7 +100,7 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
// TrainButton = record a gesture for learning
if((!this.analyzing && !this.learning) &&
event.isTrainInitEvent()) {
System.out.println("Training started!");
Log.write("Training started!");
this.learning=true;
this.fireStateEvent(1);
}
@@ -107,7 +108,7 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
// RecognitionButton = record a gesture for recognition
if((!this.analyzing && !this.learning) &&
event.isRecognitionInitEvent()) {
System.out.println("Recognition started!");
Log.write("Recognition started!");
this.analyzing=true;
this.fireStateEvent(2);
}
@@ -118,7 +119,7 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
event.isCloseGestureInitEvent()) {
if(this.trainsequence.size()>0) {
System.out.println("Training the model with "+this.trainsequence.size()+" gestures...");
Log.write("Training the model with "+this.trainsequence.size()+" gestures...");
this.fireStateEvent(1);
this.learning=true;
@@ -130,7 +131,7 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
this.trainsequence=new Vector<Gesture>();
this.learning=false;
} else {
System.out.println("There is nothing to do. Please record some gestures first.");
Log.write("There is nothing to do. Please record some gestures first.");
}
}
}
@@ -138,44 +139,44 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
public void handleStopEvent(ActionStopEvent event) {
if(this.learning) { // button release and state=learning, stops learning
if(this.current.getCountOfData()>0) {
System.out.println("Finished recording (training)...");
System.out.println("Data: "+this.current.getCountOfData());
Log.write("Finished recording (training)...");
Log.write("Data: "+this.current.getCountOfData());
Gesture gesture = new Gesture(this.current);
this.trainsequence.add(gesture);
this.current=new Gesture();
this.learning=false;
} else {
System.out.println("There is no data.");
System.out.println("Please train the gesture again.");
Log.write("There is no data.");
Log.write("Please train the gesture again.");
this.learning=false; // ?
}
}
else if(this.analyzing) { // button release and state=analyzing, stops analyzing
if(this.current.getCountOfData()>0) {
System.out.println("Finished recording (recognition)...");
System.out.println("Compare gesture with "+this.classifier.getCountOfGestures()+" other gestures.");
Log.write("Finished recording (recognition)...");
Log.write("Compare gesture with "+this.classifier.getCountOfGestures()+" other gestures.");
Gesture gesture = new Gesture(this.current);
int recognized = this.classifier.classifyGesture(gesture);
if(recognized!=-1) {
double recogprob = this.classifier.getLastProbability();
this.fireGestureEvent(recognized, recogprob);
System.out.println("######");
System.out.println("Gesture No. "+recognized+" recognized: "+recogprob);
System.out.println("######");
Log.write("######");
Log.write("Gesture No. "+recognized+" recognized: "+recogprob);
Log.write("######");
} else {
this.fireStateEvent(0);
System.out.println("######");
System.out.println("No gesture recognized.");
System.out.println("######");
Log.write("######");
Log.write("No gesture recognized.");
Log.write("######");
}
this.current=new Gesture();
this.analyzing=false;
} else {
System.out.println("There is no data.");
System.out.println("Please recognize the gesture again.");
Log.write("There is no data.");
Log.write("Please recognize the gesture again.");
this.analyzing=false; // ?
}
}