-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPLS_matlab_simulator.m
104 lines (86 loc) · 3.13 KB
/
PLS_matlab_simulator.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
% -----------------------------------------------------------
% File: PLS_matlab_simulator.m
% Author: Christoph Jurczyk
% Date: 05.03.2019
% Description: Main file for PLS simulation
% -----------------------------------------------------------
%% ----------------------------------------------------------
% Clear workspace
clearvars
% Add subfolder with classes and functions
addpath('src')
% ----------------------------------------------------------
%% ----------------------------------------------------------
% PLS parameters
pls_res = 1; % resolution in deg
pls_dof = 180; % degree of freedome in deg
pls_n = pls_dof / pls_res; % number of measurements
pls_max_dist = 5; % maximum distance of measurement in m
pls_x = 0; % start x-postion in m
pls_y = 0; % start y-postion in m
pls_angle = 0; % start angle in deg
% Resolution of simulation polar line
sim_grid = 5e-2; % grid size for PLS data measurement in m
sim_grid_rte = 0.15; % grid size for route path in m
% Simulation settings
auto_scaling = false; % auto scaling of plot during simulation
xlim_value = [-2.75 2.75]; % for manual scaling
ylim_value = [0 15]; % for manual scaling
% ----------------------------------------------------------
%% ----------------------------------------------------------
% Initialize Map
% Add some obstacles to the map
obstacles = clObstacle('box',1,2,1.5,3); % box
obstacles(end+1) = clObstacle('box',-2,8.2,-1.5,9); % box
obstacles(end+1) = clObstacle('box',-2,11,-1.75,11.5); % box
obstacles(end+1) = clObstacle('cylinder',-1.5,6,0.5); % cylinder
obstacles(end+1) = clObstacle('box',2.5,0,2.75,15); % wall
obstacles(end+1) = clObstacle('box',-2.75,0,-2.5,15); % wall
% Intialize Route
% Route points: x, y
rte_points = [
0, 0;
0, 4;
1, 8;
1, 10;
];
rte_data = calcRouteData(rte_points, sim_grid_rte);
% Set plot range
if auto_scaling == true
xlim_value = [min(rte_points(:,1))-pls_max_dist max(rte_points(:,1)) + pls_max_dist];
ylim_value = [min(rte_points(:,2)) max(rte_points(:,2)) + pls_max_dist];
end%if
% Set last run time for fps indicator
last_runtime = nan;
% ----------------------------------------------------------
%% ----------------------------------------------------------
% Compute simulation
for n = 1:length(rte_data)
% Start fps measurement
tic
% Initialize Plot
clf
hold on
grid
axis equal
xlim(xlim_value);
ylim(ylim_value);
title(sprintf('fps = %.2f',1/last_runtime))
% Set PLS coordinates from route
pls_x = rte_data(n).x;
pls_y = rte_data(n).y;
pls_angle = rte_data(n).angle;
% Plot obstacles
plotObstacles(obstacles)
% Initialize PLSdataArray with max distance points
PLSdataArray = initPoints(pls_n, pls_res, pls_x, pls_y, pls_angle, pls_max_dist);
% Check colidation of PLS beam
PLSdataArray = calcPLSdata(PLSdataArray, pls_x, pls_y, obstacles, sim_grid, pls_max_dist);
% Plot PLS data
plsDataPlot(PLSdataArray, pls_x, pls_y, pls_angle);
% Wait for plot
pause(eps)
% Save last time for fps
last_runtime = toc;
end%for
% ----------------------------------------------------------