JointDynamicsData.cpp
Go to the documentation of this file.
00001 
00002 #include "robodyn_controllers/JointDynamicsData.h"
00003 /***************************************************************************/
00008 JointDynamicsData::JointDynamicsData()
00009 {
00010 }
00011 
00012 JointDynamicsData::~JointDynamicsData()
00013 {
00014 }
00015 /***************************************************************************/
00021 void JointDynamicsData::InitializeMaps(const KDL::Tree& tree)
00022 {
00023     // Initialize zeros in the right ways
00024     JntDynData  zeroData;
00025     KDL::Wrench zeroForce = KDL::Wrench::Zero();
00026     zeroData.pos          = zeroData.vel = zeroData.acc = 0.0;
00027     double      zeroTau   = 0.0;
00028 
00029     // Clear maps before initializing them to zero
00030     extForceMap.clear();
00031     segForceMap.clear();
00032     jointDataMap.clear();
00033     jointTorqueCommandMap.clear();
00034     jointInertiaMap.clear();
00035 
00036     // Grab tree segment map and iterator
00037     KDL::SegmentMap                 segments = tree.getSegments();
00038     KDL::SegmentMap::const_iterator it       = segments.begin();
00039 
00040     // Iterate through map
00041     while (it != segments.end())
00042     {
00043         // Set all segment forces to zero
00044         extForceMap[it->first] = zeroForce;
00045         segForceMap[it->first] = zeroForce;
00046 
00047         // Find joints, and set data and torque to zero
00048         if (it->second.segment.getJoint().getType() != KDL::Joint::None)
00049         {
00050             jointDataMap[it->second.segment.getJoint().getName()] = zeroData;
00051             jointTorqueCommandMap[it->second.segment.getJoint().getName()] = zeroTau;
00052             jointInertiaMap[it->second.segment.getJoint().getName()] = zeroTau;
00053         }
00054 
00055         // Next element, please
00056         it++;
00057     }
00058 
00059     return;
00060 
00061 }
00062 /***************************************************************************/
00071 int JointDynamicsData::PopulateJointInfo(const KDL::Chain& chain, KDL::JntArray& q, KDL::JntArray& q_dot, KDL::JntArray& q_dotdot)
00072 {
00073     // Match chain properties to jntArray properties
00074     unsigned int ns = chain.getNrOfSegments();
00075     unsigned int nj = chain.getNrOfJoints();
00076 
00077     if (q.rows() != nj || q_dot.rows() != nj || q_dotdot.rows() != nj)
00078     {
00079         return -1;
00080     }
00081 
00082     // Iterate through all segments and joints in the chain
00083     unsigned int j = 0;
00084 
00085     for (unsigned int i = 0; i < ns; i++)
00086     {
00087         // Set joint data for each joint
00088         if (chain.getSegment(i).getJoint().getType() != KDL::Joint::None)
00089         {
00090             const JntDynData& data = jointDataMap[chain.getSegment(i).getJoint().getName()];
00091             q(j) = data.pos;
00092             q_dot(j) = data.vel;
00093             q_dotdot(j) = data.acc;
00094             j++;
00095         }
00096     }
00097 
00098     return 0;
00099 
00100 }
00101 /***************************************************************************/
00108 int JointDynamicsData::PopulateExtForceInfo(const KDL::Chain& chain, KDL::Wrenches& forceExt)
00109 {
00110     unsigned int ns = chain.getNrOfSegments();
00111     std::map<std::string, KDL::Wrench>::const_iterator it;
00112 
00113     if (forceExt.size() != ns)
00114     {
00115         return -1;
00116     }
00117 
00118     for (unsigned int i = 0 ; i < ns; i++)
00119     {
00120         if ((it = extForceMap.find(chain.getSegment(i).getName())) != extForceMap.end())
00121         {
00122             forceExt[i] = it->second;
00123         }
00124     }
00125 
00126     return 0;
00127 }
00128 /***************************************************************************/
00135 int JointDynamicsData::PopulateExtForceInfo(const std::string& node, KDL::Wrenches& forceExt)
00136 {
00137     if (forceExt.size() != 1)
00138     {
00139         return -1;
00140     }
00141 
00142     std::map<std::string, KDL::Wrench>::const_iterator it;
00143 
00144     if ((it = extForceMap.find(node)) != extForceMap.end())
00145     {
00146         forceExt[0] = it->second;
00147     }
00148 
00149     return 0;
00150 }
00151 /***************************************************************************/
00158 int JointDynamicsData::StoreJointTorqueCommands(const KDL::Chain& chain, const KDL::JntArray& tau)
00159 {
00160     // Match chain properties with jntArray properties
00161     unsigned int ns = chain.getNrOfSegments();
00162     unsigned int nj = chain.getNrOfJoints();
00163 
00164     if (tau.rows() != nj)
00165     {
00166         return -1;
00167     }
00168 
00169     // Iterate through joints
00170     unsigned int j = 0;
00171 
00172     for (unsigned int i = 0; i < ns; i++)
00173     {
00174         // Set torque value for each joint
00175         if (chain.getSegment(i).getJoint().getType() != KDL::Joint::None)
00176         {
00177             // joint torque commands are opposite of calculated torque on a joint
00178             jointTorqueCommandMap[chain.getSegment(i).getJoint().getName()] = -tau(j);
00179             j++;
00180         }
00181     }
00182 
00183     return 0;
00184 }
00185 /***************************************************************************/
00192 int JointDynamicsData::StoreJointInertia(const KDL::Chain& chain, const KDL::JntArray& Hv)
00193 {
00194     // Match chain properties with jntArray properties
00195     unsigned int nj = chain.getNrOfJoints();
00196     unsigned int ns = chain.getNrOfSegments();
00197 
00198     if (Hv.rows() != nj)
00199     {
00200         return -1;
00201     }
00202 
00203     // Iterate through joints
00204     unsigned int j = 0;
00205 
00206     for (unsigned int i = 0; i < ns; i++)
00207     {
00208         // Set torque value for each joint
00209         if (chain.getSegment(i).getJoint().getType() != KDL::Joint::None)
00210         {
00211             jointInertiaMap[chain.getSegment(i).getJoint().getName()] = Hv(j);
00212             j++;
00213         }
00214     }
00215 
00216     return 0;
00217 }
00218 
00219 int JointDynamicsData::StoreSegmentWrenches(const KDL::Chain& chain, const KDL::Wrenches& forceSeg)
00220 {
00221     unsigned int ns = chain.getNrOfSegments();
00222 
00223     if (forceSeg.size() != ns)
00224     {
00225         return -1;
00226     }
00227 
00228     for (unsigned int i = 0; i < ns; i++)
00229     {
00230         segForceMap[chain.getSegment(i).getName()] = forceSeg[i];
00231     }
00232 
00233     return 0;
00234 }
00235 


robodyn_controllers
Author(s):
autogenerated on Sat Jun 8 2019 20:20:53