-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathode_carrot_chase.m
49 lines (40 loc) · 1.04 KB
/
ode_carrot_chase.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
function [dydt] = ode_carrot_chase(t,y,w1_x,w1_y,w2_x,w2_y)
%% Author - Mandeep Singh
% email - [email protected]
%% Initializing Params
dydt = zeros(3,1);
v = 10;
delta = 10;
k = 60;
ugv_x = y(1);
ugv_y = y(2);
si = y(3);
%% XY Controller
% Computing the position error
% Distance of point to line (UGV Position - Desired path)
R_u = sqrt((w1_x - ugv_x)^2 + (w1_y - ugv_y)^2);
theta = atan2((w2_y - w1_y),(w2_x - w1_x));
theta_u = atan2(ugv_y - w1_y,ugv_x - w1_x);
beta = theta - theta_u;
R = sqrt(R_u^2 - (R_u*sin(beta))^2);
x_target = w1_x + (R+delta)*cos(theta);
y_target = w1_y + (R+delta)*sin(theta);
% pause(0.01)
si_d = atan2(y_target - ugv_y, x_target - ugv_x);
u = k*(si_d - si);
%% Non-Holonomic COnstraints
% Constraining the control input
% Rmin = 125;
% if(abs(u) > (v^2)/Rmin)
% if (u > 0)
% u = (v^2)/Rmin;
% else
% u = -(v^2)/Rmin;
% end
% end
% Finally heading angle
si_dot = u;
%% STATE EQUATIONS
dydt(1) = v*cos(si); % y(1) -> uav_x
dydt(2) = v*sin(si); % y(2) -> uav_y
dydt(3) = si_dot; % y(3) -> si