-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathtype2_type3.py
More file actions
49 lines (39 loc) · 1.65 KB
/
type2_type3.py
File metadata and controls
49 lines (39 loc) · 1.65 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
# type2_type3.py - demonstration for type2 versus type3 control comparing
# tracking and disturbance rejection for two proposed controllers
# Gunnar Ristroph, 15 January 2010
import os
import matplotlib.pyplot as plt # Grab MATLAB plotting functions
import control as ct
import numpy as np
integrator = ct.tf([0, 1], [1, 0]) # 1/s
# Parameters defining the system
J = 1.0
b = 10.0
Kp = 110.
Ki = Kp/2.
Kii = Ki
# Plant transfer function from torque to rate
inertia = integrator*1/J
friction = b # transfer function from rate to torque
P = inertia # friction is modelled as a separate block
# Gyro transfer function from rate to rate
gyro = 1. # for now, our gyro is perfect
# Controller transfer function from rate error to torque
C_type2 = (1. + Ki*integrator)*Kp*1.5
C_type3 = (1. + Ki*integrator)*(1. + Kii*integrator)*Kp
# System Transfer Functions
# tricky because the disturbance (base motion) is coupled in by friction
closed_loop_type2 = ct.feedback(C_type2*ct.feedback(P, friction), gyro)
disturbance_rejection_type2 = P*friction/(1. + P*friction+P*C_type2)
closed_loop_type3 = ct.feedback(C_type3*ct.feedback(P, friction), gyro)
disturbance_rejection_type3 = P*friction/(1. + P*friction + P*C_type3)
# Bode plot for the system
plt.figure(1)
ct.bode(closed_loop_type2, np.logspace(0, 2)*2*np.pi, dB=True, Hz=True) # blue
ct.bode(closed_loop_type3, np.logspace(0, 2)*2*np.pi, dB=True, Hz=True) # green
plt.show(block=False)
plt.figure(2)
ct.bode(disturbance_rejection_type2, np.logspace(0, 2)*2*np.pi, Hz=True) # blue
ct.bode(disturbance_rejection_type3, np.logspace(0, 2)*2*np.pi, Hz=True) # green
if 'PYCONTROL_TEST_EXAMPLES' not in os.environ:
plt.show()