29 if (robot_model !=
nullptr ) {
30 std::cerr <<
"[PARSER::" << __func__ <<
"]: init() already called by someone " << std::endl;;
35 this->robot_description = robot_description;
40 if (robot_model ==
nullptr) {
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; ;
49 handName = robot_model->getName();
52 lookForActiveJoints();
53 lookForPassiveJoints();
55 lookJointsTipsCorrelation();
66 return fingertipNames;
70 return activeJointNames;
74 return activeJointModels;
78 return passiveJointNames;
82 return descendantLinksOfJoint;
86 return descendantJointsOfJoint;
98 return fingertipsOfJointMap;
102 return jointsOfFingertipMap;
106 return fingerOfFingertipMap;
111 auto it = fingerOfFingertipMap.find(tipName);
113 if (it != fingerOfFingertipMap.end() ) {
122 return fingertipOfFingerMap;
127 auto it = fingertipOfFingerMap.find(fingerName);
129 if (it != fingertipOfFingerMap.end() ) {
139 std::pair<std::string, std::string> retPair;
141 auto it = mimicNLFatherOfJointMap.find(mimicNLJointName);
143 if (it != mimicNLFatherOfJointMap.end()) {
144 retPair = it->second;
151 return mimicNLFatherOfJointMap;
157 auto map = getMimicNLJointsOfFather(mimicNLFatherName);
159 auto it = map.find(mimicNLJointName);
161 if (it != map.end()) {
170 std::map<std::string, std::string> map;
172 auto it = mimicNLJointsOfFatherMap.find(mimicNLFatherName);
174 if (it != mimicNLJointsOfFatherMap.end()) {
182 return mimicNLJointsOfFatherMap;
194 std::vector < std::string > groupsReturn;
196 if (robot_model ==
nullptr) {
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() ) ;
214 if (robot_model ==
nullptr) {
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;
225 return groupIsChain(robot_model->getJointModelGroup(groupName));
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;
245 if (robot_model ==
nullptr) {
246 std::cerr <<
" [PARSER::" << __func__ <<
247 "]: robot_model is null. Have you called init() before?" << std::endl;
254 if (robot_model ==
nullptr) {
255 std::cerr <<
" [PARSER::" << __func__ <<
256 "]: robot_model is null. Have you called init() before?" << std::endl;
267 if ( limits.at(0).max_position_ - limits.at(0).min_position_ >= (2*EIGEN_PI) ) {
275 if (robot_model ==
nullptr) {
276 std::cerr <<
" [PARSER::" << __func__ <<
277 "]: robot_model is null. Have you called init() before?" << std::endl;
278 return std::vector<double>();
285 if (robot_model ==
nullptr) {
286 std::cerr <<
" [PARSER::" << __func__ <<
287 "]: robot_model is null. Have you called init() before?" << std::endl;
288 return std::vector<double>();
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_ ) ;
305 if (robot_model ==
nullptr) {
306 std::cerr <<
" [PARSER::" << __func__ <<
307 "]: robot_model is null. Have you called init() before?" << std::endl;
308 return std::vector<double>();
315 if (robot_model ==
nullptr) {
316 std::cerr <<
" [PARSER::" << __func__ <<
317 "]: robot_model is null. Have you called init() before?" << std::endl;
318 return std::vector<double>();
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_ ) ;
336 if (jointsOfFingertipMap.size() == 0) {
337 std::cerr <<
" [PARSER::" << __func__ <<
338 "]: jointsOfFingertipMap empty. Have you called init() before? Also check your URDF and SRDF files"
343 if (fingertipsOfJointMap.size() == 0) {
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;
352 for (
auto jointOfTip : jointsOfFingertipMap.find(tipName)->second ) {
354 if ( !continuosIncluded && checkIfContinuosJoint(jointOfTip) ==
true ) {
359 if ( fingertipsOfJointMap.find(jointOfTip)->second.size() == 1 ) {
361 if (fingertipsOfJointMap.find(jointOfTip)->second.at(0).compare (tipName) != 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
366 <<
" is " << fingertipsOfJointMap.find(jointOfTip)->second.at(0)
367 <<
" and not " << tipName <<
" as it should be"
375 return nExclusiveJoints;
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 ;
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");
445 }
else if (! groupIsChain ( it ) ) {
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");
480 fingertipNames.push_back(theTip);
481 fingerOfFingertipMap.insert( std::make_pair(theTip, it->getName()));
482 fingertipOfFingerMap.insert( std::make_pair(it->getName(), theTip));
487 std::cout << logGroupInfo << std::endl;
490 nFingers = fingertipNames.size();
495 for (
auto joint : robot_model->getActiveJointModels() ) {
497 if (! joint->isPassive() ) {
498 activeJointNames.push_back(joint->getName());
499 activeJointModels.push_back(joint);
506 for (
auto joint : robot_model->getJointModels() ) {
507 if ( joint->isPassive() ) {
508 passiveJointNames.push_back(joint->getName());
517 for (
const auto &it: fingertipNames) {
518 jointsOfFingertipMap.insert ( std::make_pair (it, std::vector<std::string>() ) );
522 for (
const auto &it: activeJointNames) {
523 fingertipsOfJointMap.insert ( std::make_pair (it, std::vector<std::string>() ) );
526 for (
const auto &jointLink: descendantLinksOfJoint){
528 for (
const auto &link : jointLink.second) {
531 if (std::find(fingertipNames.begin(), fingertipNames.end(), link->getName()) != fingertipNames.end()){
532 jointsOfFingertipMap.at ( link->getName() ) .push_back( jointLink.first);
533 fingertipsOfJointMap.at ( jointLink.first ) .push_back( link->getName() );
542 for (
auto actJoint : activeJointModels) {
544 std::vector < const moveit::core::LinkModel* > linksVector;
545 std::vector < const moveit::core::JointModel* > jointsVector;
547 getRealDescendantLinkModelsRecursive ( actJoint->getChildLinkModel(), linksVector, actJoint, jointsVector );
550 for (
auto mimicJ : actJoint->getMimicRequests()) {
553 if (std::find (jointsVector.begin(), jointsVector.end(), mimicJ) == jointsVector.end() ) {
554 getRealDescendantLinkModelsRecursive (mimicJ->getChildLinkModel(), linksVector, mimicJ, jointsVector );
558 descendantLinksOfJoint.insert (std::make_pair ( actJoint->getName(), linksVector ) );
559 descendantJointsOfJoint.insert (std::make_pair ( actJoint->getName(), jointsVector ) );
567 linksVect.push_back (link) ;
568 jointsVect.push_back (joint);
570 if ( childJoints.size() == 0 ) {
574 for (
auto cj : childJoints) {
576 getRealDescendantLinkModelsRecursive( cj->getChildLinkModel(), linksVect, cj, jointsVect );
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");
603 mimicNLFatherOfJointMap.insert ( std::make_pair( jointName,
604 std::make_pair(fatherName, nlAttr)) );
606 mimicNLJointsOfFatherMap[fatherName].insert(std::make_pair(jointName, nlAttr)) ;
610 jointEl = jointEl->NextSiblingElement(
"joint");