import control as cn
import matplotlib.pyplot as plt
import numpy as np
import control_add_on as cadd
import siso_controllability as scont


"""
Scaling: x* refers to the unscaled perturbation variable
q = q*/1
T_0 = T_0*/10
T = T*/10
"""

G = cn.tf([0.8],[60, 1])*cn.tf([1],[12, 1]) #this is the only tf which changes due to scaling => equates to *0.1
Gd = cn.tf([20*0.6, 0.6],[60, 1])*cn.tf([1],[12,1])
# remember the dead time in measurement which is 3 seconds
freqs = np.arange(0.001, 1, 0.001)
plt.figure(1)
scont.rule_three_four(G, Gd, R = 2, perfect = True, freq = freqs)

plt.show()
"""
Performance:
The plant will perform well to input (R) and disturbance tracking as it
is self regulating i.e. |Gd| < 1 for all frequencies.

Controllability:
It is self regulating so... this is awkward...
"""
Example #2
0
import control as cn
import matplotlib.pyplot as plt
import numpy as np
import control_add_on as cadd
import siso_controllability as scont
"""
Scaling: x* refers to the unscaled perturbation variable
q = q*/1
T_0 = T_0*/10
T = T*/10
"""

G = cn.tf([0.8], [60, 1]) * cn.tf([1], [
    12, 1
])  #this is the only tf which changes due to scaling => equates to *0.1
Gd = cn.tf([20 * 0.6, 0.6], [60, 1]) * cn.tf([1], [12, 1])
# remember the dead time in measurement which is 3 seconds
freqs = np.arange(0.001, 1, 0.001)
plt.figure(1)
scont.rule_three_four(G, Gd, R=2, perfect=True, freq=freqs)

plt.show()
"""
Performance:
The plant will perform well to input (R) and disturbance tracking as it
is self regulating i.e. |Gd| < 1 for all frequencies.

Controllability:
It is self regulating so... this is awkward...
"""
import numpy as np

import siso_controllability as scont

# There is a time delay from measurement of 100s.
# This implies that the upper bound for w_c is about 1/100 = 0.01 rad/s.

G = cn.tf([20], [1000, 1])
Gd = cn.tf([10], [1000, 1])
# from the solution
K = cn.tf([0.4], [1]) * cn.tf([200, 1], [200, 0]) * cn.tf([60, 1], [1])

plt.figure("Input Constraint Bode")
freqs = np.arange(0.00001, 0.1,
                  0.00001)  # this is the frequency range we are dealing with
scont.rule_three_four(G, Gd, R=3, freq=freqs, perfect=False)

# From Disturbance Bode you can see |G| > |Gd| always. This implies that
# there will not be any input constraints wrt disturbances. (Rule 3)
# I.e. your system will always be strong enough to counteract your disturbances.

# Using R = 3 you get an intersection of w_r = 0.0065 which implies that
# the plant will be able to track set point changes up to w_r. The required response time
# is 1/1000 = 0.001. Therefore w_r is better than the required response time.

plt.figure("Feedback Constraint Bode")
S = 1 / (1 + G * K)
scont.rule_one_two(S, Gd, R=3, freq=freqs)

# From Feedback Constraint Bode you can see that the feedback loop of the
# system will be able to handle any disturbance input.
import siso_controllability as scont




# There is a time delay from measurement of 100s.
# This implies that the upper bound for w_c is about 1/100 = 0.01 rad/s.

G = cn.tf([20],[1000,1])
Gd = cn.tf([10],[1000,1])
K = cn.tf([0.4],[1])*cn.tf([200,1],[200,0])*cn.tf([60,1],[1]) # from the solution

plt.figure("Input Constraint Bode")
freqs = np.arange(0.00001,0.1,0.00001) # this is the frequency range we are dealing with
scont.rule_three_four(G, Gd, R = 3, freq=freqs, perfect = False)

# From Disturbance Bode you can see |G| > |Gd| always. This implies that
# there will not be any input constraints wrt disturbances. (Rule 3)
# I.e. your system will always be strong enough to counteract your disturbances.

# Using R = 3 you get an intersection of w_r = 0.0065 which implies that 
# the plant will be able to track set point changes up to w_r. The required response time
# is 1/1000 = 0.001. Therefore w_r is better than the required response time.

plt.figure("Feedback Constraint Bode")
S = 1/(1+G*K)
scont.rule_one_two(S, Gd, R = 3, freq = freqs)

# From Feedback Constraint Bode you can see that the feedback loop of the
# system will be able to handle any disturbance input.