mirror of
https://gitlab.ewi.tudelft.nl/ee2l1/2025-2026/A.K.03.git
synced 2025-12-12 16:00:56 +01:00
Made 100 measurements and moved the pics
This commit is contained in:
parent
1a9b6bbf33
commit
9fda5604ea
@ -104,14 +104,12 @@
|
||||
"source": [
|
||||
"### Student Version ###\n",
|
||||
"\n",
|
||||
"# TODO: Establish a serial connection, ask for a status report, read it out, and print it\n",
|
||||
"serial = Serial('COM4', 115200)\n",
|
||||
"serial.write(b'Sd\\n')\n",
|
||||
"status = serial.read_until(b\"\\x04\")\n",
|
||||
"status = status.decode('utf-8')\n",
|
||||
"print(f\"Car status is:\\n\\n{status}\")\n",
|
||||
"\n",
|
||||
"# TODO: Close the serial connection\n",
|
||||
"serial.close()"
|
||||
]
|
||||
},
|
||||
@ -164,13 +162,11 @@
|
||||
"### Student Version ###\n",
|
||||
"\n",
|
||||
"def extract_dis ():\n",
|
||||
" # TODO: Decode the status response to a string\n",
|
||||
" serial = Serial('COM4', 115200)\n",
|
||||
" serial.write(b'S\\n')\n",
|
||||
" _status = serial.read_until(b'\\x04')\n",
|
||||
" _status = _status.decode('utf-8')\n",
|
||||
"\n",
|
||||
" # TODO: Split the status string into lines\n",
|
||||
" lines = _status.splitlines()\n",
|
||||
"\n",
|
||||
" # Initialize variables to hold distance values\n",
|
||||
@ -180,7 +176,6 @@
|
||||
" # 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 = line.split()\n",
|
||||
" # Extract distance values based on their positions\n",
|
||||
"\n",
|
||||
@ -193,6 +188,8 @@
|
||||
" print(f\"Left Distance: {dist_L}\")\n",
|
||||
" print(f\"Right Distance: {dist_R}\")\n",
|
||||
"\n",
|
||||
" serial.close()\n",
|
||||
"\n",
|
||||
" return dist_L, dist_R"
|
||||
]
|
||||
},
|
||||
@ -229,7 +226,50 @@
|
||||
"cell_type": "code",
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": "### Student Version ###\n"
|
||||
"source": "serial.close()"
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"### Student Version ###\n",
|
||||
"times = []\n",
|
||||
"new_times = []\n",
|
||||
"total_time = 0\n",
|
||||
"summed_times = 0\n",
|
||||
"serial = Serial('COM4', 115200)\n",
|
||||
"\n",
|
||||
"for i in range(100):\n",
|
||||
" start_time = time.time()\n",
|
||||
" serial.write(b'S\\n')\n",
|
||||
" _status = serial.read_until(b'\\x04')\n",
|
||||
" _status = _status.decode('utf-8')\n",
|
||||
" current_time = time.time() - start_time\n",
|
||||
" times.append(current_time)\n",
|
||||
"\n",
|
||||
"serial.close()\n",
|
||||
"#print(times)\n",
|
||||
"\n",
|
||||
"for j in range(100):\n",
|
||||
" total_time += times[j]\n",
|
||||
"\n",
|
||||
"average = total_time / 100\n",
|
||||
"\n",
|
||||
"for k in range(100):\n",
|
||||
" new_times.append((times[k] - average) ** 2)\n",
|
||||
" summed_times += new_times[k]\n",
|
||||
"\n",
|
||||
"variance = summed_times / 100\n",
|
||||
"standard_deviation = (variance) ** 0.5\n",
|
||||
"\n",
|
||||
"print(f'The average time of a distance measurement is: {average:.3f} [s]')\n",
|
||||
"print(f'The standard deviantion of a distance measurement is: {standard_deviation:.3f} [s]')\n",
|
||||
"\n",
|
||||
"plt.hist(times)\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user