Hallo
Ich war mal so frei und habe den Code nach meinen Gewohnheiten formatiert:
Code:void infrarotkollission(void) { DDRC &=~ (1<<PC3); // PC3 als Eingang infrarotempfänger if(ir_erweiterung == 0) { if (!(PINC & (1<<PC3))) { writeString_P("Infrarotempfang ein\n"); writeStringLCD("ir_counter=:"); writeString("ir_counter=:"); writeInteger(ir_counter,DEC); writeIntegerLCD(ir_counter, DEC); writeChar('\n'); ir_ende = false; ir_counter++; // infrarot empfangen } } if (ir_counter == 50) { ir_hindernis = true; ir_erweiterung = 1; } if (ir_ende) { ir_counter = 0; ir_erweiterung = 0; ir_hindernis = false; } }(Weder kompiliert noch überprüft oder getestet)Code:// IR-Radar von proevofreak 26.2.2010 // von radbruch formatierter Code #include "RP6ControlLib.h" #include "RP6ControlServoLib.h" #include "RP6I2CmasterTWI.h" #include "RP6Control_I2CMasterLib.h" // Servo 1 => PC2 // Servo 2 => PC3 // Servo 3 => PC4 // Servo 4 => PC5 // Servo 5 => PC6 uint8_t move_state = 0; // Wenn nichts anderes zugewiesen ist, ist move_state =0 void RP6_Bewegung(void) { if (ir_hindernis) { if (!(ir_ende)) { stopStopwatch3(); // stopwatch3 anhalten wenn ir erkannt wird und damit servobewegung anhalten writeString_P("ir ende gleich false\n"); } switch(move_state) { case 0: if (getStopwatch3() <1000 || getStopwatch3() >6000) { rotate(50,RIGHT,90,NON_BLOCKING); // um 90 grad rotieren move_state= 1; // move_state den wert 1 zuweisen } break; case 1: if(isMovementComplete()) { ir_ende= true; // ir_ende=true, wenn bewegung abgeschlossen startStopwatch3(); // stopwatch3 starten => servo wieder drehen writeString_P("ir ende gleich true\n"); } break; } } } void servoansteuerung(void) { if (getStopwatch3() <1000) { servo3_position = 0; writeString_P("LEFT Touch\n"); } if (getStopwatch3() >1000 && getStopwatch3() <2000) { servo3_position = 20; writeString_P("servo position 40\n"); } if (getStopwatch3() >2000 && getStopwatch3() <3000) { servo3_position = 90; } if (getStopwatch3() >3000 && getStopwatch3() <4000) { servo3_position = RIGHT_TOUCH; writeString_P("Servo Right touch\n"); } if (getStopwatch3() >4000 && getStopwatch3() <5000) { servo3_position = 90; } if (getStopwatch3() >5000 && getStopwatch3() <6000) { servo3_position = 20; } if (getStopwatch3() >6000 && getStopwatch3() <7000) { servo3_position = 0; writeString_P("LEFT Touch\n"); } if (getStopwatch3() >7000) { setStopwatch3(0); writeString_P("stopwatch3 auf 0 zurück\n"); } } int main(void) { initRP6Control(); I2CTWI_initMaster(100); initSERVO(SERVO3); startStopwatch3(); while(true) { servoansteuerung(); task_SERVO(); infrarotkollission(); RP6_Bewegung(); } return 0; }
Gruß
mic







Zitieren

Lesezeichen