mirror of
https://gitlab.ewi.tudelft.nl/ee2l1/2025-2026/A.K.03.git
synced 2025-12-12 13:50:57 +01:00
Started working on implementing the distance sensor code
This commit is contained in:
parent
4c5e27a0b3
commit
15d69eef79
2
.idea/A.K.03.iml
generated
2
.idea/A.K.03.iml
generated
@ -4,7 +4,7 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.13 (A.K.03)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.11 (A.K.03)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PyDocumentationSettings">
|
<component name="PyDocumentationSettings">
|
||||||
|
|||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -3,5 +3,5 @@
|
|||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Python 3.13 (A.K.03)" />
|
<option name="sdkName" value="Python 3.13 (A.K.03)" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (A.K.03)" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (A.K.03)" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
@ -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
|
||||||
@ -40,19 +40,18 @@ class KITT:
|
|||||||
# Use the format 'M<speed>\n'
|
# Use the format 'M<speed>\n'
|
||||||
self.send_command(f"M{speed}\n".encode())
|
self.send_command(f"M{speed}\n".encode())
|
||||||
|
|
||||||
|
|
||||||
def set_angle(self, angle):
|
def set_angle(self, angle):
|
||||||
# Send the steering angle command using send_command
|
# Send the steering angle command using send_command
|
||||||
# Use the format 'D<angle>\n'
|
# Use the format 'D<angle>\n'
|
||||||
self.send_command(f"D{angle}\n".encode())
|
self.send_command(f"D{angle}\n".encode())
|
||||||
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
# Stop the car by setting speed and angle to neutral (150)
|
# Stop the car by setting speed and angle to neutral (150)
|
||||||
# Call set_speed and set_angle with 150
|
# Call set_speed and set_angle with 150
|
||||||
self.set_speed(150)
|
self.set_speed(150)
|
||||||
self.set_angle(150)
|
self.set_angle(150)
|
||||||
|
|
||||||
|
|
||||||
def start_beacon(self):
|
def start_beacon(self):
|
||||||
# Send commands to start the beacon
|
# Send commands to start the beacon
|
||||||
# Use the command 'A1\n'
|
# Use the command 'A1\n'
|
||||||
@ -63,6 +62,12 @@ class KITT:
|
|||||||
# Use the command 'A0\n'
|
# Use the command 'A0\n'
|
||||||
self.send_command(b"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):
|
def close(self):
|
||||||
# Close the serial connection
|
# Close the serial connection
|
||||||
# self.serial.close()
|
# self.serial.close()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user