Skip to content

Commit 4454445

Browse files
christian-rauchsloretz
authored andcommitted
Standalone kdl_parser library (#13)
* remove boost dependency * make catkin and rosconsole optional, replace urdf by urdfdom * cmake modules for TinyXML and TinyXML2 source: https://github.com/ros/cmake_modules * append to cmake module path * replace urdf by urdfdom * mention source of local cmake module files * define ROS_WARN and ROS_ERROR as standard error * remove define guards from header files * always build shared library * define ROS_DEBUG as standard output
1 parent 30c9563 commit 4454445

File tree

6 files changed

+258
-49
lines changed

6 files changed

+258
-49
lines changed

kdl_parser/CMakeLists.txt

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,76 @@ cmake_minimum_required(VERSION 2.8.3)
22

33
project(kdl_parser)
44

5-
find_package(Boost REQUIRED)
6-
include_directories(${Boost_INCLUDE_DIR})
7-
8-
find_package(catkin REQUIRED
9-
COMPONENTS rosconsole urdf cmake_modules
5+
find_package(catkin QUIET
6+
COMPONENTS rosconsole cmake_modules
107
)
8+
9+
if(NOT catkin_FOUND)
10+
# use local copies of FindTinyXML.cmake and FindTinyXML2.cmake from
11+
# 'cmake_modules' (https://github.com/ros/cmake_modules)
12+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
13+
endif()
14+
15+
find_package(urdfdom REQUIRED)
16+
include_directories(${urdfdom_INCLUDE_DIRS})
17+
1118
find_package(orocos_kdl REQUIRED)
1219
find_package(TinyXML REQUIRED)
1320
find_package(TinyXML2 REQUIRED)
1421

15-
include_directories(include ${orocos_kdl_INCLUDE_DIRS} ${TinyXML_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})
22+
# check for rosconsole
23+
# We check additionally for catkin to distinguish between an "official" ROS distribution
24+
# and the one provided in the distribution's repository.
25+
find_package(rosconsole QUIET)
26+
if(rosconsole_FOUND AND catkin_FOUND)
27+
add_definitions(-DHAS_ROS)
28+
endif()
29+
30+
find_package(urdf QUIET)
31+
if(urdf_FOUND)
32+
add_definitions(-DHAS_URDF)
33+
include_directories(${urdf_INCLUDE_DIRS})
34+
endif()
1635

17-
link_directories(${catkin_LIBRARY_DIRS})
18-
link_directories(${Boost_LIBRARY_DIRS})
36+
include_directories(include ${orocos_kdl_INCLUDE_DIRS} ${TinyXML_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS})
1937

2038
add_compile_options(-std=c++11)
2139

22-
catkin_package(
23-
LIBRARIES ${PROJECT_NAME} ${orocos_kdl_LIBRARIES}
24-
INCLUDE_DIRS include
25-
CATKIN_DEPENDS rosconsole urdf
26-
DEPENDS orocos_kdl TinyXML TinyXML2
27-
)
40+
if(catkin_FOUND)
41+
link_directories(${catkin_LIBRARY_DIRS})
42+
include_directories(${catkin_INCLUDE_DIRS})
2843

29-
add_library(${PROJECT_NAME} src/kdl_parser.cpp)
44+
catkin_package(
45+
LIBRARIES ${PROJECT_NAME} ${orocos_kdl_LIBRARIES}
46+
INCLUDE_DIRS include
47+
CATKIN_DEPENDS rosconsole urdf
48+
DEPENDS orocos_kdl TinyXML TinyXML2
49+
)
50+
endif()
51+
52+
add_library(${PROJECT_NAME} SHARED src/kdl_parser.cpp)
3053
target_link_libraries(${PROJECT_NAME}
31-
${TinyXML_LIBRARIES} ${TinyXML2_LIBRARIES} ${orocos_kdl_LIBRARIES} ${catkin_LIBRARIES}
54+
${TinyXML_LIBRARIES} ${TinyXML2_LIBRARIES} ${orocos_kdl_LIBRARIES}
3255
)
3356

57+
target_link_libraries(${PROJECT_NAME} ${urdfdom_LIBRARIES})
58+
59+
if(catkin_FOUND)
60+
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})
61+
endif()
62+
63+
if(urdf_FOUND)
64+
target_link_libraries(${PROJECT_NAME} ${urdf_LIBRARIES})
65+
endif()
66+
3467
if(WIN32)
3568
target_compile_definitions(${PROJECT_NAME} PRIVATE "KDL_PARSER_BUILDING_DLL")
3669
endif()
3770

3871
add_executable(check_kdl_parser src/check_kdl_parser.cpp )
3972
target_link_libraries(check_kdl_parser ${PROJECT_NAME})
4073

41-
if(CATKIN_ENABLE_TESTING)
74+
if(catkin_FOUND AND CATKIN_ENABLE_TESTING)
4275
find_package(catkin REQUIRED COMPONENTS roscpp rostest)
4376
add_rostest_gtest(test_kdl_parser test/test_kdl_parser.launch test/test_kdl_parser.cpp )
4477
target_link_libraries(test_kdl_parser ${PROJECT_NAME})
@@ -47,10 +80,18 @@ if(CATKIN_ENABLE_TESTING)
4780
target_link_libraries(test_inertia_rpy ${PROJECT_NAME})
4881
endif()
4982

50-
# How does CATKIN do this?
51-
#rosbuild_add_rostest(${PROJECT_SOURCE_DIR}/test/test_kdl_parser.launch)
52-
install(TARGETS ${PROJECT_NAME}
53-
DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
83+
if(catkin_FOUND)
84+
# How does CATKIN do this?
85+
#rosbuild_add_rostest(${PROJECT_SOURCE_DIR}/test/test_kdl_parser.launch)
86+
install(TARGETS ${PROJECT_NAME}
87+
DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
5488

55-
install(DIRECTORY include/${PROJECT_NAME}/
56-
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
89+
install(DIRECTORY include/${PROJECT_NAME}/
90+
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
91+
else()
92+
install(TARGETS ${PROJECT_NAME}
93+
LIBRARY DESTINATION lib
94+
ARCHIVE DESTINATION lib)
95+
install(DIRECTORY include/${PROJECT_NAME}/
96+
DESTINATION include)
97+
endif()

kdl_parser/cmake/FindTinyXML.cmake

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
##################################################################################################
2+
#
3+
# CMake script for finding TinyXML.
4+
#
5+
# Input variables:
6+
#
7+
# - TinyXML_ROOT_DIR (optional): When specified, header files and libraries will be searched for in
8+
# ${TinyXML_ROOT_DIR}/include
9+
# ${TinyXML_ROOT_DIR}/libs
10+
# respectively, and the default CMake search order will be ignored. When unspecified, the default
11+
# CMake search order is used.
12+
# This variable can be specified either as a CMake or environment variable. If both are set,
13+
# preference is given to the CMake variable.
14+
# Use this variable for finding packages installed in a nonstandard location, or for enforcing
15+
# that one of multiple package installations is picked up.
16+
#
17+
#
18+
# Cache variables (not intended to be used in CMakeLists.txt files)
19+
#
20+
# - TinyXML_INCLUDE_DIR: Absolute path to package headers.
21+
# - TinyXML_LIBRARY: Absolute path to library.
22+
#
23+
#
24+
# Output variables:
25+
#
26+
# - TinyXML_FOUND: Boolean that indicates if the package was found
27+
# - TinyXML_INCLUDE_DIRS: Paths to the necessary header files
28+
# - TinyXML_LIBRARIES: Package libraries
29+
#
30+
#
31+
# Example usage:
32+
#
33+
# find_package(TinyXML)
34+
# if(NOT TinyXML_FOUND)
35+
# # Error handling
36+
# endif()
37+
# ...
38+
# include_directories(${TinyXML_INCLUDE_DIRS} ...)
39+
# ...
40+
# target_link_libraries(my_target ${TinyXML_LIBRARIES})
41+
#
42+
##################################################################################################
43+
44+
# Get package location hint from environment variable (if any)
45+
if(NOT TinyXML_ROOT_DIR AND DEFINED ENV{TinyXML_ROOT_DIR})
46+
set(TinyXML_ROOT_DIR "$ENV{TinyXML_ROOT_DIR}" CACHE PATH
47+
"TinyXML base directory location (optional, used for nonstandard installation paths)")
48+
endif()
49+
50+
# Search path for nonstandard package locations
51+
if(TinyXML_ROOT_DIR)
52+
set(TinyXML_INCLUDE_PATH PATHS "${TinyXML_ROOT_DIR}/include" NO_DEFAULT_PATH)
53+
set(TinyXML_LIBRARY_PATH PATHS "${TinyXML_ROOT_DIR}/lib" NO_DEFAULT_PATH)
54+
endif()
55+
56+
# Find headers and libraries
57+
find_path(TinyXML_INCLUDE_DIR NAMES tinyxml.h PATH_SUFFIXES "tinyxml" ${TinyXML_INCLUDE_PATH})
58+
find_library(TinyXML_LIBRARY NAMES tinyxml PATH_SUFFIXES "tinyxml" ${TinyXML_LIBRARY_PATH})
59+
60+
mark_as_advanced(TinyXML_INCLUDE_DIR
61+
TinyXML_LIBRARY)
62+
63+
# Output variables generation
64+
include(FindPackageHandleStandardArgs)
65+
find_package_handle_standard_args(TinyXML DEFAULT_MSG TinyXML_LIBRARY
66+
TinyXML_INCLUDE_DIR)
67+
68+
set(TinyXML_FOUND ${TINYXML_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
69+
unset(TINYXML_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args
70+
71+
if(TinyXML_FOUND)
72+
set(TinyXML_INCLUDE_DIRS ${TinyXML_INCLUDE_DIR})
73+
set(TinyXML_LIBRARIES ${TinyXML_LIBRARY})
74+
endif()

kdl_parser/cmake/FindTinyXML2.cmake

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
##################################################################################################
2+
#
3+
# CMake script for finding TinyXML2.
4+
#
5+
# Input variables:
6+
#
7+
# - TinyXML2_ROOT_DIR (optional): When specified, header files and libraries will be searched for in
8+
# ${TinyXML2_ROOT_DIR}/include
9+
# ${TinyXML2_ROOT_DIR}/libs
10+
# respectively, and the default CMake search order will be ignored. When unspecified, the default
11+
# CMake search order is used.
12+
# This variable can be specified either as a CMake or environment variable. If both are set,
13+
# preference is given to the CMake variable.
14+
# Use this variable for finding packages installed in a nonstandard location, or for enforcing
15+
# that one of multiple package installations is picked up.
16+
#
17+
#
18+
# Cache variables (not intended to be used in CMakeLists.txt files)
19+
#
20+
# - TinyXML2_INCLUDE_DIR: Absolute path to package headers.
21+
# - TinyXML2_LIBRARY: Absolute path to library.
22+
#
23+
#
24+
# Output variables:
25+
#
26+
# - TinyXML2_FOUND: Boolean that indicates if the package was found
27+
# - TinyXML2_INCLUDE_DIRS: Paths to the necessary header files
28+
# - TinyXML2_LIBRARIES: Package libraries
29+
#
30+
#
31+
# Example usage:
32+
#
33+
# find_package(TinyXML2)
34+
# if(NOT TinyXML2_FOUND)
35+
# # Error handling
36+
# endif()
37+
# ...
38+
# include_directories(${TinyXML2_INCLUDE_DIRS} ...)
39+
# ...
40+
# target_link_libraries(my_target ${TinyXML2_LIBRARIES})
41+
#
42+
##################################################################################################
43+
44+
# Get package location hint from environment variable (if any)
45+
if(NOT TinyXML2_ROOT_DIR AND DEFINED ENV{TinyXML2_ROOT_DIR})
46+
set(TinyXML2_ROOT_DIR "$ENV{TinyXML2_ROOT_DIR}" CACHE PATH
47+
"TinyXML2 base directory location (optional, used for nonstandard installation paths)")
48+
endif()
49+
50+
# Search path for nonstandard package locations
51+
if(TinyXML2_ROOT_DIR)
52+
set(TinyXML2_INCLUDE_PATH PATHS "${TinyXML2_ROOT_DIR}/include" NO_DEFAULT_PATH)
53+
set(TinyXML2_LIBRARY_PATH PATHS "${TinyXML2_ROOT_DIR}/lib" NO_DEFAULT_PATH)
54+
endif()
55+
56+
# Find headers and libraries
57+
find_path(TinyXML2_INCLUDE_DIR NAMES tinyxml2.h PATH_SUFFIXES "tinyxml2" ${TinyXML2_INCLUDE_PATH})
58+
find_library(TinyXML2_LIBRARY NAMES tinyxml2 PATH_SUFFIXES "tinyxml2" ${TinyXML2_LIBRARY_PATH})
59+
60+
mark_as_advanced(TinyXML2_INCLUDE_DIR
61+
TinyXML2_LIBRARY)
62+
63+
# Output variables generation
64+
include(FindPackageHandleStandardArgs)
65+
find_package_handle_standard_args(TinyXML2 DEFAULT_MSG TinyXML2_LIBRARY
66+
TinyXML2_INCLUDE_DIR)
67+
68+
set(TinyXML2_FOUND ${TINYXML2_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
69+
unset(TINYXML2_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args
70+
71+
if(TinyXML2_FOUND)
72+
set(TinyXML2_INCLUDE_DIRS ${TinyXML2_INCLUDE_DIR})
73+
set(TinyXML2_LIBRARIES ${TinyXML2_LIBRARY})
74+
endif()

kdl_parser/include/kdl_parser/kdl_parser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool treeFromFile(const std::string & file, KDL::Tree & tree);
5959
/** Constructs a KDL tree from the parameter server, given the parameter name
6060
* \param param the name of the parameter on the parameter server
6161
* \param tree The resulting KDL Tree
62-
* returns true on success, false on failure
62+
* returns true on success, false on failure or if built without ROS
6363
*/
6464
KDL_PARSER_PUBLIC
6565
bool treeFromParam(const std::string & param, KDL::Tree & tree);

kdl_parser/src/check_kdl_parser.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
#include "kdl_parser/kdl_parser.hpp"
4141
#include <kdl/chainfksolverpos_recursive.hpp>
4242
#include <kdl/frames_io.hpp>
43-
#include <urdf/model.h>
43+
#include <urdf_model/model.h>
44+
#include <urdf_parser/urdf_parser.h>
4445

4546
void printLink(const KDL::SegmentMap::const_iterator & link, const std::string & prefix)
4647
{
@@ -58,14 +59,14 @@ int main(int argc, char ** argv)
5859
std::cerr << "Expect xml file to parse" << std::endl;
5960
return -1;
6061
}
61-
urdf::Model robot_model;
62-
if (!robot_model.initFile(argv[1])) {
62+
urdf::ModelInterfaceSharedPtr robot_model = urdf::parseURDFFile(argv[1]);
63+
if (!robot_model) {
6364
std::cerr << "Could not generate robot model" << std::endl;
6465
return false;
6566
}
6667

6768
KDL::Tree my_tree;
68-
if (!kdl_parser::treeFromUrdfModel(robot_model, my_tree)) {
69+
if (!kdl_parser::treeFromUrdfModel(*robot_model, my_tree)) {
6970
std::cerr << "Could not extract kdl tree" << std::endl;
7071
return false;
7172
}

0 commit comments

Comments
 (0)