Revision 1818
| branches/16299_s10/matlab/motionModel.m (revision 1818) | ||
|---|---|---|
| 7 | 7 |
|
| 8 | 8 |
R = 3.5; |
| 9 | 9 |
L = 12.75; |
| 10 |
noise = 0.5; |
|
| 10 |
noise = 0%0.5; |
|
| 11 | 11 |
|
| 12 | 12 |
transform = [ R/2 R/2; -R/L R/L]; |
| 13 | 13 |
inverseTransform = inv(transform); |
| 14 | 14 |
|
| 15 | 15 |
%Transforms from v, omega into wheel speed, limits wheel speed and adds noise, then translates back. |
| 16 |
for i=2:numRobots, |
|
| 17 |
|
|
| 18 |
wheels = inverseTransform * [v(i); omega(i)] + noise * randn(2, n); |
|
| 16 |
for i=2:numRobots |
|
| 17 |
|
|
| 18 |
wheels = inverseTransform * [v(i); omega(i)] + noise * randn(2,1); |
|
| 19 | 19 |
wheels = min(wheels, wheelMax); |
| 20 | 20 |
wheels = max(wheels, wheelMin); |
| 21 | 21 |
q = transform * wheels; |
| ... | ... | |
| 31 | 31 |
phi = zeros(numRobots,1); |
| 32 | 32 |
|
| 33 | 33 |
|
| 34 |
|
|
| 35 |
x = xold + cos(thetaold)*v*dt; |
|
| 36 |
y = yold(i) + sin(thetaold)*v*dt; |
|
| 37 |
theta = thetaold + omega*dt; |
|
| 34 |
x = xold + cos(thetaold).*v*dt; |
|
| 35 |
y = yold + sin(thetaold).*v*dt; |
|
| 36 |
theta = thetaold + omega*dt; |
|
| 38 | 37 |
|
| 39 |
phi = theta - atan2(y(-y(1), x-x(1)); |
|
| 38 |
phi = theta - atan2(y-y(1), x-x(1)); |
|
| 40 | 39 |
|
| 41 | 40 |
|
| 42 | 41 |
|
| branches/16299_s10/matlab/evolveRobots.m (revision 1818) | ||
|---|---|---|
| 5 | 5 |
dt = 0.041709; |
| 6 | 6 |
%else: |
| 7 | 7 |
%dt = .01; |
| 8 |
tf = 40; |
|
| 8 |
tf = 5.5 %40; |
|
| 9 | 9 |
|
| 10 | 10 |
|
| 11 | 11 |
%shape numbers: |
| ... | ... | |
| 20 | 20 |
|
| 21 | 21 |
%%% output options |
| 22 | 22 |
makeMovie = false; |
| 23 |
showPlots = false; |
|
| 23 |
showPlots = true; |
|
| 24 | 24 |
doFeedback = true; |
| 25 | 25 |
shape = 1; |
| 26 | 26 |
|
| 27 | 27 |
if shape == 1 |
| 28 |
n = 100; |
|
| 28 |
n = 10%100; |
|
| 29 | 29 |
elseif shape < 4 |
| 30 | 30 |
n = 9; |
| 31 | 31 |
elseif shape == 4 |
| ... | ... | |
| 159 | 159 |
mov = moviein(numsteps+1,f,winsize); |
| 160 | 160 |
mov(:,1) = getframe(f,winsize); |
| 161 | 161 |
|
| 162 |
% init |
|
| 163 |
xoldSensor = 0; |
|
| 164 |
yoldSensor = 0; |
|
| 165 |
thetaoldSensor = 0; |
|
| 166 |
|
|
| 162 | 167 |
% Run through each timestep |
| 163 | 168 |
for t = 0:dt:tf |
| 164 | 169 |
|
| ... | ... | |
| 171 | 176 |
|
| 172 | 177 |
% Update the sensor values using the sensor model |
| 173 | 178 |
[Xs(:,idx), Ys(:,idx), Thetas(:,idx), Phis(:,idx), sensorState, encoderNoise, xoldSensor, yoldSensor, thetaoldSensor] = ... |
| 174 |
sensorModel(X(:,idx), Y(:,idx), Theta(:,idx), Phi(:,idx), sensorState, n, encoderNoise, wheels, xoldSensor, yoldSensor, thetaoldSensor); |
|
| 179 |
sensorModel(X(:,idx), Y(:,idx), Theta(:,idx), Phi(:,idx), sensorState, n, encoderNoise, wheels, xoldSensor, yoldSensor, thetaoldSensor, dt); |
|
| 175 | 180 |
%Phis |
| 176 | 181 |
|
| 177 | 182 |
% visualize real position |
| branches/16299_s10/matlab/sensorModel.m (revision 1818) | ||
|---|---|---|
| 1 | 1 |
%TODO: pass in dt for lag model |
| 2 |
function [xSensor, ySensor, thetaSensor, phiSensor, state, encoderNoise, xoldSensor, yoldSensor, thetaoldSensor] = sensorModel(xTrue,yTrue,thetaTrue,phiTrue,state, n, encoderNoise, wheels, xoldSensor, yoldSensor, thetaoldSensor) |
|
| 2 |
function [xSensor, ySensor, thetaSensor, phiSensor, state, encoderNoise, xoldSensed, yoldSensed, thetaoldSensed] = sensorModel(xTrue,yTrue,thetaTrue,phiTrue,state, n, encoderNoise, wheels, xoldSensed, yoldSensed, thetaoldSensed, dt) |
|
| 3 | 3 |
|
| 4 | 4 |
phiNoiseVar = 0.1; |
| 5 |
encoderNoiseVar = 0.1; |
|
| 5 |
encoderNoiseVar = 0; %0.1; |
|
| 6 | 6 |
noiseMean = 0; |
| 7 | 7 |
|
| 8 | 8 |
%TODO: value in time instead of number of calls |
| ... | ... | |
| 18 | 18 |
|
| 19 | 19 |
% TODO: model encoder error? |
| 20 | 20 |
% Use the lagged values for position |
| 21 |
noise = encoderNoise * encoderNoiseVar * abs(randn(2, n)); |
|
| 22 | 21 |
|
| 22 |
noise = encoderNoise .* (encoderNoiseVar * abs(randn(2, n))); |
|
| 23 |
|
|
| 23 | 24 |
R = 3.5; |
| 24 | 25 |
L = 12.75; |
| 25 | 26 |
|
| 26 | 27 |
transform = [ R/2 R/2; -R/L R/L]; |
| 27 | 28 |
|
| 28 |
for i=2:numRobots, |
|
| 29 |
for i=2:n, |
|
| 29 | 30 |
|
| 30 | 31 |
wheels = wheels + noise(:, i); |
| 31 | 32 |
q = transform * wheels; |
| ... | ... | |
| 34 | 35 |
|
| 35 | 36 |
end |
| 36 | 37 |
|
| 37 |
x = zeros(numRobots,1); |
|
| 38 |
y = zeros(numRobots,1); |
|
| 39 |
theta = zeros(numRobots,1); |
|
| 40 |
|
|
| 41 | 38 |
xSensor = xoldSensed; |
| 42 | 39 |
ySensor = yoldSensed; |
| 43 | 40 |
thetaSensor = thetaoldSensed; |
| 44 | 41 |
|
| 45 |
xoldSensed = xoldSensed + cos(thetaoldSensed)*v(i)*dt; |
|
| 46 |
yoldSensed = yoldSensed + sin(thetaoldSensed)*v(i)*dt; |
|
| 47 |
thetaoldSensed = thetaoldSensed + omega*dt; |
|
| 42 |
xoldSensed = xoldSensed + cos(thetaoldSensed).*v*dt; |
|
| 43 |
yoldSensed = yoldSensed + sin(thetaoldSensed).*v*dt; |
|
| 44 |
thetaoldSensed = thetaoldSensed + omega*dt; |
|
| 48 | 45 |
|
| 49 | 46 |
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 | 47 |
% phiSensor is the value from the BOM sensor |
| 55 | 48 |
% round past phi to the nearest pi/8 |
| 56 | 49 |
noisePhi = state.phi(1,:)' + randn(1,size(phiTrue,1))'*phiNoiseVar + noiseMean; |
Also available in: Unified diff