00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Devices/rt100.H"
00039
00040 #include "Component/OptionManager.H"
00041 #include "Devices/Serial.H"
00042
00043
00044 RT100::RT100(OptionManager& mgr, const std::string& descrName,
00045 const std::string& tagName, const char *defdev) :
00046 ModelComponent(mgr, descrName, tagName),
00047 itsPort(new Serial(mgr)),
00048 itsWristTiltVal(0),
00049 itsWristRollVal(0)
00050 {
00051
00052 itsPort->configure(defdev, 9600, "8N1", false, true, 0);
00053
00054
00055 addSubComponent(itsPort);
00056
00057 }
00058
00059
00060 RT100::~RT100()
00061 { }
00062
00063
00064
00065 int RT100::getNumJoints()
00066 {
00067 return NUM_JOINTS;
00068 }
00069
00070
00071 int RT100::setJointParam(JOINTS joint, PARAM param, short int val)
00072 {
00073
00074 switch(joint)
00075 {
00076 case BASE1:
00077 break;
00078 case BASE2:
00079 break;
00080 case WRIST1:
00081 deferredWrite(IP0, IP0WRIST1, param, val);
00082 break;
00083 case WRIST2:
00084 deferredWrite(IP0, IP0WRIST2, param, val);
00085 break;
00086 case SENSOR:
00087 break;
00088 case ELBOW:
00089 deferredWrite(IP1, IP1ELBOW, param, val);
00090 break;
00091 case SHOLDER:
00092 deferredWrite(IP1, IP1SHOLDER, param, val);
00093 break;
00094 case YAW:
00095 deferredWrite(IP1, IP1YAW, param, val);
00096 break;
00097 case ZED:
00098 deferredWrite(IP1, IP1ZED, param, val);
00099 break;
00100 case GRIPPER:
00101 deferredWrite(IP1, IP1GRIPPER, param, val);
00102 break;
00103
00104 case ROLL_WRIST:
00105 break;
00106
00107 case TILT_WRIST:
00108 break;
00109
00110 default:
00111 LFATAL("Invalid joint");
00112 break;
00113
00114 }
00115
00116 return RT100_OK;
00117 }
00118
00119
00120
00121 int RT100::setJointPosition(JOINTS joint, short int position, bool immediate)
00122 {
00123 unsigned char resCode;
00124 int wrist1Pos, wrist2Pos;
00125
00126 switch(joint)
00127 {
00128 case BASE1:
00129 break;
00130 case BASE2:
00131 break;
00132 case WRIST1:
00133 deferredWrite(IP0, IP0WRIST1, NEW_POSITION, position);
00134 break;
00135 case WRIST2:
00136 deferredWrite(IP0, IP0WRIST2, NEW_POSITION, position);
00137 break;
00138 case SENSOR:
00139 break;
00140 case ELBOW:
00141 deferredWrite(IP1, IP1ELBOW, NEW_POSITION, position);
00142 break;
00143 case SHOLDER:
00144 deferredWrite(IP1, IP1SHOLDER, NEW_POSITION, position);
00145 break;
00146 case YAW:
00147 deferredWrite(IP1, IP1YAW, NEW_POSITION, position);
00148 break;
00149 case ZED:
00150 deferredWrite(IP1, IP1ZED, NEW_POSITION, position);
00151 break;
00152 case GRIPPER:
00153 deferredWrite(IP1, IP1GRIPPER, NEW_POSITION, position);
00154 break;
00155
00156 case ROLL_WRIST:
00157 itsWristRollVal = position;
00158 wrist1Pos = itsWristTiltVal + position;
00159 wrist2Pos = itsWristTiltVal + -1*position;
00160 deferredWrite(IP0, IP0WRIST1, NEW_POSITION, wrist1Pos);
00161 deferredWrite(IP0, IP0WRIST2, NEW_POSITION, wrist2Pos);
00162 break;
00163
00164 case TILT_WRIST:
00165 itsWristTiltVal = position;
00166 wrist1Pos = itsWristRollVal + position;
00167 wrist2Pos = -1*itsWristRollVal + position;
00168 deferredWrite(IP0, IP0WRIST1, NEW_POSITION, wrist1Pos);
00169 deferredWrite(IP0, IP0WRIST2, NEW_POSITION, wrist2Pos);
00170 break;
00171
00172 default:
00173 LFATAL("Invalid joint");
00174 break;
00175
00176 }
00177
00178 if (immediate)
00179 {
00180 rawCommand(IP0, 0xAC, &resCode);
00181 rawCommand(IP1, 0xBF, &resCode);
00182 }
00183
00184
00185 return RT100_OK;
00186 }
00187
00188 int RT100::getJointPosition(JOINTS joint, short int *position)
00189 {
00190 ASSERT(position != NULL);
00191
00192 switch (joint)
00193 {
00194 case BASE1:
00195 break;
00196 case BASE2:
00197 break;
00198 case WRIST1:
00199 immediateRead(IP0, IP0WRIST1, CURRENT_POSITION, position);
00200 break;
00201 case WRIST2:
00202 immediateRead(IP0, IP0WRIST2, CURRENT_POSITION, position);
00203 break;
00204 case ROLL_WRIST:
00205 break;
00206 case TILT_WRIST:
00207 break;
00208 case SENSOR:
00209 break;
00210 case ELBOW:
00211 immediateRead(IP1, IP1ELBOW, CURRENT_POSITION, position);
00212 break;
00213 case SHOLDER:
00214 immediateRead(IP1, IP1SHOLDER, CURRENT_POSITION, position);
00215 break;
00216 case YAW:
00217 immediateRead(IP1, IP1YAW, CURRENT_POSITION, position);
00218 break;
00219 case ZED:
00220 immediateRead(IP1, IP1ZED, CURRENT_POSITION, position);
00221 break;
00222 case GRIPPER:
00223 immediateRead(IP1, IP1GRIPPER, CURRENT_POSITION, position);
00224 break;
00225
00226 default:
00227 LFATAL("Invalid joint");
00228 break;
00229 }
00230
00231 return RT100_OK;
00232 }
00233
00234
00235 int RT100::moveArm(bool waitUntilComplete)
00236 {
00237
00238 unsigned char resCode, byte1, byte2;
00239 rawCommand(IP0, 0xAC, &resCode);
00240 rawCommand(IP1, 0xBF, &resCode);
00241
00242 if (waitUntilComplete)
00243 {
00244 bool moveDone = false;
00245 for(int i=0; i<1000 && !moveDone; i++)
00246 {
00247 rawCommand(IP1, 0x17, &resCode, &byte1, &byte2);
00248 if (!(byte1 & (1 << TASK_IN_PROGRESS)))
00249 moveDone = true;
00250 }
00251 }
00252
00253
00254 return RT100_OK;
00255
00256 }
00257
00258 bool RT100::moveComplete()
00259 {
00260 unsigned char resCode, byte1, byte2;
00261
00262 rawCommand(IP1, 0x17, &resCode, &byte1, &byte2);
00263 if (!(byte1 & (1 << TASK_IN_PROGRESS)))
00264 return true;
00265 else
00266 return false;
00267 }
00268
00269
00270
00271 int RT100::interpolationMove(std::vector<short int> &moveVals)
00272 {
00273 unsigned char resCode;
00274 ASSERT(moveVals.size() == NUM_JOINTS);
00275
00276 unsigned char ip0Byte1 = 0x00, ip0Byte2 = 0x00, ip0Byte3 = 0x00;
00277 unsigned char ip1Byte1 = 0x00, ip1Byte2 = 0x00, ip1Byte3 = 0x00;
00278
00279
00280 for(unsigned int joint = 0; joint<NUM_JOINTS; joint++)
00281 {
00282 short int jointVal = moveVals[joint];
00283 if (jointVal > 7 || jointVal < -8)
00284 LINFO("WARANING!!! joint %i is out of range (-8 < %i < 7)", joint, moveVals[joint]);
00285
00286 jointVal = jointVal & 0x0F;
00287
00288
00289 enum IP0MOTORS {IP0BASE1, IP0BASE2, IP0WRIST1, IP0WRIST2, IP0SENSOR};
00290 switch (joint)
00291 {
00292 case BASE1:
00293 ip0Byte3 = 0x00;
00294 break;
00295 case BASE2:
00296 ip0Byte3 = 0x00;
00297 break;
00298 case WRIST1:
00299 ip0Byte3 += jointVal;
00300 break;
00301 case WRIST2:
00302 ip0Byte3 = ip0Byte3 + (jointVal << 4);
00303 break;
00304 case ROLL_WRIST:
00305 break;
00306 case TILT_WRIST:
00307 break;
00308 case SENSOR:
00309 ip0Byte1 = 0xC0 ;
00310 break;
00311 case ELBOW:
00312 ip1Byte2 += jointVal;
00313 break;
00314 case SHOLDER:
00315 ip1Byte2 = ip1Byte2 + (jointVal << 4);
00316 break;
00317 case YAW:
00318 ip1Byte3 = ip1Byte3 + (jointVal << 4);
00319 break;
00320 case ZED:
00321 ip1Byte3 += jointVal;
00322 break;
00323 case GRIPPER:
00324 ip1Byte1 = 0xC0 + jointVal;
00325 break;
00326
00327 default:
00328 LFATAL("Invalid joint");
00329 break;
00330 }
00331 }
00332
00333
00334 if (ip0Byte1 || ip0Byte2 || ip0Byte3)
00335 {
00336 LDEBUG("Sending interpolation command to IP0: %x %x %x", ip0Byte1, ip0Byte2, ip0Byte3);
00337 rawCommand(IP0, ip0Byte1, ip0Byte2, ip0Byte3, &resCode);
00338 }
00339
00340 if (ip1Byte1 || ip1Byte2 || ip1Byte3)
00341 {
00342 LDEBUG("Sending interpolation command to IP1: %x %x %x", ip1Byte1, ip1Byte2, ip1Byte3);
00343 rawCommand(IP1, ip1Byte1, ip1Byte2, ip1Byte3, &resCode);
00344 }
00345
00346
00347 return RT100_OK;
00348
00349 }
00350
00351
00352 int RT100::init()
00353 {
00354 unsigned char resCode;
00355 unsigned cmd;
00356 LINFO("Initalizing arm to home position...");
00357
00358
00359 cmd = 0x00;
00360 itsPort->write(&cmd,1);
00361 usleep(10000);
00362
00363
00364
00365
00366
00367
00368
00369 rawCommand(IP0, EMERGENCY_STOP + FREE_OFF, &resCode);
00370 rawCommand(IP1, EMERGENCY_STOP + FREE_OFF, &resCode);
00371
00372
00373 initZed();
00374 initGripper();
00375 initWrist();
00376 initSholder();
00377 initElbowYaw();
00378
00379
00380 immediateWrite(IP1, IP1ELBOW, CURRENT_POSITION, 62907);
00381 immediateWrite(IP1, IP1SHOLDER, CURRENT_POSITION, 2629);
00382 immediateWrite(IP1, IP1ZED, CURRENT_POSITION, 0);
00383 immediateWrite(IP1, IP1YAW, CURRENT_POSITION, 63588);
00384 immediateWrite(IP1, IP1GRIPPER, CURRENT_POSITION, 0);
00385
00386 immediateWrite(IP0, IP0WRIST1, CURRENT_POSITION, 62435);
00387 immediateWrite(IP0, IP0WRIST2, CURRENT_POSITION, 459);
00388
00389 gotoHomePosition();
00390
00391
00392
00393
00394
00395 return RT100_OK;
00396 }
00397
00398 void RT100::gotoHomePosition()
00399 {
00400
00401 unsigned char resCode;
00402 deferredWrite(IP1, IP1ELBOW, NEW_POSITION, 0);
00403 deferredWrite(IP1, IP1SHOLDER, NEW_POSITION, 0);
00404 deferredWrite(IP1, IP1ZED, NEW_POSITION, -400);
00405 deferredWrite(IP1, IP1YAW, NEW_POSITION, 0);
00406 deferredWrite(IP1, IP1GRIPPER, NEW_POSITION, 0);
00407
00408 deferredWrite(IP0, IP0WRIST1, NEW_POSITION, 0);
00409 deferredWrite(IP0, IP0WRIST2, NEW_POSITION, 0);
00410
00411 rawCommand(IP0, 0xAC, &resCode);
00412 rawCommand(IP1, 0xBF, &resCode);
00413
00414 sleep(2);
00415
00416 }
00417
00418 void RT100::initZed()
00419 {
00420 unsigned char resCode, byte1, byte2;
00421 deferredWrite(IP1, IP1ZED, SPEED, 30);
00422 deferredWrite(IP1, IP1ZED, MAX_FORCE, 30);
00423
00424 rawCommand(IP0, EMERGENCY_STOP + DEAD_STOP, &resCode);
00425 rawCommand(IP1, EMERGENCY_STOP + DEAD_STOP, &resCode);
00426
00427 rawCommand(IP0, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00428 rawCommand(IP1, 0x80, 0x10, 0x00, &resCode);
00429
00430
00431 bool hitEndStop = false;
00432 for(int i=0; i<500 && !hitEndStop; i++)
00433 {
00434 rawCommand(IP1, 0x10 + IP1ZED, &resCode, &byte1, &byte2);
00435 if (byte1 & (1 << NO_MOVEMENT))
00436 hitEndStop = true;
00437 }
00438 rawCommand(IP1, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00439
00440 if (!hitEndStop)
00441 LFATAL("ERROR: Can not init zed");
00442
00443
00444 rawCommand(IP0, 0x21, &resCode);
00445 rawCommand(IP1, 0x21, &resCode);
00446
00447 }
00448
00449 void RT100::initGripper()
00450 {
00451 unsigned char resCode, byte1, byte2;
00452
00453 deferredWrite(IP1, IP1GRIPPER, SPEED, 30);
00454 deferredWrite(IP1, IP1GRIPPER, MAX_FORCE, 30);
00455
00456 rawCommand(IP0, EMERGENCY_STOP + DEAD_STOP, &resCode);
00457 rawCommand(IP1, EMERGENCY_STOP + DEAD_STOP, &resCode);
00458
00459 rawCommand(IP0, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00460 rawCommand(IP1, 0x80, 0x00, 0x02, &resCode);
00461
00462
00463 bool hitEndStop = false;
00464 for(int i=0; i<500 && !hitEndStop; i++)
00465 {
00466 rawCommand(IP1, 0x10 + IP1GRIPPER, &resCode, &byte1, &byte2);
00467 if (byte1 & (1 << NO_MOVEMENT))
00468 hitEndStop = true;
00469 }
00470
00471
00472 rawCommand(IP1, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00473
00474 if (!hitEndStop)
00475 LFATAL("ERROR: Can not init zed");
00476
00477
00478 rawCommand(IP0, 0x21, &resCode);
00479 rawCommand(IP1, 0x21, &resCode);
00480
00481
00482 rawCommand(IP0, 0x22, &resCode);
00483 rawCommand(IP1, 0x22, &resCode);
00484
00485
00486
00487
00488 deferredWrite(IP1, IP1GRIPPER, NEW_POSITION, 30);
00489
00490 rawCommand(IP1, EMERGENCY_STOP + DEAD_STOP, &resCode);
00491 rawCommand(IP1, 0xA0|(1<<IP1GRIPPER), &resCode);
00492
00493
00494 bool taskComplete = false;
00495 for(int i=0; i<500 && !taskComplete; i++)
00496 {
00497 rawCommand(IP1, 0x10 + IP1GRIPPER, &resCode, &byte1, &byte2);
00498 if (byte1 & (1 << TASK_COMPLETE))
00499 taskComplete = true;
00500 }
00501
00502
00503 rawCommand(IP0, 0x21, &resCode);
00504 rawCommand(IP1, 0x21, &resCode);
00505
00506
00507 rawCommand(IP0, 0x22, &resCode);
00508 rawCommand(IP1, 0x22, &resCode);
00509
00510 }
00511
00512 void RT100::initWrist()
00513 {
00514 unsigned char resCode, byte1, byte2;
00515
00516
00517
00518 deferredWrite(IP0, IP0WRIST1, SPEED, 80);
00519 deferredWrite(IP0, IP0WRIST2, SPEED, 80);
00520
00521 rawCommand(IP0, EMERGENCY_STOP + DEAD_STOP, &resCode);
00522 rawCommand(IP1, EMERGENCY_STOP + DEAD_STOP, &resCode);
00523
00524
00525
00526 rawCommand(IP1, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00527 rawCommand(IP0, 0x80, 0x60, 0x00, &resCode);
00528
00529
00530 bool hitEndStop = false;
00531 for(int i=0; i<500 && !hitEndStop; i++)
00532 {
00533 rawCommand(IP0, 0x10 + IP0WRIST1, &resCode, &byte1, &byte2);
00534 if (byte1 & (1 << NO_MOVEMENT))
00535 hitEndStop = true;
00536 }
00537
00538 rawCommand(IP0, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00539
00540 if (!hitEndStop)
00541 LFATAL("ERROR: Can not init zed");
00542
00543
00544 rawCommand(IP0, 0x80, 0xa0, 0x00, &resCode);
00545
00546
00547 hitEndStop = false;
00548 for(int i=0; i<500 && !hitEndStop; i++)
00549 {
00550 rawCommand(IP0, 0x10 + IP0WRIST1, &resCode, &byte1, &byte2);
00551 if (byte1 & (1 << NO_MOVEMENT))
00552 hitEndStop = true;
00553 }
00554
00555 rawCommand(IP0, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00556
00557 if (!hitEndStop)
00558 LFATAL("ERROR: Can not init zed");
00559
00560 rawCommand(IP0, EMERGENCY_STOP + DEAD_STOP, &resCode);
00561 rawCommand(IP1, EMERGENCY_STOP + DEAD_STOP, &resCode);
00562
00563
00564
00565 rawCommand(IP0, 0x21, &resCode);
00566 rawCommand(IP1, 0x21, &resCode);
00567
00568
00569 rawCommand(IP0, 0x22, &resCode);
00570 rawCommand(IP1, 0x22, &resCode);
00571
00572 }
00573
00574 void RT100::initSholder()
00575 {
00576 unsigned char resCode, byte1, byte2;
00577 deferredWrite(IP1, IP1SHOLDER, SPEED, 30);
00578 deferredWrite(IP1, IP1SHOLDER, MAX_FORCE, 20);
00579
00580 rawCommand(IP0, EMERGENCY_STOP + DEAD_STOP, &resCode);
00581 rawCommand(IP1, EMERGENCY_STOP + DEAD_STOP, &resCode);
00582
00583 rawCommand(IP0, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00584 rawCommand(IP1, 0x80, 0x04, 0x00, &resCode);
00585
00586
00587 bool hitEndStop = false;
00588 for(int i=0; i<500 && !hitEndStop; i++)
00589 {
00590 rawCommand(IP1, 0x10 + IP1SHOLDER, &resCode, &byte1, &byte2);
00591 if (byte1 & (1 << NO_MOVEMENT))
00592 hitEndStop = true;
00593 }
00594 rawCommand(IP1, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00595
00596 if (!hitEndStop)
00597 LFATAL("ERROR: Can not init sholder");
00598
00599
00600 rawCommand(IP0, 0x21, &resCode);
00601 rawCommand(IP1, 0x21, &resCode);
00602
00603
00604 rawCommand(IP0, 0x22, &resCode);
00605 rawCommand(IP1, 0x22, &resCode);
00606
00607 }
00608
00609 void RT100::initElbowYaw()
00610 {
00611 unsigned char resCode, byte1, byte2;
00612 deferredWrite(IP1, IP1ELBOW, SPEED, 30);
00613 deferredWrite(IP1, IP1ELBOW, MAX_FORCE, 20);
00614
00615 deferredWrite(IP1, IP1YAW, SPEED, 30);
00616 deferredWrite(IP1, IP1YAW, MAX_FORCE, 20);
00617
00618 deferredWrite(IP1, IP1YAW, ERROR_LIMIT, 1500);
00619
00620 rawCommand(IP0, EMERGENCY_STOP + DEAD_STOP, &resCode);
00621 rawCommand(IP1, EMERGENCY_STOP + DEAD_STOP, &resCode);
00622
00623 rawCommand(IP0, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00624 rawCommand(IP1, 0x80, 0x82, 0x00, &resCode);
00625
00626
00627 bool hitEndStop = false;
00628 for(int i=0; i<500 && !hitEndStop; i++)
00629 {
00630 rawCommand(IP1, 0x10 + IP1YAW, &resCode, &byte1, &byte2);
00631 if (byte1 & (1 << NO_MOVEMENT))
00632 hitEndStop = true;
00633 }
00634 rawCommand(IP1, (unsigned char)0x80, (unsigned char)0x00, (unsigned char)0x00, &resCode);
00635
00636 if (!hitEndStop)
00637 LFATAL("ERROR: Can not init sholder");
00638
00639
00640 rawCommand(IP0, 0x21, &resCode);
00641 rawCommand(IP1, 0x21, &resCode);
00642
00643
00644 rawCommand(IP0, 0x22, &resCode);
00645 rawCommand(IP1, 0x22, &resCode);
00646
00647 }
00648
00649
00650 int RT100::shutdown()
00651 {
00652
00653 return RT100_OK;
00654 }
00655
00656 int RT100::deferredRead(IP ipID, unsigned int ctrl, PARAM param, short int *val)
00657 {
00658
00659 unsigned char cmd[3];
00660 unsigned char cmdResults[3];
00661
00662
00663 switchIP(ipID);
00664
00665
00666 cmd[0] = 0x06 << 4;
00667 cmd[0] += ctrl;
00668 cmd[1] = param;
00669 cmd[2] = 0xcc;
00670
00671 LDEBUG("Sending T1: %x %x %x", cmd[0], cmd[1], cmd[2]);
00672 itsPort->write(&cmd,3);
00673 usleep(10000);
00674 unsigned char result = itsPort->read();
00675 if (result != 0xC0)
00676 LFATAL("Error in deferred read\n");
00677
00678
00679 cmd[0] = 0x06 << 4;
00680 cmd[0] += 0x08 + ctrl;
00681
00682 LDEBUG("Sending T2: %x", cmd[0]);
00683 itsPort->write(&cmd,1);
00684 usleep(10000);
00685 itsPort->read(cmdResults, 3);
00686 LDEBUG("Got: %x %x %x", cmdResults[0], cmdResults[1], cmdResults[2]);
00687
00688
00689
00690 *val = cmdResults[2] << 8;
00691 *val += cmdResults[1];
00692
00693 return RT100_OK;
00694 }
00695
00696 int RT100::deferredWrite(IP ipID, unsigned int ctrl, PARAM param, short int val)
00697 {
00698
00699 unsigned char cmd[3];
00700 unsigned char cmdResults[3];
00701 switchIP(ipID);
00702
00703
00704 cmd[0] = 0x07 << 4;
00705 cmd[0] += ctrl;
00706 cmd[1] = param;
00707 cmd[2] = 0xcc;
00708
00709 LDEBUG("Sending T1: %x %x %x", cmd[0], cmd[1], cmd[2]);
00710 itsPort->write(&cmd,3);
00711 usleep(10000);
00712 unsigned char result = itsPort->read();
00713 if (result != 0xE0)
00714 LFATAL("Error in deferred Write (sent %x,%x,%x got %x)\n",
00715 cmd[0], cmd[1], cmd[2], result);
00716
00717
00718 cmd[0] = 0x07 << 4;
00719 cmd[0] += 0x08 + ctrl;
00720 cmd[1] = val;
00721 cmd[2] = val >> 8;
00722
00723 LDEBUG("Sending T2: %x %x %x", cmd[0], cmd[1], cmd[2]);
00724 itsPort->write(&cmd,3);
00725 usleep(10000);
00726 itsPort->read(cmdResults, 3);
00727 LDEBUG("Got: %x %x %x", cmdResults[0], cmdResults[1], cmdResults[2]);
00728
00729
00730
00731
00732 return RT100_OK;
00733 }
00734
00735 int RT100::immediateRead(IP ipID, unsigned int ctrl, PARAM param, short int *val)
00736 {
00737 unsigned char cmd[3];
00738 unsigned char cmdResults[3];
00739
00740 switchIP(ipID);
00741
00742 cmd[0] = 0x04 << 4;
00743 switch (param)
00744 {
00745 case CP_ERROR:
00746 cmd[0] += ctrl;
00747 break;
00748 case CURRENT_POSITION:
00749 cmd[0] += 0x08 + ctrl;
00750 break;
00751 default:
00752 LFATAL("Can not send param in immediate mode");
00753 break;
00754 }
00755
00756 LDEBUG("Sending: %x", cmd[0]);
00757 itsPort->write(&cmd,1);
00758 usleep(10000);
00759 itsPort->read(cmdResults, 3);
00760 LDEBUG("Got: %x %x %x", cmdResults[0], cmdResults[1], cmdResults[2]);
00761
00762
00763
00764 *val = cmdResults[2] << 8;
00765 *val += cmdResults[1];
00766
00767 return RT100_OK;
00768 }
00769
00770 int RT100::immediateWrite(IP ipID, unsigned int ctrl, PARAM param, short int val)
00771 {
00772
00773 unsigned char cmd[3];
00774 switchIP(ipID);
00775
00776 if (param != CURRENT_POSITION) LFATAL("Can only write to CURRENT_POSITION");
00777
00778 cmd[0] = 0x05 << 4;
00779 cmd[0] += 0x08 + ctrl;
00780 cmd[1] = val;
00781 cmd[2] = val >> 8;
00782
00783 LDEBUG("Sending: %x %x %x", cmd[0], cmd[1], cmd[2]);
00784 itsPort->write(&cmd,3);
00785 usleep(10000);
00786 itsPort->read();
00787
00788
00789
00790 return RT100_OK;
00791 }
00792
00793 int RT100::switchIP(IP ipID)
00794 {
00795 unsigned char cmd;
00796 unsigned char cmdResults[3];
00797
00798
00799
00800 cmd = 0x01;
00801 if (itsPort->write(&cmd,1) != 1)
00802 LFATAL("Can not send command to arm");
00803 usleep(10000);
00804
00805 if (itsPort->read(cmdResults, 1) != 1)
00806 LFATAL("Can not get IP id");
00807 usleep(10000);
00808
00809
00810 if ((cmdResults[0] == 0x20 && ipID == IP1) ||
00811 (cmdResults[0] == 0x21 && ipID == IP0) )
00812 {
00813 cmd = 0x29;
00814 if (itsPort->write(&cmd,1) != 1)
00815 LFATAL("Can not send command to arm");
00816 usleep(10000);
00817 if (itsPort->read(cmdResults, 1) != 1)
00818 LFATAL("Can not get results");
00819 if (cmdResults[0] != 0x00 && cmdResults[0] != 0x21)
00820 LFATAL("Can not switch IPS got: %x", cmdResults[0]);
00821 }
00822
00823
00824 usleep(10000);
00825
00826 return RT100_OK;
00827
00828 }
00829
00830
00831 int RT100::rawCommand(IP ipID, unsigned char cmdType,
00832 unsigned char *resCode, short int *results)
00833 {
00834
00835 unsigned char cmdResults[3];
00836 switchIP(ipID);
00837
00838 LDEBUG("Sending: %x", cmdType);
00839 if (itsPort->write(&cmdType,1) != 1)
00840 LFATAL("Can not send command to arm");
00841 usleep(10000);
00842
00843 cmdResults[0] = 0xFF;
00844 int n = itsPort->read(cmdResults, 3);
00845 *resCode = cmdResults[0];
00846 LDEBUG("Got: %x", cmdResults[0]);
00847 if (n > 1)
00848 {
00849
00850 }
00851 usleep(10000);
00852
00853 return RT100_OK;
00854 }
00855
00856
00857 int RT100::rawCommand(IP ipID, unsigned char cmdType,
00858 unsigned char *resCode, unsigned char *byte1, unsigned char *byte2)
00859 {
00860
00861 unsigned char cmdResults[3];
00862 switchIP(ipID);
00863
00864 LDEBUG("Sending: %x", cmdType);
00865 if (itsPort->write(&cmdType,1) != 1)
00866 LFATAL("Can not send command to arm");
00867 usleep(10000);
00868
00869 cmdResults[0] = 0xFF;
00870 int n = itsPort->read(cmdResults, 3);
00871 LDEBUG("Got: %x %x %x", cmdResults[0], cmdResults[1], cmdResults[2]);
00872
00873 *resCode = cmdResults[0];
00874 if (n > 1)
00875 {
00876 *byte1 = cmdResults[1];
00877 *byte2 = cmdResults[2];
00878 } else {
00879 *byte1 = 0xFF;
00880 *byte2 = 0xFF;
00881 }
00882
00883 usleep(10000);
00884
00885 return RT100_OK;
00886 }
00887
00888
00889 int RT100::rawCommand(IP ipID, unsigned char cmdType,
00890 unsigned char byte1, unsigned char byte2,
00891 unsigned char *resCode)
00892 {
00893 unsigned char cmdResults;
00894 unsigned char cmd[3];
00895
00896 switchIP(ipID);
00897
00898 cmd[0] = cmdType;
00899 cmd[1] = byte1;
00900 cmd[2] = byte2;
00901 LDEBUG("Sending: %x %x %x", cmd[0], cmd[1], cmd[2]);
00902 if (itsPort->write(&cmd,3) != 3)
00903 LFATAL("Can not send command to arm");
00904 usleep(10000);
00905
00906 cmdResults = 0xFF;
00907 itsPort->read(&cmdResults, 1);
00908 LDEBUG("Got: %x", cmdResults);
00909 *resCode = cmdResults;
00910 usleep(10000);
00911
00912 return RT100_OK;
00913 }
00914
00915
00916
00917
00918
00919
00920
00921