Merge branch 'module_1' into 'main'

Module 1 done

See merge request ee2l1/2025-2026/A.K.03!2
This commit is contained in:
Thijs Driessen 2025-11-21 11:32:13 +01:00
commit 435ac987c9
66 changed files with 395 additions and 116 deletions

View File

@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"# Table of Contents\n", "# Table of Contents\n",
"\n", "\n",
"\n", "\n",

View File

@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"\n", "\n",
"[Table of Contents](0_Table_of_Contents.ipynb)" "[Table of Contents](0_Table_of_Contents.ipynb)"
] ]

View File

@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"[Table of Contents](0_Table_of_Contents.ipynb)" "[Table of Contents](0_Table_of_Contents.ipynb)"
] ]
}, },
@ -385,9 +385,12 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "metadata": {
"metadata": {}, "ExecuteTime": {
"outputs": [], "end_time": "2025-11-19T15:11:05.935756Z",
"start_time": "2025-11-19T15:10:57.041172Z"
}
},
"source": [ "source": [
"from pynput import keyboard\n", "from pynput import keyboard\n",
"\n", "\n",
@ -408,8 +411,40 @@
"# Setup the listener\n", "# Setup the listener\n",
"with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:\n", "with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:\n",
" listener.join()" " 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", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -437,11 +472,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "metadata": {
"metadata": {}, "ExecuteTime": {
"outputs": [], "end_time": "2025-11-19T15:16:17.178643Z",
"start_time": "2025-11-19T15:16:07.116242Z"
}
},
"source": [ "source": [
"from KITT_Simulator.serial_simulator import Serial\n", "from Manual.KITT_Simulator.serial_simulator import Serial\n",
"import time\n", "import time\n",
"# Open serial port\n", "# Open serial port\n",
"serial = Serial('/dev/ttyUSB0', 115200)\n", "serial = Serial('/dev/ttyUSB0', 115200)\n",
@ -468,7 +506,35 @@
"\n", "\n",
"# Close the connection (important!)\n", "# Close the connection (important!)\n",
"serial.close()" "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", "cell_type": "markdown",

View File

@ -1,10 +1,10 @@
{ {
"cells": [ "cells": [
{ {
"cell_type": "markdown",
"metadata": {}, "metadata": {},
"cell_type": "markdown",
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"\n", "\n",
"[Table of Contents](0_Table_of_Contents.ipynb)\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n",
"\n", "\n",
@ -21,26 +21,29 @@
] ]
}, },
{ {
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-21T09:42:15.154065Z",
"start_time": "2025-11-21T09:42:15.133482Z"
}
},
"cell_type": "code", "cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [ "source": [
"# Import necessary libraries\n", "# Import necessary libraries\n",
"import time\n", "import time\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n", "\n",
"# Uncomment one of the following lines depending on your setup\n", "# Uncomment one of the following lines depending on your setup\n",
"\n", "\n",
"# If you are using the real car, uncomment the next line and comment the simulator line\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", "\n",
"# If you are using the simulator, uncomment the next line and comment the real car line\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", "\n",
"# Note: After changing the import statement, you need to restart the kernel for changes to take effect." "# Note: After changing the import statement, you need to restart the kernel for changes to take effect."
] ],
"outputs": [],
"execution_count": 8
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -167,16 +170,19 @@
] ]
}, },
{ {
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-21T09:38:49.876306Z",
"start_time": "2025-11-21T09:38:33.768247Z"
}
},
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [ "source": [
"### Student Version: play with this! ###\n", "### Student Version: play with this! ###\n",
"\n", "\n",
"# Open the serial port with the correct port and baud rate\n", "# Open the serial port with the correct port and baud rate\n",
"# Replace '/dev/ttyUSB0' with your actual serial port\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", "\n",
"# Allow time for any processing delays\n", "# Allow time for any processing delays\n",
"time.sleep(1)\n", "time.sleep(1)\n",
@ -187,10 +193,15 @@
"# Use serial.write() to send the direction command to turn left\n", "# Use serial.write() to send the direction command to turn left\n",
"# Example: serial.write(b'D<direction_value>\\n')\n", "# Example: serial.write(b'D<direction_value>\\n')\n",
"# Hint: To turn left, set the direction value greater than 150 (neutral position)\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", "print(\"Motors are ON\")\n",
"\n", "\n",
"# Wait for some time to observe the car's movement\n", "# Wait for some time to observe the car's movement\n",
"time.sleep(2)\n", "time.sleep(10)\n",
"\n", "\n",
"# Stop the car by setting motor speed to neutral (150)\n", "# Stop the car by setting motor speed to neutral (150)\n",
"# Use serial.write() to send the stop command\n", "# Use serial.write() to send the stop command\n",
@ -202,7 +213,36 @@
"\n", "\n",
"# Close the serial connection (important!)\n", "# Close the serial connection (important!)\n",
"serial.close()" "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": "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", "cell_type": "markdown",
@ -262,30 +302,35 @@
] ]
}, },
{ {
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-21T09:56:34.612180Z",
"start_time": "2025-11-21T09:56:29.551624Z"
}
},
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [ "source": [
"### Student Version ###\n", "### Student Version ###\n",
"\n", "\n",
"# Open the serial port with the correct port and baud rate\n", "# Open the serial port with the correct port and baud rate\n",
"# Replace '/dev/ttyUSB0' with your actual serial port\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", "\n",
"# Set carrier frequency\n", "# Set carrier frequency\n",
"# Define the desired carrier frequency in Hz (e.g., 10000)\n", "# Define the desired carrier frequency in Hz (e.g., 10000)\n",
"carrier_frequency_value = 10000 # Replace with your value\n", "carrier_frequency_value = 10000 # Replace with your value\n",
"# Convert the frequency to bytes (2 bytes, big endian)\n", "# Convert the frequency to bytes (2 bytes, big endian)\n",
"carrier_frequency = carrier_frequency_value.to_bytes(2, byteorder='big')\n", "carrier_frequency = carrier_frequency_value.to_bytes(2, byteorder='big')\n",
"# TODO: Send the 'F' command with the carrier frequency\n",
"\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", "# Set bit frequency\n",
"# Define the desired bit frequency in Hz (e.g., 5000)\n", "# Define the desired bit frequency in Hz (e.g., 5000)\n",
"bit_frequency_value = 5000 # Replace with your value\n", "bit_frequency_value = 5000 # Replace with your value\n",
"# Convert the bit frequency to bytes\n", "# Convert the bit frequency to bytes\n",
"bit_frequency = bit_frequency_value.to_bytes(2, byteorder='big')\n", "bit_frequency = bit_frequency_value.to_bytes(2, byteorder='big')\n",
"# TODO: Send the 'B' command with the bit frequency\n", "# TODO: Send the 'B' command with the bit frequency\n",
"serial.write(b\"\".join([b\"B\",bit_frequency,b\"\\n\"]))\n",
"\n", "\n",
"# Set repetition count\n", "# Set repetition count\n",
"# Calculate the repetition count (should be at least 32)\n", "# Calculate the repetition count (should be at least 32)\n",
@ -298,33 +343,48 @@
"repetition_count = repetition_count_value.to_bytes(2, byteorder='big')\n", "repetition_count = repetition_count_value.to_bytes(2, byteorder='big')\n",
"# TODO: Send the 'R' command with the repetition count\n", "# TODO: Send the 'R' command with the repetition count\n",
"\n", "\n",
"serial.write(b\"\".join([b\"R\",repetition_count,b\"\\n\"]))\n",
"\n",
"# Set code pattern\n", "# Set code pattern\n",
"# Define a 32-bit code in hexadecimal (e.g., 0x12345678)\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", "# Convert the code to bytes (4 bytes, big endian)\n",
"code = code_value.to_bytes(4, byteorder='big')\n", "code = code_value.to_bytes(4, byteorder='big')\n",
"# TODO: Send the 'C' command with the code\n", "# TODO: Send the 'C' command with the code\n",
"serial.write(b\"\".join([b\"C\",code,b\"\\n\"]))\n",
"\n", "\n",
"# TODO: Allow some time for the settings to take effect\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", "# TODO: Turn the beacon ON by sending the 'A1' command\n",
"print(\"Beacon is ON\")\n", "print(\"Beacon is ON\")\n",
"\n", "serial.write(b\"A1\\n\")\n",
"# Wait while the beacon is on\n", "# Wait while the beacon is on\n",
"time.sleep(3)\n", "time.sleep(3)\n",
"\n", "\n",
"# TODO: Turn the beacon OFF by sending the 'A0' command\n", "# TODO: Turn the beacon OFF by sending the 'A0' command\n",
"print(\"Beacon is OFF\")\n", "print(\"Beacon is OFF\")\n",
"serial.write(b\"A0\\n\")\n",
"\n", "\n",
"# Allow some time before closing\n", "# Allow some time before closing\n",
"time.sleep(1)\n", "time.sleep(1)\n",
"\n", "# TODO: Very Important! Close the serial connection\n",
"# TODO: Very Important! Close the serial connection" "serial.close()\n"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Beacon is ON\n",
"Beacon is OFF\n"
] ]
}
],
"execution_count": 37
}, },
{ {
"cell_type": "markdown",
"metadata": {}, "metadata": {},
"cell_type": "markdown",
"source": [ "source": [
"**Additional Information:**\n", "**Additional Information:**\n",
"\n", "\n",
@ -370,26 +430,74 @@
] ]
}, },
{ {
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-21T09:38:55.176015Z",
"start_time": "2025-11-21T09:38:55.092901Z"
}
},
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [ "source": [
"### Student Version ###\n", "### Student Version ###\n",
"\n", "\n",
"# TODO: Open the serial port with the correct port and baud rate\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", "# 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", "# 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", "# 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 the status information received from the car\n",
"print(f\"Car status is:\\n\\n{status}\")\n", "print(f\"Car status is:\\n\\n{status}\")\n",
"\n", "\n",
"serial.close()\n",
"# TODO: Close the serial connection (important!)" "# 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": "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", "cell_type": "markdown",
@ -455,10 +563,13 @@
] ]
}, },
{ {
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-21T10:27:10.276766Z",
"start_time": "2025-11-21T10:27:10.272096Z"
}
},
"cell_type": "code", "cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [ "source": [
"### Student Version ###\n", "### Student Version ###\n",
"\n", "\n",
@ -466,52 +577,80 @@
" def __init__(self, port, baudrate=115200):\n", " def __init__(self, port, baudrate=115200):\n",
" # Initialize the serial connection\n", " # Initialize the serial connection\n",
" # self.serial = Serial(port, baudrate, rtscts=True)\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", " # Initialize beacon parameters here using send_command\n",
" # Set carrier frequency, bit frequency, repetition count, and code pattern\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(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(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(b\"R\"+repetition_count+b\"\\n\")\n",
"\n",
" code_value = 0x67676767 # Replace with your code\n",
" code = code_value.to_bytes(4, byteorder='big')\n",
" self.send_command(b\"C\"+code+b\"\\n\")\n",
"\n", "\n",
" def send_command(self, command):\n", " def send_command(self, command):\n",
" # Send the command string over the serial connection\n", " # Send the command string over the serial connection\n",
" self.serial.write(command.encode())\n", " self.serial.write(command)\n",
" pass\n", " print(command)\n",
"\n", "\n",
" def set_speed(self, speed):\n", " def set_speed(self, speed):\n",
" # Send the motor speed command using send_command\n", " # Send the motor speed command using send_command\n",
" # Use the format 'M<speed>\\n'\n", " # Use the format 'M<speed>\\n'\n",
" pass\n", " self.send_command(f\"M{speed}\\n\".encode())\n",
"\n",
"\n", "\n",
" def set_angle(self, angle):\n", " def set_angle(self, angle):\n",
" # Send the steering angle command using send_command\n", " # Send the steering angle command using send_command\n",
" # Use the format 'D<angle>\\n'\n", " # Use the format 'D<angle>\\n'\n",
" pass\n", " self.send_command(f\"D{angle}\\n\".encode())\n",
"\n",
"\n", "\n",
" def stop(self):\n", " def stop(self):\n",
" # Stop the car by setting speed and angle to neutral (150)\n", " # Stop the car by setting speed and angle to neutral (150)\n",
" # Call set_speed and set_angle with 150\n", " # Call set_speed and set_angle with 150\n",
" pass\n", " self.set_speed(150)\n",
" self.set_angle(150)\n",
"\n", "\n",
" def start_beacon(self):\n", " def start_beacon(self):\n",
" # Send commands to start the beacon\n", " # Send commands to start the beacon\n",
" # Use the command 'A1\\n'\n", " # Use the command 'A1\\n'\n",
" pass\n", " self.send_command(b\"A1\\n\")\n",
"\n", "\n",
" def stop_beacon(self):\n", " def stop_beacon(self):\n",
" # Send commands to stop the beacon\n", " # Send commands to stop the beacon\n",
" # Use the command 'A0\\n'\n", " # Use the command 'A0\\n'\n",
" pass\n", " self.send_command(b\"A0\\n\")\n",
"\n", "\n",
" def close(self):\n", " def close(self):\n",
" # Close the serial connection\n", " # Close the serial connection\n",
" # self.serial.close()\n", " # self.serial.close()\n",
" pass" " self.serial.close()\n"
] ],
"outputs": [],
"execution_count": 44
}, },
{ {
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-21T10:27:11.326406Z",
"start_time": "2025-11-21T10:27:11.323674Z"
}
},
"cell_type": "code", "cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [ "source": [
"### Student Version ###\n", "### Student Version ###\n",
"\n", "\n",
@ -525,6 +664,20 @@
" while True:\n", " while True:\n",
" # Read input from the user\n", " # Read input from the user\n",
" command = input(\"Enter command: \").lower()\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",
" break\n",
"\n", "\n",
" # TODO: depending on the command, adjust the car speed, steering angle, or start/stop the beacon variable\n", " # TODO: depending on the command, adjust the car speed, steering angle, or start/stop the beacon variable\n",
"\n", "\n",
@ -543,28 +696,63 @@
" # Ensure the car is stopped and serial connection is closed\n", " # Ensure the car is stopped and serial connection is closed\n",
" kitt.stop()\n", " kitt.stop()\n",
" kitt.close()" " kitt.close()"
] ],
"outputs": [],
"execution_count": 45
}, },
{ {
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-21T10:29:28.965385Z",
"start_time": "2025-11-21T10:29:01.281710Z"
}
},
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [ "source": [
"### Student Version ###\n", "### Student Version ###\n",
"\n", "\n",
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" # Create an instance of KITT with the correct serial port\n", " # Create an instance of KITT with the correct serial port\n",
" # Replace '/dev/ttyUSB0' with your actual 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", "\n",
" # Start the control function\n", " # Start the control function\n",
" wasd_control(kitt)" " wasd_control(kitt)"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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": 50
}, },
{ {
"cell_type": "markdown",
"metadata": {}, "metadata": {},
"cell_type": "markdown",
"source": [ "source": [
"#### Test the Code with the Real Car\n", "#### Test the Code with the Real Car\n",
"\n", "\n",
@ -592,17 +780,64 @@
] ]
}, },
{ {
"metadata": {
"ExecuteTime": {
"end_time": "2025-11-21T09:39:10.749553211Z",
"start_time": "2025-11-19T19:27:44.033559Z"
}
},
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [ "source": [
"import serial.tools.list_ports\n", "import serial.tools.list_ports\n",
"\n", "\n",
"ports = list(serial.tools.list_ports.comports())\n", "ports = list(serial.tools.list_ports.comports())\n",
"for port in ports:\n", "for port in ports:\n",
" print(port.device)" " 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", "cell_type": "markdown",

View File

@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"\n", "\n",
"[Table of Contents](0_Table_of_Contents.ipynb)\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n",
"\n", "\n",
@ -28,7 +28,6 @@
"import numpy as np\n", "import numpy as np\n",
"import pandas as pd\n", "import pandas as pd\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"import csv\n",
"\n", "\n",
"# Uncomment one of the following lines depending on your setup\n", "# Uncomment one of the following lines depending on your setup\n",
"\n", "\n",
@ -37,8 +36,7 @@
"# import sounddevice\n", "# import sounddevice\n",
"\n", "\n",
"# If you are using the simulator, uncomment the next lines and comment the real car lines\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 Manual.KITT_Simulator.sounddevice_simulator import sounddevice\n",
"from KITT_Simulator.sounddevice_simulator import sounddevice\n",
"\n", "\n",
"# Note: After changing the import statement, you need to restart the kernel for changes to take effect." "# Note: After changing the import statement, you need to restart the kernel for changes to take effect."
] ]

View File

@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"\n", "\n",
"[Table of Contents](0_Table_of_Contents.ipynb)\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n",
"\n", "\n",
@ -34,9 +34,6 @@
"import matplotlib.pyplot as plt # For plotting purposes\n", "import matplotlib.pyplot as plt # For plotting purposes\n",
"import numpy as np # For convolution function\n", "import numpy as np # For convolution function\n",
"from scipy.io import wavfile\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", "\n",
"# Uncomment one of the following lines depending on your setup\n", "# Uncomment one of the following lines depending on your setup\n",
"\n", "\n",
@ -45,8 +42,6 @@
"# from sounddevice import sounddevice\n", "# from sounddevice import sounddevice\n",
"\n", "\n",
"# If you are using the simulator, uncomment the next lines and comment the real car lines\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", "\n",
"# Note: After changing the import statement, you need to restart the kernel for changes to take effect." "# Note: After changing the import statement, you need to restart the kernel for changes to take effect."
] ]
@ -685,12 +680,8 @@
"source": [ "source": [
"### Student Version ###\n", "### Student Version ###\n",
"\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 numpy as np\n",
"import matplotlib.pyplot as plt\n", "\n",
"\n", "\n",
"class Localization:\n", "class Localization:\n",
" \"\"\"\n", " \"\"\"\n",

View File

@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"\n", "\n",
"[Table of Contents](0_Table_of_Contents.ipynb)\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n",
"\n", "\n",
@ -23,7 +23,6 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"# Import necessary libraries\n", "# Import necessary libraries\n",
"import time\n",
"import numpy as np\n", "import numpy as np\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"\n", "\n",
@ -33,7 +32,6 @@
"# from serial import Serial\n", "# from serial import Serial\n",
"\n", "\n",
"# If you are using the simulator, uncomment the next line and comment the real car line\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", "\n",
"# Note: After changing the import statement, you need to restart the kernel for changes to take effect." "# Note: After changing the import statement, you need to restart the kernel for changes to take effect."
] ]

View File

@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"[Table of Contents](0_Table_of_Contents.ipynb)" "[Table of Contents](0_Table_of_Contents.ipynb)"
] ]
}, },

View File

@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"![book header](../pictures/header.png)\n", "![book header](pictures/header.png)\n",
"\n", "\n",
"[Table of Contents](0_Table_of_Contents.ipynb)\n", "[Table of Contents](0_Table_of_Contents.ipynb)\n",
"\n", "\n",
@ -283,7 +283,7 @@
"\n", "\n",
"The figure below is a example depiction of the Challenges (*On the old television series, KARR is the archenemy of KITT*)\n", "The figure below is a example depiction of the Challenges (*On the old television series, KARR is the archenemy of KITT*)\n",
"\n", "\n",
"![alt text](../pictures/FinalChallenge.png)\n", "![alt text](pictures/FinalChallenge.png)\n",
"\n", "\n",
"\n" "\n"
] ]

View File

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@ -6,8 +6,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from gui import GUI\n", "from Manual.KITT_Simulator.gui import GUI\n",
"from shared_state import SharedState\n", "from Manual.KITT_Simulator.shared_state import SharedState\n",
"\n", "\n",
"import time\n", "import time\n",
"import numpy as np" "import numpy as np"

View File

@ -1,14 +1,11 @@
import time import time
import threading import threading
import numpy as np import numpy as np
import matplotlib.pyplot as plt
import logging import logging
import queue # Import queue to handle inter-thread communication
from Manual.KITT_Simulator.shared_state import SharedState
from KITT_Simulator.shared_state import SharedState from Manual.KITT_Simulator.gui import GUI
from KITT_Simulator.gui import GUI from Manual.KITT_Simulator.dynamics_simulator import Dynamics
from KITT_Simulator.dynamics_simulator import Dynamics
# try: # try:
# from KITT_Simulator.shared_state import SharedState # from KITT_Simulator.shared_state import SharedState

View File

@ -1,9 +1,8 @@
import time as time
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
try: try:
from KITT_Simulator.shared_state import SharedState from Manual.KITT_Simulator.shared_state import SharedState
except: except:
from shared_state import SharedState from shared_state import SharedState

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 932 KiB

After

Width:  |  Height:  |  Size: 932 KiB

View File

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 124 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 90 KiB

View File

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View File

Before

Width:  |  Height:  |  Size: 110 KiB

After

Width:  |  Height:  |  Size: 110 KiB

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

Before

Width:  |  Height:  |  Size: 298 KiB

After

Width:  |  Height:  |  Size: 298 KiB

View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 90 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

View File

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

View File

Before

Width:  |  Height:  |  Size: 665 KiB

After

Width:  |  Height:  |  Size: 665 KiB

View File

Before

Width:  |  Height:  |  Size: 897 KiB

After

Width:  |  Height:  |  Size: 897 KiB

View File

Before

Width:  |  Height:  |  Size: 116 KiB

After

Width:  |  Height:  |  Size: 116 KiB

View File

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 160 KiB

View File

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 112 KiB

View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 156 KiB

View File

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View File

Before

Width:  |  Height:  |  Size: 234 KiB

After

Width:  |  Height:  |  Size: 234 KiB

View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

Before

Width:  |  Height:  |  Size: 244 KiB

After

Width:  |  Height:  |  Size: 244 KiB

View File

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -3,9 +3,7 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": "![book header](../Manual/pictures/header.png)"
"![book header](../pictures/header.png)"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",

View File

@ -3,9 +3,7 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": "![book header](../Manual/pictures/header.png)"
"![book header](../pictures/header.png)"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",

View File

@ -3,9 +3,7 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": "![book header](../Manual/pictures/header.png)"
"![book header](../pictures/header.png)"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",

View File

@ -1,3 +1,4 @@
pynput
jupyter-book jupyter-book
matplotlib matplotlib
numpy numpy