YouBotBase.cpp

Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2011
00004  * All rights reserved.
00005  *
00006  * Hochschule Bonn-Rhein-Sieg
00007  * University of Applied Sciences
00008  * Computer Science Department
00009  *
00010  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00011  *
00012  * Author:
00013  * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
00014  * Supervised by:
00015  * Gerhard K. Kraetzschmar
00016  *
00017  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00018  *
00019  * This sofware is published under a dual-license: GNU Lesser General Public 
00020  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
00021  * code may choose which terms they prefer.
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
00034  *       contributors may be used to endorse or promote products derived from
00035  *       this software without specific prior written permission.
00036  *
00037  * This program is free software: you can redistribute it and/or modify
00038  * it under the terms of the GNU Lesser General Public License LGPL as
00039  * published by the Free Software Foundation, either version 2.1 of the
00040  * License, or (at your option) any later version or the BSD license.
00041  *
00042  * This program is distributed in the hope that it will be useful,
00043  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00044  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00045  * GNU Lesser General Public License LGPL and the BSD license for more details.
00046  *
00047  * You should have received a copy of the GNU Lesser General Public
00048  * License LGPL and BSD license along with this program.
00049  *
00050  ****************************************************************/
00051 #include "youbot/YouBotBase.hpp"
00052 namespace youbot {
00053 
00054 YouBotBase::YouBotBase(const std::string name, const std::string configFilePath)
00055 : ethercatMaster(EthercatMaster::getInstance("youbot-ethercat.cfg", configFilePath)) {
00056   // Bouml preserved body begin 00067E71
00057 
00058     this->controllerType = 174;
00059     this->alternativeControllerType = 1632;
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 
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     this->initializeKinematic();
00079 
00080   // Bouml preserved body end 00067E71
00081 }
00082 
00083 YouBotBase::~YouBotBase() {
00084   // Bouml preserved body begin 00067EF1
00085   if(ethercatMaster.isThreadActive()){
00086       for (unsigned int i = 0; i < BASEJOINTS; i++) {
00087         ethercatMasterWithThread->deleteJointTrajectoryControllerRegistration(this->joints[i].getJointNumber());
00088       }
00089     }
00090   // Bouml preserved body end 00067EF1
00091 }
00092 
00093 ///does the sine commutation of the base joints
00094 void YouBotBase::doJointCommutation() {
00095   // Bouml preserved body begin 0008A9F1
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   // Bouml preserved body end 0008A9F1
00105 }
00106 
00107 ///return a joint form the base
00108 ///@param baseJointNumber 1-4 for the base joints
00109 YouBotJoint& YouBotBase::getBaseJoint(const unsigned int baseJointNumber) {
00110   // Bouml preserved body begin 0004F771
00111     if (baseJointNumber <= 0 || baseJointNumber > BASEJOINTS) {
00112       throw std::out_of_range("Invalid Joint Number");
00113     }
00114     return joints[baseJointNumber - 1];
00115   // Bouml preserved body end 0004F771
00116 }
00117 
00118 ///gets the cartesien base position which is calculated from the odometry
00119 ///@param longitudinalPosition is the forward or backward position
00120 ///@param transversalPosition is the sideway position
00121 ///@param orientation is the rotation around the center of the YouBot
00122 void YouBotBase::getBasePosition(quantity<si::length>& longitudinalPosition, quantity<si::length>& transversalPosition, quantity<plane_angle>& orientation) {
00123   // Bouml preserved body begin 000514F1
00124 
00125     std::vector<quantity<plane_angle> > wheelPositions;
00126     quantity<plane_angle> dummy;
00127     JointSensedAngle sensedPos;
00128     wheelPositions.assign(BASEJOINTS, dummy);
00129 
00130     ethercatMaster.AutomaticReceiveOn(false);
00131     joints[0].getData(sensedPos);
00132     wheelPositions[0] = sensedPos.angle;
00133     joints[1].getData(sensedPos);
00134     wheelPositions[1] = sensedPos.angle;
00135     joints[2].getData(sensedPos);
00136     wheelPositions[2] = sensedPos.angle;
00137     joints[3].getData(sensedPos);
00138     wheelPositions[3] = sensedPos.angle;
00139     ethercatMaster.AutomaticReceiveOn(true);
00140 
00141     youBotBaseKinematic.wheelPositionsToCartesianPosition(wheelPositions, longitudinalPosition, transversalPosition, orientation);
00142   // Bouml preserved body end 000514F1
00143 }
00144 
00145 ///sets the cartesien base position
00146 ///@param longitudinalPosition is the forward or backward position
00147 ///@param transversalPosition is the sideway position
00148 ///@param orientation is the rotation around the center of the YouBot
00149 void YouBotBase::setBasePosition(const quantity<si::length>& longitudinalPosition, const quantity<si::length>& transversalPosition, const quantity<plane_angle>& orientation) {
00150   // Bouml preserved body begin 000C0971
00151 
00152     std::vector<quantity<plane_angle> > wheelPositions;
00153     quantity<plane_angle> dummy;
00154     JointAngleSetpoint setpointPos;
00155     wheelPositions.assign(BASEJOINTS, dummy);
00156     JointSensedAngle sensedPos;
00157 
00158     youBotBaseKinematic.cartesianPositionToWheelPositions(longitudinalPosition, transversalPosition, orientation, wheelPositions);
00159     
00160     if (wheelPositions.size() < BASEJOINTS)
00161       throw std::out_of_range("To less wheel velocities");
00162     
00163     joints[0].setEncoderToZero();
00164     joints[1].setEncoderToZero();
00165     joints[2].setEncoderToZero();
00166     joints[3].setEncoderToZero();
00167     SLEEP_MILLISEC(10);
00168 
00169     ethercatMaster.AutomaticSendOn(false);
00170     joints[0].getData(sensedPos);
00171     setpointPos.angle = sensedPos.angle + wheelPositions[0];
00172     joints[0].setData(setpointPos);
00173     
00174     joints[1].getData(sensedPos);
00175     setpointPos.angle = sensedPos.angle + wheelPositions[1];
00176     joints[1].setData(setpointPos);
00177     
00178     joints[2].getData(sensedPos);
00179     setpointPos.angle = sensedPos.angle + wheelPositions[2];
00180     joints[2].setData(setpointPos);
00181     
00182     joints[3].getData(sensedPos);
00183     setpointPos.angle = sensedPos.angle + wheelPositions[3];
00184     joints[3].setData(setpointPos);
00185     ethercatMaster.AutomaticSendOn(true);
00186 
00187   // Bouml preserved body end 000C0971
00188 }
00189 
00190 ///gets the cartesien base velocity
00191 ///@param longitudinalVelocity is the forward or backward velocity
00192 ///@param transversalVelocity is the sideway velocity
00193 ///@param angularVelocity is the rotational velocity around the center of the YouBot
00194 void YouBotBase::getBaseVelocity(quantity<si::velocity>& longitudinalVelocity, quantity<si::velocity>& transversalVelocity, quantity<si::angular_velocity>& angularVelocity) {
00195   // Bouml preserved body begin 00051271
00196 
00197     std::vector<quantity<angular_velocity> > wheelVelocities;
00198     quantity<angular_velocity> dummy;
00199     JointSensedVelocity sensedVel;
00200     wheelVelocities.assign(BASEJOINTS, dummy);
00201 
00202     ethercatMaster.AutomaticReceiveOn(false);
00203     joints[0].getData(sensedVel);
00204     wheelVelocities[0] = sensedVel.angularVelocity;
00205     joints[1].getData(sensedVel);
00206     wheelVelocities[1] = sensedVel.angularVelocity;
00207     joints[2].getData(sensedVel);
00208     wheelVelocities[2] = sensedVel.angularVelocity;
00209     joints[3].getData(sensedVel);
00210     wheelVelocities[3] = sensedVel.angularVelocity;
00211     ethercatMaster.AutomaticReceiveOn(true);
00212 
00213     youBotBaseKinematic.wheelVelocitiesToCartesianVelocity(wheelVelocities, longitudinalVelocity, transversalVelocity, angularVelocity);
00214 
00215   // Bouml preserved body end 00051271
00216 }
00217 
00218 ///commands the base in cartesien velocities
00219 ///@param longitudinalVelocity is the forward or backward velocity
00220 ///@param transversalVelocity is the sideway velocity
00221 ///@param angularVelocity is the rotational velocity around the center of the YouBot
00222 void YouBotBase::setBaseVelocity(const quantity<si::velocity>& longitudinalVelocity, const quantity<si::velocity>& transversalVelocity, const quantity<si::angular_velocity>& angularVelocity) {
00223   // Bouml preserved body begin 0004DD71
00224 
00225     std::vector<quantity<angular_velocity> > wheelVelocities;
00226     JointVelocitySetpoint setVel;
00227 
00228     youBotBaseKinematic.cartesianVelocityToWheelVelocities(longitudinalVelocity, transversalVelocity, angularVelocity, wheelVelocities);
00229 
00230     if (wheelVelocities.size() < BASEJOINTS)
00231       throw std::out_of_range("To less wheel velocities");
00232 
00233     ethercatMaster.AutomaticSendOn(false);
00234     setVel.angularVelocity = wheelVelocities[0];
00235     joints[0].setData(setVel);
00236     setVel.angularVelocity = wheelVelocities[1];
00237     joints[1].setData(setVel);
00238     setVel.angularVelocity = wheelVelocities[2];
00239     joints[2].setData(setVel);
00240     setVel.angularVelocity = wheelVelocities[3];
00241     joints[3].setData(setVel);
00242     ethercatMaster.AutomaticSendOn(true);
00243   // Bouml preserved body end 0004DD71
00244 }
00245 
00246 ///commands positions or angles to all base joints
00247 ///all positions will be set at the same time
00248 ///@param JointData the to command positions
00249 void YouBotBase::setJointData(const std::vector<JointAngleSetpoint>& JointData) {
00250   // Bouml preserved body begin 0008F9F1
00251     if (JointData.size() != BASEJOINTS)
00252       throw std::out_of_range("Wrong number of JointAngleSetpoints");
00253 
00254     ethercatMaster.AutomaticSendOn(false);
00255     joints[0].setData(JointData[0]);
00256     joints[1].setData(JointData[1]);
00257     joints[2].setData(JointData[2]);
00258     joints[3].setData(JointData[3]);
00259     ethercatMaster.AutomaticSendOn(true);
00260 
00261   // Bouml preserved body end 0008F9F1
00262 }
00263 
00264 ///gets the position or angle of all base joints which have been calculated from the actual encoder value
00265 ///These values are all read at the same time from the different joints 
00266 ///@param data returns the angles by reference
00267 void YouBotBase::getJointData(std::vector<JointSensedAngle>& data) {
00268   // Bouml preserved body begin 0008FBF1
00269     data.resize(BASEJOINTS);
00270     ethercatMaster.AutomaticReceiveOn(false);
00271     joints[0].getData(data[0]);
00272     joints[1].getData(data[1]);
00273     joints[2].getData(data[2]);
00274     joints[3].getData(data[3]);
00275     ethercatMaster.AutomaticReceiveOn(true);
00276   // Bouml preserved body end 0008FBF1
00277 }
00278 
00279 ///commands velocities to all base joints
00280 ///all velocities will be set at the same time
00281 ///@param JointData the to command velocities
00282 void YouBotBase::setJointData(const std::vector<JointVelocitySetpoint>& JointData) {
00283   // Bouml preserved body begin 0008FA71
00284     if (JointData.size() != BASEJOINTS)
00285       throw std::out_of_range("Wrong number of JointVelocitySetpoints");
00286 
00287     ethercatMaster.AutomaticSendOn(false);
00288     joints[0].setData(JointData[0]);
00289     joints[1].setData(JointData[1]);
00290     joints[2].setData(JointData[2]);
00291     joints[3].setData(JointData[3]);
00292     ethercatMaster.AutomaticSendOn(true);
00293   // Bouml preserved body end 0008FA71
00294 }
00295 
00296 ///gets the velocities of all base joints which have been calculated from the actual encoder values
00297 ///These values are all read at the same time from the different joints 
00298 ///@param data returns the velocities by reference
00299 void YouBotBase::getJointData(std::vector<JointSensedVelocity>& data) {
00300   // Bouml preserved body begin 0008FC71
00301     data.resize(BASEJOINTS);
00302     ethercatMaster.AutomaticReceiveOn(false);
00303     joints[0].getData(data[0]);
00304     joints[1].getData(data[1]);
00305     joints[2].getData(data[2]);
00306     joints[3].getData(data[3]);
00307     ethercatMaster.AutomaticReceiveOn(true);
00308   // Bouml preserved body end 0008FC71
00309 }
00310 
00311 ///commands current to all base joints
00312 ///all current values will be set at the same time
00313 ///@param JointData the to command current
00314 void YouBotBase::setJointData(const std::vector<JointCurrentSetpoint>& JointData) {
00315   // Bouml preserved body begin 000CDFF1
00316     if (JointData.size() != BASEJOINTS)
00317       throw std::out_of_range("Wrong number of JointCurrentSetpoint");
00318 
00319     ethercatMaster.AutomaticSendOn(false);
00320     joints[0].setData(JointData[0]);
00321     joints[1].setData(JointData[1]);
00322     joints[2].setData(JointData[2]);
00323     joints[3].setData(JointData[3]);
00324     ethercatMaster.AutomaticSendOn(true);
00325   // Bouml preserved body end 000CDFF1
00326 }
00327 
00328 ///gets the motor currents of all base joints which have been measured by a hal sensor
00329 ///These values are all read at the same time from the different joints 
00330 ///@param data returns the actual motor currents by reference
00331 void YouBotBase::getJointData(std::vector<JointSensedCurrent>& data) {
00332   // Bouml preserved body begin 0008FD71
00333     data.resize(BASEJOINTS);
00334     ethercatMaster.AutomaticReceiveOn(false);
00335     joints[0].getData(data[0]);
00336     joints[1].getData(data[1]);
00337     joints[2].getData(data[2]);
00338     joints[3].getData(data[3]);
00339     ethercatMaster.AutomaticReceiveOn(true);
00340   // Bouml preserved body end 0008FD71
00341 }
00342 
00343 ///commands torque to all base joints
00344 ///all torque values will be set at the same time
00345 ///@param JointData the to command torque 
00346 void YouBotBase::setJointData(const std::vector<JointTorqueSetpoint>& JointData) {
00347   // Bouml preserved body begin 000CE071
00348     if (JointData.size() != BASEJOINTS)
00349       throw std::out_of_range("Wrong number of JointTorqueSetpoint");
00350 
00351     ethercatMaster.AutomaticSendOn(false);
00352     joints[0].setData(JointData[0]);
00353     joints[1].setData(JointData[1]);
00354     joints[2].setData(JointData[2]);
00355     joints[3].setData(JointData[3]);
00356     ethercatMaster.AutomaticSendOn(true);
00357   // Bouml preserved body end 000CE071
00358 }
00359 
00360 ///gets the joint torque of all base joints which have been calculated from the current
00361 ///These values are all read at the same time from the different joints 
00362 ///@param data returns the actual joint torque by reference
00363 void YouBotBase::getJointData(std::vector<JointSensedTorque>& data) {
00364   // Bouml preserved body begin 000CE0F1
00365     data.resize(BASEJOINTS);
00366     ethercatMaster.AutomaticReceiveOn(false);
00367     joints[0].getData(data[0]);
00368     joints[1].getData(data[1]);
00369     joints[2].getData(data[2]);
00370     joints[3].getData(data[3]);
00371     ethercatMaster.AutomaticReceiveOn(true);
00372   // Bouml preserved body end 000CE0F1
00373 }
00374 
00375 ///does the commutation of the arm joints with firmware 2.0
00376 void YouBotBase::commutationFirmware200() {
00377   // Bouml preserved body begin 0010D9F1
00378   
00379     InitializeJoint doInitialization;
00380     bool isInitialized = false;
00381     int noInitialization = 0;
00382     std::string jointName;
00383     unsigned int statusFlags;
00384     std::vector<bool> isCommutated;
00385     isCommutated.assign(BASEJOINTS, false);
00386     unsigned int u = 0;
00387     JointCurrentSetpoint zerocurrent;
00388     zerocurrent.current = 0.0 * ampere;
00389 
00390 
00391     ClearMotorControllerTimeoutFlag clearTimeoutFlag;
00392     for (unsigned int i = 1; i <= BASEJOINTS; i++) {
00393       this->getBaseJoint(i).setConfigurationParameter(clearTimeoutFlag);
00394     }
00395 
00396     for (unsigned int i = 1; i <= BASEJOINTS; i++) {
00397       doInitialization.setParameter(false);
00398       this->getBaseJoint(i).getConfigurationParameter(doInitialization);
00399       doInitialization.getParameter(isInitialized);
00400       if (!isInitialized) {
00401         noInitialization++;
00402       }
00403     }
00404 
00405     if (noInitialization != 0) {
00406       LOG(info) << "Base Joint Commutation with firmware 2.0";
00407       doInitialization.setParameter(true);
00408 
00409       JointRoundsPerMinuteSetpoint rpmSetpoint(100);
00410         
00411       ethercatMaster.AutomaticReceiveOn(false);
00412       this->getBaseJoint(1).setData(rpmSetpoint);
00413       this->getBaseJoint(2).setData(rpmSetpoint);
00414       this->getBaseJoint(3).setData(rpmSetpoint);
00415       this->getBaseJoint(4).setData(rpmSetpoint);
00416       ethercatMaster.AutomaticReceiveOn(true);
00417       rpmSetpoint.rpm = 0;
00418      
00419       
00420       // check for the next 5 sec if the joints are commutated
00421       for (u = 1; u <= 5000; u++) {
00422         for (unsigned int i = 1; i <= BASEJOINTS; i++) {
00423           this->getBaseJoint(i).getStatus(statusFlags);
00424           if (statusFlags & INITIALIZED) {
00425             isCommutated[i - 1] = true;
00426             this->getBaseJoint(i).setData(rpmSetpoint);
00427           }
00428         }
00429         if(!ethercatMaster.isThreadActive()){
00430           ethercatMaster.sendProcessData();
00431           ethercatMaster.receiveProcessData();
00432         }
00433         if (isCommutated[0] && isCommutated[1] && isCommutated[2] && isCommutated[3]) {
00434           break;
00435         }
00436         SLEEP_MILLISEC(1);
00437       }
00438 
00439       for (unsigned int i = 1; i <= BASEJOINTS; i++) {
00440         this->getBaseJoint(i).setData(rpmSetpoint);
00441         if(!ethercatMaster.isThreadActive()){
00442           ethercatMaster.sendProcessData();
00443           ethercatMaster.receiveProcessData();
00444         }
00445         doInitialization.setParameter(false);
00446         this->getBaseJoint(i).getConfigurationParameter(doInitialization);
00447         doInitialization.getParameter(isInitialized);
00448         if (!isInitialized) {
00449           std::stringstream jointNameStream;
00450           jointNameStream << "base joint " << i;
00451           jointName = jointNameStream.str();
00452           throw std::runtime_error("Could not commutate " + jointName);
00453         }
00454       }
00455     }
00456   // Bouml preserved body end 0010D9F1
00457 }
00458 
00459 ///does the commutation of the arm joints with firmware 1.48 and below
00460 void YouBotBase::commutationFirmware148() {
00461   // Bouml preserved body begin 0010DA71
00462   
00463     InitializeJoint doInitialization;
00464     bool isInitialized = false;
00465     int noInitialization = 0;
00466     std::string jointName;
00467 
00468 
00469     ClearMotorControllerTimeoutFlag clearTimeoutFlag;
00470     for (unsigned int i = 1; i <= BASEJOINTS; i++) {
00471       this->getBaseJoint(i).setConfigurationParameter(clearTimeoutFlag);
00472     }
00473 
00474     for (unsigned int i = 1; i <= BASEJOINTS; i++) {
00475       doInitialization.setParameter(false);
00476       this->getBaseJoint(i).getConfigurationParameter(doInitialization);
00477       doInitialization.getParameter(isInitialized);
00478       if (!isInitialized) {
00479         noInitialization++;
00480       }
00481     }
00482 
00483     if (noInitialization != 0) {
00484       LOG(info) << "Base Joint Commutation with firmware 1.48";
00485       doInitialization.setParameter(true);
00486 
00487       ethercatMaster.AutomaticReceiveOn(false);
00488       this->getBaseJoint(1).setConfigurationParameter(doInitialization);
00489       this->getBaseJoint(2).setConfigurationParameter(doInitialization);
00490       this->getBaseJoint(3).setConfigurationParameter(doInitialization);
00491       this->getBaseJoint(4).setConfigurationParameter(doInitialization);
00492       ethercatMaster.AutomaticReceiveOn(true);
00493 
00494       unsigned int statusFlags;
00495       std::vector<bool> isCommutated;
00496       isCommutated.assign(BASEJOINTS, false);
00497       unsigned int u = 0;
00498 
00499       // check for the next 5 sec if the joints are commutated
00500       for (u = 1; u <= 5000; u++) {
00501         for (unsigned int i = 1; i <= BASEJOINTS; i++) {
00502           if(!ethercatMaster.isThreadActive()){
00503             ethercatMaster.sendProcessData();
00504             ethercatMaster.receiveProcessData();
00505           }
00506           this->getBaseJoint(i).getStatus(statusFlags);
00507           if (statusFlags & INITIALIZED) {
00508             isCommutated[i - 1] = true;
00509           }
00510         }
00511         if (isCommutated[0] && isCommutated[1] && isCommutated[2] && isCommutated[3]) {
00512           break;
00513         }
00514         SLEEP_MILLISEC(1);
00515       }
00516 
00517       SLEEP_MILLISEC(10); // the controller likes it
00518 
00519       for (unsigned int i = 1; i <= BASEJOINTS; i++) {
00520         doInitialization.setParameter(false);
00521         this->getBaseJoint(i).getConfigurationParameter(doInitialization);
00522         doInitialization.getParameter(isInitialized);
00523         if (!isInitialized) {
00524           std::stringstream jointNameStream;
00525           jointNameStream << "base joint " << i;
00526           jointName = jointNameStream.str();
00527           throw std::runtime_error("Could not commutate " + jointName);
00528         }
00529       }
00530     }
00531 
00532 
00533   // Bouml preserved body end 0010DA71
00534 }
00535 
00536 void YouBotBase::initializeJoints() {
00537   // Bouml preserved body begin 000464F1
00538 
00539     LOG(trace) << "Initializing Joints";
00540 
00541     //get number of slaves
00542     unsigned int noSlaves = ethercatMaster.getNumberOfSlaves();
00543 
00544     if (noSlaves < BASEJOINTS) {
00545       throw std::out_of_range("Not enough ethercat slaves were found to create a YouBotBase!");
00546     }
00547 
00548     //read Joint Topology from config file
00549     //  configfile.setSection("JointTopology");
00550 
00551     //check if enough slave exist to create YouBotJoint for the slave numbers from config file
00552     //if enough slave exist create YouBotJoint and store it in the joints vector
00553     unsigned int slaveNumber = 0;
00554     configfile->readInto(slaveNumber, "JointTopology", "BaseLeftFront");
00555     if (slaveNumber <= noSlaves) {
00556       joints.push_back(new YouBotJoint(slaveNumber));
00557     } else {
00558       throw std::out_of_range("The ethercat slave number is not available!");
00559     }
00560 
00561     configfile->readInto(slaveNumber, "JointTopology", "BaseRightFront");
00562     if (slaveNumber <= noSlaves) {
00563       joints.push_back(new YouBotJoint(slaveNumber));
00564     } else {
00565       throw std::out_of_range("The ethercat slave number is not available!");
00566     }
00567 
00568     configfile->readInto(slaveNumber, "JointTopology", "BaseLeftBack");
00569     if (slaveNumber <= noSlaves) {
00570       joints.push_back(new YouBotJoint(slaveNumber));
00571     } else {
00572       throw std::out_of_range("The ethercat slave number is not available!");
00573     }
00574 
00575     configfile->readInto(slaveNumber, "JointTopology", "BaseRightBack");
00576     if (slaveNumber <= noSlaves) {
00577       joints.push_back(new YouBotJoint(slaveNumber));
00578     } else {
00579       throw std::out_of_range("The ethercat slave number is not available!");
00580     }
00581 
00582 
00583     //Configure Joint Parameters
00584     std::string jointName;
00585     JointName jName;
00586     GearRatio gearRatio;
00587     EncoderTicksPerRound ticksPerRound;
00588     InverseMovementDirection inverseDir;
00589     FirmwareVersion firmwareTypeVersion;
00590     TorqueConstant torqueConst;
00591 
00592     double trajectory_p=0, trajectory_i=0, trajectory_d=0, trajectory_imax=0, trajectory_imin=0;
00593     double gearRatio_numerator = 0;
00594     double gearRatio_denominator = 1;
00595     JointLimits jLimits;
00596 
00597     for (unsigned int i = 0; i < BASEJOINTS; i++) {
00598       std::stringstream jointNameStream;
00599       jointNameStream << "Joint_" << i + 1;
00600       jointName = jointNameStream.str();
00601       //  configfile.setSection(jointName.c_str());
00602 
00603       joints[i].getConfigurationParameter(firmwareTypeVersion);
00604       std::string version;
00605       int controllerType;
00606       std::string firmwareVersion;
00607       firmwareTypeVersion.getParameter(controllerType, firmwareVersion);
00608 
00609       string name;
00610       configfile->readInto(name, jointName, "JointName");
00611       jName.setParameter(name);
00612 
00613       LOG(info) << name << "\t Controller Type: " << controllerType << "  Firmware version: " << firmwareVersion;
00614 
00615       if (this->controllerType != controllerType && alternativeControllerType != controllerType) {
00616         std::stringstream ss;
00617         ss << "The youBot base motor controller have to be of type: " << this->controllerType << " or " << alternativeControllerType;
00618         throw std::runtime_error(ss.str().c_str());
00619       }
00620 
00621       //check if firmware is supported
00622       bool isfirmwareSupported = false;
00623       for(unsigned int d = 0; d < supportedFirmwareVersions.size(); d++){
00624         if(this->supportedFirmwareVersions[d] == firmwareVersion){
00625           isfirmwareSupported = true;
00626           break;
00627         }
00628       }
00629       
00630       if(!isfirmwareSupported){
00631         throw std::runtime_error("Unsupported firmware version: "+ firmwareVersion);
00632       }
00633       
00634       if(this->actualFirmwareVersionAllJoints == ""){
00635         this->actualFirmwareVersionAllJoints = firmwareVersion;
00636       }
00637       
00638       if(!(firmwareVersion == this->actualFirmwareVersionAllJoints)){
00639          throw std::runtime_error("All joints must have the same firmware version!");
00640       }
00641 
00642       configfile->readInto(gearRatio_numerator, jointName, "GearRatio_numerator");
00643       configfile->readInto(gearRatio_denominator, jointName, "GearRatio_denominator");
00644       gearRatio.setParameter(gearRatio_numerator / gearRatio_denominator);
00645       int ticks;
00646       configfile->readInto(ticks, jointName, "EncoderTicksPerRound");
00647       ticksPerRound.setParameter(ticks);
00648       
00649       double torqueConstant;
00650       configfile->readInto(torqueConstant, jointName, "TorqueConstant_[newton_meter_divided_by_ampere]");
00651       torqueConst.setParameter(torqueConstant);
00652       
00653       bool invdir = false;
00654       configfile->readInto(invdir, jointName, "InverseMovementDirection");
00655       inverseDir.setParameter(invdir);
00656 
00657       joints[i].setConfigurationParameter(jName);
00658       joints[i].setConfigurationParameter(gearRatio);
00659       joints[i].setConfigurationParameter(ticksPerRound);
00660       joints[i].setConfigurationParameter(torqueConst);
00661       joints[i].setConfigurationParameter(inverseDir);
00662    
00663       long upperlimit = 0, lowerlimit = 0;
00664       configfile->readInto(lowerlimit, jointName, "LowerLimit_[encoderTicks]");
00665       configfile->readInto(upperlimit, jointName, "UpperLimit_[encoderTicks]");
00666 
00667       jLimits.setParameter(lowerlimit, upperlimit, false);
00668       joints[i].setConfigurationParameter(jLimits);
00669       
00670       //Joint Trajectory Controller
00671       if(ethercatMaster.isThreadActive()){
00672         configfile->readInto(trajectory_p, jointName, "trajectory_controller_P");
00673         configfile->readInto(trajectory_i, jointName, "trajectory_controller_I");
00674         configfile->readInto(trajectory_d, jointName, "trajectory_controller_D");
00675         configfile->readInto(trajectory_imax, jointName, "trajectory_controller_I_max");
00676         configfile->readInto(trajectory_imin, jointName, "trajectory_controller_I_min");
00677         joints[i].trajectoryController.setConfigurationParameter(trajectory_p, trajectory_i, trajectory_d, trajectory_imax, trajectory_imin);
00678         joints[i].trajectoryController.setEncoderTicksPerRound(ticks);
00679         joints[i].trajectoryController.setGearRatio(gearRatio_numerator / gearRatio_denominator);
00680         joints[i].trajectoryController.setInverseMovementDirection(invdir);
00681         ethercatMasterWithThread->registerJointTrajectoryController(&(joints[i].trajectoryController), joints[i].getJointNumber());
00682       }
00683     }
00684 
00685     return;
00686   // Bouml preserved body end 000464F1
00687 }
00688 
00689 void YouBotBase::initializeKinematic() {
00690   // Bouml preserved body begin 0004DDF1
00691     FourSwedishWheelOmniBaseKinematicConfiguration kinematicConfig;
00692 
00693     //read the kinematics parameter from a config file
00694     configfile->readInto(kinematicConfig.rotationRatio, "YouBotKinematic", "RotationRatio");
00695     configfile->readInto(kinematicConfig.slideRatio, "YouBotKinematic", "SlideRatio");
00696     double dummy = 0;
00697     configfile->readInto(dummy, "YouBotKinematic", "LengthBetweenFrontAndRearWheels_[meter]");
00698     kinematicConfig.lengthBetweenFrontAndRearWheels = dummy * meter;
00699     configfile->readInto(dummy, "YouBotKinematic", "LengthBetweenFrontWheels_[meter]");
00700     kinematicConfig.lengthBetweenFrontWheels = dummy * meter;
00701     configfile->readInto(dummy, "YouBotKinematic", "WheelRadius_[meter]");
00702     kinematicConfig.wheelRadius = dummy * meter;
00703 
00704 
00705     youBotBaseKinematic.setConfiguration(kinematicConfig);
00706   // Bouml preserved body end 0004DDF1
00707 }
00708 
00709 
00710 } // namespace youbot
Generated by  doxygen 1.6.3