-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_tools.py
More file actions
114 lines (89 loc) · 3.92 KB
/
plot_tools.py
File metadata and controls
114 lines (89 loc) · 3.92 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
"""
A module which uses MatPlotLib to generate plots of collected the data for 1-Dimensional tests
"""
import matplotlib.pyplot as plt
__author__="Mike Fogel"
__credits__=["Mike Fogel", "Simon Kowerski"]
__credits__=["Mike Fogel", "Simon Kowerski"]
__creation_date__="7/26/2023"
def plot_sloshy(t, theta, theta_d, u, umotor, err, errdot, ecumul):
"""
Uses MatPlotLib to generate plots of collected the data
Args:
t (?): time
theta (float): current position as measured by the IMU. The current, measured angle of the satellite
theta_d (float): desired position of the satellite. The guidance. Example "Move the test bench to 90 degrees", so theta_d=90
u (float): calculated motor angular acceleration based on the PID controller
umotor (float): same as u however in previous versions of the code, I wanted to store the calculated value (u) and the actual value (umotor) I was going to send. The actual value I was from the PID controller and the actual value = calculated value (u = umotor) unless the calculate value exceeded the max safety value. Then umotor = max_accel. This entire section no longer needs both u and u motor.
max_accel (float): max allowed safety acceleration. It's a safety constraint.
err (float: PID proportional error
"""
# Graph Solution
# print("Starting GRAPHS")
fig,ax = plt.subplots(3,2)
font = {'size' : 3}
plt.rc('font', **font)
ax[0,0].plot(t,theta)
ax[0,0].axhline(y=theta_d, color = 'r', linestyle = '-')
ax[0,0].set_xlabel('t (s)')
ax[0,0].set_ylabel('Tank')
ax[0,0].set_ylim([-90,180])
ax[0,0].set_xlim([0,t[-1]])
ax[0,0].legend([r"$\theta$", r"$\theta_d$"], loc = "upper right")
ax[0,1].plot(t,u)
ax[0,1].plot(t,umotor)
ax[0,1].set_xlabel('t (s)')
ax[0,1].set_ylabel('Controller')
ax[0,1].set_ylim([-15000,15000])
ax[0,1].set_xlim([0,t[-1]])
ax[0,1].legend([r"$u_{calc}$", r"$u_{comamnd}$"], loc = "upper right")
ax[1,0].plot(t,err)
ax[1,0].set_xlabel('t (s)')
ax[1,0].set_ylabel('Error')
ax[1,0].set_xlim([0,t[-1]])
ax[1,0].legend([r"$e(t)$"], loc = "upper right")
ax[1,1].plot(t,errdot)
ax[1,1].set_xlabel('t (s)')
ax[1,1].set_ylabel('Error_dot')
ax[1,1].set_xlim([0,t[-1]])
ax[1,1].legend([r"$e_{dot}(t)$"], loc = "upper right")
ax[2,0].plot(t,ecumul)
ax[2,0].set_xlabel('t (s)')
ax[2,0].set_ylabel('Cumul Error')
ax[2,0].set_xlim([0,t[-1]])
ax[2,0].legend([r"$e_{cum}(t)$"], loc = "upper right")
ax[2,1].plot(t,ecumul)
ax[2,1].set_xlabel('t (s)')
ax[2,1].set_ylabel('Cumul Error')
ax[2,1].set_xlim([0,t[-1]])
ax[2,1].legend([r"$e_{cum}(t)$"], loc = "upper right")
fig.tight_layout(pad=5.0)
def plotforcestorques(t, u, force, torque):
"""
Uses MatPlotLib to generate plots of forces and torques during the experiment
Args:
t (?): time
u: control input at the timestep
force: the array of force values read by the sesnor
torque: the array of torque values read by the sensor
"""
fig,ax = plt.subplots(3,1)
font = {'size' : 6}
plt.rc('font', **font)
ax[0].plot(t,torque)
ax[0].set_xlabel('t (s)',fontsize=6)
ax[0].set_ylabel('Bota Torque (N-m)',fontsize=6)
ax[0].set_xlim([0,t[-1]])
ax[0].legend([r"$\Gamma_x$",r"$\Gamma_y$",r"$\Gamma_z$"], loc = "upper right")
ax[1].plot(t,force)
ax[1].set_xlabel('t (s)',fontsize=6)
ax[1].set_ylabel('Bota Forces (N)',fontsize=6)
ax[1].set_xlim([0,t[-1]])
ax[1].legend([r"$F_x$",r"$F_y$",r"$F_z$"], loc = "upper right")
ax[2].plot(t,u)
ax[2].set_xlabel('t (s)',fontsize=6)
ax[2].set_ylabel('Controller u(t)',fontsize=6)
ax[2].set_xlim([0,t[-1]])
ax[2].legend([r"$u(t)_{calc}$"], loc = "upper right")
fig.suptitle('Bota Torque Sensor', fontsize=8, fontweight='bold')