collada_urdf: urdf_to_collada catches exceptions
This commit is contained in:
parent
138cff4f75
commit
da358799d0
|
@ -54,11 +54,11 @@ ColladaWriter::ColladaWriter(std::string const& filename)
|
||||||
{
|
{
|
||||||
TiXmlDocument xml;
|
TiXmlDocument xml;
|
||||||
if (!xml.LoadFile(filename.c_str()))
|
if (!xml.LoadFile(filename.c_str()))
|
||||||
throw ColladaWriterException("Error opening file");
|
throw ColladaWriterException("Error reading XML file");
|
||||||
|
|
||||||
TiXmlElement* robot_xml = xml.FirstChildElement("robot");
|
TiXmlElement* robot_xml = xml.FirstChildElement("robot");
|
||||||
if (!robot_xml)
|
if (!robot_xml)
|
||||||
throw ColladaWriterException("Error parsing URDF model from XML");
|
throw ColladaWriterException("Error parsing URDF model from XML (robot element not found)");
|
||||||
|
|
||||||
robot_ = shared_ptr<urdf::Model>(new urdf::Model);
|
robot_ = shared_ptr<urdf::Model>(new urdf::Model);
|
||||||
if (!robot_->initXml(robot_xml))
|
if (!robot_->initXml(robot_xml))
|
||||||
|
|
|
@ -41,32 +41,18 @@ int main(int argc, char** argv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string input_filename(argv[1]);
|
try
|
||||||
std::string output_filename(argv[2]);
|
{
|
||||||
|
collada_urdf::ColladaWriter writer(argv[1]);
|
||||||
TiXmlDocument robot_model_xml;
|
if (!writer.writeDocument(argv[2])) {
|
||||||
if (!robot_model_xml.LoadFile(input_filename.c_str())) {
|
|
||||||
std::cerr << "Error opening file " << argv[1] << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TiXmlElement* robot_xml = robot_model_xml.FirstChildElement("robot");
|
|
||||||
if (!robot_xml) {
|
|
||||||
std::cerr << "Error parsing URDF model from XML" << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::shared_ptr<urdf::Model> robot(new urdf::Model);
|
|
||||||
if (!robot->initXml(robot_xml)) {
|
|
||||||
std::cerr << "Error parsing URDF model from XML" << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
collada_urdf::ColladaWriter writer(robot, input_filename);
|
|
||||||
if (!writer.writeDocument(output_filename)) {
|
|
||||||
std::cerr << "Error writing document" << std::endl;
|
std::cerr << "Error writing document" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (collada_urdf::ColladaWriterException ex) {
|
||||||
|
std::cerr << "Error converting document: " << ex.what() << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue