Skip to content

Commit 0518219

Browse files
committed
Add 'localize2d_pose'
1 parent 4a25079 commit 0518219

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

localize2d_pose.m

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function [pose, valid] = localize2d_pose(data, map)
2+
%LOCALIZE2D_POSE Estimate 2D position and orientation using poses measured from landmarks (N >= 1)
3+
%
4+
% [POSE, VALID] = LOCALIZE2D_POSE(DATA, MAP)
5+
% (matrix) DATA : The measured pose from landmarks (Nx6 matrix)
6+
% (matrix) MAP : The corresponding landmark map (Nx6 matrix)
7+
% (matrix) POSE : The estimated pose (1x6 matrix)
8+
% (matrix) VALID: A flag to represent validity of the estimated pose (1x6 matrix)
9+
%
10+
% Note: Please refer to the command, OBSERVE_POSE, for the convention of DATA, MAP, and POSE.
11+
%
12+
% Note: A flag for validity, VALID, is 1x6 matrix whose elements correspond to each
13+
% element of POSE. Since this algorithm estimates 2D position and orientation,
14+
% the expected VALID is [true, true, false, false, false, true].
15+
%
16+
% Example:
17+
% N = 1;
18+
% map = [10 * rand(N,2), zeros(N,4)]; % Random 2D landmark map
19+
% data = [10 * rand(N,2), zeros(N,3), 2 * pi (rand(N,1) - 0.5)]; % Random measurement
20+
% [pose, valid] = localize2d_pose(data, map)
21+
22+
if size(data,1) < 1
23+
error('DATA has less number of observations!');
24+
end
25+
if size(data,2) ~= 6
26+
error('DATA has wrong size!');
27+
end
28+
29+
theta = map(:,6) - data(:,6);
30+
c = cos(theta);
31+
s = sin(theta);
32+
x = map(:,1) - c .* data(:,1) + s .* data(:,2);
33+
y = map(:,2) - s .* data(:,1) - c .* data(:,2);
34+
35+
pose = [mean(x), mean(y), 0, 0, 0, atan2(mean(s), mean(c))];
36+
valid = [true, true, false, false, false, true];

run_test_localize.m

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
test_is_true(valid == [1, 1, 0, 0, 0, 1]);
6464
test_is_near(pose(valid == true), truePose(valid == true));
6565

66+
% localize2d_pose
67+
disp('==== localize2d_pose ====');
68+
[obsData, obsMap] = observe_pose(trueMap, truePose);
69+
[pose, valid] = localize2d_pose(obsData, obsMap);
70+
test_is_true(valid == [1, 1, 0, 0, 0, 1]);
71+
test_is_near(pose(valid == true), truePose(valid == true));
72+
6673
% The given landmark map and true pose for 3D localization %%%%%%%%%%%%%%%%%%%%
6774
trueMap = ...
6875
[ ...

0 commit comments

Comments
 (0)