You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.1 KiB
67 lines
2.1 KiB
#include <iostream>
|
|
|
|
#include <sdf/sdf.hh>
|
|
|
|
int main(int argc, const char* argv[])
|
|
{
|
|
// check arguments
|
|
if (argc < 2)
|
|
{
|
|
std::cerr << "Usage: " << argv[0]
|
|
<< " <sdf-path>" << std::endl;
|
|
return -1;
|
|
}
|
|
const std::string sdfPath(argv[1]);
|
|
|
|
// load and check sdf file
|
|
sdf::SDFPtr sdfElement(new sdf::SDF());
|
|
sdf::init(sdfElement);
|
|
if (!sdf::readFile(sdfPath, sdfElement))
|
|
{
|
|
std::cerr << sdfPath << " is not a valid SDF file!" << std::endl;
|
|
return -2;
|
|
}
|
|
|
|
// start parsing model
|
|
const sdf::ElementPtr rootElement = sdfElement->Root();
|
|
if (!rootElement->HasElement("model"))
|
|
{
|
|
std::cerr << sdfPath << " is not a model SDF file!" << std::endl;
|
|
return 0;
|
|
}
|
|
const sdf::ElementPtr modelElement = rootElement->GetElement("model");
|
|
const std::string modelName = modelElement->Get<std::string>("name");
|
|
std::cout << "Found " << modelName << " model!" << std::endl;
|
|
|
|
// parse model links
|
|
sdf::ElementPtr linkElement = modelElement->GetElement("link");
|
|
while (linkElement)
|
|
{
|
|
const std::string linkName = linkElement->Get<std::string>("name");
|
|
std::cout << "Found " << linkName << " link in "
|
|
<< modelName << " model!" << std::endl;
|
|
linkElement = linkElement->GetNextElement("link");
|
|
}
|
|
|
|
// parse model joints
|
|
sdf::ElementPtr jointElement = modelElement->GetElement("joint");
|
|
while (jointElement)
|
|
{
|
|
const std::string jointName = jointElement->Get<std::string>("name");
|
|
std::cout << "Found " << jointName << " joint in "
|
|
<< modelName << " model!" << std::endl;
|
|
|
|
const sdf::ElementPtr parentElement = jointElement->GetElement("parent");
|
|
const std::string parentLinkName = parentElement->Get<std::string>();
|
|
|
|
const sdf::ElementPtr childElement = jointElement->GetElement("child");
|
|
const std::string childLinkName = childElement->Get<std::string>();
|
|
|
|
std::cout << "Joint " << jointName << " connects " << parentLinkName
|
|
<< " link to " << childLinkName << " link" << std::endl;
|
|
|
|
jointElement = jointElement->GetNextElement("joint");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|