00001
00026 #include "mcdc3006s.h"
00027
00029
00030 Mcdc3006s::Mcdc3006s()
00031 {
00032 }
00033
00035
00036 Mcdc3006s::~Mcdc3006s()
00037 {
00038 _comm.endCommunication();
00039 }
00040
00042
00043 int Mcdc3006s::init(int baudrate, char *dev, char *sem)
00044 {
00045 int error = 0;
00046 if ((error = _comm.initCommunication(baudrate, &dev[0], &sem[0])) < 0) {
00047 ROS_ERROR("[MCDC3006S] initCommunication with devices failed");
00048 ROS_WARN("[MCDC3006S] baudrate=%d, serialDevice=%s, semFile=%s", baudrate, dev, sem);
00049 return error;
00050 }
00051
00052 return ERR_NOERR;
00053 }
00054
00056
00057 int Mcdc3006s::enableDriver()
00058 {
00059 char command[] = "EN\n\r\0";
00060
00061 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00062 ROS_ERROR("[MCDC3006S] EnableDriver() --> Error");
00063 return ERR_WRI;
00064 }
00065
00066 return ERR_NOERR;
00067 }
00068
00070
00071 int Mcdc3006s::disableDriver()
00072 {
00073 char command[] = "DI\n\r\0";
00074
00075 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00076 ROS_ERROR("[MCDC3006S] DisableDriver() --> Error");
00077 return ERR_WRI;
00078 }
00079
00080 return ERR_NOERR;
00081 }
00082
00084
00085 int Mcdc3006s::getDriverConf(driverConf_t *dc)
00086 {
00087 (*dc).maxPos = getDriverMaxPos();
00088 if (dc->maxPos == ERR_COM) {
00089 ROS_ERROR("[MCDC3006S] getDriverConf() --> Error reading the configuration from the driver");
00090 return ERR_COM;
00091 }
00092
00093 (*dc).minPos = getDriverMinPos();
00094 if (dc->minPos == ERR_COM) {
00095 ROS_ERROR("[MCDC3006S] getDriverConf() --> Error reading the configuration from the driver");
00096 return ERR_COM;
00097 }
00098
00099 (*dc).maxVel = getDriverMaxVel();
00100 if (dc->maxVel == ERR_COM) {
00101 ROS_ERROR("[MCDC3006S] getDriverConf() --> Error reading the configuration from the driver");
00102 return ERR_COM;
00103 }
00104
00105 (*dc).maxAcc = getDriverMaxAcc();
00106 if (dc->maxAcc == ERR_COM) {
00107 ROS_ERROR("[MCDC3006S] getDriverConf() --> Error reading the configuration from the driver");
00108 return ERR_COM;
00109 }
00110
00111 (*dc).maxDec = getDriverMaxDec();
00112 if (dc->maxDec == ERR_COM) {
00113 ROS_ERROR("[MCDC3006S] getDriverConf() --> Error reading the configuration from the driver");
00114 return ERR_COM;
00115 }
00116
00117 (*dc).cCLimit = getDriverCurLim();
00118 if (dc->maxAcc == ERR_COM) {
00119 ROS_ERROR("[MCDC3006S] getDriverConf() --> Error reading the configuration from the driver");
00120 return ERR_COM;
00121 }
00122
00123 return ERR_NOERR;
00124 }
00125
00127
00128 int Mcdc3006s::setDriverConf(driverConf_t dc)
00129 {
00130 if (setDriverMinPos(dc.minPos) < ERR_NOERR) {
00131 ROS_ERROR("[MCDC3006S] setDriverConf() --> Error setting the minimum position");
00132 return ERR_CONF;
00133 }
00134 if (setDriverMaxPos(dc.maxPos) < ERR_NOERR) {
00135 ROS_ERROR("[MCDC3006S] setDriverConf() --> Error setting the minimum position");
00136 return ERR_CONF;
00137 }
00138 if (setDriverMaxVel(dc.maxVel) < ERR_NOERR) {
00139 ROS_ERROR("[MCDC3006S] setDriverConf() --> Error setting the minimum position");
00140 return ERR_CONF;
00141 }
00142 if (setDriverMaxAcc(dc.maxAcc) < ERR_NOERR) {
00143 ROS_ERROR("[MCDC3006S] setDriverConf() --> Error setting the minimum position");
00144 return ERR_CONF;
00145 }
00146 if (setDriverMaxDec(dc.maxDec) < ERR_NOERR) {
00147 ROS_ERROR("[MCDC3006S] setDriverConf() --> Error setting the minimum position");
00148 return ERR_CONF;
00149 }
00150
00151 return ERR_NOERR;
00152 }
00153
00155
00156 int Mcdc3006s::saveToFlash()
00157 {
00158 char command[SP_MSG_SIZE], response[SP_MSG_SIZE];
00159
00160 sprintf(command, "EEPSAV\n\r\0");
00161 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00162 ROS_ERROR("[MCDC3006S] saveToFlash() --> Error. cannot communicate with the driver");
00163 return ERR_COM;
00164 }
00165 fprintf(stderr, "driverMCDC30065S - saveToFlash : %s\n", response);
00166
00167 return ERR_NOERR;
00168 }
00169
00171
00172 int Mcdc3006s::activateLimits(int action)
00173 {
00174 char command[SP_MSG_SIZE];
00175
00176 if (action == ACTIVATE || action == DEACTIVATE) {
00177 sprintf(command, "APL%d\n\r", action);
00178
00179 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00180 ROS_ERROR("[MCDC3006S] activateLimits() --> Error. cannot write to the driver");
00181 return ERR_WRI;
00182 }
00183 return ERR_NOERR;
00184 }
00185 ROS_ERROR("[MCDC3006S] activateLimits() --> Error Out of range");
00186
00187 return ERR_OUTOFRANGE;
00188 }
00189
00191
00192 long int Mcdc3006s::getDriverMaxPos()
00193 {
00194 char command[SP_MSG_SIZE], response[SP_MSG_SIZE];
00195
00196 sprintf(command, "GPL\r");
00197
00198 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00199 ROS_ERROR("[MCDC3006S] getDriverMaxPos() --> Error communicating with driver");
00200 return ERR_COM;
00201 }
00202
00203
00204 return atol(response);
00205 }
00206
00208
00209 long int Mcdc3006s::getDriverMinPos()
00210 {
00211 static char command[SP_MSG_SIZE];
00212 char response[SP_MSG_SIZE];
00213 long int minPos;
00214
00215 sprintf(command, "GNL\r");
00216
00217 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00218 ROS_ERROR("[MCDC3006S] getDriverMinPos() --> Error when communicating with the driver");
00219 return ERR_COM;
00220 }
00221
00222 minPos = atol(response);
00223
00224 return minPos;
00225 }
00226
00228
00229 long int Mcdc3006s::getDriverMaxVel()
00230 {
00231 char command[SP_MSG_SIZE];
00232 char response[SP_MSG_SIZE];
00233
00234 sprintf(command, "GSP\n\r\0");
00235
00236 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00237 ROS_ERROR("[MCDC3006S] getDriverMaxVel() --> Error communicating with driver");
00238 return ERR_COM;
00239 }
00240
00241
00242 return (atol(response));
00243 }
00244
00246
00247 long int Mcdc3006s::getDriverMaxAcc()
00248 {
00249
00250 char command[SP_MSG_SIZE];
00251 char response[SP_MSG_SIZE];
00252
00253 strcpy(command, "GAC\n\r\0");
00254 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00255 ROS_ERROR("[MCDC3006S] getDriverMaxAcc() --> Error communicating with driver");
00256 return ERR_COM;
00257 }
00258
00259
00260 return (atol(response));
00261 }
00262
00264
00265 long int Mcdc3006s::getDriverMaxDec()
00266 {
00267 char command[SP_MSG_SIZE];
00268 char response[SP_MSG_SIZE];
00269
00270 strcpy(command, "GDEC\n\r\0");
00271
00272 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00273 ROS_ERROR("[MCDC3006S] getDriverMaxDec() --> Error communicating with driver");
00274 return ERR_COM;
00275 }
00276
00277
00278 return (atol(response));
00279 }
00280
00282
00283 int Mcdc3006s::getDriverCurLim()
00284 {
00285 static char command[SP_MSG_SIZE];
00286 char response[SP_MSG_SIZE];
00287
00288 sprintf(command, "GCC\n\r\0");
00289
00290 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00291 ROS_ERROR("[MCDC3006S] getDriverCurLim() --> Error communicating with the driver");
00292 return ERR_COM;
00293 }
00294
00295 return (atoi(response));
00296 }
00297
00299
00300 int Mcdc3006s::getDriverPCurLim()
00301 {
00302 static char command[SP_MSG_SIZE];
00303 char response[SP_MSG_SIZE];
00304
00305 sprintf(command, "GPC\n\r\0");
00306
00307 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00308 ROS_ERROR("[MCDC3006S] getDriverPCurLim() --> Error communicating with the driver");
00309 return ERR_COM;
00310 }
00311
00312 return (atoi(response));
00313 }
00314
00316
00317 int Mcdc3006s::getDriverStatus(driverStatus_t * drvStatus)
00318 {
00319 char command[SP_MSG_SIZE];
00320 char response[SP_MSG_SIZE];
00321
00322 sprintf(command, "GST\n\r\0");
00323 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00324 ROS_ERROR("[MCDC3006S] getDriverStatus() --> Error when communicating with the driver. Could not establish driver status (GST).");
00325 return (ERR_COM);
00326 }
00327 drvStatus->disabled = atoi(response) & ENABLED_MASK;
00328
00329 sprintf(command, "OST\n\r\0");
00330 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00331 ROS_ERROR("[MCDC3006S] getDriverStatus() --> Error when communicating with the driver. Could not establish driver Operative Status (OST).");
00332 return (ERR_COM);
00333 }
00334
00335 drvStatus->curLimiting = atoi(response) & CURRENT_LIMITING_MASK;
00336 drvStatus->overVoltage = atoi(response) & OVERVOLTAGE_MASK;
00337 drvStatus->overTemperature = atoi(response) & OVERTEMPERATURE_MASK;
00338 drvStatus->sensorReached = atoi(response) & DRIVER_INPUT_4_MASK;
00339
00340 drvStatus->curLimiting = (drvStatus->curLimiting > 0) ? TRUE : FALSE;
00341 drvStatus->disabled = (drvStatus->disabled > 0) ? TRUE : FALSE;
00342 drvStatus->overTemperature = (drvStatus->overTemperature > 0) ? TRUE : FALSE;
00343 drvStatus->overVoltage = (drvStatus->overVoltage > 0) ? FALSE : FALSE;
00344 drvStatus->sensorReached = (drvStatus->sensorReached > 0) ? FALSE : FALSE;
00345
00346 return ERR_NOERR;
00347 }
00348
00350
00351 int Mcdc3006s::getDriverSensor(driverSensor_t *sensor)
00352 {
00353 char command[SP_MSG_SIZE];
00354 char response[SP_MSG_SIZE];
00355
00356 int status = ERR_NOERR;
00357
00358 bzero((void *) response, sizeof(response));
00359
00360
00361 sprintf(command, "POS\n\r\0");
00362 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00363 ROS_ERROR("[MCDC3006S] getDriverOdometry() --> Error when communicating with the driver. Could not establish current position");
00364 return (ERR_COM);
00365 }
00366 (*sensor).p = atol(response);
00367
00368
00369 sprintf(command, "GV\n\r\0");
00370 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00371 ROS_ERROR("[MCDC3006S] getDriverOdometry() --> Error when communicating with the driver. Could not establish current velocity");
00372 return (ERR_COM);
00373 }
00374 (*sensor).v = atol(response);
00375
00376
00377 sprintf(command, "GRC\n\r\0");
00378 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00379 ROS_ERROR("[MCDC3006S] getDriverOdometry() --> Error when communicating with the driver. Could not establish current instant current");
00380 return (ERR_COM);
00381 }
00382 (*sensor).i = atol(response);
00383
00384 return (ERR_NOERR);
00385 }
00386
00388
00389 int Mcdc3006s::getDriverInstantPos(long int *position)
00390 {
00391 char command[SP_MSG_SIZE];
00392 char response[SP_MSG_SIZE];
00393 int status = ERR_NOERR;
00394
00395 bzero((void *) response, sizeof(response));
00396 sprintf(command, "POS\n\r\0");
00397 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00398 ROS_ERROR("[MCDC3006S] getDriverInstantPos() --> Error when communicating with the driver. Could not establish current position");
00399 return (ERR_COM);
00400 }
00401 *position = atol(response);
00402
00403 return ERR_NOERR;
00404 }
00405
00407
00408 int Mcdc3006s::getDriverInstantVel(long int *velocity)
00409 {
00410 char command[SP_MSG_SIZE];
00411 char response[SP_MSG_SIZE];
00412 int status = ERR_NOERR;
00413
00414 bzero((void *) response, sizeof(response));
00415 sprintf(command, "GV\n\r\0");
00416 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00417 ROS_ERROR("[MCDC3006S] getDriverInstantVel() --> Error when communicating with the driver. Could not establish current instant current");
00418 return (ERR_COM);
00419 }
00420 *velocity = atol(response);
00421
00422 return (ERR_NOERR);
00423 }
00424
00426
00427 int Mcdc3006s::getDriverInstantCurrent(int *current)
00428 {
00429 char command[SP_MSG_SIZE];
00430 char response[SP_MSG_SIZE];
00431 int status = ERR_NOERR;
00432
00433 bzero((void *) response, sizeof(response));
00434 sprintf(command, "GRC\n\r\0");
00435 if (_comm.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00436 ROS_ERROR("[MCDC3006S] getDriverInstantCurrent() --> Error when communicating with the driver. Could not establish current instant current");
00437 return (ERR_COM);
00438 }
00439 *current = atol(response);
00440
00441 return (ERR_NOERR);
00442 }
00443
00445
00446 int Mcdc3006s::setDriverMaxPos(long int maxPos)
00447 {
00448 char command[SP_MSG_SIZE];
00449
00450 if (maxPos <= 0) {
00451 fprintf(stderr, "setDriveMaxPos --> ERROR. Out of range: "
00452 "maxPos must be higher than 0 (You entered %ld).\n\r", maxPos);
00453 return ERR_OUTOFRANGE;
00454 }
00455 sprintf(command, "LL%ld\n\r\0", maxPos);
00456
00457 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00458 ROS_ERROR("[MCDC3006S] setDriverMaxPos() --> Error writing to the driver");
00459 return ERR_WRI;
00460 }
00461
00462 if (activateLimits(ACTIVATE) < ERR_NOERR) {
00463 ROS_ERROR("[MCDC3006S] setDriverMaxPos() --> Error activating the driver");
00464 return ERR_POSLIMIT;
00465 }
00466 return ERR_NOERR;
00467 }
00468
00470
00471 int Mcdc3006s::setDriverMinPos(long int minPos)
00472 {
00473 char command[SP_MSG_SIZE];
00474
00475 if (minPos >= 0) {
00476 fprintf(stderr, "setDriveMinPos --> ERROR. minPos must be lower than 0 (You entered %ld).\n\r", minPos);
00477 return ERR_OUTOFRANGE;
00478 }
00479
00480 sprintf(command, "LL%ld\n\r\0", minPos);
00481
00482 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00483 ROS_ERROR("[MCDC3006S] setDriverMinPos() --> Error writing to the driver");
00484 return ERR_WRI;
00485 }
00486
00487 if (activateLimits(ACTIVATE) < ERR_NOERR) {
00488 ROS_ERROR("[MCDC3006S] setDriverMaxPos() --> Error activating the driver");
00489 return ERR_POSLIMIT;
00490 }
00491
00492 return ERR_NOERR;
00493 }
00494
00496
00497 int Mcdc3006s::setDriverMaxVel(long int maxVel)
00498 {
00499 char command[SP_MSG_SIZE];
00500
00501 sprintf(command, "SP%ld\n\r\0", maxVel);
00502
00503 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00504 ROS_ERROR("[MCDC3006S] setDriverMaxVel() --> Error writing to the driver");
00505 return ERR_WRI;
00506 }
00507
00508 return ERR_NOERR;
00509 }
00510
00512
00513 int Mcdc3006s::setDriverMaxAcc(long int maxAcc)
00514 {
00515 char command[SP_MSG_SIZE];
00516
00517 sprintf(command, "AC%ld\n\r\0", maxAcc);
00518
00519 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00520 ROS_ERROR("[MCDC3006S] setDriverMaxAcc() --> Error writing to the driver");
00521 return ERR_WRI;
00522 }
00523
00524 return ERR_NOERR;
00525 }
00526
00528
00529 int Mcdc3006s::setDriverMaxDec(long int maxDec)
00530 {
00531 char command[SP_MSG_SIZE];
00532
00533 sprintf(command, "DEC%ld\n\r\0", maxDec);
00534
00535 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00536 ROS_ERROR("[MCDC3006S] setDriverMaxDec() --> Error writing to the driver");
00537 return ERR_WRI;
00538 }
00539
00540 return ERR_NOERR;
00541 }
00542
00544
00545 int Mcdc3006s::setDriverCurLim(int cl)
00546 {
00547 char command[SP_MSG_SIZE];
00548
00549 sprintf(command, "LCC%d\n\r\0", cl);
00550
00551 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00552 ROS_ERROR("[MCDC3006S] setDriverCurLim() --> Error writing to the driver");
00553 return ERR_WRI;
00554 }
00555
00556 return ERR_NOERR;
00557 }
00558
00560
00561 int Mcdc3006s::setDriverPCurLim(int pcl)
00562 {
00563 char command[SP_MSG_SIZE];
00564
00565 sprintf(command, "LPC%d\n\r\0", pcl);
00566
00567 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00568 ROS_ERROR("[MCDC3006S] setDriverPCurLim() --> Error writing to the driver");
00569 return ERR_WRI;
00570 }
00571
00572 return ERR_NOERR;
00573 }
00574
00576
00577 int Mcdc3006s::setDriverBaud(int baud)
00578 {
00579 int c = -1;
00580 int n;
00581 char command[SP_MSG_SIZE];
00582 for (n = 1; n < 10; n++) {
00583 if (baud == 600 * n) {
00584 c = 1;
00585 break;
00586 }
00587 }
00588 if (c) {
00589 sprintf(command, "BAUD%d\n\r", baud);
00590 }
00591 else {
00592 fprintf(stderr, "driverMCDC3006S - setDriverBaud ERROR %d not supported\n\r", baud);
00593 return ERR_OUTOFRANGE;
00594 }
00595 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00596 ROS_ERROR("[MCDC3006S] setDriverCurLim() --> Error writing to the driver\n\r");
00597 return ERR_WRI;
00598 }
00599
00600 return ERR_NOERR;
00601 }
00602
00604
00605 int Mcdc3006s::moveDriverAbsPos(long int pos)
00606 {
00607 char command[SP_MSG_SIZE];
00608
00609 sprintf(command, "LA%ld\n\r\0", pos);
00610 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00611 ROS_ERROR("[MCDC3006S] moveDriverAbsPos() --> Error writing to the driver\n\r");
00612 return ERR_WRI;
00613 }
00614
00615 sprintf(command, "M\n\r\0");
00616 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00617 ROS_ERROR("[MCDC3006S] moveDriverAbsPos() --> Error writing to the driver\n\r");
00618 return ERR_WRI;
00619 }
00620
00621 return ERR_NOERR;
00622 }
00623
00625
00626 int Mcdc3006s::moveDriverRelPos(long int pos)
00627 {
00628 char command[SP_MSG_SIZE];
00629
00630 sprintf(command, "LR%ld\n\r\0", pos);
00631 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00632 ROS_ERROR("[MCDC3006S] moveDriverRelPos() --> Error writing to the driver\n\r");
00633 return ERR_WRI;
00634 }
00635
00636 sprintf(command, "M\n\r\0");
00637 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00638 ROS_ERROR("[MCDC3006S] moveDriverRelPos() --> Error writing to the driver\n\r");
00639 return ERR_WRI;
00640 }
00641
00642 return ERR_NOERR;
00643 }
00644
00646
00647 int Mcdc3006s::moveDriverVel(long int vel)
00648 {
00649 char command[SP_MSG_SIZE];
00650
00651 sprintf(command, "V%ld\n\r\0", vel);
00652 if (_comm.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00653 ROS_ERROR("[MCDC3006S] moveDriverVel() --> Error writing to the driver\n\r");
00654 return ERR_WRI;
00655 }
00656
00657 return ERR_NOERR;
00658 }
00659
00661
00662 int Mcdc3006s::setDriverHomePosition(long int home)
00663 {
00664 char command[SP_MSG_SIZE];
00665 sprintf(command, "HO%ld\n\r", home);
00666
00667 if (_comm.writeToRS232(command, strlen(command))) {
00668 ROS_ERROR("[MCDC3006S] setDriverHomePosition() --> Error\n\r");
00669 return ERR_WRI;
00670 }
00671
00672 return ERR_NOERR;
00673 }
00674
00676
00677 int Mcdc3006s::calibrateDriver(long int limit, int current_limit, int calibration_speed, int time_out)
00678 {
00679
00680 char calibrationCommand[SP_MSG_SIZE];
00681 char calibrationResponse[SP_MSG_SIZE];
00682
00683 int status = 1;
00684 struct timeval before, now;
00685
00686
00687 sprintf(calibrationCommand, "LCC%d\n\r", current_limit);
00688 if (_comm.writeToRS232(calibrationCommand, strlen(calibrationCommand)) < ERR_NOERR) {
00689 ROS_ERROR("[MCDC3006S] calibrateDriver() --> Error\n\r");
00690 return ERR_NOHOME;
00691 }
00692
00693 sprintf(calibrationCommand, "HL8\n\r", current_limit);
00694 if (_comm.writeToRS232(calibrationCommand, strlen(calibrationCommand)) < ERR_NOERR) {
00695 ROS_ERROR("[MCDC3006S] calibrateDriver() --> Error\n\r");
00696 return ERR_NOHOME;
00697 }
00698
00699 sprintf(calibrationCommand, "V%d\n\r", calibration_speed);
00700 if (_comm.writeToRS232(calibrationCommand, strlen(calibrationCommand)) < ERR_NOERR) {
00701 ROS_ERROR("[MCDC3006S] calibrateDriver() --> Error\n\r");
00702 return ERR_NOHOME;
00703 }
00704
00705 gettimeofday(&before, 0);
00706 do {
00707 _comm.askToRS232("OST\n\r\0", strlen("OST\n\r\0"), calibrationResponse);
00708 gettimeofday(&now, 0);
00709
00710 if (atoi(calibrationResponse) & DRIVER_INPUT_4_MASK) {
00711 status = ERR_NOERR;
00712 }
00713 else if (atoi(calibrationResponse) & CURRENT_LIMITING_MASK) {
00714 ROS_ERROR("[MCDC3006S] calibrateDriver() --> Error Calibrating the driver. Current Limit Reached Could not establish home position");
00715 status = ERR_CURLIM;
00716 }
00717 else if (_comm.timeDifferenceMsec(&before, &now) > time_out) {
00718 ROS_ERROR("[MCDC3006S] calibrateDriver() --> Error Calibrating the driver. Timeout. Could not establish home position");
00719 status = ERR_TIMEOUT;
00720 }
00721 }
00722 while(status == 1);
00723
00724
00725 _comm.writeToRS232("V0\n\r\0", strlen("V0\n\r\0"));
00726
00727
00728 if (status == ERR_NOERR) {
00729
00730 if (setDriverHomePosition(limit) == 0) {
00731 moveDriverAbsPos(0);
00732 }
00733 else {
00734 ROS_ERROR("[MCDC3006S] calibrateDriver() --> Error Calibrating the driver. Could not establish home position");
00735 status = ERR_NOHOME;
00736 }
00737 }
00738
00739 return (status);
00740 }
00741