Go to the documentation of this file.
19 #include <sdf/parser.hh>
33 pose = pose_offset * pose;
43 composite->addShape(*sub_shape, pose);
53 const char * edmpath = ::getenv(
"ED_MODEL_PATH");
60 const char * mpath = ::getenv(
"GAZEBO_MODEL_PATH");
67 const char * fpath = ::getenv(
"GAZEBO_RESOURCE_PATH");
96 return model_path.
string();
108 if (parsed_uri.
empty())
111 if (uri_type ==
MODEL)
123 return model_path.
string();
128 if (uri_type ==
FILE)
134 return file_path.
string();
163 if (!data_sdf.
empty())
167 if (!cache_data.
first.empty())
169 types = cache_data.
second;
170 return cache_data.
first;
176 if (model_path.
empty())
178 error <<
"[ed::models::loadModelData] Model '" << type <<
"' could not be found." <<
std::endl;
183 if (!model_cfg_path.
exists())
185 error <<
"[ed::models::loadModelData] ERROR loading configuration for model '" << type <<
"'; '" << model_cfg_path.
string() <<
"' file does not exist." <<
std::endl;
192 error <<
"[ed::models::loadModelData] ERROR loading configuration for model '" << type <<
"'; '" << model_cfg_path.
string() <<
"' failed to parse yaml file." <<
std::endl;
201 combined_data.
add(super_data);
202 combined_data.
add(model_cfg.
data());
206 data = combined_data;
210 data = model_cfg.
data();
215 rw.
setValue(
"__model_path__", model_path);
230 if (parsed_uri.
empty())
232 error <<
"[ed::models::loadSDFData] Incorrect URI: '" << uri <<
"'." <<
std::endl;
236 if (!cache_data.
first.empty())
238 return cache_data.
first;
242 if (!model_cfg_path.
exists())
244 error <<
"[ed::models::loadSDFData] Model '" << uri <<
"' could not be found." <<
std::endl;
251 error <<
"[ed::models::loadSDFData] ERROR loading configuration for model '" << uri <<
"'; '" << model_cfg_path <<
"' failed to parse SDF file." <<
std::endl;
267 if(!cache_data.
first.empty())
271 if(!cache_data.
first.empty())
276 if (!sdf_path.
empty())
280 return !model_path.
empty();
286 const bool allow_sdf)
336 return createSDF(r.
data(), parent_id, pose_offset, id_opt, boost::shared_ptr<const geo::Pose3D>(), req,
error);
344 if (parent_id.
str().
empty() || parent_id.
str()[0] ==
'_')
347 id = parent_id.
str() +
"/" + id_str;
365 if (super_data.
empty())
369 data_combined.
add(super_data);
370 data_combined.
add(data);
385 error <<
"[ed::models::create] No pose, while reading model: '" <<
id <<
"'" <<
std::endl;
387 pose = pose_offset * pose;
405 r.
value(
"__model_path__", shape_model_path);
454 if (r.
value(
"flag", flag))
474 bool sdf_model =
false;
481 if (!sdf_world && !sdf_model)
483 error <<
"[ed::models::createSDF] Not a valid SDF model, because no 'world' or 'model' available: " <<
std::endl << data <<
std::endl;
489 error <<
"[ed::models::createSDF] A model sdf file should only contain one model." <<
std::endl;
497 id = id_override.
str();
498 else if (r.
value(
"name", id_str) && !id_str.
empty())
504 if (!parent_id.
str().
empty() && parent_id.
str()[0] !=
'_')
505 id = parent_id.
str() +
"/" +
id.str();
511 pose = *pose_override;
512 pose = parent_pose * pose;
517 if (r.
value(
"type", type))
530 if (!
createSDF(rw.
data(),
id, pose,
"", boost::shared_ptr<const geo::Pose3D>(), req,
error))
542 ed::shared_ptr<const geo::Pose3D> child_posePtr;
544 r.
value(
"name", child_id);
546 child_posePtr = ed::make_shared<const geo::Pose3D>(child_pose);
547 if (!r.
value(
"uri", uri))
555 if (!
createSDF(child_data,
id, pose, child_id, child_posePtr, req,
error))
589 if (r.
value(
"name", volume_name))
599 if (volume_composite)
600 req.
addVolume(
id, volume_name, volume_composite);
605 if (visual_composite)
607 if (collision_composite)
std::string parseURI(const std::string &uri, ModelOrFile &uri_type)
tue::config::DataConstPointer loadModelData(std::string type, std::vector< std::string > &types, std::stringstream &error, const bool allow_sdf=false)
loadModelData load data of model of type 'type'
bool loadFromSDFFile(const std::string &filename)
void addData(const UUID &id, const tue::config::DataConstPointer &data)
bool createSDF(const tue::config::DataConstPointer &data, const UUID &parent_id, const geo::Pose3D &parent_pose, const UUID &id_override, const boost::shared_ptr< const geo::Pose3D > pose_override, UpdateRequest &req, std::stringstream &error)
createSDF add SDF entity to update_request from config data.
void addType(const UUID &id, const std::string &type)
bool value(const std::string &name, T &value, const RequiredOrOptional=REQUIRED) const
std::vector< std::string > model_paths_
bool hasGroup(const std::string &name)
bool writeArray(const std::string &name)
ModelData readModelCache(std::string type) const
readModelCache read the model cache, which contains the data and all types
bool loadFromYAMLFile(const std::string &filename, const ResolveConfig &resolve_config=ResolveConfig::defaultConfig())
tue::config::DataConstPointer loadSDFData(std::string uri, std::stringstream &error)
loadSDFData load data of SDF model of uri 'uri'
bool readGroup(const std::string &name, const RequiredOrOptional opt=OPTIONAL)
ModelOrFile
The ModelOrFile enum This is used to determine the URI type in SDF.
bool create(const UUID &id, const std::string &type, UpdateRequest &req, std::stringstream &error, const bool allow_sdf=false)
create add entity to update_request with id 'id' of the type 'type'. If allow_sdf is true,...
void setFlag(const UUID &id, const std::string &flag)
std::map< std::string, ModelData > model_cache_
DataConstPointer data() const
std::map< std::string, geo::ShapePtr > shape_cache_
geo::ShapePtr loadShape(const std::string &model_path, tue::config::Reader cfg, std::map< std::string, geo::ShapePtr > &shape_cache, std::stringstream &error)
loadShape load the shape of a model.
std::vector< std::string > split(const std::string &strToSplit, char delimeter)
split Implementation by using delimiter as a character. Multiple delimeters are removed.
const std::string & error() const
void setPose(const UUID &id, const geo::Pose3D &pose)
void setCollision(const UUID &id, const geo::ShapeConstPtr &collision)
bool readSDFGeometry(tue::config::Reader r, geo::CompositeShapePtr &composite, std::stringstream &error, geo::Pose3D pose_offset=geo::Pose3D::identity())
std::vector< std::string > ed_model_paths_
void setType(const UUID &id, const std::string &type)
void setVisual(const UUID &id, const geo::ShapeConstPtr &visual)
std::vector< std::string > file_paths_
bool value(const std::string &name, T &value, RequiredOrOptional opt=REQUIRED)
void setValue(const std::string &name, const T &value)
std::pair< tue::config::DataConstPointer, std::vector< std::string > > ModelData
bool exists(const std::string &type) const
exists Check of a model of type 'type' exist
bool add(const DataConstPointer &ptr)
const std::string & string() const
std::string getSDFPath(const std::string &uri) const
getSDFPath get file path of SDF model with uri 'uri'
bool readArray(const std::string &name, const RequiredOrOptional opt=OPTIONAL)
std::string getModelPath(const std::string &type) const
getModelPath get file path of model of type 'type'
bool readPose(tue::config::Reader &cfg, geo::Pose3D &pose, tue::config::RequiredOrOptional pos_req, tue::config::RequiredOrOptional rot_req)
readPose read pose into Pose3D. Both ED yaml and SDF. Also reads pos(position) of SDF.
const std::string & str() const
void addVolume(const UUID &id, const std::string Volume_name, const geo::ShapeConstPtr &Volume_shape)