-
Notifications
You must be signed in to change notification settings - Fork 1
/
LM_feasible_set.m
140 lines (130 loc) · 3.51 KB
/
LM_feasible_set.m
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
%% Connect to OPCUA
clear all; clc;close all
%%
addpath('C:\Users\nobar\data_driven_controller\linear_motor')
addpath('C:\Users\nobar\data_driven_controller\linear_motor\OPCUA')
ip='192.168.188.21';
sInfo = opcuaserverinfo(ip); % SPS Name
% sInfo = opcuaserverinfo('192.168.188.21'); % SPS Name
% Create Client
uaObj = opcua(sInfo.Hostname,sInfo.Port);
% Connect to OPC server
connect(uaObj,'tm','sX7Cswc34wjvwq'); % SPS Loggin
%% Load Trajectory
% load("dem_x/dem_x_9_mm.mat")
t = (0.001:0.001:7);
r= 10.*(t>2)+30-10.*(t>5);
% % set reference input
write_OPCUA(uaObj,'arrDemPos', r);
write_OPCUA(uaObj,'arrShowPos', r);
pause(1);
%% high fidelity model of plant
s = tf('s');
Kp = 0.44262;
Tp = 0.070983;
Td = 0.001;
Gp_x = Kp/(1 * Tp *s) * 1/s * exp(-Td*s);
F=0.001;
%%
actPos_all=[];
actVel_all=[];
actCur_all=[];
r_all=[];
t_all=[];
PGM_all=[];
for D=10:10:90
for P=500:500:12000
disp(D)
C=P+D*s/(F*s+1);
CLsys = feedback(Gp_x*C,1);
[Gm,Pm,Wcg,Wcp] = margin(CLsys);
if Pm>20
% Set P and D gain
% write_OPCUA(uaObj,'LQR_P_x', P);
% write_OPCUA(uaObj,'LQR_D_v', D);
% pause(0.2);
%
% % perform experiment
% write_OPCUA(uaObj,'Go', 1); % Perform Experiment
% pause(7.5);
%
% % read the results
% actPos = read_OPCUA(uaObj,'arrActPos')';
% actVel = read_OPCUA(uaObj,'arrActVel')';
% actCur = read_OPCUA(uaObj,'arrActCur')';
% t = (0.001:0.001:7);
% r= 10.*(t>2)+30-10.*(t>5);
PGM=[Pm;Gm];
else
disp(Pm)
% actPos=-1.*ones(7000,1);
% actVel=-1.*ones(7000,1);
% actCur=-1.*ones(7000,1);
% r=-1.*ones(1,7000);
% t=-1.*ones(1,7000);
PGM=[-1;-1];
end
% actPos_all=[actPos_all,actPos];
% actVel_all=[actVel_all,actVel];
% actCur_all=[actCur_all,actCur];
% r_all=[r_all,r'];
% t_all=[t_all,t'];
PGM_all=[PGM_all,PGM];
% exp_data.actPos_all=actPos_all;
% exp_data.actVel_all=actVel_all;
% exp_data.actCur_all=actCur_all;
% exp_data.r_all=r_all;
% exp_data.t_all=t_all;
exp_data.PGM_all=PGM_all;
save('/home/mahdi/ETHZ/GBO/code/data_driven_controller/linear_motor/exp_data_35.mat','exp_data')
end
end
%%
% Disconnect from OPCUA
disconnect_OPCUA(uaObj)
%%
% % Kp
% % G(s) = ---------- * exp(-Td*s)
% % 1+Tp1*s
% % Kp = 0.44262
% % Tp1 = 0.070983
% % Td = 0.001334 s = tf('s');
% Kp = 0.44262;
% Tp = 0.070983;
% Td = 0.001;
% Gp_x = Kp/(1 * Tp *s) * 1/s * exp(-Td*s);
% counter=0;
% failed=0;
% for D=10:1:90
% for P=500:100:15000
% counter=counter+1
% F=0.0002;
% C=P+D*s/(F*s+1);
% CLsys = feedback(Gp_x*C,1);
% [Gm,Pm,Wcg,Wcp] = margin(CLsys);
% if Pm<20
% disp(Pm)
% failed=failed+1;
% end
% end
% end
%%
t = (0.001:0.001:7);
r= 10.*(t>2)+30-10.*(t>5);
% % set reference input
write_OPCUA(uaObj,'arrDemPos', r);
write_OPCUA(uaObj,'arrShowPos', r);
pause(1);
%%
P_all=[];
D_all=[];
for D=10:10:90
for P=500:500:12000
P_all=[P_all,P];
D_all=[D_all,D];
end
end
load('/home/mahdi/ETHZ/GBO/code/data_driven_controller/linear_motor/exp_data_feasible.mat','exp_data')
exp_data.P=P_all;
exp_data.D=D_all;
save('/home/mahdi/ETHZ/GBO/code/data_driven_controller/linear_motor/exp_data_feasible_3.mat','exp_data')