A.K.03/student_code/dist_func.py
2025-12-03 15:34:27 +01:00

36 lines
999 B
Python

import time
from kitt import KITT
# recording_duration
def process():
# Record data for a specified duration (e.g., 10 seconds)
start_time = time.time()
while time.time() - start_time < 10:
status = KITT.get_distance_report()
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, dist_L, dist_R