46 #include <urdf_parser/urdf_parser.h> 50 #include <boost/algorithm/string.hpp> 51 #include <boost/scoped_ptr.hpp> 52 #include <boost/thread.hpp> 62 return data.find(
"<COLLADA") != std::string::npos;
68 std::string xml_string;
69 std::fstream xml_file(filename.c_str(), std::fstream::in);
70 if (xml_file.is_open()) {
71 while (xml_file.good() ) {
73 std::getline(xml_file, line);
74 xml_string += (line +
"\n");
79 ROS_ERROR(
"Could not open file [%s] for parsing.",filename.c_str());
92 std::string xml_string;
95 std::string full_param;
97 ROS_ERROR(
"Could not find parameter %s on parameter server", param.c_str());
102 if (!nh.
getParam(full_param, xml_string)){
103 ROS_ERROR(
"Could not read parameter %s on parameter server", full_param.c_str());
112 ROS_ERROR(
"Could not parse the xml document");
116 std::stringstream ss;
125 ROS_ERROR(
"Could not parse the xml element");
129 std::stringstream ss;
138 ROS_ERROR(
"Could not parse the xml document");
142 tinyxml2::XMLPrinter printer;
143 xml_doc->Print(&printer);
144 std::string str(printer.CStr());
152 ROS_ERROR(
"Could not parse the xml element");
156 std::stringstream ss;
157 tinyxml2::XMLPrinter printer;
158 robot_xml->Accept(&printer);
159 ss << printer.CStr();
166 urdf::ModelInterfaceSharedPtr model;
170 ROS_DEBUG(
"Parsing robot collada xml string");
172 static boost::mutex PARSER_PLUGIN_LOCK;
173 static boost::scoped_ptr<pluginlib::ClassLoader<urdf::URDFParser> > PARSER_PLUGIN_LOADER;
174 boost::mutex::scoped_lock _(PARSER_PLUGIN_LOCK);
177 if (!PARSER_PLUGIN_LOADER) {
180 const std::vector<std::string> &classes = PARSER_PLUGIN_LOADER->getDeclaredClasses();
182 for (std::size_t i = 0 ; i < classes.size() ; ++i) {
183 if (classes[i].find(
"urdf/ColladaURDFParser") != std::string::npos) {
186 model = instance->parse(xml_string);
193 ROS_ERROR_STREAM(
"No URDF parser plugin found for Collada files. Did you install the corresponding package?");
197 ROS_ERROR_STREAM(
"Exception while creating planning plugin loader " << ex.what() <<
". Will not parse Collada file.");
200 ROS_DEBUG(
"Parsing robot urdf xml string");
201 model = parseURDF(xml_string);
206 this->links_ = model->links_;
207 this->joints_ = model->joints_;
208 this->materials_ = model->materials_;
209 this->name_ = model->name_;
210 this->root_link_ = model->root_link_;
URDF_EXPORT bool initFile(const std::string &filename)
Load Model given a filename.
static bool IsColladaData(const std::string &data)
URDF_EXPORT bool initString(const std::string &xmlstring)
Load Model from a XML-string.
URDF_EXPORT bool initParamWithNodeHandle(const std::string ¶m, const ros::NodeHandle &nh=ros::NodeHandle())
Load Model given the name of parameter on parameter server using provided nodehandle.
bool getParam(const std::string &key, std::string &s) const
URDF_EXPORT bool initParam(const std::string ¶m)
Load Model given the name of a parameter on the parameter server.
URDF_EXPORT bool initXml(const tinyxml2::XMLElement *xml)
Load Model from tinyxml2::XMLElement.
bool searchParam(const std::string &key, std::string &result) const
#define ROS_ERROR_STREAM(args)