Skip to content

Commit 2c99186

Browse files
committed
Commenting code
1 parent 030c6bd commit 2c99186

File tree

7 files changed

+5191
-4
lines changed

7 files changed

+5191
-4
lines changed

SingleTrackAnimation.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
%------------------------------------------------------------------
2+
% Programed by:
3+
% - Lucas Rath ([email protected])
4+
% -
5+
% -
6+
7+
% Generate Animation for the main_singletrack.m script
8+
%------------------------------------------------------------------
9+
10+
111
classdef SingleTrackAnimation < handle
212

313
properties
414
% object that contains track coordinates
5-
racetrack @RaceTrack
15+
racetrack @ RaceTrack
616

717
% variables that contain history of vehicle states and inputs to be ploted
818
mu_x_pred_opt
@@ -50,7 +60,7 @@ function initTrackAnimation(obj)
5060
% updateTrackAnimation(k) to move forward with the animation.
5161
% -----------------------------------------------------------------
5262
obj.h_fig = figure('Color','w','Position',[468 128 872 633]);
53-
title('Stochastic Gaussian-Process MPC')
63+
title('Adaptive Gaussian-Process MPC')
5464
hold on;
5565
grid on;
5666
axis equal;
@@ -115,6 +125,10 @@ function initTrackAnimation(obj)
115125
c = colorbar;
116126
c.Label.String = 'Vehicle predicted velocity [m/s]';
117127
caxis([5 25])
128+
129+
% lock up axis limits
130+
xlim('manual')
131+
ylim('manual')
118132
drawnow
119133
end
120134

fp.m

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
%------------------------------------------------------------------
2+
% Programed by:
3+
% - Lucas Rath ([email protected], https://github.com/lucasrm25)
4+
% -
5+
% -
6+
7+
% Generate fancy plots (fp)
8+
%------------------------------------------------------------------
9+
10+
classdef fp
11+
properties
12+
end
13+
14+
methods(Static)
15+
16+
function savefig(fname,varargin)
17+
18+
p = inputParser;
19+
20+
defaultFormat = 'epsc';
21+
expectedFormat = {'epsc','svg','png','jpg'};
22+
addParameter(p,'format',defaultFormat, @(x) any(validatestring(x,expectedFormat)));
23+
addParameter(p,'fighandle',gcf, @(x) isa(x,'matlab.ui.Figure'));
24+
addParameter(p,'folder',fullfile(pwd,'images'), @(x) isa(x,'char'));
25+
parse(p,varargin{:});
26+
27+
if ~ exist(p.Results.folder,'dir'), mkdir(p.Results.folder); end
28+
% set(p.Results.fighandle.CurrentAxes,'LooseInset',p.Results.fighandle.CurrentAxes.TightInset)
29+
saveas(p.Results.fighandle, fullfile(p.Results.folder,fname), p.Results.format)
30+
end
31+
32+
function fig = f()
33+
fig = figure('Color','white');
34+
hold on, grid on;
35+
end
36+
37+
function latexcode = m2latex(matrix)
38+
if ~isa(matrix,'sym')
39+
matrix = sym(matrix);
40+
end
41+
latexcode = latex(vpa(simplify(matrix)));
42+
if numel(latexcode)>=6 && strcmp(latexcode(6),'(') && strcmp(latexcode(end),')')
43+
latexcode(6) = '[';
44+
latexcode(end) = ']';
45+
end
46+
clipboard('copy',latexcode);
47+
end
48+
49+
function str = figpos()
50+
a = gcf;
51+
pos = a.Position;
52+
str = ['figure(''Color'',''white'',''Position'',[' num2str(pos) ']);'];
53+
clipboard('copy',str);
54+
end
55+
56+
% varargin{1}: line opacity
57+
function cl = getColor(n, varargin)
58+
colrs = lines(max(n));
59+
if nargin >= 2
60+
opacity = varargin{1};
61+
else
62+
opacity = [];
63+
end
64+
cl = [colrs(n,:), repmat(opacity,numel(n),1)];
65+
end
66+
end
67+
end

genFigs.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
close all; clear all
2+
3+
imgname = 'trace-without-GP';
4+
outfile = fullfile(pwd,'/simresults/20-01-15-out-GP-without-GP.mat');
5+
kplot = 558;
6+
7+
imgname = 'trace-with-GP';
8+
outfile = fullfile(pwd,'/simresults/20-01-15-out-GP-with-GP-optimized.mat');
9+
kplot = 412
10+
11+
load(outfile)
12+
13+
14+
[trackdata, x0, th0, w] = RaceTrack.loadTrack_02();
15+
track = RaceTrack(trackdata, x0, th0, w);
16+
17+
trackAnim = SingleTrackAnimation(track, out.mu_x_pred_opt, out.var_x_pred_opt, out.u_pred_opt, out.x_ref);
18+
trackAnim.initTrackAnimation();
19+
drawnow;
20+
21+
% k = find(~isnan(out.xhat(1,:)), 1, 'last' ) - 1;
22+
23+
trackAnim.mu_x_pred_opt = out.mu_x_pred_opt;
24+
trackAnim.var_x_pred_opt = out.var_x_pred_opt;
25+
trackAnim.u_pred_opt = out.u_pred_opt;
26+
trackAnim.x_ref = out.x_ref;
27+
trackAnim.updateTrackAnimation(kplot); % 558
28+
29+
30+
delete(trackAnim.h_car)
31+
delete(trackAnim.h_x_ref)
32+
delete(trackAnim.h_mu_x_pred_opt)
33+
cellfun( @(h) delete(h), trackAnim.h_var_x_pred_opt )
34+
legend('off')
35+
title('')
36+
fp.savefig(imgname,'format','epsc')

0 commit comments

Comments
 (0)