30 std::cerr <<
"[PARSER::" << __func__ <<
"]: init() already called by someone " << std::endl;;
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;
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;
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;
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>();
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>();
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;
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");
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() ) {
567 linksVect.push_back (link) ;
568 jointsVect.push_back (joint);
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::map< std::string, std::vector< const moveit::core::LinkModel *> > getDescendantLinksOfJoint() const
getter for descendandsLinksOfJoint. "Descendants" is intended in a slightly different way respect to ...
std::map< std::string, std::vector< const moveit::core::JointModel *> > getDescendantJointsOfJoint() const
getter for descendandsJointsOfJoint. "Descendants" is intended in a slightly different way respect 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...
const robot_model::RobotModelPtr & getModel() const
std::string getFingerOfFingertip(std::string tipName) const
This function returns the name of the finger which the passed tipName belongs to. ...
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
std::vector< double > getSmallerBoundFromZero(std::string jointName) const
For each DOF of a joint, find the limit which is nearer from 0 position.
const JointModel * getParentJointModel() 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...
std::map< std::string, std::string > getMimicNLJointsOfFather(std::string mimicNLFatherName) const
std::map< std::string, std::map< std::string, std::string > > getMimicNLJointsOfFatherMap() const
void lookForPassiveJoints()
This function looks for all passive joints, defined so in the srdf file.
std::string getFingertipOfFinger(std::string fingerName) const
This function returns the name of the fingertip that belongs to the passed fingerName.
std::vector< std::string > getActiveJointNames() const
getter for all active (actuated) joints' names. The analogous moveit function returns also the "passi...
bool parentJointIsFixed() const
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
robot_model::RobotModelPtr getCopyModel() const
This function reload another model, same as the one loaded in init but this one can be modified exter...
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::string getMimicNLJointOfFather(std::string mimicNLFatherName, std::string mimicNLJointName) const
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::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< double > getBiggerBoundFromZero(std::string jointName) const
For each DOF of a joint, find the limit which is farther from 0 position.
std::pair< std::string, std::string > getMimicNLFatherOfJoint(std::string mimicNLJointName) const
gets for the maps of non linear mimic joints
void lookForDescendants()
Function to explore the kinematic tree from each actuated joint. It stores each descendants links and...
std::vector< std::string > getFingertipNames() const
const LinkModel * getParentLinkModel() const
bool groupIsChain(const std::string groupName) const
check if a group (defined in srdf file) is a chain. See groupIsChain ( moveit::core::JointModelGroup*...
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. the key is the name of the father, the value is a map because more than one child can mimic the father (In the other map, there is a pair)
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::map< std::string, std::pair< std::string, std::string > > getMimicNLFatherOfJointMap() const
std::vector< std::string > passiveJointNames
std::map< std::string, std::string > getFingerOfFingertipMap() const
std::vector< const moveit::core::JointModel * > getActiveJointModels() const
getter for all active (actuated) joints. The analogous moveit function returns also the "passive" one...
bool init(std::string robot_description, bool verbose=true)
Init the parser, fill the structures.
const std::string & getName() const
std::map< std::string, std::vector< std::string > > getFingertipsOfJointMap() const
void lookForActiveJoints()
This function look for all active joints in the model (i.e. not mimic, not fixed, not passive) There ...
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::vector< std::string > > getJointsOfFingertipMap() const
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...
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::string getHandName() 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...
const std::vector< const JointModel *> & getChildJointModels() 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...
void parseNonLinearMimicRelations(std::string xml)
std::map< std::string, std::string > getFingertipOfFingerMap() const
const VariableBounds & getVariableBounds(const std::string &variable) const
void lookForFingertips(bool verbose=true)
This function explore the robot_model (which was built from urdf and srdf files), and fills the finge...
unsigned int getNFingers() const
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 ...
const std::vector< const LinkModel *> & getLinkModels() const
std::vector< VariableBounds > Bounds
std::string robot_description
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 ...
JointType getType() const
const JointModel * getMimic() const
bool checkIfContinuosJoint(const std::string jointName) const
check if the passed joint is continuos (i.e. a revolute one with sum of bounds greater than 2*PI) ...
const std::string & getName() const