-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget_observations.m
50 lines (41 loc) · 1.27 KB
/
get_observations.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
function [z]= get_observations(x, lm, rmax)
%function [z]= get_observations(x, lm, rmax)
%
% INPUTS:
% x - vehicle pose [x;y;phi]
% lm - set of all landmarks
% rmax - maximum range of range-bearing sensor
%
% OUTPUTS:
% z - set of range-bearing observations
%
% Tim Bailey 2004.
% Zhang Haiqiang 2007-11-22
%
[lm]= get_visible_landmarks(x,lm,rmax);
z= compute_range_bearing(x,lm);
%
%
function [lm]= get_visible_landmarks(x,lm,rmax)
% Select set of landmarks that are visible within vehicle's semi-circular field-of-view
dx= lm(1,:) - x(1);
dy= lm(2,:) - x(2);
phi= x(3);
% incremental tests for bounding semi-circle
ii= find(abs(dx) < rmax & abs(dy) < rmax ... % bounding box
& (dx*cos(phi) + dy*sin(phi)) > 0 ... % bounding line
& (dx.^2 + dy.^2) < rmax^2); % bounding circle
% Note: the bounding box test is unnecessary but illustrates a possible speedup technique
% as it quickly eliminates distant points. Ordering the landmark set would make this operation
% O(logN) rather that O(N).
lm= lm(:,ii);
%
%
function z= compute_range_bearing(x,lm)
% Compute exact observation
dx= lm(1,:) - x(1);
dy= lm(2,:) - x(2);
phi= x(3);
z= [sqrt(dx.^2 + dy.^2);
atan2(dy,dx) - phi];
z(2,:)= pi_to_pi(z(2,:));