summaryrefslogtreecommitdiffstats
path: root/source/AVR_Studio/Soccer/sensor
diff options
context:
space:
mode:
Diffstat (limited to 'source/AVR_Studio/Soccer/sensor')
-rwxr-xr-xsource/AVR_Studio/Soccer/sensor/ballsensor.c28
-rwxr-xr-xsource/AVR_Studio/Soccer/sensor/ballsensor.h4
-rwxr-xr-xsource/AVR_Studio/Soccer/sensor/sensor.h1
3 files changed, 31 insertions, 2 deletions
diff --git a/source/AVR_Studio/Soccer/sensor/ballsensor.c b/source/AVR_Studio/Soccer/sensor/ballsensor.c
index bf97f99..af9434b 100755
--- a/source/AVR_Studio/Soccer/sensor/ballsensor.c
+++ b/source/AVR_Studio/Soccer/sensor/ballsensor.c
@@ -1,11 +1,35 @@
#include "ballsensor.h"
-Ballsensor::Ballsensor() {
+Ballsensor::Ballsensor() {
+ // Umrechnungstabelle position i in Winkel
+ winkel[0] = 0;
+ winkel[1] = 30;
+ winkel[2] = 60;
+ winkel[3] = 100;
+ winkel[4] = 180;
+ winkel[5] = 260;
+ winkel[6] = 300;
+ winkel[7] = 330;
}
Ballsensor::~Ballsensor() {
}
int Ballsensor::getBallwinkel() {
- return 0;
+ // Erstelle ein Array für die Sensorwerte
+ int sensor[NUM_BALLSENSOR];
+ int result = 0; // und einer Variable fürs Ergebnis
+ int current = 1024; // Setze aktuellen Wert auf Maximum
+
+ // Analoge Sensoren abfragen und eintragen
+ for(int i=0;i<NUM_BALLSENSOR;i++) sensor[i] = board.GetADC(i);
+
+ // Suche den kleinsten Wert
+ for(int i=0;i<NUM_BALLSENSOR;i++) {
+ // Wenn der Sensorwert kleiner ist ist der Ball näher dran
+ if(sensor[i] < current) result = i; // Ergebnis ist erstmal index
+ }
+
+ // Gebe den Winkel zum index result zurück
+ return winkel[result];
}
diff --git a/source/AVR_Studio/Soccer/sensor/ballsensor.h b/source/AVR_Studio/Soccer/sensor/ballsensor.h
index 46daf90..5fa7f08 100755
--- a/source/AVR_Studio/Soccer/sensor/ballsensor.h
+++ b/source/AVR_Studio/Soccer/sensor/ballsensor.h
@@ -3,11 +3,15 @@
#include "../hal/board.h"
+// Anzahl der Ballsensoren
+#define NUM_BALLSENSOR 8
+
extern Board board;
class Ballsensor
{
private:
+ int winkel[NUM_BALLSENSOR];
public:
Ballsensor();
~Ballsensor();
diff --git a/source/AVR_Studio/Soccer/sensor/sensor.h b/source/AVR_Studio/Soccer/sensor/sensor.h
index 25d36c2..afbb3a0 100755
--- a/source/AVR_Studio/Soccer/sensor/sensor.h
+++ b/source/AVR_Studio/Soccer/sensor/sensor.h
@@ -3,6 +3,7 @@
#include "../hal/board.h"
#include "ballsensor.h"
+#include "../hal/maussensor.h"
#include "../global.h"
extern Board board;