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