30 std::cerr <<
"[PARSER::" << __func__ <<
"]: init() already called by someone " << std::endl;;
38 robot_model_loader::RobotModelLoader robot_model_loader(robot_description,
false) ;
41 std::cerr <<
" [PARSER::" << __func__ <<
42 "]: Fail To load robot model " << robot_description <<
43 " are you sure to have put both urdf and srdf files in the parameter server " <<
44 "with names robot_description and robot_description_semantic, respectively?" << std::endl;
47 std::cout <<
"[PARSER::" << __func__ <<
"]: Parsed Model: " <<
robot_model->getName() << std::endl; ;
139 std::pair<std::string, std::string> retPair;
144 retPair = it->second;
159 auto it = map.find(mimicNLJointName);
161 if (it != map.end()) {
170 std::map<std::string, std::string> map;
189 return robot_model_loader.getModel();
194 std::vector < std::string > groupsReturn;
197 std::cerr <<
" [PARSER::" << __func__ <<
198 "]: robot_model is null. Have you called init() before?" << std::endl;
202 for (
auto group :
robot_model->getJointModelGroups() ) {
204 if ( group->hasLinkModel(linkName) ) {
206 groupsReturn.push_back ( group->getName() ) ;
215 std::cerr <<
" [PARSER::" << __func__ <<
216 "]: robot_model is null. Have you called init() before?" << std::endl;
220 if (!
robot_model->hasJointModelGroup(groupName) ) {
221 std::cerr <<
" [PARSER::" << __func__ <<
222 "]: " << groupName <<
" is not a group " << std::endl;
230 std::stringstream log;
231 log <<
"Checking if " << group->getName() <<
" is a chain ..." << std::endl;
232 for (
auto link : group->getLinkModels() ){
233 if (link->getChildJointModels().size() > 1 ) {
234 log <<
"... no because " << link->getName() <<
" has " << link->getChildJointModels().size() <<
" children " << std::endl;
246 std::cerr <<
" [PARSER::" << __func__ <<
247 "]: robot_model is null. Have you called init() before?" << std::endl;
255 std::cerr <<
" [PARSER::" << __func__ <<
256 "]: robot_model is null. Have you called init() before?" << std::endl;
261 if (joint->getType() != moveit::core::JointModel::REVOLUTE ) {
266 moveit::core::JointModel::Bounds limits = joint->getVariableBounds();
267 if ( limits.at(0).max_position_ - limits.at(0).min_position_ >= (2*EIGEN_PI) ) {
276 std::cerr <<
" [PARSER::" << __func__ <<
277 "]: robot_model is null. Have you called init() before?" << std::endl;
278 return std::vector<double>();
286 std::cerr <<
" [PARSER::" << __func__ <<
287 "]: robot_model is null. Have you called init() before?" << std::endl;
288 return std::vector<double>();
291 moveit::core::JointModel::Bounds limits = joint->getVariableBounds();
293 std::vector <double> maxPos;
294 for (
auto limit : limits ) {
295 if ( std::abs(limit.max_position_) > std::abs(limit.min_position_)) {
296 maxPos.push_back ( limit.max_position_ ) ;
298 maxPos.push_back ( limit.min_position_ ) ;
306 std::cerr <<
" [PARSER::" << __func__ <<
307 "]: robot_model is null. Have you called init() before?" << std::endl;
308 return std::vector<double>();
316 std::cerr <<
" [PARSER::" << __func__ <<
317 "]: robot_model is null. Have you called init() before?" << std::endl;
318 return std::vector<double>();
321 moveit::core::JointModel::Bounds limits = joint->getVariableBounds();
323 std::vector <double> minPos;
324 for (
auto limit : limits ) {
325 if ( std::abs(limit.max_position_) < std::abs(limit.min_position_)) {
326 minPos.push_back ( limit.max_position_ ) ;
328 minPos.push_back ( limit.min_position_ ) ;
337 std::cerr <<
" [PARSER::" << __func__ <<
338 "]: jointsOfFingertipMap empty. Have you called init() before? Also check your URDF and SRDF files" 344 std::cerr <<
" [PARSER::" << __func__ <<
345 "]: jointsOfFingertipMap empty. Have you called init() before? Also check your URDF and SRDF files" 350 unsigned int nExclusiveJoints = 0;
363 std::cerr <<
" [PARSER::" << __func__ <<
364 "]: Strange error in fingertipsOfJointMap and jointsOfFingertipMap: they are not consistent: " 365 <<
"The unique tip present in the map for the key " << jointOfTip
367 <<
" and not " << tipName <<
" as it should be" 375 return nExclusiveJoints;
381 const moveit::core::LinkModel* linkModel =
robot_model->getLinkModel ( linkName ) ;
383 while ( linkModel->getParentJointModel()->getMimic() != NULL ||
384 linkModel->parentJointIsFixed() ||
385 linkModel->getParentJointModel()->isPassive() ||
394 linkModel = linkModel->getParentLinkModel();
396 if (linkModel == NULL ) {
398 std::cerr <<
" [PARSER::" << __func__ <<
399 "]: Strange error: fingertipsOfJointMap, jointsOfFingertipMap, and/or other structures " <<
400 "may have been built badly" << std::endl ;
405 return (linkModel->getParentJointModel()->getName());
410 const moveit::core::LinkModel* linkModel =
robot_model->getLinkModel(linkName);
411 const moveit::core::JointModel* joint;
416 while ( (linkModel != NULL) && (linkModel->getChildJointModels().size() < 2) ) {
419 if ( linkModel->getParentJointModel()->getMimic() == NULL &&
420 (!linkModel->parentJointIsFixed()) &&
421 (!linkModel->getParentJointModel()->isPassive()) &&
424 joint = linkModel->getParentJointModel();
427 linkModel = linkModel->getParentLinkModel();
430 return joint->getName();
437 for (
auto it:
robot_model->getJointModelGroups()) {
439 std::string logGroupInfo;
440 logGroupInfo =
"[PARSER::" + std::string(__func__) +
"] Found Group '" + it->getName() +
"', " ;
442 if (it->getSubgroupNames().size() != 0 ) {
443 logGroupInfo.append(
"but it has some subgroups \n");
446 logGroupInfo.append(
"but it is not a chain \n");
448 }
else if (it->getLinkModels().size() == 0) {
449 logGroupInfo.append(
"but it has 0 links \n");
453 logGroupInfo.append(
"with links: \n");
455 std::string theTip =
"";
456 for (
auto itt : it->getLinkModels()) {
458 logGroupInfo.append(
"\t'" + itt->getName() +
"' ");
460 if (itt->getChildJointModels().size() != 0) {
461 logGroupInfo.append(
"(not a leaf link) ");
463 logGroupInfo.append(
"(a leaf link) ");
466 if (itt->getShapes().size() == 0 ) {
467 logGroupInfo.append(
"(no visual geometry) ");
470 theTip = itt->getName();
472 logGroupInfo.append(
"\n");
476 if (theTip.compare(
"") == 0) {
477 logGroupInfo.append(
"Warning: No link has a mesh in this group\n");
487 std::cout << logGroupInfo << std::endl;
495 for (
auto joint :
robot_model->getActiveJointModels() ) {
497 if (! joint->isPassive() ) {
506 for (
auto joint :
robot_model->getJointModels() ) {
507 if ( joint->isPassive() ) {
528 for (
const auto &link : jointLink.second) {
531 if (std::find(fingertipNames.begin(), fingertipNames.end(), link->getName()) != fingertipNames.end()){
544 std::vector < const moveit::core::LinkModel* > linksVector;
545 std::vector < const moveit::core::JointModel* > jointsVector;
550 for (
auto mimicJ : actJoint->getMimicRequests()) {
553 if (std::find (jointsVector.begin(), jointsVector.end(), mimicJ) == jointsVector.end() ) {
564 const moveit::core::LinkModel* link, std::vector< const moveit::core::LinkModel* > & linksVect,
565 const moveit::core::JointModel* joint, std::vector< const moveit::core::JointModel* > & jointsVect )
const {
567 linksVect.push_back (link) ;
568 jointsVect.push_back (joint);
569 auto childJoints = link->getChildJointModels();
570 if ( childJoints.size() == 0 ) {
574 for (
auto cj : childJoints) {
588 tiDoc.Parse(xml.c_str());
590 TiXmlElement* jointEl = tiDoc.FirstChildElement(
"robot")->FirstChildElement(
"joint") ;
594 std::string jointName = jointEl->Attribute(
"name");
595 auto mimicEl = jointEl->FirstChildElement(
"mimic");
597 auto nlAttr = mimicEl->Attribute(
"nlFunPos");
602 std::string fatherName = mimicEl->Attribute(
"joint");
604 std::make_pair(fatherName, nlAttr)) );
610 jointEl = jointEl->NextSiblingElement(
"joint");
std::string getMimicNLJointOfFather(std::string mimicNLFatherName, std::string mimicNLJointName) const
std::string getFirstActuatedJointInFinger(std::string linkName) const
Given the linkName, this function returns the actuated joint that is a parent of this link and it is ...
std::string getFingerOfFingertip(std::string tipName) const
This function returns the name of the finger which the passed tipName belongs to. ...
std::vector< std::string > activeJointNames
std::vector< std::string > fingertipNames
std::vector< std::string > getGroupOfLink(std::string linkName)
This function explores all groups of srdf and says to which ones the linkName belongs to...
std::map< std::string, std::string > getMimicNLJointsOfFather(std::string mimicNLFatherName) const
const robot_model::RobotModelPtr getRobotModel() const
the robot model can't be modified, if you want it to modify, use getCopyModel to get a copy...
std::vector< double > getSmallerBoundFromZero(std::string jointName) const
For each DOF of a joint, find the limit which is nearer from 0 position.
std::vector< std::string > getActiveJointNames() const
getter for all active (actuated) joints' names.
std::map< std::string, std::vector< const moveit::core::LinkModel * > > getDescendantLinksOfJoint() const
getter for descendandsLinksOfJoint.
void lookForPassiveJoints()
This function looks for all passive joints, defined so in the srdf file.
bool checkIfContinuosJoint(const std::string jointName) const
check if the passed joint is continuos (i.e.
std::vector< double > getBiggerBoundFromZero(std::string jointName) const
For each DOF of a joint, find the limit which is farther from 0 position.
std::vector< std::string > getPassiveJointNames() const
getter for all the passive joints (defined in this way in the srdf file) Not all the not-actuated joi...
std::vector< const moveit::core::JointModel * > getActiveJointModels() const
getter for all active (actuated) joints.
std::map< std::string, std::string > fingerOfFingertipMap
The map with as key the name of the finger (defined in srdf file) and as value the fingertip (the las...
std::map< std::string, std::string > fingertipOfFingerMap
The map with as key the name of the fingertip (the last (not virtual) link of a finger) and as value ...
std::vector< const moveit::core::JointModel * > activeJointModels
std::map< std::string, std::vector< const moveit::core::JointModel * > > getDescendantJointsOfJoint() const
getter for descendandsJointsOfJoint.
unsigned int getNExclusiveJointsOfTip(std::string tipName, bool continuosIncluded) const
Given a fingertip link, this function return the number of the joint that affect only the position of...
robot_model::RobotModelPtr robot_model
void lookJointsTipsCorrelation()
Here, we find for each tip, which are all the joints (active) that can modifies its position It is ea...
std::map< std::string, std::pair< std::string, std::string > > mimicNLFatherOfJointMap
This map contain as key the name of the mimic joint which position follows a non linear relationship ...
std::map< std::string, std::map< std::string, std::string > > getMimicNLJointsOfFatherMap() const
std::string getFirstActuatedParentJoint(std::string linkName, bool includeContinuos) const
starting from the given link, we explore the parents joint, until we found the first actuated...
void lookForDescendants()
Function to explore the kinematic tree from each actuated joint.
std::map< std::string, std::map< std::string, std::string > > mimicNLJointsOfFatherMap
inverse map of previous, even if the function is replicated, this is anyway useful, at the cost of having 2 copy of a string type.
std::map< std::string, std::pair< std::string, std::string > > getMimicNLFatherOfJointMap() const
std::map< std::string, std::vector< std::string > > fingertipsOfJointMap
The map with as key the name of the actuated joint and as value all the fingertips which pose can be ...
std::vector< std::string > passiveJointNames
bool init(std::string robot_description, bool verbose=true)
Init the parser, fill the structures.
std::map< std::string, std::string > getFingerOfFingertipMap() const
void lookForActiveJoints()
This function look for all active joints in the model (i.e.
bool groupIsChain(const std::string groupName) const
check if a group (defined in srdf file) is a chain.
robot_model::RobotModelPtr getCopyModel() const
This function reload another model, same as the one loaded in init but this one can be modified exter...
std::string getFingertipOfFinger(std::string fingerName) const
This function returns the name of the fingertip that belongs to the passed fingerName.
std::pair< std::string, std::string > getMimicNLFatherOfJoint(std::string mimicNLJointName) const
gets for the maps of non linear mimic joints
std::map< std::string, std::vector< const moveit::core::JointModel * > > descendantJointsOfJoint
Map containing info about descendants joints of a joint see lookForDescendants function for more info...
std::map< std::string, std::vector< std::string > > getJointsOfFingertipMap() const
unsigned int getNFingers() const
std::map< std::string, std::vector< const moveit::core::LinkModel * > > descendantLinksOfJoint
Map containing info about descendants links of a joint see lookForDescendants function for more info...
void parseNonLinearMimicRelations(std::string xml)
std::string getHandName() const
void lookForFingertips(bool verbose=true)
This function explore the robot_model (which was built from urdf and srdf files), and fills the finge...
std::map< std::string, std::vector< std::string > > jointsOfFingertipMap
The map with as key the name of the fingertip and as value all the joints (actuated) that can modify ...
std::map< std::string, std::vector< std::string > > getFingertipsOfJointMap() const
void getRealDescendantLinkModelsRecursive(const moveit::core::LinkModel *link, std::vector< const moveit::core::LinkModel * > &linksVect, const moveit::core::JointModel *joint, std::vector< const moveit::core::JointModel * > &jointsVect) const
Recursive function, support for lookForDescendants, to explore the urdf tree.
std::map< std::string, std::string > getFingertipOfFingerMap() const
std::string robot_description
std::vector< std::string > getFingertipNames() const