forked from zychaoqun/Implementation-of-nonholonomicRRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collcheckstline.m
29 lines (27 loc) · 939 Bytes
/
collcheckstline.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
function [isFree, stlinepath, stlinecost] = collcheckstline(envmap, start, goal)
% Collision check all states on the straight line path from start to goal
% INPUTS:
% envmap - Environment map
% start - Start state [x,y]
% goal - Goal state [x,y]
% OUTPUTS:
% isFree - True if path is free of collisions, false otherwise
% stlinepath - Discretized straight line path between start & goal (N x 2)
% (8-connected), each row is [x,y]
% stlinecost - Cost of straight line path from start to goal
% Check if the path to nextState from nearState is collision-free
[ptx, pty] = bresenham(round(start(1)), round(start(2)), round(goal(1)), round(goal(2)));
isFree = true;
start
goal
ptx
pty
for k = 1:numel(ptx) % Check end-points as well
if(envmap(pty(k), ptx(k)))
isFree = false;
break;
end
end
stlinepath = [ptx pty];
stlinecost = sum(sqrt(sum((stlinepath(1:end-1,:) - stlinepath(2:end,:)).^2,2)),1);
end