Code-Work :)

This commit is contained in:
sicarius 2007-02-15 20:15:02 +00:00
parent 7393d1d12c
commit 8d7053ca84
4 changed files with 130 additions and 0 deletions

View file

@ -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];
}

View file

@ -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

View file

@ -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;
}

View file

@ -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