Statistics
| Revision:

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

History | View | Annotate | Download (1.7 KB)

1
%TODO: pass in dt for lag model
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
4
phiNoiseVar = 0.1;
5
encoderNoiseVar = 0; %0.1;
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 = encoderNoise .* (encoderNoiseVar * abs(randn(2, n)));
23
24
R = 3.5;
25
L = 12.75;
26
27
transform = [ R/2 R/2; -R/L R/L];
28
29
for i=2:n,
30
	
31
    wheels = wheels + noise(:, i);
32
	q = transform * wheels;
33
	v(i) = q(1);
34
	omega(i) = q(2);
35
	
36
end
37
38
xSensor = xoldSensed;
39
ySensor = yoldSensed;
40
thetaSensor = thetaoldSensed;
41
42
xoldSensed = xoldSensed + cos(thetaoldSensed).*v*dt;
43
yoldSensed = yoldSensed + sin(thetaoldSensed).*v*dt;
44
thetaoldSensed = thetaoldSensed + omega*dt;
45
46
47
% phiSensor is the value from the BOM sensor
48
% round past phi to the nearest pi/8
49
noisePhi = state.phi(1,:)' + randn(1,size(phiTrue,1))'*phiNoiseVar + noiseMean;
50
phiSensor = round(noisePhi*8/pi)*pi/8;
51
%phiSensor = round(state.phi(1,:)'*8/pi)*pi/8;
52
53
% update the state
54
state.x(1:end-1,:) = state.x(2:end,:);
55
state.y(1:end-1,:) = state.y(2:end,:);
56
state.theta(1:end-1,:) = state.theta(2:end,:);
57
state.phi(1:end-1,:) = state.phi(2:end,:);
58
state.x(end,:) = xTrue';
59
state.y(end,:) = yTrue';
60
state.theta(end,:) = thetaTrue';
61
state.phi(end,:) = phiTrue';
62
63
end