JointTorqueLimiter.cpp
Go to the documentation of this file.
00001 #include "robodyn_controllers/JointTorqueLimiter.h"
00002 /***************************************************************************/
00007 JointTorqueLimiter::JointTorqueLimiter(const std::string& urdfFile)
00008 {
00009     loadFromFile(urdfFile);
00010 }
00011 
00012 JointTorqueLimiter::~JointTorqueLimiter()
00013 {
00014 }
00015 /***************************************************************************/
00021 void JointTorqueLimiter::setYankLimit(const double lim)
00022 {
00023     yl.setRateLimit(lim);
00024 }
00025 /***************************************************************************/
00031 void JointTorqueLimiter::initializeMaps()
00032 {
00033     // Initialize zeros in the right ways
00034     double zero = 0.0;
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         // Find joints, and set data and torque to zero
00044         if (it->second.segment.getJoint().getType() != KDL::Joint::None)
00045         {
00046             jointTorqueLimMap[it->second.segment.getJoint().getName()] = zero;
00047         }
00048 
00049         // Next element, please
00050         it++;
00051     }
00052 
00053     return;
00054 
00055 }
00056 /***************************************************************************/
00062 int JointTorqueLimiter::populateTorqueMsg(sensor_msgs::JointState& tauLim)
00063 {
00064 
00065     std::map<std::string, double>::const_iterator it = jointTorqueLimMap.begin();
00066 
00067     // Fill out header info
00068     tauLim.header.stamp = ros::Time::now();
00069 
00070     // Resize message appropriately (should not usually change)
00071     tauLim.name.resize(jointTorqueLimMap.size());
00072     tauLim.effort.resize(jointTorqueLimMap.size());
00073 
00074     // Fill in message
00075     unsigned int i = 0;
00076 
00077     while (it != jointTorqueLimMap.end())
00078     {
00079         tauLim.name[i]   = it->first;
00080         tauLim.effort[i] = it->second;
00081         i++;
00082         it++;
00083     }
00084 
00085     return 0;
00086 
00087 }
00088 /***************************************************************************/
00094 int JointTorqueLimiter::storeJointTorques(const double& tau)
00095 {
00096     std::map<std::string, double>::iterator it = jointTorqueLimMap.begin();
00097 
00098     // Iterate through joints
00099     while (it != jointTorqueLimMap.end())
00100     {
00101         // Set torque value for each joint
00102         it->second = yl.getLimitedValue(fabs(tau), it->second);
00103         it++;
00104 
00105     }
00106 
00107     return 0;
00108 }
00109 /***************************************************************************/
00115 int JointTorqueLimiter::storeJointTorques(const sensor_msgs::JointState& desiredTauLim)
00116 {
00117     // Match chain properties with jntArray properties
00118     unsigned int ns = desiredTauLim.name.size();
00119     std::map<std::string, double>::iterator it;
00120 
00121     // Iterate through joints
00122     for (unsigned int i = 0; i < ns; i++)
00123     {
00124         it = jointTorqueLimMap.find(desiredTauLim.name[i]);
00125 
00126         if (it != jointTorqueLimMap.end())
00127         {
00128             it->second =
00129                 yl.getLimitedValue(fabs(desiredTauLim.effort[i]), jointTorqueLimMap[desiredTauLim.name[i]]);
00130         }
00131     }
00132 
00133     return 0;
00134 }
00135 
00136 
00137 bool JointTorqueLimiter::getCompletionMessage(r2_msgs::StringArray& completionMsg)
00138 {
00139     if (yl.getCompletionCondition() == 1)
00140     {
00141         completionMsg.header.stamp = ros::Time::now();
00142         completionMsg.data.clear();
00143         completionMsg.data.push_back("torque_limits");
00144 
00145         return true;
00146     }
00147 
00148     return false;
00149 
00150 }


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