ROBOOP, A Robotics Object Oriented Package in C++
bench.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
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 Revision_history:
31 
32 2004/07/01: Ethan Tira-Thompson
33  -Added support for newmat's use_namespace #define, using ROBOOP namespace
34 
35 2004/07/02: Etienne Lachance
36  -Added doxygen documentation.
37 
38 2004/08/13: Etienne Lachance
39  -Modified robot initialisation matrix.
40 
41 2005/06/29: Richard Gourdeau
42  -Added code for the Stewart platform by Samuel Belanger
43 -------------------------------------------------------------------------------
44 */
45 
53 #include <time.h>
54 
55 #ifdef _WIN32 /* Windows 95/NT */
56 #ifdef __GNUG__ /* Cygnus Gnu C++ for win32*/
57 #include <windows.h>
58 #define clock() GetTickCount() /* quick fix for bug in clock() */
59 #endif
60 #endif
61 
62 #include "robot.h"
63 #include "stewart.h"
64 
65 #ifdef use_namespace
66 using namespace ROBOOP;
67 #endif
68 
69 #define NTRY 2000
70 
71 Real Stewart_Ini[] =
72  {1.758, 2.8, -1.015, 0.225, 0.0, -0.228, 3.358, 0.05, 4.237, 0.1406, 10, 12.5, 0.5, 0.35, 0.0, 0.0, 0.0,
73  1.6021, 3.07, -0.925, 0.1125, 0.1949, -0.228, 3.358, 0.05, 4.237, 0.1406, 10, 12.5, 0.5, 0.35, 0.0, 0.0, 0.0,
74  -1.7580, 2.8, -1.015, -0.1125, 0.1949, -0.228, 3.358, 0.05, 4.237, 0.1406, 10, 12.5, 0.5, 0.35, 0.0, 0.0, 0.0,
75  -1.6021, 3.07, -0.925, -0.225, 0.0, -0.228, 3.358, 0.05, 4.237, 0.1406, 10, 12.5, 0.5, 0.35, 0.0, 0.0, 0.0,
76  0.0, 2.8, 2.03, -0.1125, -0.1949, -0.228, 3.358, 0.05, 4.237, 0.1406, 10, 12.5, 0.5, 0.35, 0.0, 0.0, 0.0,
77  0.0, 3.07, 1.85, 0.1125, -0.1949, -0.228, 3.358, 0.05, 4.237, 0.1406, 10, 12.5, 0.5, 0.35, 0.0, 0.0, 0.0,
78  0.0, 0.0, -0.114, 1.001, 0.59, 0.843, 10, 0.12, 0.04, 0.5, 0.5, 0.5, 1.5, 0.5, 0.005, 5.44, 0.443};
79 
80 Real Stewart_q[] =
81  {0.2, 0.3, -0.4, 0.1, -1.4, 0.1};
82 Real Stewart_qg[] =
83  {0.25, 0.25, -0.45, 0.07, -1.7, 0.07};
84 Real Stewart_l[] =
85  {3.0508, 3.2324, 3.2997, 3.4560, 3.5797, 3.6935};
86 Real Stewart_dq[] =
87  {0.2, 0.3, -0.4, 0.1, -1.4, 0.1};
88 Real Stewart_ddq[]=
89  {-10.0, -10.0, -10, -10.0, -10, -10};
90 Real Stewart_tddq[]=
91  {0, 0, 0, 0, 0, 0};
92 Real Comm[]=
93  {1, 0, 0, -10, 0, 0};
94 Real Tau[]=
95  {126.219689, 789.968672, 0.708602, 79.122963, 81.806978, -31.61797};
96 
97 int stewartmain(void)
98 {
99  clock_t start, end;
100  Matrix InitPlatt(7,17);
101  Stewart platt_Stewart, platt2;
102  Matrix _q(6,1), qg(6,1), _dq(6,1), _ddq(6,1), _l(6,1), To(6,1),
103  V(6,1), L(6,1), tddq(6,1);
104  int i;
105 
106  InitPlatt<<Stewart_Ini;
107  _q << Stewart_q;
108  qg << Stewart_qg;
109  _l << Stewart_l;
110  _dq << Stewart_dq;
111  _ddq << Stewart_ddq;
112  tddq << Stewart_tddq;
113  V << Comm;
114 
115 
116  platt_Stewart = Stewart(InitPlatt);
117  // uncomment the next line to use the configuration file
118  //platt_Stewart = Stewart("conf/stewart.conf","STEWART");
119  platt_Stewart.set_q(_q);
120  platt_Stewart.set_dq(_dq);
121  platt_Stewart.set_ddq(_ddq);
122 
123  cout<<"===============================\n";
124  cout<<"Benchmarks for Stewart platform\n";
125  cout<<"===============================\n\n";
126  cout<<"Inverse Kinematics :\n";
127  start = clock();
128  for(i =0; i<20000; i++)
129  L = platt_Stewart.InvPosKine();
130  end = clock();
131  cout<<"Time : "<<((end - start)/(Real)CLOCKS_PER_SEC)*1000.0/20000<<"\nResult : "<<L.t()<<endl;
132 
133 
134  cout<<"Forward Kinematics :\n";
135  platt_Stewart.set_q(qg);
136  start = clock();
137  for(i =0; i<100; i++){
138  L = platt_Stewart.ForwardKine(qg,_l);
139  platt_Stewart.set_q(qg);}
140  end = clock();
141  cout<<"Time : "<<((end - start)/(Real)CLOCKS_PER_SEC)*1000.0/100<<"\nResult : "<<L.t()<<endl;
142 
143  platt_Stewart.set_q(_q);
144 
145  cout<<"Inverse Dynamics:\n";
146  start = clock();
147  for(i =0; i<100; i++)
148  L = platt_Stewart.Torque();
149  end = clock();
150  cout<<"Time : "<<((end - start)/(Real)CLOCKS_PER_SEC)*1000.0/100<<"\nResult : "<<L.t()<<endl;
151 
152  platt_Stewart.set_ddq(tddq);
153  To << Tau;
154  cout<<"Forward Dynamics:\n";
155  start = clock();
156  for(i =0; i<100; i++)
157  L = platt_Stewart.ForwardDyn(To);
158  end = clock();
159  cout<<"Time : "<<((end - start)/(Real)CLOCKS_PER_SEC)*1000.0/100<<"\nResult : "<<L.t()<<endl;
160 
161 
162  double t = 0.01;
163 
164  L=platt_Stewart.ForwardDyn_AD(V,t);
165 
166  cout<<"Forward Dynamics with actuators:\nResult : "<<L.t()<<endl;
167 
168  return 0;
169 }
170 
171 const Real PUMA560_data[] =
172  {0, 0, 0, 0, M_PI/2.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.35, 0, 0, 0, 0, 0, 0, 0,
173  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, 0, 0, 0, 0,
174  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, 0, 0, 0, 0,
175  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, 0, 0, 0, 0,
176  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, 0, 0, 0, 0,
177  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, 0, 0, 0, 0};
178 
179 int main(void)
180 {
181  int i;
182  clock_t start, end;
183  Matrix initrob(6,23), thomo, temp2;
184  ColumnVector q(6), qs(6), temp;
185  Robot robot;
186 
187  initrob << PUMA560_data;
188  robot = Robot(initrob);
189  q = M_PI/6.0;
190 
191  q = M_PI/4.0;
192  printf("=================================\n");
193  printf("Benchmarks for serial 6 dof robot\n");
194  printf("=================================\n\n");
195 
196  printf("Begin compute Forward Kinematics\n");
197  start = clock();
198  for (i = 1; i <= NTRY; i++) {
199  robot.set_q(q);
200  temp2 = robot.kine();
201  }
202  end = clock();
203  printf("MilliSeconds %6.2f\n", ((end - start) / (Real)CLOCKS_PER_SEC)*1000.0/NTRY);
204  printf("end \n");
205 
206  qs = 1.0;
207  qs(1) = M_PI/16.0;
208  robot.set_q(q);
209  thomo = robot.kine();
210  printf("Begin compute Inverse Kinematics\n");
211  start = clock();
212  for (i = 1; i <= NTRY; i++) {
213  robot.set_q(qs);
214  temp = robot.inv_kin(thomo);
215  }
216  end = clock();
217  printf("MilliSeconds %6.2f\n", ((end - start) / (Real)CLOCKS_PER_SEC)*1000.0/NTRY);
218  printf("end \n");
219 
220  printf("Begin compute Jacobian\n");
221  start = clock();
222  for (i = 1; i <= NTRY; i++) {
223  robot.set_q(q);
224  temp2 = robot.jacobian();
225  }
226  end = clock();
227  printf("MilliSeconds %6.2f\n", ((end - start) / (Real)CLOCKS_PER_SEC)*1000.0/NTRY);
228  printf("end \n");
229 
230  printf("Begin compute Torque\n");
231  start = clock();
232  for (i = 1; i <= NTRY; i++) {
233  temp = robot.torque(q,q,q);
234  }
235  end = clock();
236  printf("MilliSeconds %6.2f\n", ((end - start) / (Real)CLOCKS_PER_SEC)*1000.0/NTRY);
237  printf("end \n");
238 
239  printf("Begin acceleration\n");
240  start = clock();
241  for (i = 1; i <= NTRY; i++) {
242  temp = robot.acceleration(q,q,q);
243  }
244  end = clock();
245  printf("MilliSeconds %6.2f\n", ((end - start) / (Real)CLOCKS_PER_SEC)*1000.0/NTRY);
246  printf("end \n\n");
247 
248  stewartmain();
249  return 0;
250 }
251 
252 
253