Made some measurements while braking

This commit is contained in:
Nicholas Stănescu 2025-11-21 14:09:19 +01:00
parent f0e1c993fb
commit cd930318b8
3 changed files with 49 additions and 6 deletions

View File

@ -342,9 +342,9 @@
"from pathlib import Path\n", "from pathlib import Path\n",
"\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",
"serial = Serial('COM4', 115200)\n", "serial = Serial('/dev/rfcomm3', 115200)\n",
"serial.write(b'D150\\n')\n", "serial.write(b'D150\\n')\n",
"serial.write(b'M160\\n')\n", "serial.write(b'M165\\n')\n",
"\n", "\n",
"# Initialize a list to store recorded data\n", "# Initialize a list to store recorded data\n",
"data = []\n", "data = []\n",
@ -383,9 +383,9 @@
" data.append([current_time, dist_L, dist_R])\n", " data.append([current_time, dist_L, dist_R])\n",
" \n", " \n",
" # Check if KITT is too close to the wall and stop if necessary\n", " # Check if KITT is too close to the wall and stop if necessary\n",
" if dist_L < 100 or dist_R < 100:\n", " if dist_L < 130 or dist_R < 130:\n",
" serial.write(b'M145\\n')\n", " serial.write(b'M135\\n')\n",
" time.sleep(0.5)\n", " time.sleep(0.75)\n",
" serial.write(b'M150\\n') # Stop the car\n", " serial.write(b'M150\\n') # Stop the car\n",
" print(\"Stopping KITT to avoid collision.\")\n", " print(\"Stopping KITT to avoid collision.\")\n",
" break # Exit the loop\n", " break # Exit the loop\n",
@ -397,12 +397,20 @@
"serial.close()\n", "serial.close()\n",
"\n", "\n",
"# TODO: Write the recorded data to a CSV file\n", "# TODO: Write the recorded data to a CSV file\n",
"filepath = Path('kitt_wall_data_160.csv')\n", "filepath = Path('./kitt_wall_data_165.csv')\n",
"df = pd.DataFrame(data,columns = [\"Time\",\"Distance_L\",\"Distance_R\"])\n", "df = pd.DataFrame(data,columns = [\"Time\",\"Distance_L\",\"Distance_R\"])\n",
"df.to_csv(filepath,index=False)\n", "df.to_csv(filepath,index=False)\n",
"!pwd\n",
"# Recommeded file output: Files/Recordings/kitt_distance_data_{speed}.csv" "# Recommeded file output: Files/Recordings/kitt_distance_data_{speed}.csv"
] ]
}, },
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "df.to_csv(Path(\"./kitt_wall_data_165.csv\"))"
},
{ {
"metadata": {}, "metadata": {},
"cell_type": "markdown", "cell_type": "markdown",

View File

@ -0,0 +1,21 @@
Time,Distance_L,Distance_R
0.18527626991271973,293,293
0.4374089241027832,293,293
0.6661174297332764,293,291
0.8378303050994873,291,288
1.0300233364105225,287,283
1.2077486515045166,281,276
1.3909521102905273,273,267
1.5912683010101318,263,257
1.7906908988952637,253,257
1.9916656017303467,240,245
2.179856777191162,226,232
2.338029146194458,213,220
2.5159542560577393,198,206
2.7149744033813477,198,190
2.9028022289276123,182,174
3.0969913005828857,166,157
3.2479021549224854,148,140
3.4600577354431152,130,122
3.6272897720336914,112,103
3.8329083919525146,93,84
1 Time Distance_L Distance_R
2 0.18527626991271973 293 293
3 0.4374089241027832 293 293
4 0.6661174297332764 293 291
5 0.8378303050994873 291 288
6 1.0300233364105225 287 283
7 1.2077486515045166 281 276
8 1.3909521102905273 273 267
9 1.5912683010101318 263 257
10 1.7906908988952637 253 257
11 1.9916656017303467 240 245
12 2.179856777191162 226 232
13 2.338029146194458 213 220
14 2.5159542560577393 198 206
15 2.7149744033813477 198 190
16 2.9028022289276123 182 174
17 3.0969913005828857 166 157
18 3.2479021549224854 148 140
19 3.4600577354431152 130 122
20 3.6272897720336914 112 103
21 3.8329083919525146 93 84

View File

@ -0,0 +1,14 @@
Time,Distance_L,Distance_R
0.14345836639404297,345,345
0.34053707122802734,345,345
0.5649638175964355,344,345
0.8061964511871338,337,341
1.0228962898254395,327,333
1.2599327564239502,314,306
1.526465654373169,297,288
1.7780358791351318,257,268
1.948960781097412,233,246
2.1302239894866943,207,221
2.321249485015869,179,194
2.565399646759033,151,167
2.794302463531494,120,136
1 Time Distance_L Distance_R
2 0.14345836639404297 345 345
3 0.34053707122802734 345 345
4 0.5649638175964355 344 345
5 0.8061964511871338 337 341
6 1.0228962898254395 327 333
7 1.2599327564239502 314 306
8 1.526465654373169 297 288
9 1.7780358791351318 257 268
10 1.948960781097412 233 246
11 2.1302239894866943 207 221
12 2.321249485015869 179 194
13 2.565399646759033 151 167
14 2.794302463531494 120 136