diff --git a/BitS1-Robotcar.ino b/BitS1-Robotcar.ino index 93d83ba00fcdb4f12eda53eccf75ade18f3576fe..44ec96a857ee9eac00b9943afb427b356f53bfe0 100644 --- a/BitS1-Robotcar.ino +++ b/BitS1-Robotcar.ino @@ -35,7 +35,6 @@ int white_surface_reflection = 150; void setup() { //Innerhalb dieser Funktion wird alles einmal bei Start des Arduinos aufgerufen Robotcar_functions_object.initialise(); - search_time = 1.5 * total_velocity; } void loop() diff --git a/Robotcar_functions.h b/Robotcar_functions.h index 620feaf774c910e3da1c32518733a7794e6ff0e7..f72707fd419fda4b11b92d420a3fa5f8087523fd 100644 --- a/Robotcar_functions.h +++ b/Robotcar_functions.h @@ -17,6 +17,12 @@ IFK TH Köln Last Modified: + 22.12.2023 + backward_factor and search_factor needs revisit + Fall 8.1 & 8.2 if and else conditions adapted + MOTOR_IN1 & 2 changed to PIN7 + MOTOR_IN3 & 4 changed to PIN8 + check_voltage() changed from quantity sensitive to time sensitive (2000ms) 21.08.2023 Switch from libraries "DeviceDriverSet_xxx0" to "thk-motor-driver-v2.0" & "MPU6050_getdata" to "thk_imu-v2.0" 08 September 2022 @@ -39,11 +45,11 @@ const int MOTOR_COUNT = 1; const int MOTOR_STBY = 3; const int MOTOR_PWM_A = 5; -const int MOTOR_IN1 = 8; -const int MOTOR_IN2 = 8; +const int MOTOR_IN1 = 7; +const int MOTOR_IN2 = 7; const int MOTOR_PWM_B = 6; -const int MOTOR_IN3 = 7; -const int MOTOR_IN4 = 7; +const int MOTOR_IN3 = 8; +const int MOTOR_IN4 = 8; thk_MotorDriverTB6612FNG motorR(MOTOR_COUNT, MOTOR_STBY, MOTOR_PWM_A, MOTOR_IN1, MOTOR_IN2, 0, 0, 0); thk_MotorDriverTB6612FNG motorL(MOTOR_COUNT, MOTOR_STBY, MOTOR_PWM_B, MOTOR_IN3, MOTOR_IN4, 0, 0, 0); @@ -55,22 +61,22 @@ extern unsigned long start_time = 0; char commandline_input = 'E'; char last_direction = 'D'; int commandline_output = 3; -int not_enough_voltage_counter = 0; -int low_voltage_counter = 0; int modecounter; int obstacle_velocity = 0; int no_reflection = 950; int divisor = 1000; int rest = divisor / 2; +int voltagetimer = 0; boolean mode_changed = false; float voltage_low = 7.2; float voltage_min = 7.0; float yaw = 0; float pitch = 0; float roll = 0; -float backward_factor = 5.0; +float backward_factor = 3.0; //Neuer backward_factor: Muss getestet werden +float search_factor = 120000; //Neuer search_facotr: Muss getestet werden +float search_time = 0; unsigned long time_drive = 0; -float search_time = 200; float line_factor = 1.2; CRGB leds[NUM_LEDS]; @@ -144,6 +150,7 @@ class Robotcar_functions { turn_factor = turn_factor * -1.0; } + search_time = search_factor*1/((float)total_velocity); } @@ -399,34 +406,25 @@ class Robotcar_functions } } - int check_voltage() + int check_voltage() //gibt 0 wieder wenn Spannug zu niedrig, 1 wenn Spannung niedrig, 2 wenn Spannung gut { float voltage = analogRead(Voltage_pin) * 0.0375; voltage = voltage + (voltage * 0.08); - if (voltage < voltage_min) + if (voltage > voltage_min) //Wenn die gemessene Spannung größer ist, als die mindest Spannung... { - not_enough_voltage_counter++; - - if (not_enough_voltage_counter >= 500) + voltagetimer = millis(); //Speichere die Systemzeit auf die Variable voltagetimer + return 2; + } else if((millis()-voltagetimer)>=2000) //Überprüfe, ob 2 Sekunden lang die Spannung zu niedrig ist + { + if(voltage > voltage_low){ + return 1; + } else { - current_mode = standby_mode; - leds[0] = CRGB::Red; - FastLED.show(); + return 0; } - } - if (voltage < voltage_low) - { - low_voltage_counter++; - } - if (not_enough_voltage_counter >= 500) - { - return 0; - } else if (not_enough_voltage_counter < 499 && low_voltage_counter >= 500) { - return 1; } else { return 2; } - } @@ -589,28 +587,38 @@ class Robotcar_functions time_drive = millis(); } else if ((optic_Robotcar_functions_object[0] < white_surface_reflection) && (optic_Robotcar_functions_object[1] < white_surface_reflection) && (optic_Robotcar_functions_object[2] < white_surface_reflection)) // Fall 8 - { + { if ((last_direction == 'L')) // Fall 8.1 (Fahrzeug sucht die Linie mit zeitlicher Begrenzung) { - if (millis() - time_drive >= search_time) + if (millis() - time_drive < search_time) + { + drive(Left, turn_velocity); + } + else if(millis() - time_drive < 2*search_time) { drive(Right, turn_velocity); } - else + else { - drive(Left, turn_velocity); + drive(Break, 0); + current_mode = standby_mode; } } else if ((last_direction == 'R')) // Fall 8.2 (Fahrzeug sucht die Linie mit zeitlicher Begrenzung) { - if (millis() - time_drive >= search_time) + if (millis() - time_drive < search_time) + { + drive(Right, turn_velocity); + } + else if(millis() - time_drive < 2*search_time) { drive(Left, turn_velocity); } - else + else { - drive(Right, turn_velocity); + drive(Break, 0); + current_mode = standby_mode; } }