mirror of
https://gitlab.ewi.tudelft.nl/ee2l1/2025-2026/A.K.03.git
synced 2025-12-12 15:30:57 +01:00
Started working on the distance sensor code
This commit is contained in:
parent
953224d35d
commit
1b5cb5c3aa
@ -106,8 +106,14 @@
|
||||
"### Student Version ###\n",
|
||||
"\n",
|
||||
"# TODO: Establish a serial connection, ask for a status report, read it out, and print it\n",
|
||||
"serial = Serial('/dev/rfcomm2', 115200)\n",
|
||||
"serial.write(b'S\\n')\n",
|
||||
"status = serial.read_until(b'\\n')\n",
|
||||
"status = status.decode('utf-8')\n",
|
||||
"print(f\"Car status is:\\n\\n{status}\")\n",
|
||||
"\n",
|
||||
"# TODO: Close the serial connection"
|
||||
"# TODO: Close the serial connection\n",
|
||||
"serial.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -151,30 +157,36 @@
|
||||
"source": [
|
||||
"### Student Version ###\n",
|
||||
"\n",
|
||||
"# TODO: Decode the status response to a string\n",
|
||||
"def extract_dis ():\n",
|
||||
" # TODO: Decode the status response to a string\n",
|
||||
" serial.write(b'S\\n')\n",
|
||||
" _status = serial.read_until(b'\\n')\n",
|
||||
" _status = _status.decode('utf-8')\n",
|
||||
"\n",
|
||||
"# TODO: Split the status string into lines\n",
|
||||
"lines = \n",
|
||||
" # TODO: Split the status string into lines\n",
|
||||
" lines = _status.splitlines()\n",
|
||||
"\n",
|
||||
"# Initialize variables to hold distance values\n",
|
||||
"dist_L = None\n",
|
||||
"dist_R = None\n",
|
||||
" # Initialize variables to hold distance values\n",
|
||||
" dist_L = None\n",
|
||||
" dist_R = None\n",
|
||||
"\n",
|
||||
"# Iterate over each line to find distance data\n",
|
||||
"for line in lines:\n",
|
||||
" if \"Dist.\" in line:\n",
|
||||
" # TODO: Split the line into words\n",
|
||||
" words =\n",
|
||||
" # Extract distance values based on their positions\n",
|
||||
" # Iterate over each line to find distance data\n",
|
||||
" for line in lines:\n",
|
||||
" if \"Dist.\" in line:\n",
|
||||
" # TODO: Split the line into words\n",
|
||||
" words = lines.split()\n",
|
||||
" # Extract distance values based on their positions\n",
|
||||
"\n",
|
||||
" # Assign dist_L and dist_R accordingly\n",
|
||||
" dist_L = \n",
|
||||
" dist_R = \n",
|
||||
" break # Exit the loop after finding the distances\n",
|
||||
" # Assign dist_L and dist_R accordingly\n",
|
||||
" dist_L =\n",
|
||||
" dist_R =\n",
|
||||
" break # Exit the loop after finding the distances\n",
|
||||
"\n",
|
||||
"# Print the extracted distance values\n",
|
||||
"print(f\"Left Distance: {dist_L}\")\n",
|
||||
"print(f\"Right Distance: {dist_R}\")"
|
||||
" # Print the extracted distance values\n",
|
||||
" print(f\"Left Distance: {dist_L}\")\n",
|
||||
" print(f\"Right Distance: {dist_R}\")\n",
|
||||
"\n",
|
||||
" return dist_L, dist_R"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -265,6 +277,7 @@
|
||||
"\n",
|
||||
"# TODO: Open the serial connection to KITT, set the motor speed\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Initialize a list to store recorded data\n",
|
||||
"data = []\n",
|
||||
"\n",
|
||||
|
||||
0
student_code/controller.py
Normal file
0
student_code/controller.py
Normal file
Loading…
x
Reference in New Issue
Block a user