diff --git a/.idea/A.K.03.iml b/.idea/A.K.03.iml index c56ca50..7133e2f 100644 --- a/.idea/A.K.03.iml +++ b/.idea/A.K.03.iml @@ -4,7 +4,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 822c310..f42a977 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/student_code/distance_sensor.py b/student_code/distance_sensor.py index e69de29..0478956 100644 --- a/student_code/distance_sensor.py +++ b/student_code/distance_sensor.py @@ -0,0 +1,34 @@ +import time + +def read_distance_sensor(status, recording_duration): + + # Record data for a specified duration (e.g., 10 seconds) + start_time = time.time() + + while time.time() - start_time < recording_duration: + + status = status.decode('utf-8') + lines = status.splitlines() + + # Initialize variables to hold distance values + dist_L = None + dist_R = None + + # Initialize a list to store recorded data + data = [] + + # Iterate over each line to find distance data + for line in lines: + if "Dist." in line: + words = line.split() + # Extract distance values based on their positions + + # Assign dist_L and dist_R accordingly + dist_L = words[3] + dist_R = words[5] + break # Exit the loop after finding the distances + + current_time = time.time() - start_time + data.append([current_time, dist_L, dist_R]) + + return data \ No newline at end of file diff --git a/student_code/kitt_main.py b/student_code/kitt_main.py index d68169b..d5c6b31 100644 --- a/student_code/kitt_main.py +++ b/student_code/kitt_main.py @@ -40,19 +40,18 @@ class KITT: # Use the format 'M\n' self.send_command(f"M{speed}\n".encode()) - def set_angle(self, angle): # Send the steering angle command using send_command # Use the format 'D\n' self.send_command(f"D{angle}\n".encode()) - def stop(self): # Stop the car by setting speed and angle to neutral (150) # Call set_speed and set_angle with 150 self.set_speed(150) self.set_angle(150) + def start_beacon(self): # Send commands to start the beacon # Use the command 'A1\n' @@ -63,6 +62,12 @@ class KITT: # Use the command 'A0\n' self.send_command(b"A0\n") + def get_distance_report(self): + self.send_command(b"Sd\n") + #self.serial.read_until(b'\x04').decode('utf-8') + return self.serial.read_until(b'\x04').decode('utf-8') + + def close(self): # Close the serial connection # self.serial.close()