summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsource/AVR_Studio/Soccer/sensor/abstand.c24
-rwxr-xr-xsource/AVR_Studio/Soccer/sensor/abstand.h26
-rwxr-xr-xsource/AVR_Studio/Soccer/sensor/position.c46
-rwxr-xr-xsource/AVR_Studio/Soccer/sensor/position.h34
4 files changed, 130 insertions, 0 deletions
diff --git a/source/AVR_Studio/Soccer/sensor/abstand.c b/source/AVR_Studio/Soccer/sensor/abstand.c
new file mode 100755
index 0000000..5acdcaf
--- /dev/null
+++ b/source/AVR_Studio/Soccer/sensor/abstand.c
@@ -0,0 +1,24 @@
+#include "abstand.h"
+
+Abstand::Abstand() {
+ abstand[0] = ABSTAND_FEHLER;
+ abstand[1] = ABSTAND_FEHLER;
+ abstand[2] = ABSTAND_FEHLER;
+ abstand[3] = ABSTAND_FEHLER;
+}
+
+Abstand::~Abstand() {
+}
+
+void Abstand::Aktualisieren() {
+ // Gehe alle 4 Sensoren durch
+ for(int i=0;i<4;i++) {
+ abstand[i] = board.GetAbstand(i); // Und übernehme die Werte direkt vom Sensor
+ }
+}
+
+int Abstand::GetAbstand(int i) {
+ if((i < 0) || (i > 3)) return ABSTAND_FEHLER; //angebote rausfiltern ;)
+
+ return abstand[i];
+}
diff --git a/source/AVR_Studio/Soccer/sensor/abstand.h b/source/AVR_Studio/Soccer/sensor/abstand.h
new file mode 100755
index 0000000..b22c2f2
--- /dev/null
+++ b/source/AVR_Studio/Soccer/sensor/abstand.h
@@ -0,0 +1,26 @@
+#ifndef _ABSTAND_H_
+#define _ABSTAND_H_
+
+#include "../hal/board.h"
+
+extern Board board;
+
+#define ABSTAND0 0
+#define ABSTAND1 1
+#define ABSTAND2 2
+#define ABSTAND3 3
+
+#define ABSTAND_FEHLER -1
+
+class Abstand {
+private:
+ int abstand[4];
+public:
+ Abstand();
+ ~Abstand();
+
+ void Aktualisieren();
+ int GetAbstand(int i);
+};
+
+#endif
diff --git a/source/AVR_Studio/Soccer/sensor/position.c b/source/AVR_Studio/Soccer/sensor/position.c
new file mode 100755
index 0000000..cc7a345
--- /dev/null
+++ b/source/AVR_Studio/Soccer/sensor/position.c
@@ -0,0 +1,46 @@
+#include "position.h"
+#include "../global.h"
+
+Position::Position() {
+ // inititalisiere die Maussensoren
+ maussensor0.init(MAUSSENSOR0);
+ maussensor1.init(MAUSSENSOR1);
+
+ // Wir starten in der Mitte, nach vorne gerichtet
+ x = 0;
+ y = 0;
+ ausrichtung = 0;
+}
+
+Position::~Position() {
+}
+
+// Aktualisiert die internen Variablen x,y und ausrichtung
+void Position::Aktualisieren() {
+ // Lese die Maussensoren ein
+ uint8 maus0_x = maussensor0.GetX();
+ uint8 maus0_y = maussensor0.GetY();
+ uint8 maus1_x = maussensor1.GetX();
+ uint8 maus1_y = maussensor1.GetY();
+
+ // Und berechne die neuen Werte
+ // ACHTUNG!!!!! Die Funktionen sind noch ungetestet und werden fehler enthalten
+ x += (maus0_x*sin(ausrichtung+45)+maus1_x*cos(ausrichtung+45))/2;
+ y += (maus0_y*sin(ausrichtung+45)+maus1_y*cos(ausrichtung+45))/2;
+ ausrichtung += ((maus0_y + maus1_y)/2)*(360/MAUS_FULL_TURN);
+}
+
+// Gibt die X-Koordinate zurück
+int Position::GetX() {
+ return (int)x;
+}
+
+// Gibt die Y-Koordinate zurück
+int Position::GetY() {
+ return (int)y;
+}
+
+// Gibt die Ausrichtung zurück
+int Position::GetAusrichtung() {
+ return ausrichtung;
+}
diff --git a/source/AVR_Studio/Soccer/sensor/position.h b/source/AVR_Studio/Soccer/sensor/position.h
new file mode 100755
index 0000000..4246524
--- /dev/null
+++ b/source/AVR_Studio/Soccer/sensor/position.h
@@ -0,0 +1,34 @@
+#ifndef _POSITION_H_
+#define _POSITION_H_
+
+#include "../hal/maussensor.h"
+#include <math.h>
+
+// Anzahl der Ticks, die für eine ganze Umdrehung notwendig sind
+#define MAUS_FULL_TURN 160000
+
+class Position {
+private:
+ // Maussensorenklassen
+ Maussensor maussensor0;
+ Maussensor maussensor1;
+
+ // X und Y-Koordinate
+ float x;
+ float y;
+ // Und die Ausrichtung als Winkel
+ int ausrichtung;
+public:
+ Position();
+ ~Position();
+
+ // Aktualisiert die Position
+ void Aktualisieren();
+
+ // Gebe die internen Werte zurück
+ int GetX();
+ int GetY();
+ int GetAusrichtung();
+};
+
+#endif