Code-Work :)
This commit is contained in:
parent
c6ec20e5e7
commit
7393d1d12c
8 changed files with 1247 additions and 1179 deletions
Binary file not shown.
|
@ -11,23 +11,48 @@ Sensor sensor;
|
||||||
int main() {
|
int main() {
|
||||||
//board.ledOn();
|
//board.ledOn();
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
|
||||||
|
uart1_puts("Hallo hier ist das RNMega128Funk-Board");
|
||||||
|
|
||||||
|
|
||||||
int speed = 255;
|
int speed = 255;
|
||||||
/*for(int i=-255;i<=255;i+=30) {
|
board.motor(0, speed);
|
||||||
|
board.motor(1, speed);
|
||||||
|
board.motor(2, speed);
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
navigation.Aktualisieren(180,0,speed);
|
||||||
|
while(true) { sleep(1); }
|
||||||
|
/*board.motor(0,speed);
|
||||||
|
board.motor(2,speed);
|
||||||
|
sleep(2);
|
||||||
|
board.motor(0,speed);
|
||||||
|
board.motor(2,0);
|
||||||
|
board.motor(1,speed);
|
||||||
|
sleep(2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for(int i=-255;i<=255;i+=10) {
|
||||||
board.motor(0,i);
|
board.motor(0,i);
|
||||||
board.motor(1,i);
|
board.motor(1,i);
|
||||||
board.motor(2,i);
|
board.motor(2,i);
|
||||||
board.motor(3,i);
|
board.motor(3,i);
|
||||||
sleep(1);
|
msleep(500);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
board.motor(0, speed);
|
board.motor(0, speed);
|
||||||
board.motor(1, speed);
|
board.motor(1, speed);
|
||||||
board.motor(2, speed);
|
board.motor(2, speed);
|
||||||
board.motor(3, speed);
|
board.motor(3, speed);
|
||||||
PORTB |= (1 << PB5) | (1 << PB6); // Setze PWM-Ports auf high
|
while(true) { sleep(1); }*/
|
||||||
PORTE |= (1 << PE3); // | (1 << PE4);
|
/*
|
||||||
PORTA |= (1 << PA4); // | (1 << PA5);
|
//PORTB |= (1 << PB5) | (1 << PB6); // Setze PWM-Ports auf high
|
||||||
|
//PORTE |= (1 << PE3); // | (1 << PE4);
|
||||||
|
//PORTA |= (1 << PA5); // | (1 << PA5);
|
||||||
//sleep(10);
|
//sleep(10);
|
||||||
while(true) { sleep(1); }
|
*/
|
||||||
/*sleep(10);
|
/*sleep(10);
|
||||||
board.motor(0, 0);
|
board.motor(0, 0);
|
||||||
board.motor(1, 0);
|
board.motor(1, 0);
|
||||||
|
@ -56,15 +81,14 @@ int main() {
|
||||||
//board.ledOff();*/
|
//board.ledOff();*/
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
navigation.Aktualisieren(0,0,speed);
|
navigation.Aktualisieren(0,0,speed);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
navigation.Aktualisieren(90,0,speed);
|
navigation.Aktualisieren(90,0,speed);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
navigation.Aktualisieren(180,0,speed);
|
navigation.Aktualisieren(180,0,speed);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
navigation.Aktualisieren(270,0,speed);
|
navigation.Aktualisieren(270,0,speed);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
|
@ -31,13 +31,13 @@ Board::Board() {
|
||||||
DDRG = (1 << PG0) | (1 << PG1) | (1 << PG2) | (1 << PG3) | (1 << PG4);
|
DDRG = (1 << PG0) | (1 << PG1) | (1 << PG2) | (1 << PG3) | (1 << PG4);
|
||||||
PORTG = (1 << PG0) | (1 << PG1);
|
PORTG = (1 << PG0) | (1 << PG1);
|
||||||
|
|
||||||
// aktiviere Kanal A+C auf PWM1 mit 8Bit
|
// aktiviere Kanal A+B auf PWM1 mit 8Bit
|
||||||
//TCCR1A = (1<< COM1A1) | (1<< COM1C1) | (1<< WGM10);
|
TCCR1A = (1<< COM1A1) | (1<< COM1B1) | (1<< WGM10);
|
||||||
//TCCR1B = (1<<ICNC1) | (1<<CS12) | (1<<CS10); // set clock/prescaler 1/1024 -> enable counter
|
TCCR1B = (1<<ICNC1) | (1<<CS12) | (1<<CS10); // set clock/prescaler 1/1024 -> enable counter
|
||||||
|
|
||||||
// aktiviere Kanal A+B auf PWM3 mit 8Bit
|
// aktiviere Kanal A+B auf PWM3 mit 8Bit
|
||||||
//TCCR3A = (1<< COM3A1) | (1<< COM3B1) | (1<< WGM10);
|
TCCR3A = (1<< COM3A1) | (1<< COM3B1) | (1<< WGM10);
|
||||||
//TCCR3B = (1<<ICNC3) | (1<<CS32) | (1<<CS30); // set clock/prescaler 1/1024 -> enable counter
|
TCCR3B = (1<<ICNC3) | (1<<CS32) | (1<<CS30); // set clock/prescaler 1/1024 -> enable counter
|
||||||
|
|
||||||
// Schalte Motoren auf 0
|
// Schalte Motoren auf 0
|
||||||
motor(0,0);
|
motor(0,0);
|
||||||
|
@ -45,6 +45,10 @@ Board::Board() {
|
||||||
motor(2,0);
|
motor(2,0);
|
||||||
motor(3,0);
|
motor(3,0);
|
||||||
|
|
||||||
|
// Kicker-richtung einstellen
|
||||||
|
PORTE &= ~(1 << PE6); // Pin2 low
|
||||||
|
PORTA |= (1 << PA2); // Pin1 high
|
||||||
|
|
||||||
// Uart-Interface einschalten
|
// Uart-Interface einschalten
|
||||||
uart1_init( 10); // 9600 BAUD bei 16MHz Atmel
|
uart1_init( 10); // 9600 BAUD bei 16MHz Atmel
|
||||||
|
|
||||||
|
@ -198,27 +202,35 @@ void Board::motor(int i, int speed)
|
||||||
MOTOR2_PORT |= MOTOR2_A;//In 1 ein
|
MOTOR2_PORT |= MOTOR2_A;//In 1 ein
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(i == 3)
|
else if(i == 3) // Dribbler... hier haben wir kein PWM
|
||||||
{
|
{
|
||||||
DRIBBLER_PWM = pwm;
|
|
||||||
if(speed > 0)
|
if(speed > 0)
|
||||||
{
|
{
|
||||||
DRIBBLER_PORT |= DRIBBLER_A;//In 1 ein
|
DRIBBLER_PORT |= DRIBBLER_A;//In 1 ein
|
||||||
DRIBBLER_PORT &= ~DRIBBLER_B;//In 2 aus
|
DRIBBLER_PORT &= ~DRIBBLER_B;//In 2 aus
|
||||||
|
DRIBBLER_PWMPORT |= DRIBBLER_PWM;
|
||||||
}
|
}
|
||||||
else if(speed < 0)
|
else if(speed < 0)
|
||||||
{
|
{
|
||||||
DRIBBLER_PORT |= DRIBBLER_B;//In 2 ein
|
DRIBBLER_PORT |= DRIBBLER_B;//In 2 ein
|
||||||
DRIBBLER_PORT &= ~DRIBBLER_A;//In 1 aus
|
DRIBBLER_PORT &= ~DRIBBLER_A;//In 1 aus
|
||||||
|
DRIBBLER_PWMPORT |= DRIBBLER_PWM;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DRIBBLER_PORT |= DRIBBLER_B;//In 2 ein
|
DRIBBLER_PORT |= DRIBBLER_B;//In 2 ein
|
||||||
DRIBBLER_PORT |= DRIBBLER_A;//In 1 ein
|
DRIBBLER_PORT |= DRIBBLER_A;//In 1 ein
|
||||||
|
DRIBBLER_PWMPORT &= ~DRIBBLER_PWM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Board::kicker() {
|
||||||
|
KICKER_AN
|
||||||
|
usleep(KICKER_USLEEP);
|
||||||
|
KICKER_AUS
|
||||||
|
}
|
||||||
|
|
||||||
//PWM routine für den Beeper
|
//PWM routine für den Beeper
|
||||||
ISR (TIMER0_OVF_vect)
|
ISR (TIMER0_OVF_vect)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,26 +11,33 @@
|
||||||
|
|
||||||
#define BEEPER_PIN PG2
|
#define BEEPER_PIN PG2
|
||||||
|
|
||||||
// Definiere Konstanten für die Motoren/Dribbler
|
// Definiere Konstanten für die Motoren/Dribbler
|
||||||
#define MOTOR0_PORT PORTD
|
#define MOTOR0_PORT PORTB
|
||||||
#define MOTOR0_PWM OCR3A
|
#define MOTOR0_PWM OCR1A
|
||||||
#define MOTOR0_A (1 << 5)
|
#define MOTOR0_A (1 << 0)
|
||||||
#define MOTOR0_B (1 << 4)
|
#define MOTOR0_B (1 << 1)
|
||||||
|
|
||||||
#define MOTOR1_PORT PORTD
|
#define MOTOR1_PORT PORTB
|
||||||
#define MOTOR1_PWM OCR3B
|
#define MOTOR1_PWM OCR1B
|
||||||
#define MOTOR1_A (1 << 6)
|
#define MOTOR1_A (1 << 2)
|
||||||
#define MOTOR1_B (1 << 7)
|
#define MOTOR1_B (1 << 3)
|
||||||
|
|
||||||
#define MOTOR2_PORT PORTB
|
#define MOTOR2_PORT PORTD
|
||||||
#define MOTOR2_PWM OCR1A
|
#define MOTOR2_PWM OCR3A
|
||||||
#define MOTOR2_A (1 << 0)
|
#define MOTOR2_A (1 << 5)
|
||||||
#define MOTOR2_B (1 << 1)
|
#define MOTOR2_B (1 << 4)
|
||||||
|
|
||||||
#define DRIBBLER_PORT PORTB
|
#define DRIBBLER_PORT PORTD
|
||||||
#define DRIBBLER_PWM OCR1C
|
#define DRIBBLER_PWMPORT PORTA
|
||||||
#define DRIBBLER_A (1 << 2)
|
#define DRIBBLER_PWM (1 << 5)
|
||||||
#define DRIBBLER_B (1 << 3)
|
#define DRIBBLER_A (1 << 6)
|
||||||
|
#define DRIBBLER_B (1 << 7)
|
||||||
|
|
||||||
|
// Kicker
|
||||||
|
#define KICKER_AN PORTG |= (1 << PG3);
|
||||||
|
#define KICKER_AUS PORTG &= ~(1 << PG3);
|
||||||
|
#define KICKER_USLEEP 10
|
||||||
|
|
||||||
|
|
||||||
// Definiere Konstanten für Abstandsensoren
|
// Definiere Konstanten für Abstandsensoren
|
||||||
#define ABSTAND_PORT PORTC
|
#define ABSTAND_PORT PORTC
|
||||||
|
@ -54,6 +61,7 @@ public:
|
||||||
void ledOff();
|
void ledOff();
|
||||||
void led(bool status);
|
void led(bool status);
|
||||||
void motor(int i, int speed);
|
void motor(int i, int speed);
|
||||||
|
void kicker();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,21 +28,21 @@ void Navigation::SetzeGeschwindigkeit(int nGeschwindigkeit) {
|
||||||
// Aktualieren ohne Parameter
|
// Aktualieren ohne Parameter
|
||||||
void Navigation::Aktualisieren() {
|
void Navigation::Aktualisieren() {
|
||||||
// Richtung in x und y-Kompontente zerlegen
|
// Richtung in x und y-Kompontente zerlegen
|
||||||
float y = cos(richtung); // richtung ist winkel
|
double y = cos(richtung); // richtung ist winkel
|
||||||
float x = sin(richtung);
|
double x = sin(richtung);
|
||||||
|
|
||||||
// Abweichung der Ausrichtung ermitteln(als winkel)
|
// Abweichung der Ausrichtung ermitteln(als winkel)
|
||||||
int w = sensor.GetAusrichtung() - ausrichtung;
|
int w = sensor.GetAusrichtung() - ausrichtung;
|
||||||
|
|
||||||
// Stärke der einzelnen Motoren berechnen
|
// Stärke der einzelnen Motoren berechnen
|
||||||
float v0 = x;
|
double v0 = (-x-sqrt(3)*y)/2;
|
||||||
float v1 = (-x+sqrt(3)*y)/2;
|
double v1 = x;
|
||||||
float v2 = (-x-sqrt(3)*y)/2;
|
double v2 = (-x+sqrt(3)*y)/2;
|
||||||
|
|
||||||
// Ausgerechnete Stärke an die Motoren übergeben
|
// Ausgerechnete Stärke an die Motoren übergeben
|
||||||
board.motor(0,(int)v0*geschwindigkeit +w);
|
board.motor(0,(int)((double)v0*geschwindigkeit +w));
|
||||||
board.motor(1,(int)v1*geschwindigkeit +w);
|
board.motor(1,(int)((double)v1*geschwindigkeit +w));
|
||||||
board.motor(2,(int)v2*geschwindigkeit +w);
|
board.motor(2,(int)((double)v2*geschwindigkeit +w));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktualieren mit allen Parametern
|
// Aktualieren mit allen Parametern
|
||||||
|
|
|
@ -34,7 +34,10 @@ void Ballsensor::Aktualisieren() {
|
||||||
// Suche den kleinsten Wert
|
// Suche den kleinsten Wert
|
||||||
for(int i=0;i<NUM_BALLSENSOR;i++) {
|
for(int i=0;i<NUM_BALLSENSOR;i++) {
|
||||||
// Wenn der Sensorwert kleiner ist ist der Ball näher dran
|
// Wenn der Sensorwert kleiner ist ist der Ball näher dran
|
||||||
if(sensor[i] < current) result = i; // Ergebnis ist erstmal index
|
if(sensor[i] < current) {
|
||||||
|
result = i; // Ergebnis ist erstmal index
|
||||||
|
current = sensor[i]; // Setze neuen Vergleichswert
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setze den Winkel zum index result
|
// Setze den Winkel zum index result
|
||||||
|
|
Reference in a new issue