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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include "youbot/YouBotManipulator.hpp"
00052 namespace youbot {
00053
00054 YouBotManipulator::YouBotManipulator(const std::string name, const std::string configFilePath)
00055 : ethercatMaster(EthercatMaster::getInstance("youbot-ethercat.cfg", configFilePath)) {
00056
00057
00058 this->controllerType = 841;
00059 this->alternativeControllerType = 1610;
00060 this->supportedFirmwareVersions.push_back("148");
00061 this->supportedFirmwareVersions.push_back("200");
00062 this->actualFirmwareVersionAllJoints = "";
00063
00064 string filename;
00065 filename = name;
00066 filename.append(".cfg");
00067 useGripper = true;
00068 configfile.reset(new ConfigFile(filename, configFilePath));
00069
00070 if(ethercatMaster.isThreadActive()){
00071 ethercatMasterWithThread = static_cast<EthercatMasterWithThread*>(&(EthercatMaster::getInstance()));
00072 }else{
00073 ethercatMasterWithThread = NULL;
00074 }
00075
00076 this->initializeJoints();
00077
00078
00079
00080
00081 }
00082
00083 YouBotManipulator::~YouBotManipulator() {
00084
00085 if(ethercatMaster.isThreadActive()){
00086 for (unsigned int i = 0; i < ARMJOINTS; i++) {
00087 ethercatMasterWithThread->deleteJointTrajectoryControllerRegistration(this->joints[i].getJointNumber());
00088 }
00089 }
00090
00091 }
00092
00093
00094 void YouBotManipulator::doJointCommutation() {
00095
00096
00097 if(this->actualFirmwareVersionAllJoints == "148"){
00098 this->commutationFirmware148();
00099 }else if(this->actualFirmwareVersionAllJoints == "200" ){
00100 this->commutationFirmware200();
00101 }else{
00102 throw std::runtime_error("Unable to commutate joints - Unsupported firmware version!");
00103 }
00104
00105 }
00106
00107
00108 void YouBotManipulator::calibrateManipulator(const bool forceCalibration) {
00109
00110
00111
00112 std::vector<JointRoundsPerMinuteSetpoint> calibrationVel;
00113 JointRoundsPerMinuteSetpoint tempdummy;
00114 tempdummy.rpm = 0;
00115 calibrationVel.assign(ARMJOINTS, tempdummy);
00116 std::vector<quantity<si::current> > maxCurrent;
00117 quantity<si::current> tempdummy2;
00118 maxCurrent.assign(ARMJOINTS, tempdummy2);
00119 std::vector<bool> doCalibration;
00120 doCalibration.assign(ARMJOINTS, true);
00121 std::string jointName;
00122
00123 double dummy = 0;
00124 char index = 16;
00125
00126 YouBotSlaveMailboxMsg IsCalibratedReadMessage;
00127 IsCalibratedReadMessage.stctOutput.moduleAddress = DRIVE;
00128 IsCalibratedReadMessage.stctOutput.commandNumber = GGP;
00129 IsCalibratedReadMessage.stctOutput.typeNumber = index;
00130 IsCalibratedReadMessage.stctOutput.motorNumber = USER_VARIABLE_BANK;
00131 IsCalibratedReadMessage.stctOutput.value = 0;
00132 IsCalibratedReadMessage.stctInput.value = 0;
00133
00134 YouBotSlaveMailboxMsg IsCalibratedSetMessage;
00135 IsCalibratedSetMessage.stctOutput.moduleAddress = DRIVE;
00136 IsCalibratedSetMessage.stctOutput.commandNumber = SGP;
00137 IsCalibratedSetMessage.stctOutput.typeNumber = index;
00138 IsCalibratedSetMessage.stctOutput.motorNumber = USER_VARIABLE_BANK;
00139 IsCalibratedSetMessage.stctOutput.value = 1;
00140
00141
00142
00143 for (unsigned int i = 0; i < ARMJOINTS; i++) {
00144
00145 std::stringstream jointNameStream;
00146 jointNameStream << "Joint_" << i + 1;
00147 jointName = jointNameStream.str();
00148 bool calib = true;
00149 configfile->readInto(calib, jointName, "DoCalibration");
00150 doCalibration[i] = calib;
00151
00152 joints[i].getConfigurationParameter(IsCalibratedReadMessage);
00153 if (IsCalibratedReadMessage.stctInput.value == 1) {
00154 doCalibration[i] = false;
00155 }
00156
00157 if (forceCalibration) {
00158 doCalibration[i] = true;
00159 }
00160
00161 configfile->readInto(dummy, jointName, "CalibrationMaxCurrent_[ampere]");
00162 maxCurrent[i] = dummy * ampere;
00163 std::string direction;
00164 configfile->readInto(direction, jointName, "CalibrationDirection");
00165 GearRatio gearRatio;
00166 joints[i].getConfigurationParameter(gearRatio);
00167 double gearratio = 1;
00168 gearRatio.getParameter(gearratio);
00169
00170 if (direction == "POSITIV") {
00171 calibrationVel[i].rpm = 1 / gearratio;
00172 } else if (direction == "NEGATIV") {
00173 calibrationVel[i].rpm = -1 / gearratio;
00174 } else {
00175 throw std::runtime_error("Wrong calibration direction for " + jointName);
00176 }
00177 }
00178
00179
00180 LOG(info) << "Calibrate Manipulator Joints ";
00181
00182 std::vector<bool> finished;
00183 finished.assign(ARMJOINTS, false);
00184 JointSensedCurrent sensedCurrent;
00185
00186
00187
00188 for (unsigned int i = 0; i < ARMJOINTS; i++) {
00189 if (doCalibration[i] == true) {
00190 joints[i].setData(calibrationVel[i]);
00191 if(!ethercatMaster.isThreadActive()){
00192 ethercatMaster.sendProcessData();
00193 ethercatMaster.receiveProcessData();
00194 }
00195 } else {
00196 finished[i] = true;
00197 }
00198 }
00199
00200
00201 while (!(finished[0] && finished[1] && finished[2] && finished[3] && finished[4])) {
00202 for (unsigned int i = 0; i < ARMJOINTS; i++) {
00203 if(!ethercatMaster.isThreadActive()){
00204 ethercatMaster.sendProcessData();
00205 ethercatMaster.receiveProcessData();
00206 }
00207 joints[i].getData(sensedCurrent);
00208
00209 if (abs(sensedCurrent.current) > abs(maxCurrent[i])) {
00210
00211 youbot::JointCurrentSetpoint currentStopMovement;
00212 currentStopMovement.current = 0 * ampere;
00213 joints[i].setData(currentStopMovement);
00214 if(!ethercatMaster.isThreadActive()){
00215 ethercatMaster.sendProcessData();
00216 ethercatMaster.receiveProcessData();
00217 }
00218 finished[i] = true;
00219 }
00220 }
00221 SLEEP_MILLISEC(1);
00222 }
00223
00224
00225 SLEEP_MILLISEC(100);
00226
00227 for (unsigned int i = 0; i < ARMJOINTS; i++) {
00228 if (doCalibration[i] == true) {
00229
00230 joints[i].setEncoderToZero();
00231 if(!ethercatMaster.isThreadActive()){
00232 ethercatMaster.sendProcessData();
00233 ethercatMaster.receiveProcessData();
00234 }
00235
00236 joints[i].setConfigurationParameter(IsCalibratedSetMessage);
00237
00238 }
00239 }
00240
00241
00242 JointLimits jLimits;
00243 for (unsigned int i = 0; i < ARMJOINTS; i++) {
00244 long upperlimit = 0, lowerlimit = 0;
00245 std::stringstream jointNameStream;
00246 bool inverted = false;
00247 jointNameStream << "Joint_" << i + 1;
00248 jointName = jointNameStream.str();
00249 JointEncoderSetpoint minEncoderValue;
00250 configfile->readInto(lowerlimit, jointName, "LowerLimit_[encoderTicks]");
00251 configfile->readInto(upperlimit, jointName, "UpperLimit_[encoderTicks]");
00252 configfile->readInto(inverted, jointName, "InverseMovementDirection");
00253
00254 if(inverted){
00255 minEncoderValue.encoderTicks = lowerlimit + 1000;
00256 }else{
00257 minEncoderValue.encoderTicks = upperlimit - 1000;
00258 }
00259
00260 jLimits.setParameter(lowerlimit, upperlimit, true);
00261 joints[i].setConfigurationParameter(jLimits);
00262
00263 }
00264
00265
00266 }
00267
00268 void YouBotManipulator::calibrateGripper(const bool forceCalibration) {
00269
00270
00271 bool doCalibration = true;
00272 configfile->readInto(doCalibration, "Gripper", "DoCalibration");
00273 if(useGripper && doCalibration){
00274 CalibrateGripper calibrate;
00275 calibrate.setParameter(forceCalibration);
00276 gripper->setConfigurationParameter(calibrate);
00277 }
00278
00279 }
00280
00281
00282
00283 YouBotJoint& YouBotManipulator::getArmJoint(const unsigned int armJointNumber) {
00284
00285
00286 if (armJointNumber <= 0 || armJointNumber > ARMJOINTS) {
00287 throw std::out_of_range("Invalid Joint Number");
00288 }
00289 return joints[armJointNumber - 1];
00290
00291 }
00292
00293 YouBotGripper& YouBotManipulator::getArmGripper() {
00294
00295 if(!useGripper){
00296 throw std::runtime_error("The gripper is disabled!");
00297 }
00298 return *gripper;
00299
00300 }
00301
00302
00303
00304
00305 void YouBotManipulator::setJointData(const std::vector<JointAngleSetpoint>& JointData) {
00306
00307 if (JointData.size() != ARMJOINTS)
00308 throw std::out_of_range("Wrong number of JointAngleSetpoints");
00309
00310 ethercatMaster.AutomaticSendOn(false);
00311 joints[0].setData(JointData[0]);
00312 joints[1].setData(JointData[1]);
00313 joints[2].setData(JointData[2]);
00314 joints[3].setData(JointData[3]);
00315 joints[4].setData(JointData[4]);
00316 ethercatMaster.AutomaticSendOn(true);
00317
00318
00319 }
00320
00321
00322
00323
00324 void YouBotManipulator::getJointData(std::vector<JointSensedAngle>& data) {
00325
00326 data.resize(ARMJOINTS);
00327 ethercatMaster.AutomaticReceiveOn(false);
00328 joints[0].getData(data[0]);
00329 joints[1].getData(data[1]);
00330 joints[2].getData(data[2]);
00331 joints[3].getData(data[3]);
00332 joints[4].getData(data[4]);
00333 ethercatMaster.AutomaticReceiveOn(true);
00334
00335 }
00336
00337
00338
00339
00340 void YouBotManipulator::setJointData(const std::vector<JointVelocitySetpoint>& JointData) {
00341
00342 if (JointData.size() != ARMJOINTS)
00343 throw std::out_of_range("Wrong number of JointVelocitySetpoints");
00344
00345 ethercatMaster.AutomaticSendOn(false);
00346 joints[0].setData(JointData[0]);
00347 joints[1].setData(JointData[1]);
00348 joints[2].setData(JointData[2]);
00349 joints[3].setData(JointData[3]);
00350 joints[4].setData(JointData[4]);
00351 ethercatMaster.AutomaticSendOn(true);
00352
00353 }
00354
00355
00356
00357
00358 void YouBotManipulator::getJointData(std::vector<JointSensedVelocity>& data) {
00359
00360 data.resize(ARMJOINTS);
00361 ethercatMaster.AutomaticReceiveOn(false);
00362 joints[0].getData(data[0]);
00363 joints[1].getData(data[1]);
00364 joints[2].getData(data[2]);
00365 joints[3].getData(data[3]);
00366 joints[4].getData(data[4]);
00367 ethercatMaster.AutomaticReceiveOn(true);
00368
00369 }
00370
00371
00372
00373
00374 void YouBotManipulator::setJointData(const std::vector<JointCurrentSetpoint>& JointData) {
00375
00376 if (JointData.size() != ARMJOINTS)
00377 throw std::out_of_range("Wrong number of JointCurrentSetpoint");
00378
00379 ethercatMaster.AutomaticSendOn(false);
00380 joints[0].setData(JointData[0]);
00381 joints[1].setData(JointData[1]);
00382 joints[2].setData(JointData[2]);
00383 joints[3].setData(JointData[3]);
00384 joints[4].setData(JointData[4]);
00385 ethercatMaster.AutomaticSendOn(true);
00386
00387 }
00388
00389
00390
00391
00392 void YouBotManipulator::getJointData(std::vector<JointSensedCurrent>& data) {
00393
00394 data.resize(ARMJOINTS);
00395 ethercatMaster.AutomaticReceiveOn(false);
00396 joints[0].getData(data[0]);
00397 joints[1].getData(data[1]);
00398 joints[2].getData(data[2]);
00399 joints[3].getData(data[3]);
00400 joints[4].getData(data[4]);
00401 ethercatMaster.AutomaticReceiveOn(true);
00402
00403 }
00404
00405
00406
00407
00408 void YouBotManipulator::setJointData(const std::vector<JointTorqueSetpoint>& JointData) {
00409
00410 if (JointData.size() != ARMJOINTS)
00411 throw std::out_of_range("Wrong number of JointTorqueSetpoint");
00412
00413 ethercatMaster.AutomaticSendOn(false);
00414 joints[0].setData(JointData[0]);
00415 joints[1].setData(JointData[1]);
00416 joints[2].setData(JointData[2]);
00417 joints[3].setData(JointData[3]);
00418 joints[4].setData(JointData[4]);
00419 ethercatMaster.AutomaticSendOn(true);
00420
00421 }
00422
00423
00424
00425
00426 void YouBotManipulator::getJointData(std::vector<JointSensedTorque>& data) {
00427
00428 data.resize(ARMJOINTS);
00429 ethercatMaster.AutomaticReceiveOn(false);
00430 joints[0].getData(data[0]);
00431 joints[1].getData(data[1]);
00432 joints[2].getData(data[2]);
00433 joints[3].getData(data[3]);
00434 joints[4].getData(data[4]);
00435 ethercatMaster.AutomaticReceiveOn(true);
00436
00437 }
00438
00439
00440 void YouBotManipulator::commutationFirmware200() {
00441
00442
00443 InitializeJoint doInitialization;
00444 bool isInitialized = false;
00445 int noInitialization = 0;
00446 std::string jointName;
00447 unsigned int statusFlags;
00448 std::vector<bool> isCommutated;
00449 isCommutated.assign(ARMJOINTS, false);
00450 unsigned int u = 0;
00451 JointCurrentSetpoint zerocurrent;
00452 zerocurrent.current = 0.0 * ampere;
00453
00454
00455 ClearMotorControllerTimeoutFlag clearTimeoutFlag;
00456 for (unsigned int i = 1; i <= ARMJOINTS; i++) {
00457 this->getArmJoint(i).setConfigurationParameter(clearTimeoutFlag);
00458 }
00459
00460 for (unsigned int i = 1; i <= ARMJOINTS; i++) {
00461 doInitialization.setParameter(false);
00462 this->getArmJoint(i).getConfigurationParameter(doInitialization);
00463 doInitialization.getParameter(isInitialized);
00464 if (!isInitialized) {
00465 noInitialization++;
00466 }
00467 }
00468
00469 if (noInitialization != 0) {
00470 LOG(info) << "Manipulator Joint Commutation";
00471 doInitialization.setParameter(true);
00472
00473 JointRoundsPerMinuteSetpoint rpmSetpoint(100);
00474
00475 ethercatMaster.AutomaticReceiveOn(false);
00476 this->getArmJoint(1).setData(rpmSetpoint);
00477 this->getArmJoint(2).setData(rpmSetpoint);
00478 this->getArmJoint(3).setData(rpmSetpoint);
00479 this->getArmJoint(4).setData(rpmSetpoint);
00480 this->getArmJoint(5).setData(rpmSetpoint);
00481 ethercatMaster.AutomaticReceiveOn(true);
00482
00483
00484
00485 for (u = 1; u <= 5000; u++) {
00486 for (unsigned int i = 1; i <= ARMJOINTS; i++) {
00487 this->getArmJoint(i).getStatus(statusFlags);
00488 if (statusFlags & INITIALIZED) {
00489 isCommutated[i - 1] = true;
00490 this->getArmJoint(i).setData(zerocurrent);
00491 }
00492 }
00493 if(!ethercatMaster.isThreadActive()){
00494 ethercatMaster.sendProcessData();
00495 ethercatMaster.receiveProcessData();
00496 }
00497 if (isCommutated[0] && isCommutated[1] && isCommutated[2] && isCommutated[3] && isCommutated[4]) {
00498 break;
00499 }
00500 SLEEP_MILLISEC(1);
00501 }
00502
00503 for (unsigned int i = 1; i <= ARMJOINTS; i++) {
00504 this->getArmJoint(i).setData(zerocurrent);
00505 if(!ethercatMaster.isThreadActive()){
00506 ethercatMaster.sendProcessData();
00507 ethercatMaster.receiveProcessData();
00508 }
00509 doInitialization.setParameter(false);
00510 this->getArmJoint(i).getConfigurationParameter(doInitialization);
00511 doInitialization.getParameter(isInitialized);
00512 if (!isInitialized) {
00513 std::stringstream jointNameStream;
00514 jointNameStream << "manipulator joint " << i;
00515 jointName = jointNameStream.str();
00516 throw std::runtime_error("Could not commutate " + jointName);
00517 }
00518 }
00519 }
00520
00521 }
00522
00523
00524 void YouBotManipulator::commutationFirmware148() {
00525
00526
00527 InitializeJoint doInitialization;
00528 bool isInitialized = false;
00529 int noInitialization = 0;
00530 std::string jointName;
00531
00532
00533 ClearMotorControllerTimeoutFlag clearTimeoutFlag;
00534 for (unsigned int i = 1; i <= ARMJOINTS; i++) {
00535 this->getArmJoint(i).setConfigurationParameter(clearTimeoutFlag);
00536 }
00537
00538 for (unsigned int i = 1; i <= ARMJOINTS; i++) {
00539 doInitialization.setParameter(false);
00540 this->getArmJoint(i).getConfigurationParameter(doInitialization);
00541 doInitialization.getParameter(isInitialized);
00542 if (!isInitialized) {
00543 noInitialization++;
00544 }
00545 }
00546
00547 if (noInitialization != 0) {
00548 LOG(info) << "Manipulator Joint Commutation";
00549 doInitialization.setParameter(true);
00550
00551 ethercatMaster.AutomaticReceiveOn(false);
00552 this->getArmJoint(1).setConfigurationParameter(doInitialization);
00553 this->getArmJoint(2).setConfigurationParameter(doInitialization);
00554 this->getArmJoint(3).setConfigurationParameter(doInitialization);
00555 this->getArmJoint(4).setConfigurationParameter(doInitialization);
00556 this->getArmJoint(5).setConfigurationParameter(doInitialization);
00557 ethercatMaster.AutomaticReceiveOn(true);
00558
00559 unsigned int statusFlags;
00560 std::vector<bool> isCommutated;
00561 isCommutated.assign(ARMJOINTS, false);
00562 unsigned int u = 0;
00563
00564
00565 for (u = 1; u <= 5000; u++) {
00566 for (unsigned int i = 1; i <= ARMJOINTS; i++) {
00567 if(!ethercatMaster.isThreadActive()){
00568 ethercatMaster.sendProcessData();
00569 ethercatMaster.receiveProcessData();
00570 }
00571 this->getArmJoint(i).getStatus(statusFlags);
00572 if (statusFlags & INITIALIZED) {
00573 isCommutated[i - 1] = true;
00574 }
00575 }
00576 if (isCommutated[0] && isCommutated[1] && isCommutated[2] && isCommutated[3] && isCommutated[4]) {
00577 break;
00578 }
00579 SLEEP_MILLISEC(1);
00580 }
00581
00582 SLEEP_MILLISEC(10);
00583
00584 for (unsigned int i = 1; i <= ARMJOINTS; i++) {
00585 doInitialization.setParameter(false);
00586 this->getArmJoint(i).getConfigurationParameter(doInitialization);
00587 doInitialization.getParameter(isInitialized);
00588 if (!isInitialized) {
00589 std::stringstream jointNameStream;
00590 jointNameStream << "manipulator joint " << i;
00591 jointName = jointNameStream.str();
00592 throw std::runtime_error("Could not commutate " + jointName);
00593 }
00594 }
00595 }
00596
00597
00598
00599 }
00600
00601 void YouBotManipulator::initializeJoints() {
00602
00603
00604
00605
00606
00607
00608 unsigned int noSlaves = ethercatMaster.getNumberOfSlaves();
00609
00610
00611 if (noSlaves < ARMJOINTS) {
00612 throw std::runtime_error("Not enough ethercat slaves were found to create a YouBotManipulator!");
00613 }
00614
00615
00616 unsigned int slaveNumber = 0;
00617 configfile->readInto(slaveNumber, "JointTopology", "ManipulatorJoint1");
00618 if (slaveNumber <= noSlaves) {
00619 joints.push_back(new YouBotJoint(slaveNumber));
00620 } else {
00621 throw std::out_of_range("The ethercat slave number is not available!");
00622 }
00623
00624 configfile->readInto(slaveNumber, "JointTopology", "ManipulatorJoint2");
00625 if (slaveNumber <= noSlaves) {
00626 joints.push_back(new YouBotJoint(slaveNumber));
00627 } else {
00628 throw std::out_of_range("The ethercat slave number is not available!");
00629 }
00630
00631 configfile->readInto(slaveNumber, "JointTopology", "ManipulatorJoint3");
00632 if (slaveNumber <= noSlaves) {
00633 joints.push_back(new YouBotJoint(slaveNumber));
00634 } else {
00635 throw std::out_of_range("The ethercat slave number is not available!");
00636 }
00637
00638 configfile->readInto(slaveNumber, "JointTopology", "ManipulatorJoint4");
00639 if (slaveNumber <= noSlaves) {
00640 joints.push_back(new YouBotJoint(slaveNumber));
00641 } else {
00642 throw std::out_of_range("The ethercat slave number is not available!");
00643 }
00644
00645 configfile->readInto(slaveNumber, "JointTopology", "ManipulatorJoint5");
00646 if (slaveNumber <= noSlaves) {
00647 joints.push_back(new YouBotJoint(slaveNumber));
00648 } else {
00649 throw std::out_of_range("The ethercat slave number is not available!");
00650 }
00651
00652
00653
00654
00655
00656
00657 std::string jointName;
00658 JointName jName;
00659 GearRatio gearRatio;
00660 EncoderTicksPerRound ticksPerRound;
00661 InverseMovementDirection inverseDir;
00662 double gearRatio_numerator = 0;
00663 double gearRatio_denominator = 1;
00664 FirmwareVersion firmwareTypeVersion;
00665 TorqueConstant torqueConst;
00666 double trajectory_p=0, trajectory_i=0, trajectory_d=0, trajectory_imax=0, trajectory_imin=0;
00667
00668
00669 for (unsigned int i = 0; i < ARMJOINTS; i++) {
00670 std::stringstream jointNameStream;
00671 jointNameStream << "Joint_" << i + 1;
00672 jointName = jointNameStream.str();
00673
00674
00675 joints[i].getConfigurationParameter(firmwareTypeVersion);
00676 std::string version;
00677 int controllerType;
00678 std::string firmwareVersion;
00679 firmwareTypeVersion.getParameter(controllerType, firmwareVersion);
00680
00681 string name;
00682 configfile->readInto(name, jointName, "JointName");
00683 jName.setParameter(name);
00684
00685 LOG(info) << name << "\t Controller Type: " << controllerType << " Firmware version: " << firmwareVersion;
00686
00687 if (this->controllerType != controllerType && alternativeControllerType != controllerType) {
00688 std::stringstream ss;
00689 ss << "The youBot manipulator motor controller have to be of type: " << this->controllerType << " or " << alternativeControllerType;
00690 throw std::runtime_error(ss.str().c_str());
00691 }
00692
00693
00694 bool isfirmwareSupported = false;
00695 for(unsigned int d = 0; d < supportedFirmwareVersions.size(); d++){
00696 if(this->supportedFirmwareVersions[d] == firmwareVersion){
00697 isfirmwareSupported = true;
00698 break;
00699 }
00700 }
00701
00702 if(!isfirmwareSupported){
00703 throw std::runtime_error("Unsupported firmware version: " + firmwareVersion);
00704 }
00705
00706 if(this->actualFirmwareVersionAllJoints == ""){
00707 this->actualFirmwareVersionAllJoints = firmwareVersion;
00708 }
00709
00710 if(!(firmwareVersion == this->actualFirmwareVersionAllJoints)){
00711 throw std::runtime_error("All joints must have the same firmware version!");
00712 }
00713
00714 configfile->readInto(gearRatio_numerator, jointName, "GearRatio_numerator");
00715 configfile->readInto(gearRatio_denominator, jointName, "GearRatio_denominator");
00716 gearRatio.setParameter(gearRatio_numerator / gearRatio_denominator);
00717 int ticks;
00718 configfile->readInto(ticks, jointName, "EncoderTicksPerRound");
00719 ticksPerRound.setParameter(ticks);
00720
00721 double torqueConstant;
00722 configfile->readInto(torqueConstant, jointName, "TorqueConstant_[newton_meter_divided_by_ampere]");
00723 torqueConst.setParameter(torqueConstant);
00724
00725 bool invdir = false;
00726 configfile->readInto(invdir, jointName, "InverseMovementDirection");
00727 inverseDir.setParameter(invdir);
00728
00729 joints[i].setConfigurationParameter(jName);
00730 joints[i].setConfigurationParameter(gearRatio);
00731 joints[i].setConfigurationParameter(ticksPerRound);
00732 joints[i].setConfigurationParameter(torqueConst);
00733 joints[i].setConfigurationParameter(inverseDir);
00734
00735
00736 if(ethercatMaster.isThreadActive()){
00737 configfile->readInto(trajectory_p, jointName, "trajectory_controller_P");
00738 configfile->readInto(trajectory_i, jointName, "trajectory_controller_I");
00739 configfile->readInto(trajectory_d, jointName, "trajectory_controller_D");
00740 configfile->readInto(trajectory_imax, jointName, "trajectory_controller_I_max");
00741 configfile->readInto(trajectory_imin, jointName, "trajectory_controller_I_min");
00742 joints[i].trajectoryController.setConfigurationParameter(trajectory_p, trajectory_i, trajectory_d, trajectory_imax, trajectory_imin);
00743 joints[i].trajectoryController.setEncoderTicksPerRound(ticks);
00744 joints[i].trajectoryController.setGearRatio(gearRatio_numerator / gearRatio_denominator);
00745 joints[i].trajectoryController.setInverseMovementDirection(invdir);
00746 ethercatMasterWithThread->registerJointTrajectoryController(&(joints[i].trajectoryController), joints[i].getJointNumber());
00747 }
00748 }
00749
00750
00751 configfile->readInto(useGripper, "Gripper", "EnableGripper");
00752
00753 if(useGripper){
00754
00755 configfile->readInto(slaveNumber, "JointTopology", "ManipulatorJoint5");
00756 this->gripper.reset(new YouBotGripper(slaveNumber));
00757 BarSpacingOffset barOffest;
00758 MaxTravelDistance maxDistance;
00759 MaxEncoderValue maxEncoder;
00760 GripperBarName BarName;
00761 double dummy = 0;
00762 int controllerType;
00763 double firmwareVersion;
00764 string barname;
00765
00766 GripperFirmwareVersion gripperVersion;
00767 this->gripper->getConfigurationParameter(gripperVersion);
00768 gripperVersion.getParameter(controllerType, firmwareVersion);
00769
00770 LOG(info) << "Gripper" << "\t\t Controller Type: " << controllerType << " Firmware version: " << firmwareVersion;
00771
00772
00773 configfile->readInto(barname, "GripperBar1", "BarName");
00774 BarName.setParameter(barname);
00775 this->gripper->getGripperBar1().setConfigurationParameter(BarName);
00776
00777 configfile->readInto(dummy, "GripperBar1", "BarSpacingOffset_[meter]");
00778 barOffest.setParameter(dummy * meter);
00779 this->gripper->getGripperBar1().setConfigurationParameter(barOffest);
00780
00781 configfile->readInto(dummy, "GripperBar1", "MaxTravelDistance_[meter]");
00782 maxDistance.setParameter(dummy * meter);
00783 this->gripper->getGripperBar1().setConfigurationParameter(maxDistance);
00784
00785 int maxenc = 0;
00786 configfile->readInto(maxenc, "GripperBar1", "MaxEncoderValue");
00787 maxEncoder.setParameter(maxenc);
00788 this->gripper->getGripperBar1().setConfigurationParameter(maxEncoder);
00789
00790 int stallThreshold = 0;
00791 configfile->readInto(stallThreshold, "GripperBar1", "StallGuard2Threshold");
00792 StallGuard2Threshold threshold;
00793 threshold.setParameter(stallThreshold);
00794 this->gripper->getGripperBar1().setConfigurationParameter(threshold);
00795
00796 bool stallGuardFilter = false;
00797 configfile->readInto(stallGuardFilter, "GripperBar1", "StallGuard2FilterEnable");
00798 StallGuard2FilterEnable filter;
00799 filter.setParameter(stallGuardFilter);
00800 this->gripper->getGripperBar1().setConfigurationParameter(filter);
00801
00802
00803 configfile->readInto(barname, "GripperBar2", "BarName");
00804 BarName.setParameter(barname);
00805 this->gripper->getGripperBar2().setConfigurationParameter(BarName);
00806
00807 configfile->readInto(dummy, "GripperBar2", "BarSpacingOffset_[meter]");
00808 barOffest.setParameter(dummy * meter);
00809 this->gripper->getGripperBar2().setConfigurationParameter(barOffest);
00810
00811 configfile->readInto(dummy, "GripperBar2", "MaxTravelDistance_[meter]");
00812 maxDistance.setParameter(dummy * meter);
00813 this->gripper->getGripperBar2().setConfigurationParameter(maxDistance);
00814
00815 configfile->readInto(maxenc, "GripperBar2", "MaxEncoderValue");
00816 maxEncoder.setParameter(maxenc);
00817 this->gripper->getGripperBar2().setConfigurationParameter(maxEncoder);
00818
00819 configfile->readInto(stallThreshold, "GripperBar2", "StallGuard2Threshold");
00820 threshold.setParameter(stallThreshold);
00821 this->gripper->getGripperBar2().setConfigurationParameter(threshold);
00822
00823 configfile->readInto(stallGuardFilter, "GripperBar2", "StallGuard2FilterEnable");
00824 filter.setParameter(stallGuardFilter);
00825 this->gripper->getGripperBar2().setConfigurationParameter(filter);
00826 }
00827
00828
00829 return;
00830
00831 }
00832
00833
00834 }