-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect_data.m
More file actions
42 lines (38 loc) · 1.26 KB
/
Copy pathcollect_data.m
File metadata and controls
42 lines (38 loc) · 1.26 KB
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
output_filename = sprintf('test.mat');
N = 31; % number of knot points
T = 2; % max duration allowed
K = 1; % number of iterations
u_limit = 5; % input limit
theta_bounds = [-pi,pi]; % sampling bounds
thetadot_bounds = [-8,8]; % sampling bounds
[p, traj_opt] = dircol_setup(N, T, u_limit);
failures = 0;
elapsed = zeros(1, K);
for k = 1:K
tic;
x0 = [random_sample(theta_bounds); random_sample(thetadot_bounds)];
xf = [random_sample(theta_bounds); random_sample(thetadot_bounds)];
[x_traj, u_traj, pairs, dists, success] = dircol(p, traj_opt, N, T, x0, xf);
elapsed(k) = toc;
if(success)
if exist(output_filename, 'file') ~= 2
X = pairs;
Y = dists;
save(output_filename, 'X', 'Y');
else
load(output_filename)
X = [X pairs];
Y = [Y dists];
save(output_filename, 'X', 'Y');
end
else
failures = failures + 1;
end
disp(['Trial: ', num2str(k), '/', num2str(K), ' Total time: ', ...
num2str(sum(elapsed)),' (', num2str(failures), ' failures', ')']);
end
% bounds = [a,b]
% returns a random decimal within [a,b]
function sample = random_sample(bounds)
sample = bounds(1) + (bounds(2) - bounds(1))*rand();
end