55 #include "rnr/rnrconfig.h" 66 #include "gtest/gtest.h" 68 using namespace ::
std;
86 " 3 [<file>] Read xml cfg <file>. DEFAULT: /etc/hekateros.conf\n" 87 " 4 [<file>] Read xml tune <file>. DEFAULT: /etc/hek_tune.conf\n" 88 " 5 [<dev>] Connect to dynamixel bus <dev>. DEFAULT: /dev/ttyUSB0\n" 89 " 6 Disconnect from dynamixel bus.\n" 90 " 7 <how> [A]synchronously calibrate arm. <how> is 'a' or 's'. " 92 " 8 <move> Execute pre-defined move: calibrated balanced parked " 93 " 9 <deg> Rotate wrist by the given degrees." 94 " a Cancel asynchronous task." 97 " d Enable library diagnostics logging.\n" 98 " ? Show this menu.\n" 99 " q Quit unit test.\n\n";
102 void dbgPrintTunes(HekTunes &tunes)
104 HekTunes::MapJointTunes::iterator iter;
106 fprintf(stderr,
"HekTunes\n");
107 fprintf(stderr,
"{\n");
108 fprintf(stderr,
" m_fKinematicsHz = %lf;\n", tunes.m_fKinematicsHz);
109 fprintf(stderr,
" m_fClearTorqueOffset = %lf;\n", tunes.m_fClearTorqueOffset);
110 fprintf(stderr,
" m_fVelDerate = %lf;\n", tunes.m_fVelDerate);
111 fprintf(stderr,
" m_eTrajNorm = %d;\n", tunes.m_eTrajNorm);
112 fprintf(stderr,
" m_fTrajEpsilon = %lf;\n", tunes.m_fTrajEpsilon);
113 for(iter = tunes.m_mapJointTunes.begin();
114 iter != tunes.m_mapJointTunes.end();
117 fprintf(stderr,
" joint %s\n", iter->first.c_str());
118 fprintf(stderr,
" {\n");
119 fprintf(stderr,
" m_fTolPos = %lf;\n", iter->second.m_fTolPos);
120 fprintf(stderr,
" m_fTolVel = %lf;\n", iter->second.m_fTolVel);
121 fprintf(stderr,
" m_fPidKp = %lf;\n", iter->second.m_fPidKp);
122 fprintf(stderr,
" m_fPidKi = %lf;\n", iter->second.m_fPidKi);
123 fprintf(stderr,
" m_fPidKd = %lf;\n", iter->second.m_fPidKd);
124 fprintf(stderr,
" m_fOverTorqueTh = %lf;\n", iter->second.m_fOverTorqueTh);
125 fprintf(stderr,
" };\n");
127 fprintf(stderr,
"};\n");
145 #define BOT_CHK(conn) \ 146 if( pRobot == NULL ) \ 148 printf("Error: Robot object does not exist - create first.\n"); \ 151 else if( conn && !pRobot->isConnected() ) \ 153 printf("Error: Robot not connected.\n"); \ 157 HekRobot *pRobot = NULL;
171 if( gets(line) == NULL )
176 if( (nArgs = sscanf(line,
" %c %s", &c, arg1)) == EOF )
182 fprintf(stderr,
"#%d ", nArgs);
185 fprintf(stderr,
"c=%c ", c);
189 fprintf(stderr,
"arg1=%s ", arg1);
191 fprintf(stderr,
"\n");
200 pRobot =
new HekRobot;
201 printf(
"Robot created.\n");
205 printf(
"Robot already created.\n");
215 printf(
"Robot deleted.\n");
219 printf(
"Robot not created.\n");
227 string str = nArgs<2?
"/etc/hekateros.conf": arg1;
229 if( xml.loadFile(str) < 0 )
231 printf(
"Error: Loading XML file '%s' failed.\n", str.c_str());
233 else if( xml.setHekDescFromDOM(*pRobot->getHekDesc()) < 0 )
235 printf(
"Error: Setting robot description failed.\n");
237 else if( pRobot->getHekDesc()->markAsDescribed() < 0 )
239 printf(
"Error: Failed to finalize descriptions.\n");
243 printf(
"Robot description complete for %s.\n",
244 pRobot->getHekDesc()->getFullProdBrief().c_str());
253 string str = nArgs<2?
"/etc/hek_tune.conf": arg1;
254 fprintf(stderr,
"rdk here 1\n");
256 fprintf(stderr,
"rdk here 2\n");
258 fprintf(stderr,
"rdk here 3\n");
259 if( xml.loadFile(str) < 0 )
261 printf(
"Error: Loading XML file '%s' failed.\n", str.c_str());
263 else if( xml.setTunesFromDOM(tunes) < 0 )
265 printf(
"Error: Setting robot tune parameters failed.\n");
269 printf(
"Robot tuning complete.\n");
270 dbgPrintTunes(tunes);
279 string str = nArgs<2?
"/dev/ttyUSB0": arg1;
280 if( pRobot->connect(str) < 0 )
282 printf(
"Error: Failed to connnect to '%s'.\n", str.c_str());
286 printf(
"Robot connected.\n");
294 if( pRobot->isConnected() )
296 pRobot->disconnect();
297 printf(
"Robot disconnected.\n");
301 printf(
"Robot not connected.\n");
309 string str = nArgs<2?
"a": arg1;
310 if( (str ==
"s") || (str ==
"sync") )
312 if( pRobot->calibrate() < 0 )
314 printf(
"Error: Calibration failed.\n");
318 printf(
"Robot calibrated.\n");
323 if( pRobot->calibrateAsync() < 0 )
325 printf(
"Error: Async calibration failed.\n");
329 printf(
"Calibrating robot - enter '9' to cancel.\n");
338 if( !pRobot->isCalibrated() )
340 printf(
"Error: Robot not calibrated.\n");
344 printf(
"Error: Missing <move> argument.\n");
346 else if( strlen(arg1) < 2 )
348 printf(
"Error: \"%s\": Ambiguous <move>.\n", arg1);
350 else if( !strncmp(arg1,
"calibrated", strlen(arg1)) )
352 pRobot->gotoZeroPtPos();
354 else if( !strncmp(arg1,
"balanced", strlen(arg1)) )
356 pRobot->gotoBalancedPos();
358 else if( !strncmp(arg1,
"park", strlen(arg1)) )
360 pRobot->gotoParkedPos();
362 else if( !strncmp(arg1,
"gopen", strlen(arg1)) )
364 pRobot->openGripper();
366 else if( !strncmp(arg1,
"gclose", strlen(arg1)) )
368 pRobot->closeGripper();
372 printf(
"Error: \"%s\": Unknown <move>.\n", arg1);
379 if( !pRobot->isCalibrated() )
381 printf(
"Error: Robot not calibrated.\n");
385 printf(
"Error: Missing <deg> argument.\n");
387 else if( sscanf(arg1,
"%lf", &fVal) < 1 )
389 printf(
"Error: \"%s\": NaN.\n", arg1);
393 HekJointTrajectoryPoint trajPoint;
394 trajPoint.append(
string(
"wrist_rot"),
degToRad(fVal), 5.0);
395 pRobot->moveArm(trajPoint);
402 pRobot->cancelAsyncTask();
406 LOG_SET_THRESHOLD(LOG_LEVEL_DIAG3);
421 printf(
"'%c': huh?\n", c);
TEST(HEKROBOT, HEKROBOT)
Test State Machine class.
Joint points and trajectory class interfaces.
HekXmlCfg - <b><i>Hekateros</i></b> XML configuration class interface.
static int testHekRobot()
Test HekRobot connected to hekateros.
HekRobot - Hekateros Robot Class interface.
Top-level package include file.
double degToRad(double d)
Convert degrees to radians.
Hekateros common utilities.
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
<b><i>Hekateros</i></b> XML tuning class interface.
static const char * TestMenu
Test menu.