Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
acceleration_mapper.py
Go to the documentation of this file.
1# pylint: skip-file
2# mypy: ignore-errors
3import numpy as np
4import matplotlib.pyplot as plt
5
6# Define track parameters
7startLine, endLine = -0.3, 100.0
8straightPoints = 30
9roundCases = 3
10
11# Initialize lists to store coordinates and colors
12xPoints = []
13yPoints = []
14
15xCones = []
16yCones = []
17
18colorList = []
19
20# Generate blue cones on the left side of the track
21for i in np.arange(0, 75.01, 5):
22 xCones.append(-1.5)
23 yCones.append(i)
24 colorList.append("#0000ff")
25
26# Generate red cones on the right side of the track
27for i in np.arange(0, 75.01, 5):
28 xCones.append(1.5)
29 yCones.append(i)
30 colorList.append("#ff0000")
31
32# Generate points on the straight section of the track
33for i in np.arange(startLine, endLine, abs(endLine - startLine) // straightPoints):
34 x = 0.0
35 y = round(i, roundCases)
36 xPoints.append(x)
37 yPoints.append(y)
38 colorList.append("#00aa00")
39
40# Print lengths of lists for debugging
41print(len(xPoints))
42print(len(yPoints))
43print(len(xCones))
44print(len(yCones))
45print(len(yPoints + yCones))
46print(len(colorList))
47
48# Reflect cone coordinates across the y-axis
49for i in range(len(yCones)):
50 yCones[i], xCones[i] = -xCones[i], yCones[i]
51
52# Reflect point coordinates across the y-axis
53for i in range(len(yPoints)):
54 yPoints[i], xPoints[i] = -xPoints[i], yPoints[i]
55
56# Write point coordinates to a file
57f1 = open("acceleration.txt", "w")
58for i in range(0, len(xPoints)):
59 f1.write(f"{xPoints[i]} {yPoints[i]}\n")
60f1.close()
61
62# Write cone coordinates to a file
63f2 = open("acceleration_map.txt", "w")
64for i in range(0, len(xCones)):
65 f2.write(f"{xCones[i]} {yCones[i]}\n")
66f2.close()
67
68# Visualize cones and points using scatter plot
69plt.scatter(xCones + xPoints, yCones + yPoints, s=2, c=colorList)
70plt.axis("equal")
71plt.show()
double round(double number, int n)
round to n decimal places
Definition tests.cpp:17