Merge branch 'module_1' into 'main'
Module 1 done See merge request ee2l1/2025-2026/A.K.03!2
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"# Table of Contents\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"[Table of Contents](0_Table_of_Contents.ipynb)"
|
||||
]
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\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",
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"[Table of Contents](0_Table_of_Contents.ipynb)\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",
|
||||
"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": 8
|
||||
},
|
||||
{
|
||||
"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",
|
||||
"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<direction_value>\\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": "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",
|
||||
@ -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",
|
||||
"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",
|
||||
"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",
|
||||
"# TODO: Send the 'F' command with the carrier frequency\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",
|
||||
"# 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 +343,48 @@
|
||||
"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": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Beacon is ON\n",
|
||||
"Beacon is OFF\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 37
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"**Additional Information:**\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",
|
||||
"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": "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",
|
||||
@ -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",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"### Student Version ###\n",
|
||||
"\n",
|
||||
@ -466,52 +577,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(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",
|
||||
" def send_command(self, command):\n",
|
||||
" # Send the command string over the serial connection\n",
|
||||
" self.serial.write(command.encode())\n",
|
||||
" pass\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<speed>\\n'\n",
|
||||
" pass\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<angle>\\n'\n",
|
||||
" pass\n",
|
||||
" self.send_command(f\"D{angle}\\n\".encode())\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(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(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": 44
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-11-21T10:27:11.326406Z",
|
||||
"start_time": "2025-11-21T10:27:11.323674Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"### Student Version ###\n",
|
||||
"\n",
|
||||
@ -525,6 +664,20 @@
|
||||
" 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",
|
||||
" break\n",
|
||||
"\n",
|
||||
" # TODO: depending on the command, adjust the car speed, steering angle, or start/stop the beacon variable\n",
|
||||
"\n",
|
||||
@ -543,28 +696,63 @@
|
||||
" # Ensure the car is stopped and serial connection is closed\n",
|
||||
" kitt.stop()\n",
|
||||
" 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",
|
||||
"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": [
|
||||
{
|
||||
"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": {},
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"#### Test the Code with the Real Car\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",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"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",
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\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."
|
||||
]
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\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",
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\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."
|
||||
]
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"[Table of Contents](0_Table_of_Contents.ipynb)"
|
||||
]
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"\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",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
|
||||
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
@ -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"
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 932 KiB After Width: | Height: | Size: 932 KiB |
|
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 298 KiB After Width: | Height: | Size: 298 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 665 KiB After Width: | Height: | Size: 665 KiB |
|
Before Width: | Height: | Size: 897 KiB After Width: | Height: | Size: 897 KiB |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
|
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB |
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 156 KiB |
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 165 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 234 KiB After Width: | Height: | Size: 234 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 244 KiB After Width: | Height: | Size: 244 KiB |
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 47 KiB |
@ -3,9 +3,7 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
""
|
||||
]
|
||||
"source": ""
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
||||
@ -3,9 +3,7 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
""
|
||||
]
|
||||
"source": ""
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
||||
@ -3,9 +3,7 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
""
|
||||
]
|
||||
"source": ""
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
pynput
|
||||
jupyter-book
|
||||
matplotlib
|
||||
numpy
|
||||
|
||||