38 #include <Rcs_resourcePath.h> 39 #include <Rcs_macros.h> 40 #include <Rcs_basicMath.h> 46 #include <Rcs_parser.h> 47 #include <Rcs_collisionModel.h> 56 if (xmlName ==
nullptr) {
63 xmlSetProp(node, BAD_CAST xmlName, BAD_CAST value.c_str());
74 bool fileExists = Rcs_getAbsoluteFileName(file.c_str(), txt);
77 RMSG(
"Resource path is:");
78 Rcs_printResourcePath();
80 std::ostringstream os;
81 os <<
"Could not find collision model file: " << file;
82 throw std::invalid_argument(os.str());
86 xmlDocPtr doc =
nullptr;
87 xmlNodePtr node = parseXMLFile(txt,
"CollisionModel", &doc);
89 throw std::invalid_argument(
"Error parsing collision model XML.");
93 auto collisionMdl = RcsCollisionModel_createFromXML(graph, node);
98 throw std::invalid_argument(
"Error in collision model configuration! (see stderr)");
105 xmlDocPtr doc = xmlNewDoc(
nullptr);
106 xmlNodePtr cmNode = xmlNewDocNode(doc,
nullptr, BAD_CAST
"CollisionModel",
nullptr);
107 xmlDocSetRootElement(doc, cmNode);
116 if (pairs->empty()) {
119 for (
auto child : *pairs) {
120 xmlNodePtr pairNode = xmlNewDocNode(doc,
nullptr, BAD_CAST
"CollisionPair",
nullptr);
121 xmlAddChild(cmNode, pairNode);
131 auto collisionMdl = RcsCollisionModel_createFromXML(graph, cmNode);
138 throw std::invalid_argument(
"Error in collision model configuration! (see stderr)");
144 static std::map<std::string, ExperimentConfig::ExperimentConfigCreateFunction>
registry;
149 registry[name] = creator;
159 throw std::invalid_argument(
"Property source is missing 'envType' entry.");
163 auto iter = registry.find(key);
164 if (iter == registry.end()) {
165 std::ostringstream os;
166 os <<
"Unknown experiment type '" << key <<
"'.";
167 throw std::invalid_argument(os.str());
171 result = iter->second();
182 result->
load(properties);
207 RcsGraph_destroy(
graph);
224 Rcs_addResourcePath(RCS_CONFIG_DIR);
226 std::string extraConfigDir;
227 if (properties->
getProperty(extraConfigDir,
"extraConfigDir")) {
228 Rcs_addResourcePath(extraConfigDir.c_str());
232 std::string graphFileName =
"gScenario.xml";
233 properties->
getProperty(graphFileName,
"graphFileName");
234 graph = RcsGraph_create(graphFileName.c_str());
236 throw std::invalid_argument(
"Graph not found: " + graphFileName);
240 auto collCfg = properties->
getChild(
"collisionConfig");
241 if (collCfg->exists()) {
273 auto partialObs = properties->
getChild(
"partialObservation");
276 std::vector<std::string> names;
277 if (partialObs->getProperty(names,
"names")) {
279 bool autoSelectVelocity = partialObs->getPropertyBool(
"autoSelectVelocity");
310 std::string physicsEngine =
"Bullet";
311 std::string physicsConfigFile =
"physics/physics.xml";
329 std::ostringstream os;
330 os <<
"Unable to create physics simulator using " << physicsEngine <<
" engine.";
331 throw std::invalid_argument(os.str());
348 std::vector<std::string>& linesOut,
350 const MatNd* currentObservation,
351 const MatNd* currentAction,
352 PhysicsBase* simulator,
358 if (simulator !=
nullptr) {
359 simName = simulator->getClassName();
366 sprintf(hudText,
"physics engine: %s simulation time: %2.3f s", simName, currentTime);
367 linesOut.emplace_back(hudText);
372 const MatNd* currentObservation,
373 const MatNd* currentAction,
374 PhysicsBase* simulator,
379 std::vector<std::string> lines;
380 getHUDText(lines, currentTime, currentObservation, currentAction, simulator, physicsManager, forceDisturber);
383 std::ostringstream os;
384 for (
size_t i = 0; i < lines.size(); ++i) {
385 if (i > 0) { os <<
'\n'; }
virtual bool getProperty(std::string &out, const char *property)=0
virtual bool getPropertyBool(const char *property, bool def=false)=0
PhysicsBase * createSimulator(PropertySource *values)
virtual void initViewer(Rcs::Viewer *viewer)
virtual ActionModel * createActionModel()=0
virtual PropertySource * getChild(const char *prefix)=0
virtual ForceDisturber * createForceDisturber()
bool checkJointLimits
Flag to enable joint limit checking.
double dt
The time step [s].
virtual const std::vector< PropertySource * > & getChildList(const char *prefix)=0
virtual ObservationModel * createObservationModel()=0
static std::map< std::string, ControlPolicy::ControlPolicyCreateFunction > registry
static void copy_prop_to_xml_attr(xmlNodePtr node, PropertySource *source, const char *name, const char *xmlName=nullptr)
static PropertySource * empty()
virtual void load(PropertySource *properties)
virtual InitStateSetter * createInitStateSetter()
static ExperimentConfig * create(PropertySource *properties)
ObservationModel * observationModel
Observation model (pluggable) used to create the observation which will be returned from step() ...
PropertySource * properties
Property source (owned)
virtual void getHUDText(std::vector< std::string > &linesOut, double currentTime, const MatNd *currentObservation, const MatNd *currentAction, PhysicsBase *simulator, PhysicsParameterManager *physicsManager, ForceDisturber *forceDisturber)
static OMPartial * fromNames(ObservationModel *wrapped, const std::vector< std::string > &names, bool exclude=false, bool autoSelectVelocity=false)
RcsCollisionMdl * RcsCollisionModel_createFromConfig(RcsGraph *graph, PropertySource *config)
ExperimentConfig *(* ExperimentConfigCreateFunction)()
ActionModel * actionModel
Action model (pluggable)
RcsCollisionMdl * collisionMdl
Collision model to use. Is based on the graph, so take care when using with IK etc.
virtual void populatePhysicsParameters(PhysicsParameterManager *manager)
static void registerType(const char *name, ExperimentConfigCreateFunction creator)
RcsGraph * graph
Graph description.
PhysicsParameterManager * createPhysicsParameterManager()
virtual ~ExperimentConfig()