Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.93 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.001;
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

    
23
noise = noise + ((encoderNoise .* (encoderNoiseVar * abs(randn(2, n)))) .* wheels);
24

    
25

    
26
R = 3.5;
27
L = 12.75;
28

    
29
transform = [ R/2 R/2; -R/L R/L];
30

    
31

    
32

    
33
for i=2:n,
34
	
35
	
36
    wheels(:, i) = wheels(:, i) + noise(:, i) ;
37
	q = transform * wheels(:, i);
38
	v(i) = q(1);
39
	omega(i) = q(2);
40
	% disp(wheels)
41
	
42
end
43

    
44

    
45
xSensor = xoldSensed;
46
ySensor = yoldSensed;
47
thetaSensor = thetaoldSensed;
48

    
49
% xoldSensed = xoldSensed + cos(thetaoldSensed).*v*dt;
50
% yoldSensed = yoldSensed + sin(thetaoldSensed).*v*dt;
51
% thetaoldSensed = thetaoldSensed + omega*dt;
52

    
53
xoldSensed = state.x(1,:) + cos(state.theta(1,:)).*v*dt;
54
yoldSensed = state.y(1,:) + sin(state.theta(1,:)).*v*dt;
55
thetaoldSensed = state.theta(1,:) + omega*dt;
56

    
57

    
58

    
59
% phiSensor is the value from the BOM sensor
60
% round past phi to the nearest pi/8
61
noisePhi = state.phi(1,:)' + randn(1,size(phiTrue,1))'*phiNoiseVar + noiseMean;
62
phiSensor = round(noisePhi*8/pi)*pi/8;
63
%phiSensor = round(state.phi(1,:)'*8/pi)*pi/8;
64

    
65
% update the state
66
state.x(1:end-1,:) = state.x(2:end,:);
67
state.y(1:end-1,:) = state.y(2:end,:);
68
state.theta(1:end-1,:) = state.theta(2:end,:);
69
state.phi(1:end-1,:) = state.phi(2:end,:);
70
state.x(end,:) = xTrue';
71
state.y(end,:) = yTrue';
72
state.theta(end,:) = thetaTrue';
73
state.phi(end,:) = phiTrue';
74

    
75
end