|
| 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]; |
0 commit comments