-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateScript.m
105 lines (85 loc) · 3.45 KB
/
generateScript.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
%generateScript: simulates the trajectory of the robot using square
% path given by generate motion
%
%data=generateScript(initialstatemean,numSteps,alphas,betas)
% generates data of the form
% [realObservation', noisefreeMotion', noisefreeObservation',
% realRobot', noisefreeRobot']
%
%realObservation and noisefreeMotion is the only data available to
%filter. All other data for debugging/display purposes.
%
%alphas are the 4-d noise for robot motion
%beta: noise for observations
%
%right now, observation ids not based on relationship between robot and marker
%
% TODO: update generateScript so that observations are for the
% closest marker
function Data = generateScript(initialStateMean, numSteps, maxObs, alphas, beta, deltaT)
%--------------------------------------------------------------
% Initializations
%--------------------------------------------------------------
motionDim = 3;
observationDim = 3; % observation size (range, bearing, marker ID)
realRobot = initialStateMean;
noisefreeRobot = initialStateMean;
global Param;
% soccer field
nSideMarks = 3;
global FIELDINFO;
FIELDINFO = getfieldinfo(Param.nLandmarksPerSide);
Data.time = zeros(1, numSteps);
Data.noisefreeControl = zeros(motionDim, numSteps);
Data.realObservation = nan(observationDim, maxObs, numSteps);
Data.Sim.realRobot = zeros(motionDim, numSteps);
Data.Sim.noisefreeRobot = zeros(motionDim, numSteps);
Data.Sim.noisefreeObservation = nan(observationDim, maxObs, numSteps);
for n = 1:numSteps
% --------------------------------------------
% Simulate motion
% --------------------------------------------
t=n*deltaT;
noisefreeMotion = generateMotion(t,deltaT);
% Shift real robot
prevNoisefreeRobot = noisefreeRobot;
noisefreeRobot = sampleOdometry( noisefreeMotion, noisefreeRobot, [0 0 0 0]);
% Move robot
realRobot = sampleOdometry( noisefreeMotion, realRobot, alphas);
%--------------------------------------------------------------
% Simulate observation
%--------------------------------------------------------------
% Observation noise
Q = diag([beta.^2, 0]);
% select landmarks for sensing
noisefreeObservation = senseLandmarks(realRobot, maxObs, FIELDINFO);
numObs = size(noisefreeObservation,2);
realObservation = nan(size(noisefreeObservation));
for k=1:numObs
observationNoise = sample( zeros(observationDim,1), Q, observationDim);
realObservation(:,k) = noisefreeObservation(:,k) + observationNoise;
end
Data.time(n) = t;
Data.noisefreeControl(:,n) = noisefreeMotion;
Data.realObservation(:,1:numObs,n) = realObservation;
Data.Sim.realRobot(:,n) = realRobot;
Data.Sim.noisefreeRobot(:,n) = noisefreeRobot;
Data.Sim.noisefreeObservation(:,1:numObs,n) = noisefreeObservation;
end
%==========================================================================
function noisefreeObservation = senseLandmarks(realRobot, maxObs, FIELDINFO, fov)
M = FIELDINFO.NUM_MARKERS;
noisefreeObservation = zeros(3, M);
for m=1:M
noisefreeObservation(:,m) = observation( realRobot, FIELDINFO, m);
end
% orders landmarks with mininum bearing angle w.r.t robot
[dummy, ii] = sort(abs(noisefreeObservation(2,:)));
noisefreeObservation = noisefreeObservation(:,ii);
% keeps those within front plane
ii = find(-pi/2 < noisefreeObservation(2,:) & noisefreeObservation(2,:) < pi/2);
if length(ii) <= maxObs
noisefreeObservation = noisefreeObservation(:,ii);
else
noisefreeObservation = noisefreeObservation(:,1:maxObs);
end