-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (26 loc) · 994 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from controller import *
from hardware_simulated import *
import numpy as np
from scipy.interpolate import spline
import matplotlib.pyplot as plt
def simulate():
hardware = SimulatedHardware()
timestamps = np.arange(0, 3, 0.1)
positions = np.empty(timestamps.shape)
# Get positions over time via controller+simulator:
curr_state = hardware.get_state()
controller = PIDController(0.2, 0.1, 0.05, curr_state, 0)
for i, time in enumerate(timestamps):
controller_output = controller.get_controller_output(i + 1, curr_state)
hardware.update_state(controller_output)
curr_state = hardware.get_state()
positions[i] = curr_state
print(curr_state)
x_smooth = np.linspace(timestamps.min(), timestamps.max(), 2000)
positions_smooth = spline(timestamps, positions, x_smooth)
plt.plot(x_smooth, positions_smooth)
plt.xlabel("Time")
plt.ylabel("Position")
plt.show()
if __name__ == "__main__":
simulate()