-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtestLexyRobot.m
232 lines (175 loc) · 5.16 KB
/
testLexyRobot.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
%% Test Function
function mRobot = testLexyRobot()
% Start Robotic Toolkit
startup_rvc();
% Create Robot Object
mRobot = lexyRobot();
mRobot.printName();
% Connect Arduino
mRobot.robotArduino = mRobot.connectArduino('/dev/ttyACM0');
mRobot.isConnected2Arduino = true;
% Start Simulation
mRobot.robotModel.plot([pi/2 pi/2]);
%testMove(mRobot);
%testCalibrationMove(mRobot);
%testInverseKinematics(mRobot,3,4);
%testDrawSquare(mRobot);
%testDrawWord(mRobot,'RAFAEL',3)
%testSizeLetter(mRobot);
testPlottingMap();
%testDrawingPath(mRobot);
% Disconnect Arduino
mRobot.disconnectArduino();
end
function testMove(mRobot)
% Test Rotine for the function move
% Using Robotic Toolkit (Direct Use)
% use mRobot.robotModel for the SerialLink object
q= [0 0]
mRobot.robotModel.plot(q)
% Using Arduino (Direct Use)
% use mRobot.robotArduino to access the Arduino functions
try
mRobot.robotArduino.servolink1.writePosition(q(1)/pi);
mRobot.robotArduino.servolink2.writePosition(q(2)/pi);
catch
disp('Unable to move Arm!')
end
% Using Both combined
q1 = [pi/2 pi/2];
mRobot.moveFast(q1);
end
function testCalibrationMove(mRobot)
% Test Rotine to calibrate the Servo Motors
q0 = [0 0];
q1 = [pi pi];
mRobot.move(q0);
mRobot.move(q1)
end
function testInverseKinematics(mRobot,X,Y)
q = mRobot.ikine(X,Y)
mRobot.robotModel.plot(q);
end
function testDrawSquare(mRobot)
shape = [1 1;1 2;2 2;2 1]
% Plot Shape
for i = 1:size(shape,1)
q = mRobot.ikine(shape(i,1),shape(i,2))
mRobot.robotModel.plot(q);
pause(0.5);
end
% Go Back to the Begining of shape
q = mRobot.ikine(shape(1,1),shape(1,2))
mRobot.robotModel.plot(q);
end
function testDrawChar(mRobot, msg, scale)
qz = [90 150]*pi/180;
mRobot.moveSync(qz);
char = msg(1,1);
nameFile = ['Letters/letter',char,'.mat']
load(nameFile,'letter');
q = mRobot.robotModel.getpos();
posX = q(1,1);
posY = q(1,2);
letter(:,1) = scale*letter(:,1) + posX;
letter(:,2) = scale*letter(:,2) + posY;
letter(:,3) = mRobot.PEN_DOWN;
mRobot.robotModel.plot(letter(:,1:2),'fps',12);
mRobot.penUpDown(mRobot.PEN_DOWN);
% Plot Shape
for i = 1:size(letter,1)
q = mRobot.ikine(letter(i,1),letter(i,2));
mRobot.moveFast(q);
mRobot.penUpDown(letter(i,3));
end
% mRobot.penUpDown(mRobot.PEN_UP);
% % Move to the next Letter
% finalLetter = zeros(2);
% finalLetter(1) = max(letter(:,1));
% finalLetter(2) = min(letter(:,2));
% q = mRobot.ikine(finalLetter(1,1),finalLetter(1,2));
% mRobot.moveFast(q);
end
function testDrawWord(mRobot, msg, scale)
for i = 1:size(msg,2);
mRobot.drawLetter(msg(i),scale);
mRobot.penUpDown(mRobot.PEN_UP);
end
end
function testNormLetter(char)
nameFile = ['Letters/letter',char,'.mat'];
load(nameFile,'letter');
nletter = letter;
x1 = min(letter(:,1));x2=max(letter(:,1)); nletter(:,1) = (letter(:,1)-x1)/(x2 -x1);
y1 = min(letter(:,2));y2=max(letter(:,2)); nletter(:,2) = (letter(:,2)-y1)/(y2 -y1);
P = (x2 - x1)/(y2-y1);
nletter(:,1) = nletter(:,1)*P;
letter = nletter;
nameFile = ['Letters/nletter',char,'.mat'];
save(nameFile,'letter');
end
function testTransposeLetter(char)
nameFile = ['Letters/letter',char,'.mat'];
load(nameFile,'letter');
nletter = letter;
x1 = min(letter(:,2));x2=max(letter(:,2)); nletter(:,2) = (letter(:,2)-x1)/(x2 -x1);
y1 = min(letter(:,1));y2=max(letter(:,1)); nletter(:,1) = (letter(:,1)-y1)/(y2 -y1);
P = (x2 - x1)/(y2-y1);
nletter(:,1) = nletter(:,1)*P;
letter = nletter;
nameFile = ['Letters/nletter',char,'.mat'];
save(nameFile,'letter');
end
function testSizeLetter(mRobot)
nchar = 3
dx = 0;
dy = 3;
q = mRobot.robotModel.getpos();
T = mRobot.robotModel.fkine(q);
posx = T(1,4);
posy = T(2,4);
for i=1:nchar
mRobot.penUpDown(mRobot.PEN_DOWN);
posx = posx + dx;
posy = posy + dy;
newQ = mRobot.ikine(posx, posy)
mRobot.penUpDown(mRobot.PEN_UP);
pause(0.2)
mRobot.moveFast(newQ)
end
end
function testNormAll()
abc = 'ABCDEFGHILMNOPQRSTUVWXYZ'
for i = 1:size(abc,2)
testNormLetter(abc(i));
end
end
function testPlottingMap()
map = makemap(20)
ds = Dstar(map);
figure;
ds.plot();
end
function testDrawingPath(mRobot)
% Create Map
res = 20
map = makemap(res)
% Calculate Path base on this coordinates
start = [2,18]
goal = [18,2]
ds = Dstar(map);
ds.plan(goal);
figure;
path = ds.path(start);
posX = 1;
posY = 1;
scale = 5/res
q = mRobot.ikine(posX,posY);
mRobot.penUpDown(mRobot.PEN_UP);
mRobot.robotModel.plot(mRobot.robotPos);
mRobot.moveFast(q);
mRobot.robotToolkitDisp(['Drawing Path ',char]);
path(:,1) = scale*path(:,1) + posX
path(:,2) = scale*path(:,2) + posY
mRobot.drawCurve(path);
end