Guten Morgen Community
Geht um folgendes:
Ich programmiere derzeit für ein Schulprojekt eine Drohne.
Die Drohne soll auf einer bestimmten Höhe schweben und sich selbst ausbalancieren.
Ich habe aktuell ein Problem mit den Cases.
Ich kann von Case 0 nicht ins nächste Case Springen.
Wäre mega cool, wenn Ihr mir dabei Helfen könntet ich verzweifle langsam ^^.
volatile unsigned long alteZeit=0, entprellZeit=100;
byte EnalbedFlying = 1;
int State = 0, TextShown = 0;
switch (State) {
case 0:
if(TextShown == 0){
Serial.println("Status Start Speed 1000");
Serial.println("\nDrücken Sie eine Taste um zum Mindest Speed zu wechseln!");
TextShown = 1;
}
myESC1.stop(); // ESC1 wird gestoppt
myESC2.stop(); // ESC2 wird gestoppt
myESC3.stop(); // ESC3 wird gestoppt
myESC4.stop(); // ESC4 wird gestoppt
//delay (1000);
break;
// digitalRead(3)== LOW;
////////////////////////////////////////////////////////////////////////////////////////////////////// Bereitschafts-Zustand
case 1:
if(TextShown == 0){
Serial.println("Status Minimal Speed 1440");
Serial.println("\nDrücken Sie eine Taste um zum Mindest Speed zu wechseln!");
TextShown = 1;
}
myESC1.arm();
myESC2.arm();
myESC3.arm();
myESC4.arm();
//delay(3000); // Wait for a while
break;
////////////////////////////////////////////////////////////////////////////////////////////////////// PID-Initialisierung
case 2:
if(TextShown == 0){
Serial.println("Status Initialisiere Flug");
Serial.println("\nDrücken Sie eine Taste um zum Mindest Speed zu wechseln!");
TextShown = 1;
}
Serial.print("Höhe in cm: ");Serial.print((int)maDist);
Serial.print(" \t\tWinkelX in Grad (Roll): ");Serial.print(pid_angle_roll);
Serial.print("\tWinkelY in Grad (Pitch): ");Serial.println(pid_angle_pitch);
if(EnalbedFlying == 1){
State = 3;
TextShown = 0;
}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////// Flug
case 3:
// PID Parameter zurücksetzen
pid_roll_setpoint = 0;
pid_pitch_setpoint = 0;
pid_yaw_setpoint = 0;
calculate_pid(); //PID Regler Output berechnen
esc_1 = (pid_output_roll/2) - (pid_output_pitch/2);// - pid_output_yaw; // Power für esc 1 berechnen (vorne-rechts)
esc_2 = (pid_output_roll/2) + (pid_output_pitch/2);// + pid_output_yaw; // Power für esc 2 berechnen (hinten-rechts)
esc_3 = ((pid_output_roll/2)*(-1)) + (pid_output_pitch/2);// - pid_output_yaw; // Power für esc 3 berechnen (hinten-links)
esc_4 = ((pid_output_roll/2)*(-1)) - (pid_output_pitch/2);// + pid_output_yaw; // Power für esc 4 berechnen (vorne-links)
if (esc_1 < -30) esc_1 = -30; //unteres Power Limit für ESC 1
if (esc_2 < -30) esc_2 = -30; //unteres Power Limit für ESC 2
if (esc_3 < -30) esc_3 = -30; //unteres Power Limit für ESC 3
if (esc_4 < -30) esc_4 = -30; //unteres Power Limit für ESC 4
if(esc_1 > 30)esc_1 = 30; //oberes Power Limit für ESC 1
if(esc_2 > 30)esc_2 = 30; //oberes Power Limit für ESC 2
if(esc_3 > 30)esc_3 = 30; //oberes Power Limit für ESC 3
if(esc_4 > 30)esc_4 = 30; //oberes Power Limit für ESC 4
esc_1 = (esc_1);
esc_2 = (esc_2);
esc_3 = (esc_3);
esc_4 = (esc_4);
myESC1.speed(esc_1+throttle); // Weist den ESC an, zum oESC-Geschwindigkeitswert zu wechseln
myESC2.speed(esc_2+throttle);
myESC3.speed(esc_3+throttle);
myESC4.speed(esc_4+throttle);
Serial.print("Höhe in cm: ");Serial.print((int)maDist);
Serial.print("\tESC 1: ");Serial.print(esc_1+throttle);
Serial.print("\tESC 2: ");Serial.print(esc_2+throttle);
Serial.print("\tESC 3: ");Serial.println(esc_3+throttle);
Serial.print("\tESC 4: ");Serial.println(esc_4+throttle);
delay(10);
break;
}
}
if((millis() - alteZeit) > entprellZeit) { // innerhalb der entprellZeit nichts machen
if( EnalbedFlying == 1){
if (State == 0) {
State ++;
}
else
{
}
}
if( State =0 && EnalbedFlying == 1){
if (State == 1 )
{
State ++;
}
else
{
}
}
if( State =1 && EnalbedFlying == 1){
if (State == 2 )
{
State ++;
}
else
{
}
}
if( State =2 && EnalbedFlying == 1){
if (State == 3 )
{
State ++;
}
else
{
}
}
}
alteZeit = millis(); // letzte Schaltzeit merken
}
Solltet Ihr mehr Code benötigen bitte Bescheid geben.
Ich danke Euch und hoffe, Ihr könnt mir helfen.