Statistics
| Revision:

root / branches / 16299_s10 / matlab / sensorModel.m @ 1820

History | View | Annotate | Download (1.9 KB)

1
%TODO: pass in dt for lag model
2
function [xSensor, ySensor, thetaSensor, phiSensor, state, encoderNoise, xoldSensed, yoldSensed, thetaoldSensed, noise] = sensorModel(xTrue,yTrue,thetaTrue,phiTrue,state, n, encoderNoise, wheels, xoldSensed, yoldSensed, thetaoldSensed, dt, noise)
3
4
phiNoiseVar = 0.1;
5
encoderNoiseVar = 0.05;
6
noiseMean = 0;
7
8
%TODO: value in time instead of number of calls
9
sensorLag = 2;
10
11
% state contains historical phi values
12
if size(state,1) == 0
13
    state.phi = zeros(sensorLag,size(phiTrue,1));
14
    state.x = zeros(sensorLag,size(phiTrue,1));
15
    state.y = zeros(sensorLag,size(phiTrue,1));
16
    state.theta = zeros(sensorLag,size(phiTrue,1));
17
end
18
19
% TODO: model encoder error?
20
% Use the lagged values for position
21
22
noise = noise + encoderNoise .* (encoderNoiseVar * abs(randn(2, n)));
23
24
25
R = 3.5;
26
L = 12.75;
27
28
transform = [ R/2 R/2; -R/L R/L];
29
30
for i=2:n,
31
	
32
    wheels = wheels + noise(:, i);
33
	q = transform * wheels;
34
	v(i) = q(1);
35
	omega(i) = q(2);
36
	
37
end
38
39
xSensor = xoldSensed;
40
ySensor = yoldSensed;
41
thetaSensor = thetaoldSensed;
42
43
% xoldSensed = xoldSensed + cos(thetaoldSensed).*v*dt;
44
% yoldSensed = yoldSensed + sin(thetaoldSensed).*v*dt;
45
% thetaoldSensed = thetaoldSensed + omega*dt;
46
47
xoldSensed = state.x(1,:) + cos(state.theta(1,:)).*v*dt;
48
yoldSensed = state.y(1,:) + sin(state.theta(1,:)).*v*dt;
49
thetaoldSensed = state.theta(1,:) + omega*dt;
50
51
52
53
% phiSensor is the value from the BOM sensor
54
% round past phi to the nearest pi/8
55
noisePhi = state.phi(1,:)' + randn(1,size(phiTrue,1))'*phiNoiseVar + noiseMean;
56
phiSensor = round(noisePhi*8/pi)*pi/8;
57
%phiSensor = round(state.phi(1,:)'*8/pi)*pi/8;
58
59
% update the state
60
state.x(1:end-1,:) = state.x(2:end,:);
61
state.y(1:end-1,:) = state.y(2:end,:);
62
state.theta(1:end-1,:) = state.theta(2:end,:);
63
state.phi(1:end-1,:) = state.phi(2:end,:);
64
state.x(end,:) = xTrue';
65
state.y(end,:) = yTrue';
66
state.theta(end,:) = thetaTrue';
67
state.phi(end,:) = phiTrue';
68
69
end