Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.78 KB)

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)
3

    
4
phiNoiseVar = 0.1;
5
encoderNoiseVar = 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
noise = encoderNoise * encoderNoiseVar * abs(randn(2, n));
22

    
23
R = 3.5;
24
L = 12.75;
25

    
26
transform = [ R/2 R/2; -R/L R/L];
27

    
28
for i=2:numRobots,
29
	
30
    wheels = wheels + noise(:, i);
31
	q = transform * wheels;
32
	v(i) = q(1);
33
	omega(i) = q(2);
34
	
35
end
36

    
37
x = zeros(numRobots,1);
38
y = zeros(numRobots,1);
39
theta = zeros(numRobots,1);
40

    
41
xSensor = xoldSensed;
42
ySensor = yoldSensed;
43
thetaSensor = thetaoldSensed;
44

    
45
    xoldSensed = xoldSensed + cos(thetaoldSensed)*v(i)*dt;
46
    yoldSensed = yoldSensed + sin(thetaoldSensed)*v(i)*dt;
47
    thetaoldSensed = thetaoldSensed + omega*dt;
48

    
49

    
50

    
51

    
52

    
53

    
54
% phiSensor is the value from the BOM sensor
55
% round past phi to the nearest pi/8
56
noisePhi = state.phi(1,:)' + randn(1,size(phiTrue,1))'*phiNoiseVar + noiseMean;
57
phiSensor = round(noisePhi*8/pi)*pi/8;
58
%phiSensor = round(state.phi(1,:)'*8/pi)*pi/8;
59

    
60
% update the state
61
state.x(1:end-1,:) = state.x(2:end,:);
62
state.y(1:end-1,:) = state.y(2:end,:);
63
state.theta(1:end-1,:) = state.theta(2:end,:);
64
state.phi(1:end-1,:) = state.phi(2:end,:);
65
state.x(end,:) = xTrue';
66
state.y(end,:) = yTrue';
67
state.theta(end,:) = thetaTrue';
68
state.phi(end,:) = phiTrue';
69

    
70
end