use plugin to load collada files

This commit is contained in:
Ioan Sucan 2013-05-20 15:19:41 +03:00
parent 84b96c265f
commit 6604330b51
4 changed files with 45 additions and 16 deletions

View File

@ -34,7 +34,7 @@
#include <fstream>
#include <sstream>
#include <string>
/*
std::string readTestUrdfString() {
std::ifstream file("test/pr2.urdf");
std::stringstream ss;
@ -79,7 +79,7 @@ TEST(collada_urdf, collada_from_urdf_model_works)
ASSERT_TRUE(collada_urdf::colladaFromUrdfModel(robot_model, dom));
ASSERT_TRUE(collada_urdf::colladaToFile(dom, "test/pr2.dae"));
}
*/
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();

View File

@ -1,28 +1,28 @@
cmake_minimum_required(VERSION 2.8.3)
project(urdf)
find_package(catkin REQUIRED COMPONENTS urdfdom urdfdom_headers collada_parser rosconsole_bridge roscpp)
find_package(Boost REQUIRED thread)
find_package(catkin REQUIRED COMPONENTS urdfdom urdfdom_headers urdf_parser_plugin pluginlib rosconsole_bridge roscpp)
catkin_package(
LIBRARIES ${PROJECT_NAME}
INCLUDE_DIRS include
CATKIN_DEPENDS collada_parser rosconsole_bridge roscpp
DEPENDS urdfdom_headers urdfdom
CATKIN_DEPENDS rosconsole_bridge roscpp
DEPENDS urdfdom_headers urdfdom Boost
)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
include_directories(include)
include_directories(${catkin_INCLUDE_DIRS})
link_directories(${catkin_LIBRARY_DIRS})
find_package(catkin REQUIRED COMPONENTS roscpp rosconsole_bridge rostime)
include_directories(${catkin_INCLUDE_DIRS})
link_directories(${catkin_LIBRARY_DIRS})
find_library(TINYXML tinyxml)
add_library(${PROJECT_NAME} src/model.cpp src/rosconsole_bridge.cpp)
target_link_libraries(${PROJECT_NAME} ${urdfdom_LIBRARIES} ${collada_parser_LIBRARIES} ${rosconsole_bridge_LIBRARIES} ${TINYXML} ${catkin_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${TINYXML} ${catkin_LIBRARIES})
if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")

View File

@ -19,16 +19,18 @@
<buildtool_depend>catkin</buildtool_depend>
<build_depend>collada_parser</build_depend>
<build_depend>rosconsole_bridge</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>urdfdom</build_depend>
<build_depend>urdfdom_headers</build_depend>
<build_depend>urdf_parser_plugin</build_depend>
<build_depend>pluginlib</build_depend>
<run_depend>collada_parser</run_depend>
<run_depend>rosconsole_bridge</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>urdfdom</run_depend>
<run_depend>urdfdom_headers</run_depend>
<run_depend>urdf_parser_plugin</run_depend>
<run_depend>pluginlib</run_depend>
</package>

View File

@ -44,16 +44,17 @@
#include <urdf_parser_plugin/parser.h>
#include <pluginlib/class_loader.h>
#include <collada_parser/collada_parser.h>
#include <boost/algorithm/string.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/thread.hpp>
#include <vector>
#include <fstream>
#include <iostream>
namespace urdf{
bool IsColladaData(const std::string& data)
static bool IsColladaData(const std::string& data)
{
return data.find("<COLLADA") != std::string::npos;
}
@ -140,7 +141,33 @@ bool Model::initString(const std::string& xml_string)
// necessary for COLLADA compatibility
if( IsColladaData(xml_string) ) {
ROS_DEBUG("Parsing robot collada xml string");
model = parseCollada(xml_string);
static boost::mutex PARSER_PLUGIN_LOCK;
static boost::scoped_ptr<pluginlib::ClassLoader<urdf::URDFParser> > PARSER_PLUGIN_LOADER;
boost::mutex::scoped_lock _(PARSER_PLUGIN_LOCK);
try
{
if (!PARSER_PLUGIN_LOADER)
PARSER_PLUGIN_LOADER.reset(new pluginlib::ClassLoader<urdf::URDFParser>("urdf_parser_plugin", "urdf::URDFParser"));
const std::vector<std::string> &classes = PARSER_PLUGIN_LOADER->getDeclaredClasses();
bool found = false;
for (std::size_t i = 0 ; i < classes.size() ; ++i)
if (classes[i].find("collada") != std::string::npos)
{
boost::shared_ptr<urdf::URDFParser> instance = PARSER_PLUGIN_LOADER->createInstance(classes[i]);
if (instance)
model = instance->parse(xml_string);
found = true;
break;
}
if (!found)
ROS_ERROR_STREAM("No URDF parser plugin found for Collada files. Did you install the corresponding package?");
}
catch(pluginlib::PluginlibException& ex)
{
ROS_ERROR_STREAM("Exception while creating planning plugin loader " << ex.what() << ". Will not parse Collada file.");
}
}
else {
ROS_DEBUG("Parsing robot urdf xml string");