From afd6aa35dec27378753345bc430af791dfd5fc61 Mon Sep 17 00:00:00 2001 From: Dmitry Rozhkov Date: Thu, 5 Apr 2018 01:19:18 +0300 Subject: [PATCH] kdl_parser: switch from TinyXML to TinyXML2 (#4) * kdl_parser: switch from TinyXML to TinyXML2 The library TinyXML is considered to be unmaintained and since all future development is focused on TinyXML2 this patch updates kdl_parser to use TinyXML2. Signed-off-by: Dmitry Rozhkov * Switch to using initString() for parsing in the TiXmlDocument API. This gets rid of a deprecation message when building against newer urdf. Signed-off-by: Chris Lalancette * Switch to const pointers for the tinyxml2 versions of the APIs. This matches what we are doing in URDF and what tinyxml2 itself does. Signed-off-by: Chris Lalancette --- kdl_parser/CMakeLists.txt | 7 +++--- kdl_parser/include/kdl_parser/kdl_parser.hpp | 18 ++++++++++--- .../include/kdl_parser/visibility_control.hpp | 2 ++ kdl_parser/package.xml | 8 +++--- kdl_parser/src/kdl_parser.cpp | 25 +++++++++++++++---- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/kdl_parser/CMakeLists.txt b/kdl_parser/CMakeLists.txt index b9d649a..cc67e9b 100644 --- a/kdl_parser/CMakeLists.txt +++ b/kdl_parser/CMakeLists.txt @@ -10,8 +10,9 @@ find_package(catkin REQUIRED ) find_package(orocos_kdl REQUIRED) find_package(TinyXML REQUIRED) +find_package(TinyXML2 REQUIRED) -include_directories(include ${orocos_kdl_INCLUDE_DIRS} ${TinyXML_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) +include_directories(include ${orocos_kdl_INCLUDE_DIRS} ${TinyXML_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) link_directories(${catkin_LIBRARY_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) @@ -22,12 +23,12 @@ catkin_package( LIBRARIES ${PROJECT_NAME} ${orocos_kdl_LIBRARIES} INCLUDE_DIRS include CATKIN_DEPENDS rosconsole urdf - DEPENDS orocos_kdl TinyXML + DEPENDS orocos_kdl TinyXML TinyXML2 ) add_library(${PROJECT_NAME} src/kdl_parser.cpp) target_link_libraries(${PROJECT_NAME} - ${TinyXML_LIBRARIES} ${orocos_kdl_LIBRARIES} ${catkin_LIBRARIES} + ${TinyXML_LIBRARIES} ${TinyXML2_LIBRARIES} ${orocos_kdl_LIBRARIES} ${catkin_LIBRARIES} ) if(WIN32) diff --git a/kdl_parser/include/kdl_parser/kdl_parser.hpp b/kdl_parser/include/kdl_parser/kdl_parser.hpp index 8d46a4e..f56e5f1 100644 --- a/kdl_parser/include/kdl_parser/kdl_parser.hpp +++ b/kdl_parser/include/kdl_parser/kdl_parser.hpp @@ -40,6 +40,7 @@ #include #include #include +#include #include // NOLINT #include "kdl_parser/visibility_control.hpp" @@ -64,19 +65,28 @@ KDL_PARSER_PUBLIC bool treeFromParam(const std::string & param, KDL::Tree & tree); /** Constructs a KDL tree from a string containing xml - * \param xml A string containting the xml description of the robot + * \param xml A string containing the xml description of the robot * \param tree The resulting KDL Tree * returns true on success, false on failure */ KDL_PARSER_PUBLIC bool treeFromString(const std::string & xml, KDL::Tree & tree); -/** Constructs a KDL tree from a TiXmlDocument - * \param xml_doc The TiXmlDocument containting the xml description of the robot - * \param tree The resulting KDL Tree +/** Constructs a KDL tree from a TinyXML2 document + * \param[in] xml_doc The document containing the xml description of the robot + * \param[out] tree The resulting KDL Tree + * \return true on success, false on failure + */ +KDL_PARSER_PUBLIC +bool treeFromXml(const tinyxml2::XMLDocument * xml_doc, KDL::Tree & tree); + +/** Constructs a KDL tree from a TinyXML document + * \param[in] xml_doc The document containing the xml description of the robot + * \param[out] tree The resulting KDL Tree * returns true on success, false on failure */ KDL_PARSER_PUBLIC +KDL_PARSER_DEPRECATED("TinyXML API is deprecated, use the TinyXML2 version instead") bool treeFromXml(TiXmlDocument * xml_doc, KDL::Tree & tree); /** Constructs a KDL tree from a URDF robot model diff --git a/kdl_parser/include/kdl_parser/visibility_control.hpp b/kdl_parser/include/kdl_parser/visibility_control.hpp index 2e2a5f8..8ca3752 100644 --- a/kdl_parser/include/kdl_parser/visibility_control.hpp +++ b/kdl_parser/include/kdl_parser/visibility_control.hpp @@ -45,6 +45,8 @@ // This logic was borrowed (then namespaced) from the examples on the gcc wiki: // https://gcc.gnu.org/wiki/Visibility +#define KDL_PARSER_DEPRECATED(msg) __attribute__((deprecated(msg))) + #if defined _WIN32 || defined __CYGWIN__ #ifdef __GNUC__ #define KDL_PARSER_EXPORT __attribute__ ((dllexport)) diff --git a/kdl_parser/package.xml b/kdl_parser/package.xml index f677f62..7627c5a 100644 --- a/kdl_parser/package.xml +++ b/kdl_parser/package.xml @@ -21,20 +21,20 @@ https://github.com/ros/kdl_parser/issues catkin - urdf orocos_kdl cmake_modules liburdfdom-headers-dev rosconsole - tinyxml liburdfdom-headers-dev - tinyxml rosconsole - tinyxml + + tinyxml + tinyxml2 + urdf roscpp rostest diff --git a/kdl_parser/src/kdl_parser.cpp b/kdl_parser/src/kdl_parser.cpp index b7f040a..b69d6c7 100644 --- a/kdl_parser/src/kdl_parser.cpp +++ b/kdl_parser/src/kdl_parser.cpp @@ -46,7 +46,6 @@ namespace kdl_parser { - // construct vector KDL::Vector toKdl(urdf::Vector3 v) { @@ -160,8 +159,8 @@ bool addChildrenToTree(urdf::LinkConstSharedPtr root, KDL::Tree & tree) bool treeFromFile(const std::string & file, KDL::Tree & tree) { - TiXmlDocument urdf_xml; - urdf_xml.LoadFile(file); + tinyxml2::XMLDocument urdf_xml; + urdf_xml.LoadFile(file.c_str()); return treeFromXml(&urdf_xml, tree); } @@ -177,12 +176,12 @@ bool treeFromParam(const std::string & param, KDL::Tree & tree) bool treeFromString(const std::string & xml, KDL::Tree & tree) { - TiXmlDocument urdf_xml; + tinyxml2::XMLDocument urdf_xml; urdf_xml.Parse(xml.c_str()); return treeFromXml(&urdf_xml, tree); } -bool treeFromXml(TiXmlDocument * xml_doc, KDL::Tree & tree) +bool treeFromXml(const tinyxml2::XMLDocument * xml_doc, KDL::Tree & tree) { urdf::Model robot_model; if (!robot_model.initXml(xml_doc)) { @@ -192,6 +191,22 @@ bool treeFromXml(TiXmlDocument * xml_doc, KDL::Tree & tree) return treeFromUrdfModel(robot_model, tree); } +bool treeFromXml(TiXmlDocument * xml_doc, KDL::Tree & tree) +{ + if (!xml_doc) { + ROS_ERROR("Could not parse the xml document"); + return false; + } + + urdf::Model robot_model; + std::stringstream ss; + ss << *xml_doc; + if (!robot_model.initString(ss.str())) { + ROS_ERROR("Could not generate robot model"); + return false; + } + return treeFromUrdfModel(robot_model, tree); +} bool treeFromUrdfModel(const urdf::ModelInterface & robot_model, KDL::Tree & tree) {