-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaircraft-pitch-notebook.py
79 lines (55 loc) · 1.94 KB
/
aircraft-pitch-notebook.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
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
# Aircraft Pitch Loop
"""
# Objective
# Optimally tune a PI controller for a car Aircraft Pitch Loop
"""
"""
# Project Description
# Using Collimator's python notebook we will show how to design a PID tuner for an aircraft's pitch control loop.
"""
"""
# Model Requirements
# N/A
"""
import numpy as np
import matplotlib.pyplot as plt
import control as ctrl
import collimator as C
# The state-space matrices are defined as follows:
A = np.matrix([[-0.298, 54.3, 0],
[-0.0141, -0.399, 0],
[0, 54.3, 0]])
B = np.matrix([0.223, 0.0199, 0]).T
C = np.matrix([0, 0, 1])
D = [0]
pitch_sys = ctrl.ss(A,B,C,D)
print(pitch_sys)
# A look at the poles and zeros of the aircraft pitch system:
print(ctrl.zero(pitch_sys))
print(ctrl.pole(pitch_sys))
# a look at the open-loop and closed-loop step responses for the pitch control system
plt.figure(figsize=(12,8))
plt.grid(which='both')
T, yout = ctrl.step_response(0.2*pitch_sys,T=np.arange(0, 20, 0.01))
plt.plot(T, yout,label='Open Loop')
pitch_sys_closed = ctrl.feedback(pitch_sys,1)
T, yout = ctrl.step_response(0.2*pitch_sys_closed,T=np.arange(0, 60, 0.01))
plt.plot(T, yout,label='Closed Loop')
plt.legend()
# the closed-loop step response though stable is unsatisfying:
ctrl.step_info(0.2*pitch_sys_closed)
# define a function that computes the step response and time-domain characteristics for the output step response
def interactive_tuning(kp = 1, ki=0, kd=0):
s = ctrl.tf('s')
pid = kp+ki/s+kd*10000*s/(s+10000)
pitch_y = ctrl.feedback(pid*pitch_sys,1)
print(ctrl.step_info(0.2*pitch_y))
plt.figure(figsize=(12,8))
T, y = ctrl.step_response(0.2*pitch_y,T=np.arange(0, 50, 0.1))
plt.grid(which='both')
plt.plot(T, y)
plt.ylabel('Pitch Angle')
plt.xlabel('Time')
# We now define the interactive variables for the tuning function.
from ipywidgets import interact, fixed
interact(interactive_tuning,kp = (0,10,0.01),ki = (0,10,0.01),kd = (0,10,0.01))