From ee4d929042f2c795c0aa0e4956cc1f3baf64ad1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicholas=20St=C4=83nescu?= Date: Wed, 19 Nov 2025 18:20:05 +0100 Subject: [PATCH 1/3] done --- Manual/0_Table_of_Contents.ipynb | 2 +- Manual/1_Introduction.ipynb | 2 +- Manual/2_Module_0.ipynb | 86 ++++- Manual/3_Module_1.ipynb | 324 ++++++++++++++---- Manual/4_Module_2.ipynb | 6 +- Manual/5_Module_3.ipynb | 13 +- Manual/6_Module_4.ipynb | 4 +- Manual/7_Midterm_Report.ipynb | 2 +- Manual/8_Module_5.ipynb | 4 +- .../KITT_Simulator}/GUI/car.png | Bin .../KITT_Simulator}/GUI/explosion.png | Bin .../KITT_Simulator}/dynamics_simulator.py | 0 .../KITT_Simulator}/gui.py | 0 .../KITT_Simulator}/gui_tester.ipynb | 4 +- .../KITT_Simulator}/serial_simulator.py | 9 +- .../KITT_Simulator}/shared_state.py | 0 .../simulator_data/motor_parameters.txt | 0 .../simulator_data/pulses_recording.txt | 0 .../simulator_data/servo_parameters.txt | 0 .../simulator_data/silence.txt | 0 .../KITT_Simulator}/sounddevice_simulator.py | 3 +- ...r-angles-of-the-inner-and-outer-wheels.png | Bin {pictures => Manual/pictures}/Beacon.png | Bin .../pictures}/FinalChallenge.png | Bin {pictures => Manual/pictures}/KITT_leds.png | Bin {pictures => Manual/pictures}/KITTwind.jpg | Bin {pictures => Manual/pictures}/Step1.PNG | Bin {pictures => Manual/pictures}/Step2.PNG | Bin {pictures => Manual/pictures}/Step3.PNG | Bin {pictures => Manual/pictures}/Step4.PNG | Bin {pictures => Manual/pictures}/Step5.PNG | Bin {pictures => Manual/pictures}/Step6.PNG | Bin {pictures => Manual/pictures}/Step6Arrow.png | Bin {pictures => Manual/pictures}/Step7.PNG | Bin {pictures => Manual/pictures}/TDOA.png | Bin {pictures => Manual/pictures}/XFplot.png | Bin {pictures => Manual/pictures}/axisdef.png | Bin {pictures => Manual/pictures}/bicycle.png | Bin .../pictures}/communication_overview.png | Bin .../pictures}/figaudiocode.pdf | Bin {pictures => Manual/pictures}/figurejoin.png | Bin {pictures => Manual/pictures}/gui_example.png | Bin {pictures => Manual/pictures}/header.png | Bin {pictures => Manual/pictures}/intro_setup.jpg | Bin {pictures => Manual/pictures}/logo.png | Bin {pictures => Manual/pictures}/mcu_board.jpg | Bin {pictures => Manual/pictures}/potential.png | Bin .../pictures}/potentialfunction.png | Bin {pictures => Manual/pictures}/projectBD.png | Bin {pictures => Manual/pictures}/projection.png | Bin .../pictures}/scrum_backlog-1.png | Bin .../pictures}/scrum_chart-1.png | Bin .../pictures}/scrum_overview-1.png | Bin .../pictures}/srf02-ultrasonic-sensor.jpg | Bin {pictures => Manual/pictures}/steering.png | Bin {pictures => Manual/pictures}/steps.png | Bin .../pictures}/systemoverview.png | Bin .../pictures}/systemoverview1.pdf | Bin {pictures => Manual/pictures}/test_pic | 0 {pictures => Manual/pictures}/trajectory.png | Bin .../pictures}/traxxas_e-maxx.png | Bin {pictures => Manual/pictures}/truck.jpg | Bin appendix/0_Installation_Linux.ipynb | 4 +- appendix/0_Installation_Mac.ipynb | 4 +- appendix/0_Installation_Windows.ipynb | 4 +- requirements.txt | 1 + 66 files changed, 359 insertions(+), 113 deletions(-) rename {KITT_Simulator => Manual/KITT_Simulator}/GUI/car.png (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/GUI/explosion.png (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/dynamics_simulator.py (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/gui.py (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/gui_tester.ipynb (92%) rename {KITT_Simulator => Manual/KITT_Simulator}/serial_simulator.py (95%) rename {KITT_Simulator => Manual/KITT_Simulator}/shared_state.py (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/simulator_data/motor_parameters.txt (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/simulator_data/pulses_recording.txt (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/simulator_data/servo_parameters.txt (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/simulator_data/silence.txt (100%) rename {KITT_Simulator => Manual/KITT_Simulator}/sounddevice_simulator.py (97%) rename {pictures => Manual/pictures}/Ackermann-steering-geometry-for-the-front-steer-angles-of-the-inner-and-outer-wheels.png (100%) rename {pictures => Manual/pictures}/Beacon.png (100%) rename {pictures => Manual/pictures}/FinalChallenge.png (100%) rename {pictures => Manual/pictures}/KITT_leds.png (100%) rename {pictures => Manual/pictures}/KITTwind.jpg (100%) rename {pictures => Manual/pictures}/Step1.PNG (100%) rename {pictures => Manual/pictures}/Step2.PNG (100%) rename {pictures => Manual/pictures}/Step3.PNG (100%) rename {pictures => Manual/pictures}/Step4.PNG (100%) rename {pictures => Manual/pictures}/Step5.PNG (100%) rename {pictures => Manual/pictures}/Step6.PNG (100%) rename {pictures => Manual/pictures}/Step6Arrow.png (100%) rename {pictures => Manual/pictures}/Step7.PNG (100%) rename {pictures => Manual/pictures}/TDOA.png (100%) rename {pictures => Manual/pictures}/XFplot.png (100%) rename {pictures => Manual/pictures}/axisdef.png (100%) rename {pictures => Manual/pictures}/bicycle.png (100%) rename {pictures => Manual/pictures}/communication_overview.png (100%) rename {pictures => Manual/pictures}/figaudiocode.pdf (100%) rename {pictures => Manual/pictures}/figurejoin.png (100%) rename {pictures => Manual/pictures}/gui_example.png (100%) rename {pictures => Manual/pictures}/header.png (100%) rename {pictures => Manual/pictures}/intro_setup.jpg (100%) rename {pictures => Manual/pictures}/logo.png (100%) rename {pictures => Manual/pictures}/mcu_board.jpg (100%) rename {pictures => Manual/pictures}/potential.png (100%) rename {pictures => Manual/pictures}/potentialfunction.png (100%) rename {pictures => Manual/pictures}/projectBD.png (100%) rename {pictures => Manual/pictures}/projection.png (100%) rename {pictures => Manual/pictures}/scrum_backlog-1.png (100%) rename {pictures => Manual/pictures}/scrum_chart-1.png (100%) rename {pictures => Manual/pictures}/scrum_overview-1.png (100%) rename {pictures => Manual/pictures}/srf02-ultrasonic-sensor.jpg (100%) rename {pictures => Manual/pictures}/steering.png (100%) rename {pictures => Manual/pictures}/steps.png (100%) rename {pictures => Manual/pictures}/systemoverview.png (100%) rename {pictures => Manual/pictures}/systemoverview1.pdf (100%) rename {pictures => Manual/pictures}/test_pic (100%) rename {pictures => Manual/pictures}/trajectory.png (100%) rename {pictures => Manual/pictures}/traxxas_e-maxx.png (100%) rename {pictures => Manual/pictures}/truck.jpg (100%) diff --git a/Manual/0_Table_of_Contents.ipynb b/Manual/0_Table_of_Contents.ipynb index 0eea8e6..9113074 100644 --- a/Manual/0_Table_of_Contents.ipynb +++ b/Manual/0_Table_of_Contents.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "# Table of Contents\n", "\n", "\n", diff --git a/Manual/1_Introduction.ipynb b/Manual/1_Introduction.ipynb index 3835bf6..dc60ccc 100644 --- a/Manual/1_Introduction.ipynb +++ b/Manual/1_Introduction.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "\n", "[Table of Contents](0_Table_of_Contents.ipynb)" ] diff --git a/Manual/2_Module_0.ipynb b/Manual/2_Module_0.ipynb index 1113665..a7417c4 100644 --- a/Manual/2_Module_0.ipynb +++ b/Manual/2_Module_0.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "[Table of Contents](0_Table_of_Contents.ipynb)" ] }, @@ -385,9 +385,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T15:11:05.935756Z", + "start_time": "2025-11-19T15:10:57.041172Z" + } + }, "source": [ "from pynput import keyboard\n", "\n", @@ -408,7 +411,39 @@ "# Setup the listener\n", "with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:\n", " listener.join()" - ] + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Key w pressed\n", + "Key 'w' released\n", + "Special key Key.backspace pressed\n", + "Key Key.backspace released\n", + "Key s pressed\n", + "Key 's' released\n", + "Key s pressed\n", + "Key 's' released\n", + "Key s pressed\n", + "Key 's' released\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "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[1]\u001B[39m\u001B[32m, line 19\u001B[39m\n\u001B[32m 17\u001B[39m \u001B[38;5;66;03m# Setup the listener\u001B[39;00m\n\u001B[32m 18\u001B[39m \u001B[38;5;28;01mwith\u001B[39;00m keyboard.Listener(on_press=on_press, on_release=on_release) \u001B[38;5;28;01mas\u001B[39;00m listener:\n\u001B[32m---> \u001B[39m\u001B[32m19\u001B[39m \u001B[43mlistener\u001B[49m\u001B[43m.\u001B[49m\u001B[43mjoin\u001B[49m\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/pynput/_util/__init__.py:295\u001B[39m, in \u001B[36mAbstractListener.join\u001B[39m\u001B[34m(self, timeout, *args)\u001B[39m\n\u001B[32m 293\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mjoin\u001B[39m(\u001B[38;5;28mself\u001B[39m, timeout=\u001B[38;5;28;01mNone\u001B[39;00m, *args):\n\u001B[32m 294\u001B[39m start = time.time()\n\u001B[32m--> \u001B[39m\u001B[32m295\u001B[39m \u001B[38;5;28;43msuper\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mAbstractListener\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m.\u001B[49m\u001B[43mjoin\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtimeout\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43m*\u001B[49m\u001B[43margs\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 296\u001B[39m timeout = \u001B[38;5;28mmax\u001B[39m(\u001B[32m0.0\u001B[39m, timeout - (time.time() - start)) \\\n\u001B[32m 297\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m timeout \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \\\n\u001B[32m 298\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[32m 300\u001B[39m \u001B[38;5;66;03m# Reraise any exceptions; make sure not to block if a timeout was\u001B[39;00m\n\u001B[32m 301\u001B[39m \u001B[38;5;66;03m# provided\u001B[39;00m\n", + "\u001B[36mFile \u001B[39m\u001B[32m/usr/lib64/python3.13/threading.py:1094\u001B[39m, in \u001B[36mThread.join\u001B[39m\u001B[34m(self, timeout)\u001B[39m\n\u001B[32m 1091\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m timeout \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[32m 1092\u001B[39m timeout = \u001B[38;5;28mmax\u001B[39m(timeout, \u001B[32m0\u001B[39m)\n\u001B[32m-> \u001B[39m\u001B[32m1094\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_handle\u001B[49m\u001B[43m.\u001B[49m\u001B[43mjoin\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtimeout\u001B[49m\u001B[43m)\u001B[49m\n", + "\u001B[31mKeyboardInterrupt\u001B[39m: " + ] + } + ], + "execution_count": 1 }, { "cell_type": "markdown", @@ -437,11 +472,14 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T15:16:17.178643Z", + "start_time": "2025-11-19T15:16:07.116242Z" + } + }, "source": [ - "from KITT_Simulator.serial_simulator import Serial\n", + "from Manual.KITT_Simulator.serial_simulator import Serial\n", "import time\n", "# Open serial port\n", "serial = Serial('/dev/ttyUSB0', 115200)\n", @@ -468,7 +506,35 @@ "\n", "# Close the 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": "187f73460eec4ee189ade521ede30a12" + } + }, + "metadata": {}, + "output_type": "display_data", + "jetTransient": { + "display_id": null + } + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Motors are OFF\n", + "Car is outside the field boundaries!\n" + ] + } + ], + "execution_count": 5 }, { "cell_type": "markdown", diff --git a/Manual/3_Module_1.ipynb b/Manual/3_Module_1.ipynb index 0a5685c..c0be467 100644 --- a/Manual/3_Module_1.ipynb +++ b/Manual/3_Module_1.ipynb @@ -1,10 +1,10 @@ { "cells": [ { - "cell_type": "markdown", "metadata": {}, + "cell_type": "markdown", "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n", "\n", @@ -21,26 +21,29 @@ ] }, { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T17:06:41.856101Z", + "start_time": "2025-11-19T17:06:41.668014Z" + } + }, "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], "source": [ "# Import necessary libraries\n", "import time\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", "\n", "# Uncomment one of the following lines depending on your setup\n", "\n", "# If you are using the real car, uncomment the next line and comment the simulator line\n", - "# from serial import Serial\n", + "#from serial import Serial\n", "\n", "# If you are using the simulator, uncomment the next line and comment the real car line\n", - "from KITT_Simulator.serial_simulator import Serial\n", + "from Manual.KITT_Simulator.serial_simulator import Serial\n", "\n", "# Note: After changing the import statement, you need to restart the kernel for changes to take effect." - ] + ], + "outputs": [], + "execution_count": 1 }, { "cell_type": "markdown", @@ -167,16 +170,19 @@ ] }, { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T17:06:57.927792Z", + "start_time": "2025-11-19T17:06:41.870747Z" + } + }, "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ "### Student Version: play with this! ###\n", "\n", "# Open the serial port with the correct port and baud rate\n", "# Replace '/dev/ttyUSB0' with your actual serial port\n", - "serial = Serial('/path/to/serial/port', 115200)\n", + "serial = Serial('/dev/rfcomm2', 115200)\n", "\n", "# Allow time for any processing delays\n", "time.sleep(1)\n", @@ -187,10 +193,15 @@ "# Use serial.write() to send the direction command to turn left\n", "# Example: serial.write(b'D\\n')\n", "# Hint: To turn left, set the direction value greater than 150 (neutral position)\n", + "\n", + "serial.write(b\"D150\\n\")\n", + "\n", + "serial.write(b\"M160\\n\")\n", + "\n", "print(\"Motors are ON\")\n", "\n", "# Wait for some time to observe the car's movement\n", - "time.sleep(2)\n", + "time.sleep(10)\n", "\n", "# Stop the car by setting motor speed to neutral (150)\n", "# Use serial.write() to send the stop command\n", @@ -202,7 +213,36 @@ "\n", "# 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 }, { "cell_type": "markdown", @@ -262,16 +302,19 @@ ] }, { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T17:07:03.101925Z", + "start_time": "2025-11-19T17:06:58.026789Z" + } + }, "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ "### Student Version ###\n", "\n", "# Open the serial port with the correct port and baud rate\n", "# Replace '/dev/ttyUSB0' with your actual serial port\n", - "serial = Serial('/path/to/serial/port', 115200)\n", + "serial = Serial('/dev/rfcomm2', 115200)\n", "\n", "# Set carrier frequency\n", "# Define the desired carrier frequency in Hz (e.g., 10000)\n", @@ -279,13 +322,14 @@ "# Convert the frequency to bytes (2 bytes, big endian)\n", "carrier_frequency = carrier_frequency_value.to_bytes(2, byteorder='big')\n", "# TODO: Send the 'F' command with the carrier frequency\n", - "\n", + "serial.write(b\"\".join([b\"F\",carrier_frequency,b\"\\n\"]))\n", "# Set bit frequency\n", "# Define the desired bit frequency in Hz (e.g., 5000)\n", "bit_frequency_value = 5000 # Replace with your value\n", "# Convert the bit frequency to bytes\n", "bit_frequency = bit_frequency_value.to_bytes(2, byteorder='big')\n", "# TODO: Send the 'B' command with the bit frequency\n", + "serial.write(b\"\".join([b\"B\",bit_frequency,b\"\\n\"]))\n", "\n", "# Set repetition count\n", "# Calculate the repetition count (should be at least 32)\n", @@ -298,33 +342,65 @@ "repetition_count = repetition_count_value.to_bytes(2, byteorder='big')\n", "# TODO: Send the 'R' command with the repetition count\n", "\n", + "serial.write(b\"\".join([b\"R\",repetition_count,b\"\\n\"]))\n", + "\n", "# Set code pattern\n", "# Define a 32-bit code in hexadecimal (e.g., 0x12345678)\n", - "code_value = 0x12345678 # Replace with your code\n", + "code_value = 0x99999999 # Replace with your code\n", "# Convert the code to bytes (4 bytes, big endian)\n", "code = code_value.to_bytes(4, byteorder='big')\n", "# TODO: Send the 'C' command with the code\n", + "serial.write(b\"\".join([b\"C\",code,b\"\\n\"]))\n", "\n", "# TODO: Allow some time for the settings to take effect\n", - "\n", + "time.sleep(1)\n", "# TODO: Turn the beacon ON by sending the 'A1' command\n", "print(\"Beacon is ON\")\n", - "\n", + "serial.write(b\"A1\\n\")\n", "# Wait while the beacon is on\n", "time.sleep(3)\n", "\n", "# TODO: Turn the beacon OFF by sending the 'A0' command\n", "print(\"Beacon is OFF\")\n", + "serial.write(b\"A0\\n\")\n", "\n", "# Allow some time before closing\n", "time.sleep(1)\n", - "\n", - "# TODO: Very Important! Close the serial connection" - ] + "# 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 }, { - "cell_type": "markdown", "metadata": {}, + "cell_type": "markdown", "source": [ "**Additional Information:**\n", "\n", @@ -370,26 +446,74 @@ ] }, { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T17:07:03.301301Z", + "start_time": "2025-11-19T17:07:03.206413Z" + } + }, "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ "### Student Version ###\n", "\n", "# TODO: Open the serial port with the correct port and baud rate\n", - "\n", + "serial = Serial(\"/dev/rfcomm2\", 115200)\n", "# TODO: Send the status command 'S\\n'\n", - "\n", + "serial.write(b'S\\n')\n", "# TODO: Read the response until the End-of-Transmission character (EOT): '\\x04'\n", - "\n", + "status = serial.read_until(b\"\\x04\")\n", "# TODO: Decode the status information received from the car\n", - "\n", + "status = status.decode(\"utf-8\")\n", "# Print the status information received from the car\n", "print(f\"Car status is:\\n\\n{status}\")\n", "\n", + "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 }, { "cell_type": "markdown", @@ -455,10 +579,13 @@ ] }, { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T17:09:36.903066Z", + "start_time": "2025-11-19T17:09:36.884806Z" + } + }, "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], "source": [ "### Student Version ###\n", "\n", @@ -466,52 +593,80 @@ " def __init__(self, port, baudrate=115200):\n", " # Initialize the serial connection\n", " # self.serial = Serial(port, baudrate, rtscts=True)\n", - " \n", + " self.serial = Serial(port, baudrate,rtscts=True)\n", " # Initialize beacon parameters here using send_command\n", " # Set carrier frequency, bit frequency, repetition count, and code pattern\n", - " pass # Replace with actual initialization code\n", + " carrier_frequency_value = 10000\n", + " carrier_frequency = carrier_frequency_value.to_bytes(2, byteorder='big')\n", + " self.send_command(str(b\"\".join([b\"F\",carrier_frequency,b\"\\n\"])))\n", + "\n", + "\n", + " bit_frequency_value = 5000\n", + " bit_frequency = bit_frequency_value.to_bytes(2, byteorder='big')\n", + " self.send_command(str(b\"\".join([b\"B\",bit_frequency,b\"\\n\"])))\n", + "\n", + "\n", + " desired_repetition_frequency = 2 # Replace with your value\n", + " repetition_count_value = bit_frequency_value // desired_repetition_frequency\n", + " repetition_count = repetition_count_value.to_bytes(2, byteorder='big')\n", + " # Ensure repetition_count_value is at least 32\n", + " repetition_count_value = max(repetition_count_value, 32)\n", + " repetition_count = repetition_count_value.to_bytes(2, byteorder='big')\n", + " self.send_command(str(b\"\".join([b\"R\",repetition_count,b\"\\n\"])))\n", + "\n", + " code_value = 0x99999999 # Replace with your code\n", + " code = code_value.to_bytes(4, byteorder='big')\n", + " self.send_command(str(b\"\".join([b\"C\",code,b\"\\n\"])))\n", "\n", " def send_command(self, command):\n", " # Send the command string over the serial connection\n", " self.serial.write(command.encode())\n", - " pass\n", + "\n", "\n", " def set_speed(self, speed):\n", " # Send the motor speed command using send_command\n", " # Use the format 'M\\n'\n", - " pass\n", + " self.send_command(f\"M{speed}\\n\")\n", + "\n", "\n", " def set_angle(self, angle):\n", " # Send the steering angle command using send_command\n", " # Use the format 'D\\n'\n", - " pass\n", + " self.send_command(f\"D{angle}\\n\")\n", + "\n", "\n", " def stop(self):\n", " # Stop the car by setting speed and angle to neutral (150)\n", " # Call set_speed and set_angle with 150\n", - " pass\n", + " self.set_speed(150)\n", + " self.set_angle(150)\n", "\n", " def start_beacon(self):\n", " # Send commands to start the beacon\n", " # Use the command 'A1\\n'\n", - " pass\n", + " self.send_command(str(b\"A1\\n\"))\n", "\n", " def stop_beacon(self):\n", " # Send commands to stop the beacon\n", " # Use the command 'A0\\n'\n", - " pass\n", + " self.send_command(str(b\"A0\\n\"))\n", "\n", " def close(self):\n", " # Close the serial connection\n", " # self.serial.close()\n", - " pass" - ] + " self.serial.close()\n" + ], + "outputs": [], + "execution_count": 11 }, { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T17:15:34.819411Z", + "start_time": "2025-11-19T17:15:34.810196Z" + } + }, "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], "source": [ "### Student Version ###\n", "\n", @@ -525,6 +680,21 @@ " while True:\n", " # Read input from the user\n", " command = input(\"Enter command: \").lower()\n", + " if command == \"w\":\n", + " car_speed = car_speed + 5\n", + " elif command == \"s\":\n", + " car_speed -=5\n", + " elif command == \"a\":\n", + " car_steering +=5\n", + " elif command == \"d\":\n", + " car_steering -=5\n", + " elif command == \"e\":\n", + " kitt.start_beacon()\n", + " elif command == \"r\":\n", + " kitt.stop_beacon()\n", + " elif command == \"q\":\n", + " kitt.close()\n", + " break\n", "\n", " # TODO: depending on the command, adjust the car speed, steering angle, or start/stop the beacon variable\n", "\n", @@ -543,28 +713,60 @@ " # Ensure the car is stopped and serial connection is closed\n", " kitt.stop()\n", " kitt.close()" - ] + ], + "outputs": [], + "execution_count": 14 }, { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-19T17:15:43.089078Z", + "start_time": "2025-11-19T17:15:36.212088Z" + } + }, "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ "### Student Version ###\n", "\n", "if __name__ == \"__main__\":\n", " # Create an instance of KITT with the correct serial port\n", " # Replace '/dev/ttyUSB0' with your actual serial port\n", - " kitt = KITT('/path/to/serial/port') # Replace with the actual port\n", + " kitt = KITT('/dev/rfcomm2') # Replace with the actual port\n", "\n", " # Start the control function\n", " wasd_control(kitt)" - ] + ], + "outputs": [ + { + "data": { + "text/plain": [ + "Canvas(height=520, width=520)" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "4498f99b8dbd43e895b0854ee6ddf7be" + } + }, + "metadata": {}, + "output_type": "display_data", + "jetTransient": { + "display_id": null + } + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Control the car with W (forward), S (backward), A (left), D (right), E (start beacon), R (stop beacon), and Q (to exit).\n" + ] + } + ], + "execution_count": 15 }, { - "cell_type": "markdown", "metadata": {}, + "cell_type": "markdown", "source": [ "#### Test the Code with the Real Car\n", "\n", @@ -592,10 +794,10 @@ ] }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "cell_type": "code", "outputs": [], + "execution_count": null, "source": [ "import serial.tools.list_ports\n", "\n", diff --git a/Manual/4_Module_2.ipynb b/Manual/4_Module_2.ipynb index 5bda07e..210c52f 100644 --- a/Manual/4_Module_2.ipynb +++ b/Manual/4_Module_2.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n", "\n", @@ -28,7 +28,6 @@ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", - "import csv\n", "\n", "# Uncomment one of the following lines depending on your setup\n", "\n", @@ -37,8 +36,7 @@ "# import sounddevice\n", "\n", "# If you are using the simulator, uncomment the next lines and comment the real car lines\n", - "from KITT_Simulator.serial_simulator import Serial\n", - "from KITT_Simulator.sounddevice_simulator import sounddevice\n", + "from Manual.KITT_Simulator.sounddevice_simulator import sounddevice\n", "\n", "# Note: After changing the import statement, you need to restart the kernel for changes to take effect." ] diff --git a/Manual/5_Module_3.ipynb b/Manual/5_Module_3.ipynb index 0439802..1545486 100644 --- a/Manual/5_Module_3.ipynb +++ b/Manual/5_Module_3.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n", "\n", @@ -34,9 +34,6 @@ "import matplotlib.pyplot as plt # For plotting purposes\n", "import numpy as np # For convolution function\n", "from scipy.io import wavfile\n", - "from scipy.signal import find_peaks\n", - "import time\n", - "from scipy.fft import fft, ifft\n", "\n", "# Uncomment one of the following lines depending on your setup\n", "\n", @@ -45,8 +42,6 @@ "# from sounddevice import sounddevice\n", "\n", "# If you are using the simulator, uncomment the next lines and comment the real car lines\n", - "from KITT_Simulator.serial_simulator import Serial\n", - "from KITT_Simulator.sounddevice_simulator import sounddevice\n", "\n", "# Note: After changing the import statement, you need to restart the kernel for changes to take effect." ] @@ -685,12 +680,8 @@ "source": [ "### Student Version ###\n", "\n", - "from scipy.io import wavfile\n", - "import logging\n", - "import scipy.signal as signal\n", - "from scipy.fft import fft, ifft\n", "import numpy as np\n", - "import matplotlib.pyplot as plt\n", + "\n", "\n", "class Localization:\n", " \"\"\"\n", diff --git a/Manual/6_Module_4.ipynb b/Manual/6_Module_4.ipynb index 0724e3c..98bbc3a 100644 --- a/Manual/6_Module_4.ipynb +++ b/Manual/6_Module_4.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n", "\n", @@ -23,7 +23,6 @@ "outputs": [], "source": [ "# Import necessary libraries\n", - "import time\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", @@ -33,7 +32,6 @@ "# from serial import Serial\n", "\n", "# If you are using the simulator, uncomment the next line and comment the real car line\n", - "from KITT_Simulator.serial_simulator import Serial\n", "\n", "# Note: After changing the import statement, you need to restart the kernel for changes to take effect." ] diff --git a/Manual/7_Midterm_Report.ipynb b/Manual/7_Midterm_Report.ipynb index c9da081..5b13478 100644 --- a/Manual/7_Midterm_Report.ipynb +++ b/Manual/7_Midterm_Report.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "[Table of Contents](0_Table_of_Contents.ipynb)" ] }, diff --git a/Manual/8_Module_5.ipynb b/Manual/8_Module_5.ipynb index 67bf78d..86520b9 100644 --- a/Manual/8_Module_5.ipynb +++ b/Manual/8_Module_5.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![book header](../pictures/header.png)\n", + "![book header](pictures/header.png)\n", "\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n", "\n", @@ -283,7 +283,7 @@ "\n", "The figure below is a example depiction of the Challenges (*On the old television series, KARR is the archenemy of KITT*)\n", "\n", - "![alt text](../pictures/FinalChallenge.png)\n", + "![alt text](pictures/FinalChallenge.png)\n", "\n", "\n" ] diff --git a/KITT_Simulator/GUI/car.png b/Manual/KITT_Simulator/GUI/car.png similarity index 100% rename from KITT_Simulator/GUI/car.png rename to Manual/KITT_Simulator/GUI/car.png diff --git a/KITT_Simulator/GUI/explosion.png b/Manual/KITT_Simulator/GUI/explosion.png similarity index 100% rename from KITT_Simulator/GUI/explosion.png rename to Manual/KITT_Simulator/GUI/explosion.png diff --git a/KITT_Simulator/dynamics_simulator.py b/Manual/KITT_Simulator/dynamics_simulator.py similarity index 100% rename from KITT_Simulator/dynamics_simulator.py rename to Manual/KITT_Simulator/dynamics_simulator.py diff --git a/KITT_Simulator/gui.py b/Manual/KITT_Simulator/gui.py similarity index 100% rename from KITT_Simulator/gui.py rename to Manual/KITT_Simulator/gui.py diff --git a/KITT_Simulator/gui_tester.ipynb b/Manual/KITT_Simulator/gui_tester.ipynb similarity index 92% rename from KITT_Simulator/gui_tester.ipynb rename to Manual/KITT_Simulator/gui_tester.ipynb index 8fc9261..c3c17ea 100644 --- a/KITT_Simulator/gui_tester.ipynb +++ b/Manual/KITT_Simulator/gui_tester.ipynb @@ -6,8 +6,8 @@ "metadata": {}, "outputs": [], "source": [ - "from gui import GUI\n", - "from shared_state import SharedState\n", + "from Manual.KITT_Simulator.gui import GUI\n", + "from Manual.KITT_Simulator.shared_state import SharedState\n", "\n", "import time\n", "import numpy as np" diff --git a/KITT_Simulator/serial_simulator.py b/Manual/KITT_Simulator/serial_simulator.py similarity index 95% rename from KITT_Simulator/serial_simulator.py rename to Manual/KITT_Simulator/serial_simulator.py index 79f91f2..26ee2da 100644 --- a/KITT_Simulator/serial_simulator.py +++ b/Manual/KITT_Simulator/serial_simulator.py @@ -1,14 +1,11 @@ import time import threading import numpy as np -import matplotlib.pyplot as plt import logging -import queue # Import queue to handle inter-thread communication - -from KITT_Simulator.shared_state import SharedState -from KITT_Simulator.gui import GUI -from KITT_Simulator.dynamics_simulator import Dynamics +from Manual.KITT_Simulator.shared_state import SharedState +from Manual.KITT_Simulator.gui import GUI +from Manual.KITT_Simulator.dynamics_simulator import Dynamics # try: # from KITT_Simulator.shared_state import SharedState diff --git a/KITT_Simulator/shared_state.py b/Manual/KITT_Simulator/shared_state.py similarity index 100% rename from KITT_Simulator/shared_state.py rename to Manual/KITT_Simulator/shared_state.py diff --git a/KITT_Simulator/simulator_data/motor_parameters.txt b/Manual/KITT_Simulator/simulator_data/motor_parameters.txt similarity index 100% rename from KITT_Simulator/simulator_data/motor_parameters.txt rename to Manual/KITT_Simulator/simulator_data/motor_parameters.txt diff --git a/KITT_Simulator/simulator_data/pulses_recording.txt b/Manual/KITT_Simulator/simulator_data/pulses_recording.txt similarity index 100% rename from KITT_Simulator/simulator_data/pulses_recording.txt rename to Manual/KITT_Simulator/simulator_data/pulses_recording.txt diff --git a/KITT_Simulator/simulator_data/servo_parameters.txt b/Manual/KITT_Simulator/simulator_data/servo_parameters.txt similarity index 100% rename from KITT_Simulator/simulator_data/servo_parameters.txt rename to Manual/KITT_Simulator/simulator_data/servo_parameters.txt diff --git a/KITT_Simulator/simulator_data/silence.txt b/Manual/KITT_Simulator/simulator_data/silence.txt similarity index 100% rename from KITT_Simulator/simulator_data/silence.txt rename to Manual/KITT_Simulator/simulator_data/silence.txt diff --git a/KITT_Simulator/sounddevice_simulator.py b/Manual/KITT_Simulator/sounddevice_simulator.py similarity index 97% rename from KITT_Simulator/sounddevice_simulator.py rename to Manual/KITT_Simulator/sounddevice_simulator.py index c5534f5..98d5a34 100644 --- a/KITT_Simulator/sounddevice_simulator.py +++ b/Manual/KITT_Simulator/sounddevice_simulator.py @@ -1,9 +1,8 @@ -import time as time import numpy as np import matplotlib.pyplot as plt try: - from KITT_Simulator.shared_state import SharedState + from Manual.KITT_Simulator.shared_state import SharedState except: from shared_state import SharedState diff --git a/pictures/Ackermann-steering-geometry-for-the-front-steer-angles-of-the-inner-and-outer-wheels.png b/Manual/pictures/Ackermann-steering-geometry-for-the-front-steer-angles-of-the-inner-and-outer-wheels.png similarity index 100% rename from pictures/Ackermann-steering-geometry-for-the-front-steer-angles-of-the-inner-and-outer-wheels.png rename to Manual/pictures/Ackermann-steering-geometry-for-the-front-steer-angles-of-the-inner-and-outer-wheels.png diff --git a/pictures/Beacon.png b/Manual/pictures/Beacon.png similarity index 100% rename from pictures/Beacon.png rename to Manual/pictures/Beacon.png diff --git a/pictures/FinalChallenge.png b/Manual/pictures/FinalChallenge.png similarity index 100% rename from pictures/FinalChallenge.png rename to Manual/pictures/FinalChallenge.png diff --git a/pictures/KITT_leds.png b/Manual/pictures/KITT_leds.png similarity index 100% rename from pictures/KITT_leds.png rename to Manual/pictures/KITT_leds.png diff --git a/pictures/KITTwind.jpg b/Manual/pictures/KITTwind.jpg similarity index 100% rename from pictures/KITTwind.jpg rename to Manual/pictures/KITTwind.jpg diff --git a/pictures/Step1.PNG b/Manual/pictures/Step1.PNG similarity index 100% rename from pictures/Step1.PNG rename to Manual/pictures/Step1.PNG diff --git a/pictures/Step2.PNG b/Manual/pictures/Step2.PNG similarity index 100% rename from pictures/Step2.PNG rename to Manual/pictures/Step2.PNG diff --git a/pictures/Step3.PNG b/Manual/pictures/Step3.PNG similarity index 100% rename from pictures/Step3.PNG rename to Manual/pictures/Step3.PNG diff --git a/pictures/Step4.PNG b/Manual/pictures/Step4.PNG similarity index 100% rename from pictures/Step4.PNG rename to Manual/pictures/Step4.PNG diff --git a/pictures/Step5.PNG b/Manual/pictures/Step5.PNG similarity index 100% rename from pictures/Step5.PNG rename to Manual/pictures/Step5.PNG diff --git a/pictures/Step6.PNG b/Manual/pictures/Step6.PNG similarity index 100% rename from pictures/Step6.PNG rename to Manual/pictures/Step6.PNG diff --git a/pictures/Step6Arrow.png b/Manual/pictures/Step6Arrow.png similarity index 100% rename from pictures/Step6Arrow.png rename to Manual/pictures/Step6Arrow.png diff --git a/pictures/Step7.PNG b/Manual/pictures/Step7.PNG similarity index 100% rename from pictures/Step7.PNG rename to Manual/pictures/Step7.PNG diff --git a/pictures/TDOA.png b/Manual/pictures/TDOA.png similarity index 100% rename from pictures/TDOA.png rename to Manual/pictures/TDOA.png diff --git a/pictures/XFplot.png b/Manual/pictures/XFplot.png similarity index 100% rename from pictures/XFplot.png rename to Manual/pictures/XFplot.png diff --git a/pictures/axisdef.png b/Manual/pictures/axisdef.png similarity index 100% rename from pictures/axisdef.png rename to Manual/pictures/axisdef.png diff --git a/pictures/bicycle.png b/Manual/pictures/bicycle.png similarity index 100% rename from pictures/bicycle.png rename to Manual/pictures/bicycle.png diff --git a/pictures/communication_overview.png b/Manual/pictures/communication_overview.png similarity index 100% rename from pictures/communication_overview.png rename to Manual/pictures/communication_overview.png diff --git a/pictures/figaudiocode.pdf b/Manual/pictures/figaudiocode.pdf similarity index 100% rename from pictures/figaudiocode.pdf rename to Manual/pictures/figaudiocode.pdf diff --git a/pictures/figurejoin.png b/Manual/pictures/figurejoin.png similarity index 100% rename from pictures/figurejoin.png rename to Manual/pictures/figurejoin.png diff --git a/pictures/gui_example.png b/Manual/pictures/gui_example.png similarity index 100% rename from pictures/gui_example.png rename to Manual/pictures/gui_example.png diff --git a/pictures/header.png b/Manual/pictures/header.png similarity index 100% rename from pictures/header.png rename to Manual/pictures/header.png diff --git a/pictures/intro_setup.jpg b/Manual/pictures/intro_setup.jpg similarity index 100% rename from pictures/intro_setup.jpg rename to Manual/pictures/intro_setup.jpg diff --git a/pictures/logo.png b/Manual/pictures/logo.png similarity index 100% rename from pictures/logo.png rename to Manual/pictures/logo.png diff --git a/pictures/mcu_board.jpg b/Manual/pictures/mcu_board.jpg similarity index 100% rename from pictures/mcu_board.jpg rename to Manual/pictures/mcu_board.jpg diff --git a/pictures/potential.png b/Manual/pictures/potential.png similarity index 100% rename from pictures/potential.png rename to Manual/pictures/potential.png diff --git a/pictures/potentialfunction.png b/Manual/pictures/potentialfunction.png similarity index 100% rename from pictures/potentialfunction.png rename to Manual/pictures/potentialfunction.png diff --git a/pictures/projectBD.png b/Manual/pictures/projectBD.png similarity index 100% rename from pictures/projectBD.png rename to Manual/pictures/projectBD.png diff --git a/pictures/projection.png b/Manual/pictures/projection.png similarity index 100% rename from pictures/projection.png rename to Manual/pictures/projection.png diff --git a/pictures/scrum_backlog-1.png b/Manual/pictures/scrum_backlog-1.png similarity index 100% rename from pictures/scrum_backlog-1.png rename to Manual/pictures/scrum_backlog-1.png diff --git a/pictures/scrum_chart-1.png b/Manual/pictures/scrum_chart-1.png similarity index 100% rename from pictures/scrum_chart-1.png rename to Manual/pictures/scrum_chart-1.png diff --git a/pictures/scrum_overview-1.png b/Manual/pictures/scrum_overview-1.png similarity index 100% rename from pictures/scrum_overview-1.png rename to Manual/pictures/scrum_overview-1.png diff --git a/pictures/srf02-ultrasonic-sensor.jpg b/Manual/pictures/srf02-ultrasonic-sensor.jpg similarity index 100% rename from pictures/srf02-ultrasonic-sensor.jpg rename to Manual/pictures/srf02-ultrasonic-sensor.jpg diff --git a/pictures/steering.png b/Manual/pictures/steering.png similarity index 100% rename from pictures/steering.png rename to Manual/pictures/steering.png diff --git a/pictures/steps.png b/Manual/pictures/steps.png similarity index 100% rename from pictures/steps.png rename to Manual/pictures/steps.png diff --git a/pictures/systemoverview.png b/Manual/pictures/systemoverview.png similarity index 100% rename from pictures/systemoverview.png rename to Manual/pictures/systemoverview.png diff --git a/pictures/systemoverview1.pdf b/Manual/pictures/systemoverview1.pdf similarity index 100% rename from pictures/systemoverview1.pdf rename to Manual/pictures/systemoverview1.pdf diff --git a/pictures/test_pic b/Manual/pictures/test_pic similarity index 100% rename from pictures/test_pic rename to Manual/pictures/test_pic diff --git a/pictures/trajectory.png b/Manual/pictures/trajectory.png similarity index 100% rename from pictures/trajectory.png rename to Manual/pictures/trajectory.png diff --git a/pictures/traxxas_e-maxx.png b/Manual/pictures/traxxas_e-maxx.png similarity index 100% rename from pictures/traxxas_e-maxx.png rename to Manual/pictures/traxxas_e-maxx.png diff --git a/pictures/truck.jpg b/Manual/pictures/truck.jpg similarity index 100% rename from pictures/truck.jpg rename to Manual/pictures/truck.jpg diff --git a/appendix/0_Installation_Linux.ipynb b/appendix/0_Installation_Linux.ipynb index 84f8756..3a35b99 100644 --- a/appendix/0_Installation_Linux.ipynb +++ b/appendix/0_Installation_Linux.ipynb @@ -3,9 +3,7 @@ { "cell_type": "markdown", "metadata": {}, - "source": [ - "![book header](../pictures/header.png)" - ] + "source": "![book header](../Manual/pictures/header.png)" }, { "cell_type": "markdown", diff --git a/appendix/0_Installation_Mac.ipynb b/appendix/0_Installation_Mac.ipynb index f7ce9f4..6fe8600 100644 --- a/appendix/0_Installation_Mac.ipynb +++ b/appendix/0_Installation_Mac.ipynb @@ -3,9 +3,7 @@ { "cell_type": "markdown", "metadata": {}, - "source": [ - "![book header](../pictures/header.png)" - ] + "source": "![book header](../Manual/pictures/header.png)" }, { "cell_type": "markdown", diff --git a/appendix/0_Installation_Windows.ipynb b/appendix/0_Installation_Windows.ipynb index d9a18d2..00e60bb 100644 --- a/appendix/0_Installation_Windows.ipynb +++ b/appendix/0_Installation_Windows.ipynb @@ -3,9 +3,7 @@ { "cell_type": "markdown", "metadata": {}, - "source": [ - "![book header](../pictures/header.png)" - ] + "source": "![book header](../Manual/pictures/header.png)" }, { "cell_type": "markdown", diff --git a/requirements.txt b/requirements.txt index 8cad1da..9797fe5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +pynput jupyter-book matplotlib numpy From a7c2e64d9cb1f5278240e9f2b460694ef3f1cc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicholas=20St=C4=83nescu?= Date: Thu, 20 Nov 2025 16:35:06 +0100 Subject: [PATCH 2/3] fixed the beacon not starting --- Manual/3_Module_1.ipynb | 230 +++++++++++++++------------------------- 1 file changed, 88 insertions(+), 142 deletions(-) diff --git a/Manual/3_Module_1.ipynb b/Manual/3_Module_1.ipynb index c0be467..2cc342e 100644 --- a/Manual/3_Module_1.ipynb +++ b/Manual/3_Module_1.ipynb @@ -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", From b0a21852cb238116de437a176712721d24f0b8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicholas=20St=C4=83nescu?= Date: Fri, 21 Nov 2025 11:30:32 +0100 Subject: [PATCH 3/3] fully working :tada: --- Manual/3_Module_1.ipynb | 221 ++++++++++++++++++++++++++++------------ 1 file changed, 154 insertions(+), 67 deletions(-) diff --git a/Manual/3_Module_1.ipynb b/Manual/3_Module_1.ipynb index 2cc342e..a931145 100644 --- a/Manual/3_Module_1.ipynb +++ b/Manual/3_Module_1.ipynb @@ -21,7 +21,12 @@ ] }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-21T09:42:15.154065Z", + "start_time": "2025-11-21T09:42:15.133482Z" + } + }, "cell_type": "code", "source": [ "# Import necessary libraries\n", @@ -30,15 +35,15 @@ "# Uncomment one of the following lines depending on your setup\n", "\n", "# If you are using the real car, uncomment the next line and comment the simulator line\n", - "#from serial import Serial\n", + "from serial import Serial\n", "\n", "# If you are using the simulator, uncomment the next line and comment the real car line\n", - "from Manual.KITT_Simulator.serial_simulator import Serial\n", + "#from Manual.KITT_Simulator.serial_simulator import Serial\n", "\n", "# Note: After changing the import statement, you need to restart the kernel for changes to take effect." ], "outputs": [], - "execution_count": null + "execution_count": 8 }, { "cell_type": "markdown", @@ -165,7 +170,12 @@ ] }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-21T09:38:49.876306Z", + "start_time": "2025-11-21T09:38:33.768247Z" + } + }, "cell_type": "code", "source": [ "### Student Version: play with this! ###\n", @@ -204,8 +214,35 @@ "# Close the serial connection (important!)\n", "serial.close()" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "data": { + "text/plain": [ + "Canvas(height=520, width=520)" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "2d74e35cf2874410947b571c2686a44f" + } + }, + "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 }, { "cell_type": "markdown", @@ -265,7 +302,12 @@ ] }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-21T09:56:34.612180Z", + "start_time": "2025-11-21T09:56:29.551624Z" + } + }, "cell_type": "code", "source": [ "### Student Version ###\n", @@ -279,6 +321,7 @@ "carrier_frequency_value = 10000 # Replace with your value\n", "# Convert the frequency to bytes (2 bytes, big endian)\n", "carrier_frequency = carrier_frequency_value.to_bytes(2, byteorder='big')\n", + "\n", "# TODO: Send the 'F' command with the carrier frequency\n", "serial.write(b\"\".join([b\"F\",carrier_frequency,b\"\\n\"]))\n", "# Set bit frequency\n", @@ -327,8 +370,17 @@ "# TODO: Very Important! Close the serial connection\n", "serial.close()\n" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Beacon is ON\n", + "Beacon is OFF\n" + ] + } + ], + "execution_count": 37 }, { "metadata": {}, @@ -378,7 +430,12 @@ ] }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-21T09:38:55.176015Z", + "start_time": "2025-11-21T09:38:55.092901Z" + } + }, "cell_type": "code", "source": [ "### Student Version ###\n", @@ -397,8 +454,50 @@ "serial.close()\n", "# TODO: Close the serial connection (important!)" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "data": { + "text/plain": [ + "Canvas(height=520, width=520)" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "3017800da43140a2b518e020dcce5af4" + } + }, + "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 }, { "cell_type": "markdown", @@ -466,8 +565,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-11-19T20:47:25.030226Z", - "start_time": "2025-11-19T20:47:25.017941Z" + "end_time": "2025-11-21T10:27:10.276766Z", + "start_time": "2025-11-21T10:27:10.272096Z" } }, "cell_type": "code", @@ -483,12 +582,12 @@ " # Set carrier frequency, bit frequency, repetition count, and code pattern\n", " carrier_frequency_value = 10000\n", " carrier_frequency = carrier_frequency_value.to_bytes(2, byteorder='big')\n", - " self.send_command(str(b\"\".join([b\"F\",carrier_frequency,b\"\\n\"])))\n", + " self.send_command(b\"F\"+carrier_frequency+b\"\\n\")\n", "\n", "\n", " bit_frequency_value = 5000\n", " bit_frequency = bit_frequency_value.to_bytes(2, byteorder='big')\n", - " self.send_command(str(b\"\".join([b\"B\",bit_frequency,b\"\\n\"])))\n", + " self.send_command(b\"B\"+bit_frequency+b\"\\n\")\n", "\n", "\n", " desired_repetition_frequency = 2 # Replace with your value\n", @@ -497,27 +596,27 @@ " # Ensure repetition_count_value is at least 32\n", " repetition_count_value = max(repetition_count_value, 32)\n", " repetition_count = repetition_count_value.to_bytes(2, byteorder='big')\n", - " self.send_command(str(b\"\".join([b\"R\",repetition_count,b\"\\n\"])))\n", + " self.send_command(b\"R\"+repetition_count+b\"\\n\")\n", "\n", - " code_value = 0x99999999 # Replace with your code\n", + " code_value = 0x67676767 # Replace with your code\n", " code = code_value.to_bytes(4, byteorder='big')\n", - " self.send_command(str(b\"\".join([b\"C\",code,b\"\\n\"])))\n", + " self.send_command(b\"C\"+code+b\"\\n\")\n", "\n", " def send_command(self, command):\n", " # Send the command string over the serial connection\n", - " self.serial.write(command.encode())\n", - "\n", + " self.serial.write(command)\n", + " print(command)\n", "\n", " def set_speed(self, speed):\n", " # Send the motor speed command using send_command\n", " # Use the format 'M\\n'\n", - " self.send_command(f\"M{speed}\\n\")\n", + " self.send_command(f\"M{speed}\\n\".encode())\n", "\n", "\n", " def set_angle(self, angle):\n", " # Send the steering angle command using send_command\n", " # Use the format 'D\\n'\n", - " self.send_command(f\"D{angle}\\n\")\n", + " self.send_command(f\"D{angle}\\n\".encode())\n", "\n", "\n", " def stop(self):\n", @@ -529,12 +628,12 @@ " def start_beacon(self):\n", " # Send commands to start the beacon\n", " # Use the command 'A1\\n'\n", - " self.send_command(\"A1\\n\")\n", + " self.send_command(b\"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(\"A0\\n\")\n", + " self.send_command(b\"A0\\n\")\n", "\n", " def close(self):\n", " # Close the serial connection\n", @@ -542,13 +641,13 @@ " self.serial.close()\n" ], "outputs": [], - "execution_count": 20 + "execution_count": 44 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-11-19T20:47:26.839827Z", - "start_time": "2025-11-19T20:47:26.826565Z" + "end_time": "2025-11-21T10:27:11.326406Z", + "start_time": "2025-11-21T10:27:11.323674Z" } }, "cell_type": "code", @@ -578,7 +677,6 @@ " elif command == \"r\":\n", " kitt.stop_beacon()\n", " elif command == \"q\":\n", - " kitt.close()\n", " break\n", "\n", " # TODO: depending on the command, adjust the car speed, steering angle, or start/stop the beacon variable\n", @@ -600,13 +698,13 @@ " kitt.close()" ], "outputs": [], - "execution_count": 21 + "execution_count": 45 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-11-19T20:47:41.559047Z", - "start_time": "2025-11-19T20:47:30.566425Z" + "end_time": "2025-11-21T10:29:28.965385Z", + "start_time": "2025-11-21T10:29:01.281710Z" } }, "cell_type": "code", @@ -622,46 +720,35 @@ " wasd_control(kitt)" ], "outputs": [ - { - "data": { - "text/plain": [ - "Canvas(height=520, width=520)" - ], - "application/vnd.jupyter.widget-view+json": { - "version_major": 2, - "version_minor": 0, - "model_id": "bf6b02cc69244330a431bf392738a083" - } - }, - "metadata": {}, - "output_type": "display_data", - "jetTransient": { - "display_id": null - } - }, { "name": "stdout", "output_type": "stream", "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" + "b\"F'\\x10\\n\"\n", + "b'B\\x13\\x88\\n'\n", + "b'R\\t\\xc4\\n'\n", + "b'Cgggg\\n'\n", + "Control the car with W (forward), S (backward), A (left), D (right), E (start beacon), R (stop beacon), and Q (to exit).\n", + "b'M150\\n'\n", + "b'D145\\n'\n", + "b'M150\\n'\n", + "b'D140\\n'\n", + "b'M150\\n'\n", + "b'D135\\n'\n", + "b'M150\\n'\n", + "b'D130\\n'\n", + "b'M150\\n'\n", + "b'D125\\n'\n", + "b'M145\\n'\n", + "b'D125\\n'\n", + "b'M140\\n'\n", + "b'D125\\n'\n", + "b'M150\\n'\n", + "b'D150\\n'\n" ] } ], - "execution_count": 22 + "execution_count": 50 }, { "metadata": {}, @@ -695,7 +782,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-11-19T19:27:44.069076Z", + "end_time": "2025-11-21T09:39:10.749553211Z", "start_time": "2025-11-19T19:27:44.033559Z" } },