mirror of
https://gitlab.ewi.tudelft.nl/ee2l1/2025-2026/A.K.03.git
synced 2025-12-12 16:00:56 +01:00
Started working on the distance sensor code
This commit is contained in:
parent
bc87f43be8
commit
54892b9c6d
@ -104,8 +104,14 @@
|
|||||||
"### Student Version ###\n",
|
"### Student Version ###\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# TODO: Establish a serial connection, ask for a status report, read it out, and print it\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",
|
"\n",
|
||||||
"# TODO: Close the serial connection"
|
"# TODO: Close the serial connection\n",
|
||||||
|
"serial.close()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -149,30 +155,36 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"### Student Version ###\n",
|
"### Student Version ###\n",
|
||||||
"\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",
|
"\n",
|
||||||
"# TODO: Split the status string into lines\n",
|
" # TODO: Split the status string into lines\n",
|
||||||
"lines = \n",
|
" lines = _status.splitlines()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Initialize variables to hold distance values\n",
|
" # Initialize variables to hold distance values\n",
|
||||||
"dist_L = None\n",
|
" dist_L = None\n",
|
||||||
"dist_R = None\n",
|
" dist_R = None\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Iterate over each line to find distance data\n",
|
" # Iterate over each line to find distance data\n",
|
||||||
"for line in lines:\n",
|
" for line in lines:\n",
|
||||||
" if \"Dist.\" in line:\n",
|
" if \"Dist.\" in line:\n",
|
||||||
" # TODO: Split the line into words\n",
|
" # TODO: Split the line into words\n",
|
||||||
" words =\n",
|
" words = lines.split()\n",
|
||||||
" # Extract distance values based on their positions\n",
|
" # Extract distance values based on their positions\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # Assign dist_L and dist_R accordingly\n",
|
" # Assign dist_L and dist_R accordingly\n",
|
||||||
" dist_L = \n",
|
" dist_L =\n",
|
||||||
" dist_R = \n",
|
" dist_R =\n",
|
||||||
" break # Exit the loop after finding the distances\n",
|
" break # Exit the loop after finding the distances\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Print the extracted distance values\n",
|
" # Print the extracted distance values\n",
|
||||||
"print(f\"Left Distance: {dist_L}\")\n",
|
" print(f\"Left Distance: {dist_L}\")\n",
|
||||||
"print(f\"Right Distance: {dist_R}\")"
|
" print(f\"Right Distance: {dist_R}\")\n",
|
||||||
|
"\n",
|
||||||
|
" return dist_L, dist_R"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -263,6 +275,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"# TODO: Open the serial connection to KITT, set the motor speed\n",
|
"# TODO: Open the serial connection to KITT, set the motor speed\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\n",
|
||||||
"# Initialize a list to store recorded data\n",
|
"# Initialize a list to store recorded data\n",
|
||||||
"data = []\n",
|
"data = []\n",
|
||||||
"\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