-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSixLinkPRMScript.m
88 lines (53 loc) · 1.85 KB
/
SixLinkPRMScript.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
%
% SixLinkPRMScript.
%
%% Drawing the robot
figure;
% The SixLinkRobot function computes layout of all of the links in the
% robot as a function of the 6 configuration space parameters. You can
% adjust these sixe numbers to see what happens.
fv = SixLinkRobot ([-120 120 -120 120 -120 60]);
fv2 = SixLinkRobot ([0 0 0 0 0 180]);
p = patch (fv);
p.FaceColor = 'red';
p.EdgeColor = 'none';
p2 = patch(fv2);
p2.FaceColor = 'green';
p2.EdgeColor = 'none';
sz = 30;
axis equal;
axis (sz*[-1 1 -1 1]);
%% Add obstacles
obstacle = boxFV(10, 20, 10, 20);
obstacle = appendFV (obstacle, boxFV(-20, 0, -20, -10));
obstacle = appendFV (obstacle, transformFV(boxFV(-10, 10, -10, 10), 30, [-20 20]));
patch (obstacle);
%% Build roadmap
nsamples = 200;
neighbors = 5;
roadmap = PRM (@()(RandomSampleSixLink(obstacle)), @DistSixLink, @(x,y)(LocalPlannerSixLink(x,y,obstacle)), nsamples, neighbors);
%% Add nodes
roadmap2 = AddNode2PRM ([240 120 240 120 240 60]', roadmap, @DistSixLink, @(x,y)(LocalPlannerSixLink(x,y,obstacle)), neighbors);
roadmap2 = AddNode2PRM ([0 0 0 0 0 180]', roadmap2, @DistSixLink, @(x,y)(LocalPlannerSixLink(x,y,obstacle)), neighbors);
%% Plan a route
route = ShortestPathDijkstra(roadmap2.edges, roadmap2.edge_lengths, nsamples+1, nsamples+2);
%% Plot the trajectory
for i = 2:length(route)
x1 = roadmap2.samples(:,route(i-1));
x2 = roadmap2.samples(:,route(i));
delta = x2 - x1;
t = delta > 180;
delta(t) = delta(t) - 360;
t = delta < -180;
delta(t) = delta(t) + 360;
n = ceil(sum(abs(delta)) / 10);
for j = 0:n
x = mod(x1 + (j/n)*delta, 360);
fv = SixLinkRobot (x);
p.Vertices = fv.vertices;
drawnow;
if (CollisionCheck(fv, obstacle))
fprintf (1, 'Ouch\n');
end
end
end