root / branches / 16299_s10 / matlab / evolveRobots.m @ 1715
History | View | Annotate | Download (1.62 KB)
1 |
% 4 robots |
---|---|
2 |
% Robot #1 is the queen |
3 |
n = 4; |
4 |
dt = 0.05; |
5 |
tf = 10; |
6 |
|
7 |
X = zeros(n,1); %cm |
8 |
Y = zeros(n,1); %cm |
9 |
R = zeros(n,1); |
10 |
Theta = zeros(n,1); %rads |
11 |
Phi = zeros(n,1); %rads |
12 |
V = zeros(n,1); %0-255 |
13 |
W = zeros(n,1); %0-255 |
14 |
|
15 |
%W(1,1) = pi; |
16 |
%X(2,1) = 2.3; |
17 |
%Y(2,1) = 5.7; |
18 |
|
19 |
|
20 |
|
21 |
for i=1:n |
22 |
X(i) = rand(1,1)*10; |
23 |
Y(i) = rand(1,1)*10; |
24 |
V(i) = rand(1,1)*10; |
25 |
W(i) = rand(1,1)*2*pi; |
26 |
end |
27 |
|
28 |
|
29 |
|
30 |
% The things that end in s are the sensor values |
31 |
Xs = zeros(n,1); |
32 |
Ys = zeros(n,1); |
33 |
Thetas = zeros(n,1); |
34 |
Phis = zeros(n,1); |
35 |
|
36 |
% These state variables allow the models to maintain some state across calls |
37 |
motorState = []; |
38 |
sensorState = []; |
39 |
|
40 |
% Run through each timestep |
41 |
for t = 0:dt:tf |
42 |
|
43 |
% update the true positions using the motor model |
44 |
[X, Y, Theta, R, Phi, motorState] = motionModel(V, W, X, Y, Theta, dt, motorState); |
45 |
%Phi |
46 |
|
47 |
% Update the sensor values using the sensor model |
48 |
[Xs, Ys, Thetas, Phis, sensorState] = sensorModel(X, Y, Theta, Phi, sensorState); |
49 |
%Phis |
50 |
|
51 |
axis([0 20 0 20]) |
52 |
axis manual |
53 |
|
54 |
% set( gca,'nextplot','add' ); |
55 |
% for j = 1:n |
56 |
% color = [rand rand rand]; |
57 |
% h = plot_arrow( X(j),Y(j),X(j)+cos(Theta(j)),Y(j)+sin(Theta(j)),... |
58 |
% 'color',color,'facecolor',color,'edgecolor',color ); |
59 |
% set( h,'linewidth',2 ); |
60 |
% end |
61 |
% hold off; |
62 |
|
63 |
set( gca,'nextplot','add' ); |
64 |
for j = 1:n |
65 |
color = [rand rand rand]; |
66 |
h = plot_arrow( Xs(j),Ys(j),Xs(j)+cos(Thetas(j)),Ys(j)+sin(Thetas(j)),... |
67 |
'color',color,'facecolor',color,'edgecolor',color ); |
68 |
set( h,'linewidth',2 ); |
69 |
end |
70 |
hold off; |
71 |
|
72 |
%TODO: at some point, out controller will go here |
73 |
end |