summaryrefslogtreecommitdiffstats
path: root/source/AVR_Studio/Soccer/sensor/ballsensor.c
blob: 81365814e0b40529f872510d1d17e5f938e7f179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "ballsensor.h"

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;
	
	// Der Winkel ist erstmal 0
	ballwinkel = 0;
}

Ballsensor::~Ballsensor() {
}

int Ballsensor::GetBallwinkel() {
	return ballwinkel;
}

void Ballsensor::Aktualisieren() {
	// 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
	}

	// Setze den Winkel zum index result
	ballwinkel = winkel[result];
}