cyclic pursuit

1 次查看(过去 30 天)
Twinkle
Twinkle 2012-3-2
function main
close all
clear all
clc
global v n k rho x_t y_t;
n=input('Enter the number of agents:');
v=zeros(1,n);
v=input('Enter the velocity of the agents:');
h0=zeros(1,n);
h0=input('Enter the heading angle of the agents in degrees:');
k=zeros(1,n);
k=input('Enter the controller gain of the agents:');
x_t=input('enter the x coord of the target:');
y_t=input('enter the y coord of the target:');
rho=input('enter the value of rho:');
x_0=zeros(1,n);
x_0=input('Enter the initial x positions of the agents:');
y_0=zeros(1,n);
y_0=input('Enter the initial y positions of the agents:');
x0=zeros(3*n,1);
for i=1:n
x0(i*3-2)=x_0(i);
x0(i*3-1)=y_0(i);
x0(i*3)=h0(i);
end
options=odeset('RelTol',1e-6);
tspan=[0,100];
[t,x] = ode45(@F,tspan,x0,options);
plot(x_t,y_t,'.g');
hold on
for i=1:n
plot(x_0(i),y_0(i),'*r');
hold on
end
for i=1:n
plot(x(:,3*i-2),x(:,3*i-1),'- y');
hold on
end
function dx=F(t,x)
global v n k rho x_t y_t;
dx=zeros(3*n,1);
for i=1:n
if (i==n)
j=1;
else
j=i+1;
end
vl_x(i)=rho*x(j*3-2)+(1-rho)*x_t; %for the x coordinate of virtual target for the ith agent
vl_y(i)=rho*x(j*3-1)+(1-rho)*y_t; %for the y coordinate of virtual target for the ith agent
phi(i)=atand((vl_y(i)-x(3*i-1))/(vl_x(i)-x(3*i-2)))-x(3*i);
dx(i*3-2)=v(i)*cos(x(3*i)); %for the x coordinate of each agent
dx(i*3-1)=v(i)*sin(x(3*i)); %for the y coordiante of each agent
dx(i*3)=(k(i)*phi(i)/v(i))*pi/180; %for the heading angle of each agent
end %i have converted phi from degrees to radians
return
DOUBT :Why do the agents not reach the target?? Although, theoretically, it shows good results. rate of change of heading angle is proportional to phi.

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by