ROBOOP, A Robotics Object Oriented Package in C++
rtest.cpp
Go to the documentation of this file.
1 /*
2 ROBOOP -- A robotics object oriented package in C++
3 Copyright (C) 1996-2004 Richard Gourdeau and Etienne Lachance
4 
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 
19 
20 Report problems and direct all questions to:
21 
22 Richard Gourdeau, Professeur
23 Departement de genie electrique
24 Ecole Polytechnique de Montreal
25 C.P. 6079, Succ. Centre-Ville
26 Montreal, Quebec, H3C 3A7
27 
28 email: richard.gourdeau@polymtl.ca
29 
30 -------------------------------------------------------------------------------
31 Revision_history:
32 
33 2004/07/01: Ethan Tira-Thompson
34  -Added support for newmat's use_namespace #define, using ROBOOP namespace
35 
36 2004/08/13: Etienne Lachance
37  -Modified robot initialisation matrix.
38 -------------------------------------------------------------------------------
39 */
40 
48 #include "robot.h"
49 #include "quaternion.h"
50 #include "precisio.h"
51 #include <fstream>
52 
53 #ifdef use_namespace
54 using namespace ROBOOP;
55 #endif
56 
57 const Real PUMA560_data_DH[] =
58  {0, 0, 0, 0, M_PI/2.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.35, 0, 0, 0,
59  0, 0, 0, 0.4318, 0, 0, 0, 0, 17.4, -0.3638, 0.006, 0.2275, 0.13, 0, 0, 0.524, 0, 0.539, 0,
60  0, 0, 0.15005, 0.0203, -M_PI/2.0, 0, 0, 0, 4.8, -0.0203, -0.0141, 0.07, 0.066, 0, 0, 0.086, 0, 0.0125, 0,
61  0, 0, 0.4318, 0.0, M_PI/2.0, 0, 0, 0, 0.82, 0, 0.019, 0, 0.0018, 0, 0, 0.0013, 0, 0.0018, 0,
62  0, 0, 0, 0.0, -M_PI/2.0, 0, 0, 0, 0.34, 0.0, 0.0, 0.0, 0.0003, 0.0, 0.0, 0.0004, 0.0, 0.0003, 0,
63  0, 0, 0, 0, 0, 0, 0, 0, 0.09, 0.0, 0.0, 0.032, 0.00015, 0.0, 0.0, 0.00015, 0.0, 0.00004, 0};
64 Real PUMA560_data_mDH[] =
65  //joint_type, theta, d, a, alpha
66 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.35, 0,
67  0, 0, 0, 0.0, -M_PI/2, 0, 0, 0, 17.4, 0.068, 0.006, -0.016, 0.13, 0, 0, 0.524, 0, 0.539, 0,
68  0, 0, -0.15005, 0.4318, 0, 0, 0, 0, 4.8, 0, -0.070, 0.014, 0.066, 0, 0, 0.0125, 0, 0.066, 0,
69  0, 0, -0.4318, 0.0203, -M_PI/2.0, 0, 0, 0, 0.82, 0.0, 0.0, -0.019, 0.0018, 0, 0, 0.0018, 0, 0.0013, 0,
70  0, 0, 0, 0, M_PI/2.0, 0, 0, 0, 0.34, 0, 0, 0.0, 0.0003, 0, 0, 0.0003, 0, 0.0004, 0,
71  0, 0, 0, 0, -M_PI/2, 0, 0, 0, 0.09, 0, 0, 0.032, 0.00015, 0, 0, 0.00015, 0, 0.00004, 0};
72 const Real PUMA560_motor[] =
73  {200e-6, -62.6111, 1.48e-3, 0, // using + and - directions average
74  200e-6, 107.815, .817e-3, 0,
75  200e-6, -53.7063, 1.38e-3, 0,
76  33e-6, 76.0364, 71.2e-6, 0,
77  33e-6, 71.923, 82.6e-6, 0,
78  33e-6, 76.686, 36.7e-6, 0};
79 
80 const Real STANFORD_data_DH[] =
81  {0.0, 0.0, 0.4120, 0.0, -M_PI/2, 0,0,0,9.29, 0.0, 0.0175, -0.1105, 0.276, 0.0, 0, 0.255, 0.0, 0.071,0,0,0,0,0,
82  0.0, 0.0, 0.1540, 0.0, M_PI/2.0, 0,0,0,5.01, 0.0, -1.054, 0.0, 0.108, 0.0, 0.0, 0.018, 0.0, 0.1,0,0,0,0,0,
83  1.0, -M_PI/2.0, 0.0, 0.0, 0.0, 0,0,0,4.25, 0.0, 0.0, -6.447, 2.51, 0.0, 0.0, 2.51, 0.0, 0.006,0,0,0,0,0,
84  0.0, 0.0, 0.0, 0.0, -M_PI/2.0, 0,0,0,1.08, 0.0, 0.092, -0.054, 0.002, 0.0, 0.0, 0.001, 0.0, 0.001,0,0,0,0,0,
85  0.0, 0.0, 0.0, 0.0, M_PI/2.0, 0,0,0,0.63, 0.0, 0.0, 0.566, 0.003, 0.0, 0.0, 0.003, 0.0, 0.0004,0,0,0,0,0,
86  0.0, 0.0, 0.2630, 0.0, 0.0, 0,0,0,0.51, 0.0, 0.0, 1.5540, 0.013, 0.0, 0.0, 0.013, 0.0, 0.0003,0,0,0,0,0};
87 
88 int main(void)
89 {
90  int i;
91  std::ifstream infile;
92  infile.open("source/test.txt");
93  if(!infile) {
94  cerr << "Cannot open file:";
95  cerr << "source/test.txt\n";
96  exit (1);
97  }
98  Matrix Test(4,4), p1(3,1);
99  Real a, eps = FloatingPointPrecision::Epsilon(); /* floating point eps */
100 
101  cout << "=====================================================\n";
102  cout << " ROBOOP -- A robotics object oriented package in C++ \n";;
103  cout << " TEST program \n";
104  cout << "=====================================================\n";
105  cout << "\n";
106  cout << "Machine epsilon = " << eps << endl;
107  eps *= 150.0;
108 
109  cout << "Testing translation : ";
110  Real ott[] = {1.0,2.0,3.0};
111  p1 << ott;
112  for(i = 1; i <= 4; i++) {
113  for(int j = 1; j <= 4; j++) {
114  infile >> Test(i,j);
115  }
116  }
117  a = (Test-trans(p1)).MaximumAbsoluteValue();
118  if(a > eps) {
119  cout << "Erreur = " << a << endl;
120  } else {
121  cout << "Ok" << endl;
122  }
123 
124  cout << "Testing rotx : ";
125  for(i = 1; i <= 4; i++) {
126  for(int j = 1; j <= 4; j++) {
127  infile >> Test(i,j);
128  }
129  }
130  a = (Test-rotx(M_PI/6)).MaximumAbsoluteValue();
131  if(a > eps) {
132  cout << "Erreur = " << a << endl;
133  } else {
134  cout << "Ok" << endl;
135  }
136 
137  cout << "Testing roty : ";
138  for(i = 1; i <= 4; i++) {
139  for(int j = 1; j <= 4; j++) {
140  infile >> Test(i,j);
141  }
142  }
143  a = (Test-roty(M_PI/6)).MaximumAbsoluteValue();
144  if(a > eps) {
145  cout << "Erreur = " << a << endl;
146  } else {
147  cout << "Ok" << endl;
148  }
149 
150  cout << "Testing rotz : ";
151  for(i = 1; i <= 4; i++) {
152  for(int j = 1; j <= 4; j++) {
153  infile >> Test(i,j);
154  }
155  }
156  a = (Test-rotz(M_PI/6)).MaximumAbsoluteValue();
157  if(a > eps) {
158  cout << "Erreur = " << a << endl;
159  } else {
160  cout << "Ok" << endl;
161  }
162 
163  cout << "Testing roll-pitch-yaw : ";
164  for(i = 1; i <= 4; i++) {
165  for(int j = 1; j <= 4; j++) {
166  infile >> Test(i,j);
167  }
168  }
169  a = (Test-rpy(p1)).MaximumAbsoluteValue();
170  if(a > eps) {
171  cout << "Erreur = " << a << endl;
172  } else {
173  cout << "Ok" << endl;
174  }
175 
176  cout << "Testing rotation around vector : ";
177  for(i = 1; i <= 4; i++) {
178  for(int j = 1; j <= 4; j++) {
179  infile >> Test(i,j);
180  }
181  }
182  a = (Test-rotk(M_PI/2,p1)).MaximumAbsoluteValue();
183  if(a > eps) {
184  cout << "Erreur = " << a << endl;
185  } else {
186  cout << "Ok" << endl;
187  }
188 
189  // R(z) with angle=pi/4.
190  cout << "Testing quaternion to rotation matrix : ";
191  for(i = 1; i <= 3; i++) {
192  for(int j = 1; j <= 3; j++) {
193  infile >> Test(i,j);
194  }
195  }
196  {
197  // quaternion from angle + vector
198  ColumnVector v(3); v(1)=v(2)=0.0; v(3)=1.0;
199  Quaternion q(M_PI/4, v);
200  a = (Test.SubMatrix(1,3,1,3)-q.R()).MaximumAbsoluteValue();
201  if(a > eps) {
202  cout << "Erreur = " << a << endl;
203  } else {
204  cout << "Ok" << endl;
205  }
206  }
207 
208  cout << "Testing quaternion to rotation matrix : ";
209  for(i = 1; i <= 3; i++) {
210  for(int j = 1; j <= 3; j++) {
211  infile >> Test(i,j);
212  }
213  }
214 
215  {
216  // quaternion from 4 parameters
217  Quaternion q(M_PI/4, M_PI/6, M_PI/8, 1);
218  q.unit();
219  a = (Test.SubMatrix(1,3,1,3)-q.R()).MaximumAbsoluteValue();
220  if(a > eps) {
221  cout << "Erreur = " << a << endl;
222  } else {
223  cout << "Ok" << endl;
224  }
225 
226  cout << "Testing quaternion to transformation matrix : ";
227  for(i = 1; i <= 4; i++) {
228  for(int j = 1; j <= 4; j++) {
229  infile >> Test(i,j);
230  }
231  }
232  a = (Test-q.T()).MaximumAbsoluteValue();
233  if(a > eps) {
234  cout << "Erreur = " << a << endl;
235  } else {
236  cout << "Ok" << endl;
237  }
238 
239  cout << "Testing rotation matrix to quaternion : ";
240  ColumnVector quat(4);
241  Quaternion qq(q.R());
242  Test = Matrix(4,1);
243  for(i = 1; i <= 4; i++) {
244  infile >> Test(i,1);
245  }
246  quat(1) = qq.s();
247  quat.SubMatrix(2,4,1,1) = qq.v();
248  a = (Test-quat).MaximumAbsoluteValue();
249  if(a > eps) {
250  cout << "Erreur = " << a << endl;
251  } else {
252  cout << "Ok" << endl;
253  }
254 
255  cout << "Testing transformation matrix to quaternion : ";
256  qq = Quaternion(q.T());
257  Test = Matrix(4,1);
258  for(i = 1; i <= 4; i++) {
259  infile >> Test(i,1);
260  }
261  quat(1) = qq.s();
262  quat.SubMatrix(2,4,1,1) = qq.v();
263  a = (Test-quat).MaximumAbsoluteValue();
264  if(a > eps) {
265  cout << "Erreur = " << a << endl;
266  } else {
267  cout << "Ok" << endl;
268  }
269  }
270 
271 
272  // ---------------------- R O B O T S -------------------------------------
273  Robot robot_DH;
274  mRobot robot_mDH;
275  Matrix initrob;
276  Matrix initrobm;
277  short dof;
278 
279  ColumnVector qr, q, qd, qdd;
280  ColumnVector Fext(3), Next(3);
281 
282  // Puma 560 in DH notation without motor
283  cout << "Testing Puma 560 (DH) forward kinematic : ";
284  Test = Matrix(4,4);
285  for(i = 1; i <= 4; i++) {
286  for(int j = 1; j <= 4; j++) {
287  infile >> Test(i,j);
288  }
289  }
290  initrob = Matrix(6,19);
291  initrobm = Matrix(6,4);
292  initrob << PUMA560_data_DH;
293  initrobm << PUMA560_motor;
294  robot_DH = Robot(initrob, initrobm);
295  dof = robot_DH.get_dof();
296  qr = ColumnVector(dof);
297  qr = M_PI/4.0;
298  robot_DH.set_q(qr);
299  a = (Test-robot_DH.kine()).MaximumAbsoluteValue();
300  if(a > eps) {
301  cout << "Erreur = " << a << endl;
302  } else {
303  cout << "Ok" << endl;
304  }
305 
306  cout << "Testing Puma 560 (DH) jacobian in base frame : ";
307  Test = Matrix(6,6);
308  for(i = 1; i <= 6; i++) {
309  for(int j = 1; j <= 6; j++) {
310  infile >> Test(i,j);
311  }
312  }
313  a = (Test-robot_DH.jacobian()).MaximumAbsoluteValue();
314  if(a > eps) {
315  cout << "Erreur = " << a << endl;
316  } else {
317  cout << "Ok" << endl;
318  }
319 
320  cout << "Testing Puma 560 (DH) jacobian in tool frame : ";
321  for(i = 1; i <= 6; i++) {
322  for(int j = 1; j <= 6; j++) {
323  infile >> Test(i,j);
324  }
325  }
326  a = (Test-robot_DH.jacobian(dof)).MaximumAbsoluteValue();
327  if(a > eps) {
328  cout << "Erreur = " << a << endl;
329  } else {
330  cout << "Ok" << endl;
331  }
332 
333  initrobm = Matrix(6,4);
334  initrobm = 0.0;
335  robot_DH = Robot(initrob,initrobm);
336  Test = Matrix(dof,1); Test = 0;
337  cout << "Testing Puma 560 (DH) torque : ";
338  for(i = 1; i <= dof; i++) {
339  infile >> Test(i,1);
340  }
341 
342  qd = qr;
343  qdd = qr;
344  a = (Test-robot_DH.torque(qr, qd, qdd)).MaximumAbsoluteValue();
345  if(a > eps) {
346  cout << "Erreur = " << a << endl;
347  } else {
348  cout << "Ok" << endl;
349  }
350 
351  cout << "Testing Puma 560 (DH) inertia : ";
352  Test = Matrix(6,6);
353  for(i = 1; i <= 6; i++) {
354  for(int j = 1; j <= 6; j++){
355  infile >> Test(i,j);
356  }
357  }
358  a = (Test-robot_DH.inertia(qr)).MaximumAbsoluteValue();
359  if(a > eps) {
360  cout << "Erreur = " << a << endl;
361  } else {
362  cout << "Ok" << endl;
363  }
364 
365  initrobm = Matrix(6,4);
366  initrobm << PUMA560_motor;
367  robot_DH = Robot(initrob,initrobm);
368  dof = robot_DH.get_dof();
369 
370  cout << "Testing Puma 560 (DH) motor, torque : ";
371  Test = Matrix(dof,1);
372  for(i = 1; i <= dof; i++) {
373  infile >> Test(i,1);
374  }
375  a = (Test-robot_DH.torque(qr, qd, qdd)).MaximumAbsoluteValue();
376  if(a > eps) {
377  cout << "Erreur = " << a << endl;
378  } else {
379  cout << "Ok" << endl;
380  }
381 
382  // Stanford in DH notation
383  cout << "Testing Stanford (DH) forward kinematic : ";
384  Test = Matrix(4,4);
385  for(i = 1; i <= 4; i++) {
386  for(int j = 1; j <= 4; j++) {
387  infile >> Test(i,j);
388  }
389  }
390  initrob = Matrix(6,23);
391  initrob << STANFORD_data_DH;
392  robot_DH = Robot(initrob);
393  dof = robot_DH.get_dof();
394  qr = ColumnVector(dof);
395  qr = M_PI/4.0;
396  robot_DH.set_q(qr);
397  a = (Test-robot_DH.kine()).MaximumAbsoluteValue();
398  if(a > eps) {
399  cout << "Erreur = " << a << endl;
400  } else {
401  cout << "Ok" << endl;
402  }
403 
404  cout << "Testing Stanford (DH) jacobian in base frame : ";
405  Test = Matrix(6,6);
406  for(i = 1; i <= 6; i++) {
407  for(int j = 1; j <= 6; j++) {
408  infile >> Test(i,j);
409  }
410  }
411  a = (Test-robot_DH.jacobian()).MaximumAbsoluteValue();
412  if(a > eps) {
413  cout << "Erreur = " << a << endl;
414  } else {
415  cout << "Ok" << endl;
416  }
417 
418  cout << "Testing Stanford (DH) jacobian in tool frame : ";
419  for(i = 1; i <= 6; i++) {
420  for(int j = 1; j <= 6; j++) {
421  infile >> Test(i,j);
422  }
423  }
424  a = (Test-robot_DH.jacobian(dof)).MaximumAbsoluteValue();
425  if(a > eps) {
426  cout << "Erreur = " << a << endl;
427  } else {
428  cout << "Ok" << endl;
429  }
430 
431  Test = Matrix(dof,1); Test = 0;
432  cout << "Testing Stanford (DH) torque : ";
433  for(i = 1; i <= dof; i++) {
434  infile >> Test(i,1);
435  }
436  a = (Test-robot_DH.torque(qr, qd, qdd)).MaximumAbsoluteValue();
437  if(a > eps) {
438  cout << "Erreur = " << a << endl;
439  } else {
440  cout << "Ok" << endl;
441  }
442 
443  cout << "Testing Stanford (DH) torque with load on link n: ";
444  Fext(1)=10; Fext(2)=5; Fext(3)=7;
445  Next(1)=11; Next(2)=22; Next(3)=33;
446  for(i = 1; i <= dof; i++) {
447  infile >> Test(i,1);
448  }
449  a = (Test-robot_DH.torque(qr, qd, qdd, Fext, Next)).MaximumAbsoluteValue();
450  if(a > eps) {
451  cout << "Erreur = " << a << endl;
452  } else {
453  cout << "Ok" << endl;
454  }
455 
456  cout << "Testing Stanford (DH) inertia : ";
457  Test = Matrix(6,6); Test = 0;
458  for(i = 1; i <= 6; i++) {
459  for(int j = 1; j <= 6; j++){
460  infile >> Test(i,j);
461  }
462  }
463  a = (Test-robot_DH.inertia(qr)).MaximumAbsoluteValue();
464  if(a > eps) {
465  cout << "Erreur = " << a << endl;
466  } else {
467  cout << "Ok" << endl;
468  }
469 
470  Test = Matrix(4,4);
471 
472  // ATTENTION J'AI CHANGE LES PARAMETRES DH DANS PUMA560AKD.M, j'ai ecris a P. Corke
473  // Puma 560 DH modified
474  cout << "Testing Puma 560 (mDH) forward kinematic : ";
475  for(i = 1; i <= 4; i++) {
476  for(int j = 1; j <= 4; j++) {
477  infile >> Test(i,j);
478  }
479  }
480  initrob = Matrix(6,19);
481  initrob << PUMA560_data_mDH;
482  initrobm = Matrix(6,4);
483  initrobm = 0.0;
484  robot_mDH = mRobot(initrob, initrobm);
485  dof = robot_mDH.get_dof();
486  qr = ColumnVector(dof);
487  qr = M_PI/4.0;
488  robot_mDH.set_q(qr);
489  a = (Test-robot_mDH.kine()).MaximumAbsoluteValue();
490  if(a > eps) {
491  cout << "Erreur = " << a << endl;
492  } else {
493  cout << "Ok" << endl;
494  }
495 
496  // faut revoir jacobian pour dernier link
497  cout << "Testing Puma 560 (mDH) jacobian in base frame : ";
498  Test = Matrix(6,6);
499  for(i = 1; i <= 6; i++) {
500  for(int j = 1; j <= 6; j++) {
501  infile >> Test(i,j);
502  }
503  }
504  a = (Test-robot_mDH.jacobian()).MaximumAbsoluteValue();
505  if(a > eps) {
506  cout << "Erreur = " << a << endl;
507  } else {
508  cout << "Ok" << endl;
509  }
510 
511  cout << "Testing Puma 560 (mDH) jacobian in tool frame : ";
512  for(i = 1; i <= 6; i++) {
513  for(int j = 1; j <= 6; j++) {
514  infile >> Test(i,j);
515  }
516  }
517  a = (Test-robot_mDH.jacobian(dof)).MaximumAbsoluteValue();
518  if(a > eps) {
519  cout << "Erreur = " << a << endl;
520  } else {
521  cout << "Ok" << endl;
522  }
523 
524  initrobm = Matrix(6,4);
525  initrobm = 0.0;
526  robot_mDH = mRobot(initrob,initrobm);
527 
528  cout << "Testing Puma 560 (mDH) torque : ";
529  Test = Matrix(dof,1);
530  for(i = 1; i <= dof; i++) {
531  infile >> Test(i,1);
532  }
533  a = (Test-robot_mDH.torque(qr, qd, qdd)).MaximumAbsoluteValue();
534  if(a > eps) {
535  cout << "Erreur = " << a << endl;
536  } else {
537  cout << "Ok" << endl;
538  }
539 
540  cout << "Testing Puma 560 (mDH) inertia : ";
541  Test = Matrix(6,6); Test = 0;
542  for(i = 1; i <= 6; i++) {
543  for(int j = 1; j <= 6; j++){
544  infile >> Test(i,j);
545  }
546  }
547  a = (Test-robot_mDH.inertia(qr)).MaximumAbsoluteValue();
548  if(a > eps) {
549  cout << "Erreur = " << a << endl;
550  } else {
551  cout << "Ok" << endl;
552  }
553 
554  cout << "Testing Puma 560 (mDH) motor, torque : ";
555  initrobm = Matrix(6,4);
556  initrobm << PUMA560_motor;
557  robot_mDH = mRobot(initrob,initrobm);
558  Test = Matrix(dof,1);
559  for(i = 1; i <= dof; i++) {
560  infile >> Test(i,1);
561  }
562  a = (Test-robot_mDH.torque(qr, qd, qdd)).MaximumAbsoluteValue();
563  if(a > eps) {
564  cout << "Erreur = " << a << endl;
565  } else {
566  cout << "Ok" << endl;
567  }
568 
569  cout << "Testing Puma 560 (mDH) motor, torque with load on link n: ";
570  Fext(1)=10; Fext(2)=5; Fext(3)=7;
571  Next(1)=11; Next(2)=22; Next(3)=33;
572  for(i = 1; i <= dof; i++) {
573  infile >> Test(i,1);
574  }
575  a = (Test-robot_mDH.torque(qr, qd, qdd, Fext, Next)).MaximumAbsoluteValue();
576  if(a > eps) {
577  cout << "Erreur = " << a << endl;
578  } else {
579  cout << "Ok" << endl;
580  }
581 
582  return(0);
583 }