19 ObjectModelParser::ObjectModelParser(
const std::string& filename) : filename_(filename),
34 const tinyxml2::XMLElement* p = elem->FirstChildElement(prop_name.c_str());
36 return p->Attribute(
"value", std::to_string(value).c_str());
39 error <<
"Could not find property '" << prop_name <<
"' of element '" << elem->Value() <<
"'" << endl;
45 if (!elem)
return false;
47 const char*
value = elem->Attribute(att_name.c_str());
49 error <<
"Could not find attribute '" << att_name <<
"' of element '" << elem->Value() <<
"'" << endl;
58 if (!elem)
return false;
60 const char*
value = elem->Attribute(att_name.c_str(), std::to_string(att_value).c_str());
63 error <<
"Could not find attribute '" << att_name <<
"' of element '" << elem->Value() <<
"'" << endl;
71 if (!elem)
return false;
73 const char*
value = elem->Attribute(att_name.c_str());
74 if (!value)
return false;
76 string valueStr =
value;
77 return (att_value == valueStr);
81 const char* pdf_type = pdf_elem->Attribute(
"type");
83 if (
string(pdf_type) ==
"uniform") {
90 }
else if (
string(pdf_type) ==
"discrete") {
93 return new pbl::PMF((
int)domain_size);
96 error <<
"Unknown pdf type: " << pdf_type << endl;
99 error <<
"PDF specification should contain 'type' attribute" << endl;
107 string attribute_name, model_type;
117 for(
unsigned int i = 0; i < classes.size(); ++i){
120 ROS_WARN(
"Planner specifications should now include the package name. You are using a deprecated API. Please switch from %s to %s in your yaml file.",
121 model_type.c_str(), classes[i].c_str());
122 model_type = classes[i];
133 error <<
"Unknown model: " << model_type << endl;
138 const tinyxml2::XMLElement*
param = elem->FirstChildElement(
"param");
140 const char* param_name = param->Attribute(
"name");
147 bool set_param_ok =
true;
148 if (param->QueryDoubleAttribute(
"value", &v_double) == tinyxml2::XML_SUCCESS) {
149 set_param_ok = estimator->
setParameter(
string(param_name), v_double);
150 }
else if (param->QueryIntAttribute(
"value", &v_int) == tinyxml2::XML_SUCCESS) {
151 set_param_ok = estimator->
setParameter(
string(param_name), (
double)v_int);
152 }
else if (param->QueryBoolAttribute(
"value", &v_bool) == tinyxml2::XML_SUCCESS) {
153 set_param_ok = estimator->
setParameter(
string(param_name), v_bool);
155 const char* v_str = param->Attribute(
"value");
157 set_param_ok = estimator->
setParameter(
string(param_name),
string(v_str));
159 error <<
"State estimator parameters should always have a 'name' and 'value' attribute." << endl;
164 error <<
"Unknown parameter for estimator '" << model_type <<
"': " << param_name << endl;
168 error <<
"State estimator parameters should always have a 'name' and 'value' attribute." << endl;
171 param = param->NextSiblingElement(
"param");
174 const tinyxml2::XMLElement* pnew = elem->FirstChildElement(
"pnew");
178 obj_model->
setNewPDF(attribute, *pdf_new);
180 estimator->
update(*pdf_new, 0);
187 error <<
"Estimator specification does not contain 'pnew'." << endl;
191 const tinyxml2::XMLElement* pclutter = elem->FirstChildElement(
"pclutter");
202 error <<
"Estimator specification does not contain 'pclutter'." << endl;
213 const tinyxml2::XMLElement*
param = elem->FirstChildElement(
"param");
215 const char* v = param->Attribute(
"name");
216 if (v && (
string)v == param_name) {
217 param->Attribute(
"value", std::to_string(value).c_str());
220 param = param->NextSiblingElement(
"param");
228 tinyxml2::XMLDocument doc;
232 ROS_ERROR_STREAM(
"While parsing '" <<
filename_ <<
"': " << endl << endl << doc.ErrorStr() <<
" at line " << doc.ErrorLineNum());
236 const tinyxml2::XMLElement* root = doc.RootElement();
239 const tinyxml2::XMLElement* prior_new_elem = root->FirstChildElement(
"prior_new");
240 if (prior_new_elem) {
245 parse_errors_ <<
"Knowledge file does not contain 'prior_new'" << endl;
248 double prior_existing;
249 const tinyxml2::XMLElement* prior_existing_elem = root->FirstChildElement(
"prior_existing");
250 if (prior_existing_elem) {
255 parse_errors_ <<
"Knowledge file does not contain 'prior_existing'" << endl;
258 double prior_clutter;
259 const tinyxml2::XMLElement* prior_clutter_elem = root->FirstChildElement(
"prior_clutter");
260 if (prior_clutter_elem) {
265 parse_errors_ <<
"Knowledge file does not contain 'prior_clutter'" << endl;
269 const tinyxml2::XMLElement* class_element = root->FirstChildElement(
"object_class");
273 while(class_element) {
279 cout <<
"Parsing model for class " << model_name << endl;
281 string base_class =
"";
282 const char*
value = class_element->Attribute(
"base");
293 parse_errors_ <<
"Error in class definition of '" << model_name <<
"': unknown base class '" << base_class <<
"'." << endl;
301 const tinyxml2::XMLElement* prop = class_element->FirstChildElement();
303 string prop_name = prop->Value();
304 if (prop_name ==
"behavior_model") {
305 stringstream bh_errors;
307 if (bh_errors.str() !=
"") {
311 parse_errors_ <<
"In class description for '" << class_model->
getModelName() <<
"': Unknown class property: '" << prop_name <<
"'" << endl;
313 prop = prop->NextSiblingElement();
318 class_element = class_element->NextSiblingElement(
"object_class");
std::string getPropertyValue(const tinyxml2::XMLElement *elem, std::string prop_name, double &value, std::stringstream &error, bool optional=false)
const ClassModel * getClassModel(const std::string &class_name) const
bool parseStateEstimator(ClassModel *obj_model, const tinyxml2::XMLElement *elem, std::stringstream &error)
std::string getErrorMessage() const
void setPriorExisting(double prior_existing)
void setPriorClutter(double prior_clutter)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
static Attribute attribute(const std::string &attribute_str)
attribute
pbl::PDF * parsePDF(const tinyxml2::XMLElement *elem, std::stringstream &error)
void setPriorNew(double prior_new)
pluginlib::ClassLoader< IStateEstimator > * object_model_loader_
void addClassModel(const std::string &class_name, ClassModel *model)
Base class for all state estimators used by the world model.
bool getAttributeValue(const tinyxml2::XMLElement *elem, std::string att_name, std::string &att_value, std::stringstream &error)
void setEstimator(const Attribute &attribute, const IStateEstimator &estimator)
virtual ~ObjectModelParser()
virtual bool setParameter(const std::string ¶m, bool b)
Resets the internal state of the estimator to the given PDF.
void setNewPDF(const Attribute &attribute, const pbl::PDF &pdf)
virtual void update(const pbl::PDF &z, const Time &time)=0
Updates the internal state based on measurement z.
const std::string & getModelName() const
bool getStateEstimatorParameter(const tinyxml2::XMLElement *elem, const std::string ¶m_name, double &value)
bool hasAttributeValue(const tinyxml2::XMLElement *elem, std::string att_name, std::string att_value)
Contains knowledge about a specific object class on where to expect new objects of that class (new) a...
bool parse(KnowledgeDatabase &obj_models)
void setModelName(const std::string &name)
arma_inline subview_elem1< eT, T1 > elem(const Base< uword, T1 > &a)
#define ROS_ERROR_STREAM(args)
std::stringstream parse_errors_
void setClutterPDF(const Attribute &attribute, const pbl::PDF &pdf)