-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrawrobot.m
147 lines (134 loc) · 5.22 KB
/
drawrobot.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
%DRAWROBOT Draw robot.
% DRAWROBOT(X,COLOR) draws a robot at pose X = [x y theta] such
% that the robot reference frame is attached to the center of
% the wheelbase with the x-axis looking forward. COLOR is a
% [r g b]-vector or a color string such as 'r' or 'g'.
%
% DRAWROBOT(X,COLOR,TYPE) draws a robot of type TYPE. Five
% different models are implemented:
% TYPE = 0 draws only a cross with orientation theta
% TYPE = 1 is a differential drive robot without contour
% TYPE = 2 is a differential drive robot with round shape
% TYPE = 3 is a round shaped robot with a line at theta
% TYPE = 4 is a differential drive robot with rectangular shape
% TYPE = 5 is a rectangular shaped robot with a line at theta
%
% DRAWROBOT(X,COLOR,TYPE,W,L) draws a robot of type TYPE with
% width W and length L in [m].
%
% H = DRAWROBOT(...) returns a column vector of handles to all
% graphic objects of the robot drawing. Remember that not all
% graphic properties apply to all types of graphic objects. Use
% FINDOBJ to find and access the individual objects.
%
% See also DRAWRECT, DRAWARROW, FINDOBJ, PLOT.
% v.1.0, 16.06.03, Kai Arras, ASL-EPFL
% v.1.1, 12.10.03, Kai Arras, ASL-EPFL: uses drawrect
% v.1.2, 03.12.03, Kai Arras, CAS-KTH : types implemented
function h = drawrobot(varargin);
% Constants
DEFT = 2; % default robot type
DEFB = 30; % default robot width in [m], defines y-dir. of {R}
WT = 0.03; % wheel thickness in [m]
DEFL = DEFB+0.2; % default robot length in [m]
WD = 0.2; % wheel diameter in [m]
RR = WT/2; % wheel roundness radius in [m]
RRR = 0.04; % roundness radius for rectangular robots in [m]
HL = 0.09; % arrow head length in [m]
CS = 0.1; % cross size in [m], showing the {R} origin
% Input argument check
inputerr = 0;
switch nargin,
case 2,
xvec = varargin{1};
color = varargin{2};
type = DEFT;
B = DEFB;
L = DEFL;
case 3;
xvec = varargin{1};
color = varargin{2};
type = varargin{3};
B = DEFB;
L = DEFL;
case 5;
xvec = varargin{1};
color = varargin{2};
type = varargin{3};
B = varargin{4};
L = varargin{5};
otherwise
inputerr = 1;
end;
% Main switch statement
if ~inputerr,
x = xvec(1); y = xvec(2); theta = xvec(3);
T = [x; y];
R = [cos(theta), -sin(theta); sin(theta), cos(theta)];
switch type
case 0,
% Draw origin cross
p = R*[CS, -CS, 0, 0; 0, 0, -CS, CS] + T*ones(1,4); % horiz. line
h = plot(p(1,1:2),p(2,1:2),'Color',color,p(1,3:4),p(2,3:4),'Color',color);
case 1,
% Draw wheel pair with axis and arrow
xlw = [x+B/2*cos(theta+pi/2); y+B/2*sin(theta+pi/2); theta];
h1 = drawrect(xlw,WD,WT,RR,1,color); % left wheel
xlw = [x-B/2*cos(theta+pi/2); y-B/2*sin(theta+pi/2); theta];
h2 = drawrect(xlw,WD,WT,RR,1,color); % right wheel
% Draw axis cross with arrow
p = R*[0, 0; -B/2+WT/2, B/2-WT/2] + T*ones(1,2);
h3 = plot(p(1,:),p(2,:),'Color',color);
p = R*[L/2; 0] + T;
h4 = drawarrow(T,p,1,HL,color);
h = cat(1,h1,h2,h3,h4);
case 2,
% Draw wheel pair with axis and arrow
xlw = [x+B/2*cos(theta+pi/2); y+B/2*sin(theta+pi/2); theta];
h1 = drawrect(xlw,WD,WT,RR,1,color); % left wheel
xlw = [x-B/2*cos(theta+pi/2); y-B/2*sin(theta+pi/2); theta];
h2 = drawrect(xlw,WD,WT,RR,1,color); % right wheel
% Draw axis cross with arrow
p = R*[0, 0; -B/2+WT/2, B/2-WT/2] + T*ones(1,2);
h3 = plot(p(1,:),p(2,:),'Color',color);
p = R*[(B+WT)/2; 0] + T;
h4 = drawarrow(T,p,1,HL,color);
% Draw circular contour
radius = (B+WT)/2;
h5 = drawellipse(xvec,radius,radius,color);
h = cat(1,h1,h2,h3,h4,h5);
case 3,
% Draw circular contour
radius = (B+WT)/2;
h1 = drawellipse(xvec,radius,radius,color);
% Draw line with orientation theta with length radius
p = R*[(B+WT)/2;0] + T;
h2 = plot([T(1) p(1)],[T(2) p(2)],'Color',color);
h = cat(1,h1,h2);
case 4,
% Draw wheel pair with axis and arrow
xlw = [x+B/2*cos(theta+pi/2); y+B/2*sin(theta+pi/2); theta];
h1 = drawrect(xlw,WD,WT,RR,1,color); % left wheel
xlw = [x-B/2*cos(theta+pi/2); y-B/2*sin(theta+pi/2); theta];
h2 = drawrect(xlw,WD,WT,RR,1,color); % right wheel
% Draw axis cross with arrow
p = R*[0, 0; -B/2+WT/2, B/2-WT/2] + T*ones(1,2);
h3 = plot(p(1,:),p(2,:),'Color',color);
p = R*[L/2; 0] + T;
h4 = drawarrow(T,p,1,HL,color);
% Draw rectangular contour
h5 = drawrect(xvec,L,B,RRR,0,color);
h = cat(1,h1,h2,h3,h4,h5);
case 5,
% Draw rectangular contour
h1 = drawrect(xvec,L,B,RRR,0,color);
% Draw line with orientation theta with length L
p = R*[L/2; 0] + T;
h2 = plot([T(1) p(1)],[T(2) p(2)],'Color',color);
h = cat(1,h1,h2);
otherwise
display('drawrobot: Unsupported robot type'); h = [];
end;
else
display('drawrobot: Wrong number of input arguments'); h = [];
end;