This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
rc2007-soccer/source/AVR_Studio/Soccer/sensor/ballsensor.c
2007-02-15 19:03:00 +00:00

45 lines
1.1 KiB
C
Executable file

#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
current = sensor[i]; // Setze neuen Vergleichswert
}
}
// Setze den Winkel zum index result
ballwinkel = winkel[result];
}