forked from petercorke/robotics-toolbox-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LandmarkMap.m
182 lines (161 loc) · 5.53 KB
/
LandmarkMap.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
%LandmarkMap Map of planar point landmarks
%
% A LandmarkMap object represents a square 2D environment with a number of landmark
% landmark points.
%
% Methods::
% plot Plot the landmark map
% landmark Return a specified map landmark
% display Display map parameters in human readable form
% char Convert map parameters to human readable string
%
% Properties::
% map Matrix of map landmark coordinates 2xN
% dim The dimensions of the map region x,y in [-dim,dim]
% nlandmarks The number of map landmarks N
%
% Examples::
%
% To create a map for an area where X and Y are in the range -10 to +10 metres
% and with 50 random landmark points
% map = LandmarkMap(50, 10);
% which can be displayed by
% map.plot();
%
% Reference::
%
% Robotics, Vision & Control, Chap 6,
% Peter Corke,
% Springer 2011
%
% See also RangeBearingSensor, EKF.
% Copyright (C) 1993-2017, by Peter I. Corke
%
% This file is part of The Robotics Toolbox for MATLAB (RTB).
%
% RTB is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% RTB is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Leser General Public License
% along with RTB. If not, see <http://www.gnu.org/licenses/>.
%
% http://www.petercorke.com
classdef LandmarkMap < handle
% TODO:
% add a name property, show in char()
properties
map % map landmarks
dim % map dimension
nlandmarks % number of landmarks in map
verbose
end
methods
% constructor
function map = LandmarkMap(nlandmarks, varargin)
%LandmarkMap.LandmarkMap Create a map of point landmark landmarks
%
% M = LandmarkMap(N, DIM, OPTIONS) is a LandmarkMap object that represents N random point landmarks
% in a planar region bounded by +/-DIM in the x- and y-directions.
%
% Options::
% 'verbose' Be verbose
%% TODO: dim can be a 4-vector
opt = [];
[opt,args] = tb_optparse(opt, varargin);
map.verbose = opt.verbose;
if ~isempty(args) && isnumeric(args{1})
dim = args{1};
else
dim = 10;
end
map.dim = dim;
map.nlandmarks = nlandmarks;
map.map = dim * (2*rand(2, nlandmarks)-1);
map.verbose = false;
end
function f = landmark(map, k)
%LandmarkMap.landmark Get landmarks from map
%
% F = M.landmark(K) is the coordinate (2x1) of the K'th landmark (landmark).
f = map.map(:,k);
end
function plot(map, varargin)
%LandmarkMap.plot Plot the map
%
% M.plot() plots the landmark map in the current figure, as a square
% region with dimensions given by the M.dim property. Each landmark
% is marked by a black diamond.
%
% M.plot(LS) as above, but the arguments LS
% are passed to plot and override the default marker style.
%
% Notes::
% - The plot is left with HOLD ON.
clf
d = map.dim;
axis equal
axis([-d d -d d]);
xlabel('x');
ylabel('y');
if nargin == 1
args = {'kh'};
else
args = varargin;
end
h = plot(map.map(1,:)', map.map(2,:)', args{:});
set(h, 'Tag', 'map');
grid on
hold on
end
function show(map, varargin)
%map.SHOW Show the landmark map
%
% Notes::
% - Deprecated, use plot method.
warning('show method is deprecated, use plot() instead');
map.plot(varargin{:});
end
function verbosity(map, v)
%map.verbosity Set verbosity
%
% M.verbosity(V) set verbosity to V, where 0 is silent and greater
% values display more information.
map.verbose = v;
end
function display(map)
%map.display Display map parameters
%
% M.display() displays map parameters in a compact
% human readable form.
%
% Notes::
% - This method is invoked implicitly at the command line when the result
% of an expression is a LandmarkMap object and the command has no trailing
% semicolon.
%
% See also map.char.
loose = strcmp( get(0, 'FormatSpacing'), 'loose');
if loose
disp(' ');
end
disp([inputname(1), ' = '])
disp( char(map) );
end % display()
function s = char(map)
%map.char Convert map parameters to a string
%
% s = M.char() is a string showing map parameters in
% a compact human readable format.
s = 'LandmarkMap object';
s = char(s, sprintf(' %d landmarks', map.nlandmarks));
s = char(s, sprintf(' dimension %.1f', map.dim));
end
end % method
end % classdef