-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsolveBruteforcePointToPoint_helper.m
58 lines (45 loc) · 1.72 KB
/
solveBruteforcePointToPoint_helper.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
function f = solveBruteforcePointToPoint_helperFun(x)
%% SOLVEBRUTEFORCEPOINTTOPOINT_HELPERFUN cost function for fmincon
%============ Check input and workspace variables ============
global ptpPathOptions ptpPathWaypoints ptpPathStartConfig;
if ~isa(ptpPathOptions, 'PathOptions')
error('You must define ptpPathOptions in the workspace.');
end
if isequal(size(ptpPathWaypoints), [0 0])
error('You must define ptpPathWaypoints in the workspace.');
end
if isequal(size(ptpPathStartConfig), [0 0])
error('You must define ptpPathStartConfig in the worksapce.');
end
if isempty(x)
error('x is empty!');
end
[m, ~] = size(x);
[n, ~] = size(ptpPathWaypoints);
if ((strcmp(ptpPathOptions.Circuit, 'off') && (n ~= m))...
|| (strcmp(ptpPathOptions.Circuit, 'on') && ((n + 1) ~= m)))
error('Expected x and ptpPathWaypoints to have compatible dimensions.');
end
%====================== Compute cost =======================
position = ptpPathStartConfig(1:2);
heading = ptpPathStartConfig(3);
f = 0;
for i=1:n
v = ptpPathWaypoints(i, :);
theta = x(i);
f = f + findPTPCost(position,heading,v,theta,ptpPathOptions.TurnRadius);
position = v;
heading = theta;
end
% Return cost
if strcmp(ptpPathOptions.Circuit, 'on')
theta = x(n+1);
%theta = findHeadingFrom(position,ptpPathStartConfig(1:2));
f = f + findPTPCost(position,heading,ptpPathStartConfig(1:2),...
theta, ptpPathOptions.TurnRadius);
end
% Minimize or maximize cost
if strcmp(ptpPathOptions.MaximizeCost, 'on')
f = f * -1;
end
end