-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plotter.m
291 lines (256 loc) · 9.47 KB
/
Plotter.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
%%
clc
close all
global Start_X Start_Y
%load('ReferenceStates.mat');
[NumberOfSamples,~]=size(StatesLog);
[NumberOfSamples_PP,~]=size(StatesLog_PP);
%
% figure
% plot(ReferenceStates(1:NumberOfSamples,2)-OutputStates(1:NumberOfSamples,2));
% title('X-Pos Error (m)');
% figure
% plot(ReferenceStates(1:NumberOfSamples,3)-OutputStates(1:NumberOfSamples,3));
% title('Y-Pos Error (m)');
% figure
% plot(ReferenceStates(1:NumberOfSamples,7)-OutputStates(1:NumberOfSamples,7));
% title('Yaw-Pos Error (m)');
% figure
% plot(ReferenceStates(1:NumberOfSamples,8)-OutputStates(1:NumberOfSamples,8));
% title('X-Spd Error (m)');
% figure
% plot(ReferenceStates(1:NumberOfSamples,9)-OutputStates(1:NumberOfSamples,9));
% title('Y-Spd Error (m)');
% figure
% plot(ReferenceStates(1:NumberOfSamples,13)-OutputStates(1:NumberOfSamples,13));
% title('Yaw-Spd Error (m)');
figure
plot(StatesLog(1:NumberOfSamples,2),StatesLog(1:NumberOfSamples,3),...
'LineWidth',2,'Color', 'b');
%%Plot Parking Spot
%--------------------------------------------------------------------------
% hold on
% rectangle('Position',[0,0,4,1],'FaceColor',[1 0 0],'EdgeColor','b',...
% 'LineWidth',2)
% hold on
% rectangle('Position',[6,0,3,1],'FaceColor',[1 0 0],'EdgeColor','b',...
% 'LineWidth',2)
% plot_x = 3:0.1:8.5;
% plot_y = zeros(length(plot_x));
% hold on
% plot(plot_x,plot_y,'LineWidth',2,'Color', 'b');
%
% hold on
% th = 0:pi/100:pi;
% xunit = 10 * cos(th) + 5;
% yunit = 10 * sin(th) + 1.5;
% plot(xunit, yunit,'LineStyle','--','LineWidth',3,'Color', 'g');
% hold on
% straight_line_x = min(xunit):0.1:max(xunit);
% plot(straight_line_x,1.5*ones(length(straight_line_x)),'LineStyle','--',...
% 'LineWidth',0.5,'Color', 'g')
%--------------------------------------------------------------------------
%%
for i = 1:10:length(StatesLog)
hold on
Back_Right_Corner_T = ...
[cos(StatesLog(i,4)) -sin(StatesLog(i,4)); ...
sin(StatesLog(i,4)) cos(StatesLog(i,4))]* ...
[-0.5; -0.25];
Back_Right_Corner_X = StatesLog(i,2) + Back_Right_Corner_T(1);
Back_Right_Corner_Y = StatesLog(i,3) + Back_Right_Corner_T(2);
Front_Right_Corner_T = ...
[cos(StatesLog(i,4)) -sin(StatesLog(i,4)); ...
sin(StatesLog(i,4)) cos(StatesLog(i,4))]* ...
[0.5; -0.25];
Front_Right_Corner_X = StatesLog(i,2) + Front_Right_Corner_T(1);
Front_Right_Corner_Y = StatesLog(i,3) + Front_Right_Corner_T(2);
Front_Left_Corner_T = ...
[cos(StatesLog(i,4)) -sin(StatesLog(i,4)); ...
sin(StatesLog(i,4)) cos(StatesLog(i,4))]* ...
[0.5; 0.25];
Front_Left_Corner_X = StatesLog(i,2) + Front_Left_Corner_T(1);
Front_Left_Corner_Y = StatesLog(i,3) + Front_Left_Corner_T(2);
Back_Left_Corner_T = ...
[cos(StatesLog(i,4)) -sin(StatesLog(i,4)); ...
sin(StatesLog(i,4)) cos(StatesLog(i,4))]* ...
[-0.5; 0.25];
Back_Left_Corner_X = StatesLog(i,2) + Back_Left_Corner_T(1);
Back_Left_Corner_Y = StatesLog(i,3) + Back_Left_Corner_T(2);
Head_T = ...
[cos(StatesLog(i,4)) -sin(StatesLog(i,4)); ...
sin(StatesLog(i,4)) cos(StatesLog(i,4))]* ...
[0.7; 0];
Head_X = StatesLog(i,2) + Head_T(1);
Head_Y = StatesLog(i,3) + Head_T(2);
%
% hold on
% plot(StatesLog(i,2),StatesLog(i,3),'o');
hold on
plot([Back_Right_Corner_X Front_Right_Corner_X Head_X ...
Front_Left_Corner_X Back_Left_Corner_X Back_Right_Corner_X], ...
[Back_Right_Corner_Y Front_Right_Corner_Y Head_Y ...
Front_Left_Corner_Y Back_Left_Corner_Y Back_Right_Corner_Y],...
'Color','black','LineStyle','-', 'LineWidth',0.5);
end
% Enterance of Park Region -----------------------------------------------%
% strmin = ['Enterance of Park Region'];
% t = text(StatesLog(1,2)-2,StatesLog(1,3)+1,strmin);
% t(1).Color = 'red';
% t(1).FontSize = 14;
% ------------------------------------------------------------------------%
%%Plot Parking Spot
% hold on
% rectangle('Position',[Obstacle1Position_X - LengthOfObstacle/2,...
% Obstacle1Position_Y - WidthOfObstacle/2,...
% LengthOfObstacle,WidthOfObstacle], ...
% 'FaceColor',[1 0 0],'EdgeColor','b','LineWidth',2)
%%Plot Parking Spot
for j = 1:Number_Of_Obstacles
hold on
rectangle('Position',[Array_Of_Obstacles(j,1)-Array_Of_Obstacles(j,3)/2, ...
Array_Of_Obstacles(j,2)-Array_Of_Obstacles(j,4)/2, ...
Array_Of_Obstacles(j,3),Array_Of_Obstacles(j,4)],...
'FaceColor',[1 0 0],'EdgeColor','b','LineWidth',2)
end
hold on
xlabel('x position(m)')
ylabel('y position(m)')
%legend('Simulation', 'Optimal Path','WayPoints')
xlim([-1 20])
ylim([-3 5])
%% Plot 1
figure
plot(StatesLog_PP(1:NumberOfSamples_PP,2), ...
StatesLog_PP(1:NumberOfSamples_PP,4), 'LineWidth', 2, 'Color', 'b');
%%Plot Parking Spot
% hold on
% rectangle('Position',[Obstacle1Position_X - LengthOfObstacle/2,...
% Obstacle1Position_Y - WidthOfObstacle/2,...
% LengthOfObstacle,WidthOfObstacle], ...
% 'FaceColor',[1 0 0],'EdgeColor','b','LineWidth',2)
%%Plot Parking Spot
for j = 1:Number_Of_Obstacles
hold on
rectangle('Position',[Array_Of_Obstacles(j,1)-Array_Of_Obstacles(j,3)/2, ...
Array_Of_Obstacles(j,2)-Array_Of_Obstacles(j,4)/2, ...
Array_Of_Obstacles(j,3),Array_Of_Obstacles(j,4)],...
'FaceColor',[1 0 0],'EdgeColor','b','LineWidth',2)
end
xlabel('x position(m)')
ylabel('y position(m)')
%legend('Simulation', 'Optimal Path','WayPoints')
xlim([-1 20])
ylim([-3 5])
%%
figure
subplot(2,1,1)
plot(StatesLog(1:NumberOfSamples,1),180*StatesLog(1:NumberOfSamples,4)/pi,'LineWidth',2,'Color', 'b');
hold on
plot(Desired_Outputs(1:NumberOfSamples,1),180*Desired_Outputs(1:NumberOfSamples,3)/pi,'LineWidth',2,'Color','r')
grid on
xlabel('time(sec)')
ylabel('Yaw angle (deg)')
legend('Yaw angle of the Vehicle','Desired Yaw Angle')
ylim([-180 180])
subplot(2,1,2)
plot(StatesLog(1:NumberOfSamples,1),StatesLog(1:NumberOfSamples,5),'LineWidth',2,'Color', 'b');hold on;
plot(Desired_Outputs(1:NumberOfSamples,1),Desired_Outputs(1:NumberOfSamples,2),'LineWidth',2,'Color','r')
grid on
xlabel('time(sec)')
ylabel('Surge Speed (m/s)')
legend('Surge Speed of the Vehicle','Desired Surge Speed')
figure
subplot(2,1,1)
stairs(StatesLog(1:NumberOfSamples,1),...
StatesLog(1:NumberOfSamples,5),'LineWidth',2);
legend('v_x in Body vs Time')
xlabel('Time(s)')
ylabel('v_x velocity in Body Frame(m/s)')
subplot(2,1,2)
grid on
stairs(StatesLog(1:NumberOfSamples,1),...
StatesLog(1:NumberOfSamples,6),'LineWidth',2);
legend('v_y in Body vs Time')
xlabel('Time(s)')
ylabel('v_y velocity in Body Frame(m/s)')
%% Plot 2
figure
subplot(2,1,1)
stairs(StatesLog_PP(1:NumberOfSamples_PP,1),...
StatesLog_PP(1:NumberOfSamples_PP,3),'LineWidth',2);
legend('v_x in NED vs Time')
xlabel('Time(s)')
ylabel('v_x velocity in NED Frame(m/s)')
subplot(2,1,2)
grid on
stairs(StatesLog_PP(1:NumberOfSamples_PP,1),...
StatesLog_PP(1:NumberOfSamples_PP,5),'LineWidth',2);
legend('v_y in NED vs Time')
xlabel('Time(s)')
ylabel('v_y velocity in NED Frame(m/s)')
%%
%
% figure
% plot(StatesLog(1:NumberOfSamples,1),StatesLog(1:NumberOfSamples,6),'LineWidth',2,'Color', 'b');
% grid on
% xlabel('time(sec)')
% ylabel('Sway Speed (m/s)')
% legend('Sway Speed of the Vehicle')
%
% figure
% plot(StatesLog(1:NumberOfSamples,1),StatesLog(1:NumberOfSamples,7),'LineWidth',2,'Color', 'b'); hold on;
% grid on
% xlabel('time(sec)')
% ylabel('Yaw rate (rad/s)')
% legend('Yaw rate of the Vehicle')
% ylim([-pi/2 pi/2])
% figure
% stairs(Normalized_Distance(:,1),Normalized_Distance(:,2),'LineWidth',2);
% legend('Distance of Vehicle to Path')
% xlabel('Time(s)')
% ylabel('Distance')
%
figure
subplot(2,1,1)
stairs(LThrusterForceXLog(:,1),LThrusterForceXLog(:,2),'LineWidth',2);
legend('Left thruster force(N)')
xlabel('Time(s)')
ylabel('Torque(N)')
subplot(2,1,2)
grid on
stairs(RThrusterForceXLog(:,1),RThrusterForceXLog(:,2),'r','LineWidth',2);
xlabel('Time(s)')
ylabel('Torque(N)')
legend('Right thruster force(N)')
figure
stairs(StatesLog_PP(1:NumberOfSamples_PP,1),...
StatesLog_PP(1:NumberOfSamples_PP,Number_Of_Obstacles*4+8),'LineWidth',2);
legend('Quadrant vs Time')
xlabel('Time(s)')
ylabel('Quadrant')
%
%
% figure
% plot(Tot_Forces(1:NumberOfSamples,1),Tot_Forces(1:NumberOfSamples,2),'LineWidth',2,'Color', 'b');
% hold on
% plot(Dist_Forces(1:NumberOfSamples,1),Dist_Forces(1:NumberOfSamples,2),'LineWidth',2,'Color','r')
% grid on
% xlabel('time(sec)')
% ylabel('X Force')
%
% figure
% plot(Tot_Forces(1:NumberOfSamples,1),Tot_Forces(1:NumberOfSamples,3),'LineWidth',2,'Color', 'b');
% hold on
% plot(Dist_Forces(1:NumberOfSamples,1),Dist_Forces(1:NumberOfSamples,3),'LineWidth',2,'Color','r')
% grid on
% xlabel('time(sec)')
% ylabel('Y Force')
%
% figure
% plot(Tot_Forces(1:NumberOfSamples,1),Tot_Forces(1:NumberOfSamples,4),'LineWidth',2,'Color', 'b');
% hold on
% plot(Dist_Forces(1:NumberOfSamples,1),Dist_Forces(1:NumberOfSamples,4),'LineWidth',2,'Color','r')
% grid on
% xlabel('time(sec)')
% ylabel('N Force')