-
Notifications
You must be signed in to change notification settings - Fork 9
/
Untitled.m
131 lines (121 loc) · 2.64 KB
/
Untitled.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
clc; clear all; close all;
%
vl=1.3;
tfinal=100;
%f=1;
%
i=1;
vf(i)=0;
t(i)=0;
f=0.55;
wl(i)=-sin(1.1*t(i));
%wl(i)=6;
xl(i)=1/sqrt(2);
yl(i)=1/sqrt(2);
thtl(i)=pi/2;
xf(i)=0;
yf(i)=0;
thtf(i)=pi/8;
%a(i)=sin(f*t(i));
%
%phi(i)=atan((yl(i)-yf(i))/((xl(i)-xf(i))))-thtf(i);
%d(i)=sqrt((yl(i)-yf(i))^2+((xl(i)-xf(i)))^2);
phi=-pi/3;
d=1;
%
h=0.01;
%
wfmax=pi;
K=0.7692;
Kpp=3;
Kp=-2;
vlmax=2;
vfmax=4;
%
%
bta(i) = thtl(i)-thtf(i);
%alpha=asin(K*d*cos(phi));
%while (beta(i)>=0 && beta(i)>alpha) || (beta(i)<0 && beta(i)<alpha)
% vf(i)=0;
% if beta(i)>alpha
% wf(i)=wfmax;
% else
% wf(i)=-wfmax;
% end
%end
%
%
while t(i)<tfinal
%Leader
% Koo=0.5;
% Ko=-1;
%
% alpha1=asin(Koo*d*cos(phi));
% alpha2=asin(Ko*d*cos(phi));
% while beta(i)>alpha1 && beta(i)<alpha2
% vf(i)=
% end
xl(i+1) = xl(i) + h*vl*cos(thtl(i));
yl(i+1) = yl(i) + h*vl*sin(thtl(i));
thtl(i+1) = thtl(i) + h*wl(i);
%Follower
%
%
%phi(i)=atan((yl(i)-yf(i))/((xl(i)-xf(i))))-thtf(i);
%d(i)=sqrt((yl(i)-yf(i))^2+((xl(i)-xf(i)))^2);
%vf(i)=(vl*cos(thtl(i)-thtf(i)-phi)/cos(phi));
%
%a(i)=sin(f*t(i));
%a(i)=0.4;
%beta(i) = thtl(i)-thtf(i);
%alpha=asin(Kpp*d*cos(phi));
%
% if beta(i)>=0
% if beta(i)>alpha
% vf(i)=vfmax;
% wf(i)=vfmax*Kpp;
% else
% vf(i)=(vl*cos(beta(i)-phi))/(cos(phi));
% if vf(i)>vfmax
% vf(i)=vfmax;
% end
% wf(i)=(vl*sin(beta(i)))/(d*cos(phi));
% end
% else
% if beta(i) < alpha
% vf(i)=vfmax;
% wf(i)=vfmax*Kp;
% else
% vf(i)=(vl*cos(beta(i)-phi))/(cos(phi));
% if vf(i)>vfmax
% vf(i)=vfmax;
% end
% wf(i)=(vl*sin(beta(i)))/(d*cos(phi));
% end
% end
% %
vf(i)=(vl*cos(bta(i)-phi))/(cos(phi));
wf(i)=(vl*sin(bta(i)))/(d*cos(phi));
xf(i+1) = xf(i) + h*vf(i)*cos(thtf(i));
yf(i+1) = yf(i) + h*vf(i)*sin(thtf(i));
thtf(i+1)= thtf(i) + h*wf(i);
%
i=i+1;
t(i)=t(i-1)+h;
wl(i)=-sin(1.1*t(i));
bta(i)=thtl(i)-thtf(i);
%wl(i)=6;
end
%
plot(xl,yl,'r',xf,yf); axis equal; grid on;
%figure; plot(t,a); grid on;
figure; plot(t,thtf); grid on;
figure; plot(t,thtl); grid on;
%figure; plot(t, a); grid on;
%figure; plot(t, tht); grid on;
%
%tht_d(1)=0;
%for j=2: length(tht)
% tht_d(j)=(tht(j)-tht(j-1))/h;
%end
%figure(2); hold on; plot(t, tht_d, 'r');