diff --git a/src/model_io/urdf/include/iDynTree/ModelIO/ModelExporter.h b/src/model_io/urdf/include/iDynTree/ModelIO/ModelExporter.h index 9fb5195e416..d93960ed6f2 100644 --- a/src/model_io/urdf/include/iDynTree/ModelIO/ModelExporter.h +++ b/src/model_io/urdf/include/iDynTree/ModelIO/ModelExporter.h @@ -42,6 +42,19 @@ class ModelExporterOptions */ std::string baseLink; + /** + * Select if the first additional frame of the base link is exported as fake base link. + * + * The URDF exporter by default exports the first additional frame of the base link as + * a parent "fake" link to the actual base link, as a workaround for https://github.com/ros/kdl_parser/issues/27). + * By setting this option to false, is possible to disable this behaviour, for more info see iDynTree::ModelExporter docs. + * This option is ignored in non-URDF exporter. + * + * Default value: true. + * Supported formats: urdf. + */ + bool exportFirstBaseLinkAdditionalFrameAsFakeURDFBase{true}; + /** * Constructor. */ @@ -84,9 +97,10 @@ class ModelExporterOptions * * Furthermore, it is widespread use in URDF models to never use a real link (with mass) as the root link of a model, mainly * due to workaround a bug in official %KDL parser used in ROS (see https://github.com/ros/kdl_parser/issues/27 for more info). For this reason, - * if the selected base_link has at least one additional frame, the first additional frame of the base link is added as a **parent** fake URDF link, + * if the selected base_link has at least one additional frame, by default the first additional frame of the base link is added as a **parent** fake URDF link, * instead as a **child** fake URDF link as done with the rest of %iDynTree's additional frames. If no additional frame is available for the base link, * the base link of the URDF will have a mass, and will generate a warning then used with the ROS's [`kdl_parser`](https://github.com/ros/kdl_parser) . + * This behaviour can be disabled by setting to false the `exportFirstBaseLinkAdditionalFrameAsFakeURDFBase` attribute of ModelExporterOptions. * */ class ModelExporter diff --git a/src/model_io/urdf/src/URDFModelExport.cpp b/src/model_io/urdf/src/URDFModelExport.cpp index 05c7603c7a1..5cdba6df77c 100644 --- a/src/model_io/urdf/src/URDFModelExport.cpp +++ b/src/model_io/urdf/src/URDFModelExport.cpp @@ -345,11 +345,16 @@ bool URDFStringFromModel(const iDynTree::Model & model, } // If the base link has at least an additional frame, add it as parent URDF link - // as a workaround for https://github.com/ros/kdl_parser/issues/27 + // as a workaround for https://github.com/ros/kdl_parser/issues/27, unless + // options.exportFirstBaseLinkAdditionalFrameAsFakeURDFBase is set to false + // If options.exportFirstBaseLinkAdditionalFrameAsFakeURDFBase is set to false, + // baseFakeLinkFrameIndex remains set to FRAME_INVALID_INDEX, a + // and all the additional frames of the base link get exported as child fake links + // in the loop and the end of this function FrameIndex baseFakeLinkFrameIndex = FRAME_INVALID_INDEX; std::vector frameIndices; ok = model.getLinkAdditionalFrames(baseLinkIndex, frameIndices); - if (ok && frameIndices.size() >= 1) { + if (ok && frameIndices.size() >= 1 && options.exportFirstBaseLinkAdditionalFrameAsFakeURDFBase) { baseFakeLinkFrameIndex = frameIndices[0]; ok = ok && exportAdditionalFrame(model.getFrameName(baseFakeLinkFrameIndex), model.getFrameTransform(baseFakeLinkFrameIndex),