-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestModelling.py
81 lines (58 loc) · 1.68 KB
/
TestModelling.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
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 20 19:06:09 2016
@author: r
"""
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 14 20:06:45 2016
@author: r
"""
import os
import scipy.signal as sig
import matplotlib.pyplot as plt
import numpy as np
from numpy import matlib
import Model as LTImodel # dynamic models
import StatePredictor as StatePred # state predictor
import CommonUtils as Tools # few usefull tools
def tic():
#Homemade version of matlab tic and toc functions
import time
global startTime_for_tictoc
startTime_for_tictoc = time.time()
def toc():
import time
if 'startTime_for_tictoc' in globals():
print("Elapsed time is " + str(time.time() - startTime_for_tictoc) + " seconds.")
else:
print("Toc: start time not set")
###############################################################################
clear = lambda: os.system('cls')
clear()
# Create the model
G = matlib.repmat(None, 2, 2)
G[0][0] = sig.lti([1], [30, 1.0])
G[0][1] = sig.lti([-1], [40, 1.0])
G[1][0] = sig.lti([0.4], [50.0, 3.0, 1.0])
G[1][1] = sig.lti(100.0*np.array([0.5, -0.01]), [80.0, 15.0, 3.0])
# state predictor config
pred_H = 100
cont_H = 20
deltaT = 2
# Create the model object
G_model = LTImodel.Mod(G, deltaT, pred_H)
u = np.random.rand( 20, 2 )
y_plant = [[]]
for i in range(1, len(u[:,1])):
tic()
t, y = G_model.simulate(u[0:i,:])
if i == 1:
y_plant = np.append(y_plant, [y[:,-1]], axis=1)
else:
y_plant = np.append(y_plant, [y[:,-1]], axis=0)
toc()
plt.plot(y_plant[:,0])
plt.plot(y_plant[:,1])
plt.show()
##############################################################################