Add OnePlugin read/write functions and remove redundant plugin attributes from mjCActuator.
PiperOrigin-RevId: 525708657 Change-Id: I762de238f989b13877d5f9198c83c16ea9dc1d8b
This commit is contained in:
committed by
Copybara-Service
parent
34e62aa3c1
commit
4f5da9c554
@@ -929,12 +929,6 @@ class mjCActuator : public mjCBase {
|
|||||||
std::string slidersite; // site defining cylinder, for slider-crank only
|
std::string slidersite; // site defining cylinder, for slider-crank only
|
||||||
std::string refsite; // reference site, for site transmission only
|
std::string refsite; // reference site, for site transmission only
|
||||||
|
|
||||||
// plugin support
|
|
||||||
bool is_plugin;
|
|
||||||
std::string plugin_name;
|
|
||||||
std::string plugin_instance_name;
|
|
||||||
mjCPlugin* plugin_instance;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mjCActuator(mjCModel* = 0, mjCDef* = 0);// constructor
|
mjCActuator(mjCModel* = 0, mjCDef* = 0);// constructor
|
||||||
void Compile(void); // compiler
|
void Compile(void); // compiler
|
||||||
|
|||||||
@@ -1841,15 +1841,7 @@ void mjXReader::OneActuator(XMLElement* elem, mjCActuator* pact) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (type == "plugin") {
|
else if (type == "plugin") {
|
||||||
pact->is_plugin = true;
|
OnePlugin(elem, pact);
|
||||||
ReadAttrTxt(elem, "plugin", pact->plugin_name);
|
|
||||||
ReadAttrTxt(elem, "instance", pact->plugin_instance_name);
|
|
||||||
if (pact->plugin_instance_name.empty()) {
|
|
||||||
pact->plugin_instance = model->AddPlugin();
|
|
||||||
} else {
|
|
||||||
model->hasImplicitPluginElem = true;
|
|
||||||
}
|
|
||||||
ReadPluginConfigs(elem, pact->plugin_instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else { // SHOULD NOT OCCUR
|
else { // SHOULD NOT OCCUR
|
||||||
@@ -2087,6 +2079,20 @@ void mjXReader::OneComposite(XMLElement* elem, mjCBody* pbody, mjCDef* def) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void mjXReader::OnePlugin(XMLElement* elem, mjCBase* object) {
|
||||||
|
object->is_plugin = true;
|
||||||
|
ReadAttrTxt(elem, "plugin", object->plugin_name);
|
||||||
|
ReadAttrTxt(elem, "instance", object->plugin_instance_name);
|
||||||
|
if (object->plugin_instance_name.empty()) {
|
||||||
|
object->plugin_instance = model->AddPlugin();
|
||||||
|
} else {
|
||||||
|
model->hasImplicitPluginElem = true;
|
||||||
|
}
|
||||||
|
ReadPluginConfigs(elem, object->plugin_instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------ MJCF-specific sections --------------------------------------------------------
|
//------------------ MJCF-specific sections --------------------------------------------------------
|
||||||
|
|
||||||
// default section parser
|
// default section parser
|
||||||
@@ -2699,15 +2705,7 @@ void mjXReader::Body(XMLElement* section, mjCBody* pbody) {
|
|||||||
|
|
||||||
// plugin sub-element
|
// plugin sub-element
|
||||||
else if (name == "plugin") {
|
else if (name == "plugin") {
|
||||||
pbody->is_plugin = true;
|
OnePlugin(elem, pbody);
|
||||||
ReadAttrTxt(elem, "plugin", pbody->plugin_name);
|
|
||||||
ReadAttrTxt(elem, "instance", pbody->plugin_instance_name);
|
|
||||||
if (pbody->plugin_instance_name.empty()) {
|
|
||||||
pbody->plugin_instance = model->AddPlugin();
|
|
||||||
} else {
|
|
||||||
model->hasImplicitPluginElem = true;
|
|
||||||
}
|
|
||||||
ReadPluginConfigs(elem, pbody->plugin_instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// composite sub-element
|
// composite sub-element
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class mjXReader : public mjXBase {
|
|||||||
void OneTendon(tinyxml2::XMLElement* elem, mjCTendon* ptendon);
|
void OneTendon(tinyxml2::XMLElement* elem, mjCTendon* ptendon);
|
||||||
void OneActuator(tinyxml2::XMLElement* elem, mjCActuator* pactuator);
|
void OneActuator(tinyxml2::XMLElement* elem, mjCActuator* pactuator);
|
||||||
void OneComposite(tinyxml2::XMLElement* elem, mjCBody* pbody, mjCDef* def);
|
void OneComposite(tinyxml2::XMLElement* elem, mjCBody* pbody, mjCDef* def);
|
||||||
|
void OnePlugin(tinyxml2::XMLElement* elem, mjCBase* object);
|
||||||
|
|
||||||
mjXSchema schema; // schema used for validation
|
mjXSchema schema; // schema used for validation
|
||||||
mjCDef* GetClass(tinyxml2::XMLElement* section); // get default class name
|
mjCDef* GetClass(tinyxml2::XMLElement* section); // get default class name
|
||||||
|
|||||||
@@ -618,24 +618,7 @@ void mjXWriter::OneActuator(XMLElement* elem, mjCActuator* pact, mjCDef* def) {
|
|||||||
|
|
||||||
// plugins: write config attributes
|
// plugins: write config attributes
|
||||||
if (pact->is_plugin) {
|
if (pact->is_plugin) {
|
||||||
if (!pact->plugin_instance_name.empty()) {
|
OnePlugin(elem, pact);
|
||||||
WriteAttrTxt(elem, "instance", pact->plugin_instance_name);
|
|
||||||
} else {
|
|
||||||
WriteAttrTxt(elem, "plugin", pact->plugin_name);
|
|
||||||
const mjpPlugin* plugin = mjp_getPluginAtSlot(
|
|
||||||
pact->plugin_instance->plugin_slot);
|
|
||||||
const char* c = &pact->plugin_instance->flattened_attributes[0];
|
|
||||||
for (int i = 0; i < plugin->nattribute; ++i) {
|
|
||||||
std::string value(c);
|
|
||||||
if (!value.empty()) {
|
|
||||||
XMLElement* config_elem = InsertEnd(elem, "config");
|
|
||||||
WriteAttrTxt(config_elem, "key", plugin->attributes[i]);
|
|
||||||
WriteAttrTxt(config_elem, "value", value);
|
|
||||||
c += value.size();
|
|
||||||
}
|
|
||||||
++c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// non-plugins: write actuator parameters
|
// non-plugins: write actuator parameters
|
||||||
@@ -665,6 +648,30 @@ void mjXWriter::OneActuator(XMLElement* elem, mjCActuator* pact, mjCDef* def) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// write plugin
|
||||||
|
void mjXWriter::OnePlugin(XMLElement* elem, mjCBase* object) {
|
||||||
|
if (!object->plugin_instance_name.empty()) {
|
||||||
|
WriteAttrTxt(elem, "instance", object->plugin_instance_name);
|
||||||
|
} else {
|
||||||
|
WriteAttrTxt(elem, "plugin", object->plugin_name);
|
||||||
|
const mjpPlugin* plugin = mjp_getPluginAtSlot(
|
||||||
|
object->plugin_instance->plugin_slot);
|
||||||
|
const char* c = &object->plugin_instance->flattened_attributes[0];
|
||||||
|
for (int i = 0; i < plugin->nattribute; ++i) {
|
||||||
|
std::string value(c);
|
||||||
|
if (!value.empty()) {
|
||||||
|
XMLElement* config_elem = InsertEnd(elem, "config");
|
||||||
|
WriteAttrTxt(config_elem, "key", plugin->attributes[i]);
|
||||||
|
WriteAttrTxt(config_elem, "value", value);
|
||||||
|
c += value.size();
|
||||||
|
}
|
||||||
|
++c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------- class mjXWriter: top-level API --------------------------------
|
//---------------------------------- class mjXWriter: top-level API --------------------------------
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
@@ -1382,24 +1389,7 @@ void mjXWriter::Body(XMLElement* elem, mjCBody* body) {
|
|||||||
|
|
||||||
// write plugin
|
// write plugin
|
||||||
if (body->is_plugin) {
|
if (body->is_plugin) {
|
||||||
XMLElement *child = InsertEnd(elem, "plugin");
|
OnePlugin(elem, body);
|
||||||
if (!body->plugin_instance_name.empty()) {
|
|
||||||
WriteAttrTxt(child, "instance", body->plugin_instance_name);
|
|
||||||
} else {
|
|
||||||
WriteAttrTxt(child, "plugin", body->plugin_name);
|
|
||||||
const mjpPlugin* plugin = mjp_getPluginAtSlot(
|
|
||||||
body->plugin_instance->plugin_slot);
|
|
||||||
const char* c = &body->plugin_instance->flattened_attributes[0];
|
|
||||||
for (int i = 0; i < plugin->nattribute; ++i) {
|
|
||||||
std::string value(c);
|
|
||||||
if (!value.empty()) {
|
|
||||||
WriteAttrTxt(child, std::string("plugin:") + plugin->attributes[i],
|
|
||||||
value);
|
|
||||||
c += value.size();
|
|
||||||
}
|
|
||||||
++c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// write child bodies recursively
|
// write child bodies recursively
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class mjXWriter : public mjXBase {
|
|||||||
void OneEquality(tinyxml2::XMLElement* elem, mjCEquality* pequality, mjCDef* def);
|
void OneEquality(tinyxml2::XMLElement* elem, mjCEquality* pequality, mjCDef* def);
|
||||||
void OneTendon(tinyxml2::XMLElement* elem, mjCTendon* ptendon, mjCDef* def);
|
void OneTendon(tinyxml2::XMLElement* elem, mjCTendon* ptendon, mjCDef* def);
|
||||||
void OneActuator(tinyxml2::XMLElement* elem, mjCActuator* pactuator, mjCDef* def);
|
void OneActuator(tinyxml2::XMLElement* elem, mjCActuator* pactuator, mjCDef* def);
|
||||||
|
void OnePlugin(tinyxml2::XMLElement* elem, mjCBase* object);
|
||||||
|
|
||||||
bool writingdefaults; // true during defaults write
|
bool writingdefaults; // true during defaults write
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user