root / branches / 16299_s10 / matlab / sensorModel.m @ 1797
History | View | Annotate | Download (1.16 KB)
1 |
%TODO: pass in dt for lag model |
---|---|
2 |
function [xSensor, ySensor, thetaSensor, phiSensor, state] = sensorModel(xTrue,yTrue,thetaTrue,phiTrue,state) |
3 |
|
4 |
noiseVar = 0.5; |
5 |
noiseMean = 0; |
6 |
|
7 |
%TODO: value in time instead of number of calls |
8 |
sensorLag = 10; |
9 |
|
10 |
% state contains historical phi values |
11 |
if size(state,1) == 0 |
12 |
state.phi = zeros(sensorLag,size(phiTrue,1)); |
13 |
state.x = zeros(sensorLag,size(phiTrue,1)); |
14 |
state.y = zeros(sensorLag,size(phiTrue,1)); |
15 |
state.theta = zeros(sensorLag,size(phiTrue,1)); |
16 |
end |
17 |
|
18 |
% TODO: model encoder error? |
19 |
% Use the lagged values for position |
20 |
xSensor = state.x(1,:)'; |
21 |
ySensor = state.y(1,:)'; |
22 |
|
23 |
thetaSensor = state.theta(1,:)'; |
24 |
|
25 |
% phiSensor is the value from the BOM sensor |
26 |
% round past phi to the nearest pi/8 |
27 |
noisePhi = state.phi(1,:)' + randn()*noiseVar + noiseMean; |
28 |
phiSensor = round(noisePhi*8/pi)*pi/8; |
29 |
%phiSensor = round(state.phi(1,:)'*8/pi)*pi/8; |
30 |
|
31 |
% update the state |
32 |
state.x(1:end-1,:) = state.x(2:end,:); |
33 |
state.y(1:end-1,:) = state.y(2:end,:); |
34 |
state.theta(1:end-1,:) = state.theta(2:end,:); |
35 |
state.phi(1:end-1,:) = state.phi(2:end,:); |
36 |
state.x(end,:) = xTrue'; |
37 |
state.y(end,:) = yTrue'; |
38 |
state.theta(end,:) = thetaTrue'; |
39 |
state.phi(end,:) = phiTrue'; |
40 |
|
41 |
end |