-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBarRocketDisturbedPlant.m
140 lines (110 loc) · 3.67 KB
/
BarRocketDisturbedPlant.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
139
140
classdef BarRocketDisturbedPlant < SecondOrderSystem
% state (world coordinates):
% q(1) - x position
% q(2) - z position
% q(3) - pitch (theta)
% input:
% u(1) - prop 1 thrust
% u(2) - prop 2 thrust
properties % based on (Bouadi, Bouchoucha, Tadjine 2007)
%bar rocket properties
L = 0.25; % length of rotor arm
m = 0.486; % mass of quadrotor
I = 0.00383; % moment of inertia
%environment properties
g = 9.81; % gravity
%kx = 1; %spring
kx = 0;
%b = [1; 1; 0.1]*1; %friction
b = [0; 0; 0];
% %horizontal cross-wind
% %bounded between [-w_max, w_max]
w_sigma = 0.25;
% %w_max = 5*w_sigma;
w_max = 0.05;
% %w_base = makedist('Normal', 'mu', 0, 'sigma', w_sigma);
% w_dist = truncate(makedist('Normal', 'mu', 0, 'sigma', w_sigma), -1, 1);
%
%Delta = makedist
%Bw = [1; 0; 0]*w_max;
%Bw = [0; 0; 0];
w_dist;
Bw;
%Equilibrium Position
x0;
u0;
end
methods
function obj = BarRocketPlant()
obj = obj@SecondOrderSystem(3,2,true);
obj = obj.setOutputFrame(obj.getStateFrame); % allow full-state feedback
%equilibrium system
obj.x0 = Point(obj.getStateFrame,zeros(6,1));
obj.u0 = Point(obj.getInputFrame,obj.m*obj.g/2 * [1;1]);
%noise
obj.w_dist = truncate(makedist('Normal', 'mu', 0, 'sigma', obj.w_sigma), -1, 1);
obj.Bw = [1; 0; 0]*obj.w_max;
end
function qdd = sodynamics(obj,~,q,qd,u)
%Implement the second-order dynamics for the bar rocket
%time invariant system
%f(x) + g(x) u
%nonlinearity affine in control
%force term
mass_inertia = [obj.m; obj.m; obj.I];
%g
force_response = [-sin(q(3)), -sin(q(3));
cos(q(3)), cos(q(3));
-obj.L/2, obj.L/2];
spring = [-obj.kx; 0; 0].*q;
friction = -obj.b'*qd;
gravity = [0; -obj.m*obj.g; 0];
force = spring + friction + gravity;
gu = force_response*u;
%cross-wind
%w = obj.Bw * random(obj.w_dist, 1);
w = [0; 0; 0];
%w = [0; -0.05; 0];
qdd = (force + gu + w) ./ mass_inertia;
end
function x = getInitialState(obj)
x = randn(6,1);
%x = [0.8; -0.5; 0.5; 0; 0; 0];
end
function [c,V] = hoverLQR(obj)
Q = diag([10 10 10 1 1 (obj.L/2/pi)]); %Q = diag([10*ones(1,3) ones(1,3)]);
R = [0.1 0.05; 0.05 0.1]; %R = diag([0.1 0.1]);
if (nargout>1)
[c,V0] = tilqr(obj,obj.x0,obj.u0,Q,R);
sys = feedback(obj,c);
pp = sys.taylorApprox(0,obj.x0,[],3); % make polynomial approximation
options=struct();
options.degL1=2;
%options.method='bilinear';
%options.degV=4;
V=regionOfAttraction(pp,V0,options);
else
c = tilqr(obj,obj.x0,obj.u0,Q,R);
end
end
function [c, V] = hoverHinf(obj)
obj.x0 = Point(obj.getStateFrame,zeros(6,1));
obj.u0 = Point(obj.getInputFrame,obj.m*obj.g/2 * [1;1]);
Q = diag([10 10 10 1 1 (obj.L/2/pi)]); %Q = diag([10*ones(1,3) ones(1,3)]);
R = [0.1 0.05; 0.05 0.1]; %R = diag([0.1 0.1]);
gamma = 10;
if (nargout>1)
[c,V0] = tiHinf(obj,obj.x0,obj.u0,Q,R, obj.Bw, gamma);
sys = feedback(obj,c);
pp = sys.taylorApprox(0,obj.x0,[],3); % make polynomial approximation
options=struct();
options.degL1=2;
%options.method='bilinear';
%options.degV=4;
V=regionOfAttraction(pp,V0,options);
else
c = tiHinf(obj,obj.x0,obj.u0,Q,R, obj.Bw, gamma);
end
end
end
end