fixed the beacon not starting

This commit is contained in:
Nicholas Stănescu 2025-11-20 16:35:06 +01:00
parent ee4d929042
commit a7c2e64d9c

View File

@ -21,12 +21,7 @@
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-19T17:06:41.856101Z",
"start_time": "2025-11-19T17:06:41.668014Z"
}
},
"metadata": {},
"cell_type": "code",
"source": [
"# Import necessary libraries\n",
@ -43,7 +38,7 @@
"# Note: After changing the import statement, you need to restart the kernel for changes to take effect."
],
"outputs": [],
"execution_count": 1
"execution_count": null
},
{
"cell_type": "markdown",
@ -170,12 +165,7 @@
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-19T17:06:57.927792Z",
"start_time": "2025-11-19T17:06:41.870747Z"
}
},
"metadata": {},
"cell_type": "code",
"source": [
"### Student Version: play with this! ###\n",
@ -214,35 +204,8 @@
"# Close the serial connection (important!)\n",
"serial.close()"
],
"outputs": [
{
"data": {
"text/plain": [
"Canvas(height=520, width=520)"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "21304a88906c4d9f9de4a2379cb59850"
}
},
"metadata": {},
"output_type": "display_data",
"jetTransient": {
"display_id": null
}
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Motors are ON\n",
"Car is outside the field boundaries!\n",
"Motors are OFF\n"
]
}
],
"execution_count": 2
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
@ -302,12 +265,7 @@
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-19T17:07:03.101925Z",
"start_time": "2025-11-19T17:06:58.026789Z"
}
},
"metadata": {},
"cell_type": "code",
"source": [
"### Student Version ###\n",
@ -369,34 +327,8 @@
"# TODO: Very Important! Close the serial connection\n",
"serial.close()\n"
],
"outputs": [
{
"data": {
"text/plain": [
"Canvas(height=520, width=520)"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "1d9fa86f637f476d8ec8f4cce01a4b5f"
}
},
"metadata": {},
"output_type": "display_data",
"jetTransient": {
"display_id": null
}
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Beacon is ON\n",
"Beacon is OFF\n"
]
}
],
"execution_count": 3
"outputs": [],
"execution_count": null
},
{
"metadata": {},
@ -446,12 +378,7 @@
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-19T17:07:03.301301Z",
"start_time": "2025-11-19T17:07:03.206413Z"
}
},
"metadata": {},
"cell_type": "code",
"source": [
"### Student Version ###\n",
@ -470,50 +397,8 @@
"serial.close()\n",
"# TODO: Close the serial connection (important!)"
],
"outputs": [
{
"data": {
"text/plain": [
"Canvas(height=520, width=520)"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "0e272aeb98f24f13a805d0bccaf4596b"
}
},
"metadata": {},
"output_type": "display_data",
"jetTransient": {
"display_id": null
}
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Car status is:\n",
"\n",
"**************************\n",
"* Audio Beacon: off\n",
"* c: 0xabcdef00\n",
"* f_c: 5678\n",
"* f_b: 1234\n",
"* c_r: 1337\n",
"**************************\n",
"* PWM:\n",
"* Dir. 150\n",
"* Mot. 150\n",
"**************************\n",
"* Sensors:\n",
"* Dist. L 0 R 0\n",
"* V_batt 11.5 V\n",
"**************************\n",
"\u0004\n"
]
}
],
"execution_count": 4
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
@ -581,8 +466,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-19T17:09:36.903066Z",
"start_time": "2025-11-19T17:09:36.884806Z"
"end_time": "2025-11-19T20:47:25.030226Z",
"start_time": "2025-11-19T20:47:25.017941Z"
}
},
"cell_type": "code",
@ -644,12 +529,12 @@
" def start_beacon(self):\n",
" # Send commands to start the beacon\n",
" # Use the command 'A1\\n'\n",
" self.send_command(str(b\"A1\\n\"))\n",
" self.send_command(\"A1\\n\")\n",
"\n",
" def stop_beacon(self):\n",
" # Send commands to stop the beacon\n",
" # Use the command 'A0\\n'\n",
" self.send_command(str(b\"A0\\n\"))\n",
" self.send_command(\"A0\\n\")\n",
"\n",
" def close(self):\n",
" # Close the serial connection\n",
@ -657,13 +542,13 @@
" self.serial.close()\n"
],
"outputs": [],
"execution_count": 11
"execution_count": 20
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-19T17:15:34.819411Z",
"start_time": "2025-11-19T17:15:34.810196Z"
"end_time": "2025-11-19T20:47:26.839827Z",
"start_time": "2025-11-19T20:47:26.826565Z"
}
},
"cell_type": "code",
@ -715,13 +600,13 @@
" kitt.close()"
],
"outputs": [],
"execution_count": 14
"execution_count": 21
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-19T17:15:43.089078Z",
"start_time": "2025-11-19T17:15:36.212088Z"
"end_time": "2025-11-19T20:47:41.559047Z",
"start_time": "2025-11-19T20:47:30.566425Z"
}
},
"cell_type": "code",
@ -745,7 +630,7 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "4498f99b8dbd43e895b0854ee6ddf7be"
"model_id": "bf6b02cc69244330a431bf392738a083"
}
},
"metadata": {},
@ -760,9 +645,23 @@
"text": [
"Control the car with W (forward), S (backward), A (left), D (right), E (start beacon), R (stop beacon), and Q (to exit).\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "Interrupted by user",
"output_type": "error",
"traceback": [
"\u001B[31m---------------------------------------------------------------------------\u001B[39m",
"\u001B[31mKeyboardInterrupt\u001B[39m Traceback (most recent call last)",
"\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[22]\u001B[39m\u001B[32m, line 9\u001B[39m\n\u001B[32m 6\u001B[39m kitt = KITT(\u001B[33m'\u001B[39m\u001B[33m/dev/rfcomm2\u001B[39m\u001B[33m'\u001B[39m) \u001B[38;5;66;03m# Replace with the actual port\u001B[39;00m\n\u001B[32m 8\u001B[39m \u001B[38;5;66;03m# Start the control function\u001B[39;00m\n\u001B[32m----> \u001B[39m\u001B[32m9\u001B[39m \u001B[43mwasd_control\u001B[49m\u001B[43m(\u001B[49m\u001B[43mkitt\u001B[49m\u001B[43m)\u001B[49m\n",
"\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[21]\u001B[39m\u001B[32m, line 12\u001B[39m, in \u001B[36mwasd_control\u001B[39m\u001B[34m(kitt)\u001B[39m\n\u001B[32m 9\u001B[39m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[32m 10\u001B[39m \u001B[38;5;28;01mwhile\u001B[39;00m \u001B[38;5;28;01mTrue\u001B[39;00m:\n\u001B[32m 11\u001B[39m \u001B[38;5;66;03m# Read input from the user\u001B[39;00m\n\u001B[32m---> \u001B[39m\u001B[32m12\u001B[39m command = \u001B[38;5;28;43minput\u001B[39;49m\u001B[43m(\u001B[49m\u001B[33;43m\"\u001B[39;49m\u001B[33;43mEnter command: \u001B[39;49m\u001B[33;43m\"\u001B[39;49m\u001B[43m)\u001B[49m.lower()\n\u001B[32m 13\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m command == \u001B[33m\"\u001B[39m\u001B[33mw\u001B[39m\u001B[33m\"\u001B[39m:\n\u001B[32m 14\u001B[39m car_speed = car_speed + \u001B[32m5\u001B[39m\n",
"\u001B[36mFile \u001B[39m\u001B[32m~/Documents/EE/Y2/IP3/A.K.03/.venv/lib/python3.13/site-packages/ipykernel/kernelbase.py:1396\u001B[39m, in \u001B[36mKernel.raw_input\u001B[39m\u001B[34m(self, prompt)\u001B[39m\n\u001B[32m 1394\u001B[39m msg = \u001B[33m\"\u001B[39m\u001B[33mraw_input was called, but this frontend does not support input requests.\u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m 1395\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m StdinNotImplementedError(msg)\n\u001B[32m-> \u001B[39m\u001B[32m1396\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_input_request\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m 1397\u001B[39m \u001B[43m \u001B[49m\u001B[38;5;28;43mstr\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mprompt\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1398\u001B[39m \u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_get_shell_context_var\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_shell_parent_ident\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1399\u001B[39m \u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mget_parent\u001B[49m\u001B[43m(\u001B[49m\u001B[33;43m\"\u001B[39;49m\u001B[33;43mshell\u001B[39;49m\u001B[33;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1400\u001B[39m \u001B[43m \u001B[49m\u001B[43mpassword\u001B[49m\u001B[43m=\u001B[49m\u001B[38;5;28;43;01mFalse\u001B[39;49;00m\u001B[43m,\u001B[49m\n\u001B[32m 1401\u001B[39m \u001B[43m\u001B[49m\u001B[43m)\u001B[49m\n",
"\u001B[36mFile \u001B[39m\u001B[32m~/Documents/EE/Y2/IP3/A.K.03/.venv/lib/python3.13/site-packages/ipykernel/kernelbase.py:1441\u001B[39m, in \u001B[36mKernel._input_request\u001B[39m\u001B[34m(self, prompt, ident, parent, password)\u001B[39m\n\u001B[32m 1438\u001B[39m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mKeyboardInterrupt\u001B[39;00m:\n\u001B[32m 1439\u001B[39m \u001B[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001B[39;00m\n\u001B[32m 1440\u001B[39m msg = \u001B[33m\"\u001B[39m\u001B[33mInterrupted by user\u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m-> \u001B[39m\u001B[32m1441\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mKeyboardInterrupt\u001B[39;00m(msg) \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[32m 1442\u001B[39m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mException\u001B[39;00m:\n\u001B[32m 1443\u001B[39m \u001B[38;5;28mself\u001B[39m.log.warning(\u001B[33m\"\u001B[39m\u001B[33mInvalid Message:\u001B[39m\u001B[33m\"\u001B[39m, exc_info=\u001B[38;5;28;01mTrue\u001B[39;00m)\n",
"\u001B[31mKeyboardInterrupt\u001B[39m: Interrupted by user"
]
}
],
"execution_count": 15
"execution_count": 22
},
{
"metadata": {},
@ -794,17 +693,64 @@
]
},
{
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-19T19:27:44.069076Z",
"start_time": "2025-11-19T19:27:44.033559Z"
}
},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"import serial.tools.list_ports\n",
"\n",
"ports = list(serial.tools.list_ports.comports())\n",
"for port in ports:\n",
" print(port.device)"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/dev/ttyS31\n",
"/dev/ttyS30\n",
"/dev/ttyS29\n",
"/dev/ttyS28\n",
"/dev/ttyS27\n",
"/dev/ttyS26\n",
"/dev/ttyS25\n",
"/dev/ttyS24\n",
"/dev/ttyS23\n",
"/dev/ttyS22\n",
"/dev/ttyS21\n",
"/dev/ttyS20\n",
"/dev/ttyS19\n",
"/dev/ttyS18\n",
"/dev/ttyS17\n",
"/dev/ttyS16\n",
"/dev/ttyS15\n",
"/dev/ttyS14\n",
"/dev/ttyS13\n",
"/dev/ttyS12\n",
"/dev/ttyS11\n",
"/dev/ttyS10\n",
"/dev/ttyS9\n",
"/dev/ttyS8\n",
"/dev/ttyS7\n",
"/dev/ttyS6\n",
"/dev/ttyS5\n",
"/dev/ttyS4\n",
"/dev/ttyS3\n",
"/dev/ttyS2\n",
"/dev/ttyS1\n",
"/dev/ttyS0\n",
"/dev/rfcomm2\n",
"/dev/rfcomm1\n",
"/dev/rfcomm0\n"
]
}
],
"execution_count": 18
},
{
"cell_type": "markdown",