Skip to content

Commit

Permalink
function to load parameters for each model from xml file
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkoves authored and TSC21 committed May 30, 2018
1 parent 651ca35 commit b4b7245
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/


#include <tinyxml.h>
#include <Eigen/Dense>
#include <gazebo/gazebo.hh>
#include <ignition/math.hh>
Expand Down Expand Up @@ -50,6 +51,36 @@ bool getSdfParam(sdf::ElementPtr sdf, const std::string& name, T& param, const T
return false;
}

template <typename T>
void model_param(const std::string& world_name, const std::string& model_name, const std::string& param, T& param_value)
{
TiXmlDocument doc(world_name + ".xml");
if (doc.LoadFile())
{
TiXmlHandle hDoc(&doc);

TiXmlElement* pElem=hDoc.FirstChild( "options" ).FirstChild("model").Element();
for( pElem; pElem; pElem=pElem->NextSiblingElement("model"))
{
TiXmlElement* pName = pElem->FirstChildElement("name");
if (pName && model_name.compare(pName->GetText()) == 0)
{
TiXmlElement* pValue = pElem->FirstChildElement(param);

if (pValue)
{
std::istringstream iss(pValue->GetText());
iss >> param_value;

gzdbg << "get " << param << " " << param_value <<" for " << model_name << " model from " << doc.Value() << "\n";
break;
}
}
}
}

}

/**
* \brief Get a math::Angle as an angle from [0, 360)
*/
Expand Down

0 comments on commit b4b7245

Please sign in to comment.