-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_collision.m
More file actions
73 lines (48 loc) · 1.92 KB
/
check_collision.m
File metadata and controls
73 lines (48 loc) · 1.92 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
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
function [c, status_flag] = check_collision( uav_x, uav_y, uav_v, uav_h, obs_x, obs_y, obs_v, obs_h, safety_r, TCPA)
% theta is the angle between the tangent line that from the usv to the intruder safety circle and the line that is between
% the intruder and the usv.
theta = atan(safety_r/sqrt((uav_x-obs_x)^2+(uav_y-obs_y)^2));
% theta 1 is the tangential angle of the vector that is between the
% intruder and the usv
theta1 = atan2(obs_y-uav_y, obs_x-uav_x);
if theta1 < 0
theta1 = theta1 + 2*pi;
end
% theta 2 is the tangential angle of the relative speed vector that is between
% the usv speed and the intruder speed
theta2 = atan2(uav_v*sin(uav_h)-obs_v*sin(obs_h),uav_v*cos(uav_h)-obs_v*cos(obs_h));%convert_angle(uav_v*cos(uav_h)-obs_v*cos(obs_h), uav_v*sin(uav_h)-obs_v*sin(obs_h));
if theta2 < 0
theta2 = theta2 + 2*pi;
end
delta = abs(theta1-theta2);
delta = vpa(delta,4);
theta = vpa(theta,4);
% Due to the equation solving accuracy, the error is assumed to be 0.01
if delta > theta+0.01
c = 0;
else c =1;
end
if abs(delta) > 2*pi-theta
c = 1;
end
status_flag = 0;
% % Check the TCPA
if c == 1
status_flag = 1;
distance_uav_obs = sqrt((uav_x-obs_x)^2+(uav_y-obs_y)^2);
% the line of the relative speed crossing the uav
% y = tan(theta2)x - tan(theta2)*uav_x + uav_y
distance_obs_line = abs(tan(theta2)*obs_x-obs_y-tan(theta2)*uav_x + uav_y)/sqrt((tan(theta2))^2+1);
distance_CPA = sqrt((distance_uav_obs)^2-(distance_obs_line)^2);
relative_uav_obs = sqrt((uav_v*cos(uav_h)-obs_v*cos(obs_h))^2+(uav_v*sin(uav_h)-obs_v*sin(obs_h))^2);
if distance_CPA/relative_uav_obs <= TCPA
c = 1;
status_flag = 2;
elseif distance_CPA/relative_uav_obs >TCPA && distance_CPA/relative_uav_obs < 2*TCPA
c = 0;
status_flag = 1;
else c = 0;
status_flag = 0;
end
end
end