-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathPlanning_multObs.m
61 lines (45 loc) · 1.42 KB
/
pathPlanning_multObs.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
clc;
clear all;
close all;
%%
%carga de datos
run('obstacles0');
%%
%optimizacion
cvx_begin quiet
variable p(N,d,2) %number of steps, number of dimensions, number of trajectories
expression gasolina
gasolina = 0;
for k=1:2 %two trajectories
for i=2:N-1 %steps
gasolina = gasolina + pow_pos(norm(p(i-1,:,k)-2*p(i,:,k)+p(i+1,:,k),2),2);
end
end
minimize(gasolina)
subject to
for k=1:2
p(1,:,k) == pInitial
p(N,:,k) == pFinal
%collision avoidance for multiple obstacles, two trajectories (we assume
%the goal is in the upper right quadrant in terms of the obstacle, and initial position is
%not)
for o=1:obstacles %for each obstacle
if (pInitial(1) <= pObs(o,1)+rObs(o)) && (pInitial(2) <= pObs(o,2)+rObs(o))
if k==1
p(N/2,1,k) <= pObs(o,1)-(rObs(o)) %passing on the left
p(N/2,2,k) >= pObs(o,2)+(rObs(o)) %passing above
elseif k==2
p(N/2,1,k) >= pObs(o,1)+(rObs(o)) %passing on the right
p(N/2,2,k) <= pObs(o,2)-(rObs(o)) %passing below
end
end
end
end
cvx_end
%%
dist = (1:N)*h;
plot(p(:,1,1),p(:,2,1));
hold on
plot(p(:,1,2),p(:,2,2));
%figure;
viscircles(pObs,rObs);