Skip to content
Snippets Groups Projects
Commit 48792a3a authored by Sven Marian Göbel's avatar Sven Marian Göbel
Browse files

Motor Pins 7 & 8 changed, Case 8.1 & 8.2 conditions changed, check_voltage...

Motor Pins 7 & 8 changed, Case 8.1 & 8.2 conditions changed, check_voltage changed from number based to time based, backward_factor & search_factor changed (needs revisit)
parent 3db40d5f
No related branches found
No related tags found
1 merge request!1Motor Pins 7 & 8 changed, Case 8.1 & 8.2 conditions changed, check_voltage...
...@@ -35,7 +35,6 @@ int white_surface_reflection = 150; ...@@ -35,7 +35,6 @@ int white_surface_reflection = 150;
void setup() void setup()
{ //Innerhalb dieser Funktion wird alles einmal bei Start des Arduinos aufgerufen { //Innerhalb dieser Funktion wird alles einmal bei Start des Arduinos aufgerufen
Robotcar_functions_object.initialise(); Robotcar_functions_object.initialise();
search_time = 1.5 * total_velocity;
} }
void loop() void loop()
......
...@@ -17,6 +17,12 @@ ...@@ -17,6 +17,12 @@
IFK TH Köln IFK TH Köln
Last Modified: 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 21.08.2023
Switch from libraries "DeviceDriverSet_xxx0" to "thk-motor-driver-v2.0" & "MPU6050_getdata" to "thk_imu-v2.0" Switch from libraries "DeviceDriverSet_xxx0" to "thk-motor-driver-v2.0" & "MPU6050_getdata" to "thk_imu-v2.0"
08 September 2022 08 September 2022
...@@ -39,11 +45,11 @@ ...@@ -39,11 +45,11 @@
const int MOTOR_COUNT = 1; const int MOTOR_COUNT = 1;
const int MOTOR_STBY = 3; const int MOTOR_STBY = 3;
const int MOTOR_PWM_A = 5; const int MOTOR_PWM_A = 5;
const int MOTOR_IN1 = 8; const int MOTOR_IN1 = 7;
const int MOTOR_IN2 = 8; const int MOTOR_IN2 = 7;
const int MOTOR_PWM_B = 6; const int MOTOR_PWM_B = 6;
const int MOTOR_IN3 = 7; const int MOTOR_IN3 = 8;
const int MOTOR_IN4 = 7; const int MOTOR_IN4 = 8;
thk_MotorDriverTB6612FNG motorR(MOTOR_COUNT, MOTOR_STBY, MOTOR_PWM_A, MOTOR_IN1, MOTOR_IN2, 0, 0, 0); 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); thk_MotorDriverTB6612FNG motorL(MOTOR_COUNT, MOTOR_STBY, MOTOR_PWM_B, MOTOR_IN3, MOTOR_IN4, 0, 0, 0);
...@@ -55,22 +61,24 @@ extern unsigned long start_time = 0; ...@@ -55,22 +61,24 @@ extern unsigned long start_time = 0;
char commandline_input = 'E'; char commandline_input = 'E';
char last_direction = 'D'; char last_direction = 'D';
int commandline_output = 3; int commandline_output = 3;
int not_enough_voltage_counter = 0;
int low_voltage_counter = 0;
int modecounter; int modecounter;
int obstacle_velocity = 0; int obstacle_velocity = 0;
int no_reflection = 950; int no_reflection = 950;
int divisor = 1000; int divisor = 1000;
int rest = divisor / 2; int rest = divisor / 2;
int voltagetimer = 0;
boolean mode_changed = false; boolean mode_changed = false;
float voltage_low = 7.2; float voltage_low = 7.2;
float voltage_min = 7.0; float voltage_min = 7.0;
float yaw = 0; float yaw = 0;
float pitch = 0; float pitch = 0;
float roll = 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
boolean last_d_F = false; //test
int delay_factor = 10; //Neuer factor, muss getestet werden DELAY beim stehenbleiben könnte quadratisch mit der Geschwindigkeit skalieren?
float search_time = 0;
unsigned long time_drive = 0; unsigned long time_drive = 0;
float search_time = 200;
float line_factor = 1.2; float line_factor = 1.2;
CRGB leds[NUM_LEDS]; CRGB leds[NUM_LEDS];
...@@ -144,6 +152,7 @@ class Robotcar_functions ...@@ -144,6 +152,7 @@ class Robotcar_functions
{ {
turn_factor = turn_factor * -1.0; turn_factor = turn_factor * -1.0;
} }
search_time = search_factor*1/((float)total_velocity);
} }
...@@ -399,34 +408,25 @@ class Robotcar_functions ...@@ -399,34 +408,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; float voltage = analogRead(Voltage_pin) * 0.0375;
voltage = voltage + (voltage * 0.08); 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++; voltagetimer = millis(); //Speichere die Systemzeit auf die Variable voltagetimer
return 2;
if (not_enough_voltage_counter >= 500) } 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; return 0;
leds[0] = CRGB::Red;
FastLED.show();
} }
}
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 { } else {
return 2; return 2;
} }
} }
...@@ -589,35 +589,45 @@ class Robotcar_functions ...@@ -589,35 +589,45 @@ class Robotcar_functions
time_drive = millis(); 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 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 ((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); 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) 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); drive(Left, turn_velocity);
} }
else else
{ {
drive(Right, turn_velocity); drive(Break, 0);
current_mode = standby_mode;
} }
} }
else if (last_direction == 'F') // Fall 8.3 (Fahrzeug fährt Rückwärts bis wieder eine Linie erkannt wird) else if (last_direction == 'F') // Fall 8.3 (Fahrzeug fährt Rückwärts bis wieder eine Linie erkannt wird)
{ {
drive(Break, 0); drive(Break, 0);
delay(2000); delay(total_velocity*delay_factor);
while ((get_brightness('L') < white_surface_reflection) && (get_brightness('M') < white_surface_reflection) && (get_brightness('R') < white_surface_reflection)) while ((get_brightness('L') < white_surface_reflection) && (get_brightness('M') < white_surface_reflection) && (get_brightness('R') < white_surface_reflection))
{ {
drive(Backward, (total_velocity / backward_factor)); drive(Backward, (total_velocity / backward_factor));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment