diff --git a/Manual/4_Module_2.ipynb b/Manual/4_Module_2.ipynb index 5bda07e..13afe38 100644 --- a/Manual/4_Module_2.ipynb +++ b/Manual/4_Module_2.ipynb @@ -106,8 +106,14 @@ "### Student Version ###\n", "\n", "# TODO: Establish a serial connection, ask for a status report, read it out, and print it\n", + "serial = Serial('/dev/rfcomm2', 115200)\n", + "serial.write(b'S\\n')\n", + "status = serial.read_until(b'\\n')\n", + "status = status.decode('utf-8')\n", + "print(f\"Car status is:\\n\\n{status}\")\n", "\n", - "# TODO: Close the serial connection" + "# TODO: Close the serial connection\n", + "serial.close()" ] }, { @@ -151,30 +157,36 @@ "source": [ "### Student Version ###\n", "\n", - "# TODO: Decode the status response to a string\n", + "def extract_dis ():\n", + " # TODO: Decode the status response to a string\n", + " serial.write(b'S\\n')\n", + " _status = serial.read_until(b'\\n')\n", + " _status = _status.decode('utf-8')\n", "\n", - "# TODO: Split the status string into lines\n", - "lines = \n", + " # TODO: Split the status string into lines\n", + " lines = _status.splitlines()\n", "\n", - "# Initialize variables to hold distance values\n", - "dist_L = None\n", - "dist_R = None\n", + " # Initialize variables to hold distance values\n", + " dist_L = None\n", + " dist_R = None\n", "\n", - "# Iterate over each line to find distance data\n", - "for line in lines:\n", - " if \"Dist.\" in line:\n", - " # TODO: Split the line into words\n", - " words =\n", - " # Extract distance values based on their positions\n", + " # Iterate over each line to find distance data\n", + " for line in lines:\n", + " if \"Dist.\" in line:\n", + " # TODO: Split the line into words\n", + " words = lines.split()\n", + " # Extract distance values based on their positions\n", "\n", - " # Assign dist_L and dist_R accordingly\n", - " dist_L = \n", - " dist_R = \n", - " break # Exit the loop after finding the distances\n", + " # Assign dist_L and dist_R accordingly\n", + " dist_L =\n", + " dist_R =\n", + " break # Exit the loop after finding the distances\n", "\n", - "# Print the extracted distance values\n", - "print(f\"Left Distance: {dist_L}\")\n", - "print(f\"Right Distance: {dist_R}\")" + " # Print the extracted distance values\n", + " print(f\"Left Distance: {dist_L}\")\n", + " print(f\"Right Distance: {dist_R}\")\n", + "\n", + " return dist_L, dist_R" ] }, { @@ -265,6 +277,7 @@ "\n", "# TODO: Open the serial connection to KITT, set the motor speed\n", "\n", + "\n", "# Initialize a list to store recorded data\n", "data = []\n", "\n", diff --git a/student_code/controller.py b/student_code/controller.py new file mode 100644 index 0000000..e69de29 diff --git a/student_code/control.py b/student_code/kitt_main.py similarity index 100% rename from student_code/control.py rename to student_code/kitt_main.py