Remove mjCAlternative and user_objects dependency from xml_urdf.

PiperOrigin-RevId: 618832482
Change-Id: I626bb956cd3eb35317811b9b577cc7db128262ea
This commit is contained in:
Alessio Quaglino
2024-03-25 07:20:01 -07:00
committed by Copybara-Service
parent 7875e93fea
commit 357ff8bbdc
8 changed files with 50 additions and 59 deletions
+8
View File
@@ -498,6 +498,14 @@ void mjs_setFrame(mjElement dest, mjsFrame* frame) {
// Resolve alternative orientations.
const char* mjs_resolveOrientation(double quat[4], mjtByte degree, const char* sequence,
const mjsOrientation* orientation) {
return ResolveOrientation(quat, degree, sequence, *orientation);
}
// get id
int mjs_getId(mjElement element) {
return reinterpret_cast<mjCBase*>(element)->id;
+7
View File
@@ -915,6 +915,10 @@ MJAPI void mjs_setDefault(mjElement element, mjmDefault* def);
// Set frame.
MJAPI void mjs_setFrame(mjElement dest, mjsFrame* frame);
// Resolve alternative orientations to quat.
MJAPI const char* mjs_resolveOrientation(double quat[4], mjtByte degree, const char* sequence,
const mjsOrientation* orientation);
// Compute quat and inertia from body->fullinertia.
MJAPI const char* mjs_setFullInertia(mjsBody* body, double quat[4], double inertia[3]);
@@ -924,6 +928,9 @@ MJAPI const char* mjs_setFullInertia(mjsBody* body, double quat[4], double inert
// Default model attributes.
MJAPI void mjs_defaultSpec(mjSpec& model);
// Default orientation attributes.
MJAPI void mjs_defaultOrientation(mjsOrientation& orient);
// Default body attributes.
MJAPI void mjs_defaultBody(mjsBody& body);
+2 -1
View File
@@ -73,6 +73,7 @@ mjCFlexcomp::mjCFlexcomp(void) {
centered = false;
mjs_defaultPlugin(plugin);
mjs_defaultOrientation(alt);
plugin_name = "";
plugin_instance_name = "";
plugin.name = (mjString)&plugin_name;
@@ -131,7 +132,7 @@ bool mjCFlexcomp::Make(mjSpec* spec, mjsBody* body, char* error, int error_sz) {
}
// compute orientation
const char* alterr = alt.Set(quat, model->spec.degree, model->spec.euler);
const char* alterr = mjs_resolveOrientation(quat, model->spec.degree, model->spec.euler, &alt);
if (alterr) {
return comperr(error, alterr, error_sz);
}
+1 -1
View File
@@ -79,7 +79,7 @@ class mjCFlexcomp {
// pose transform relative to parent body
double pos[3]; // position
double quat[4]; // orientation
mjCAlternative alt; // alternative orientation
mjsOrientation alt; // alternative orientation
// set by user or computed internally
bool rigid; // all vertices are in parent body (all pinned)
+7
View File
@@ -75,6 +75,13 @@ void mjs_defaultSpec(mjSpec& model) {
// default orientation attributes
void mjs_defaultOrientation(mjsOrientation& orient) {
orient.axisangle[0] = orient.xyaxes[0] = orient.zaxis[0] = orient.euler[0] = mjNAN;
}
// default body attributes
void mjs_defaultBody(mjsBody& body) {
memset(&body, 0, sizeof(mjsBody));
+18 -37
View File
@@ -141,17 +141,22 @@ mjCError::mjCError(const mjCBase* obj, const char* msg, const char* str, int pos
//------------------ class mjCAlternative implementation -------------------------------------------
// constructor
mjCAlternative::mjCAlternative() {
axisangle[0] = xyaxes[0] = zaxis[0] = euler[0] = mjNAN;
}
//------------------ alternative orientation implementation ----------------------------------------
// compute frame orientation given alternative specifications
// used for geom, site, body and camera frames
const char* mjCAlternative::Set(double* quat, bool degree, const char* sequence) {
const char* ResolveOrientation(double* quat, bool degree, const char* sequence,
const mjsOrientation& orient) {
mjtNum axisangle[4];
mjtNum xyaxes[6];
mjtNum zaxis[3];
mjtNum euler[3];
mjuu_copyvec(axisangle, orient.axisangle, 4);
mjuu_copyvec(xyaxes, orient.xyaxes, 6);
mjuu_copyvec(zaxis, orient.zaxis, 3);
mjuu_copyvec(euler, orient.euler, 3);
// set quat using axisangle
if (mjuu_defined(axisangle[0])) {
// convert to radians if necessary, normalize axis
@@ -754,14 +759,6 @@ void mjCBody::CopyFromSpec() {
*static_cast<mjsBody*>(this) = spec;
userdata_ = spec_userdata_;
userdata = (mjDoubleVec)&userdata_;
mju_copy4(alt_.axisangle, alt.axisangle);
mju_copy(alt_.xyaxes, alt.xyaxes, 6);
mju_copy3(alt_.zaxis, alt.zaxis);
mju_copy3(alt_.euler, alt.euler);
mju_copy4(ialt_.axisangle, ialt.axisangle);
mju_copy(ialt_.xyaxes, ialt.xyaxes, 6);
mju_copy3(ialt_.zaxis, ialt.zaxis);
mju_copy3(ialt_.euler, ialt.euler);
plugin.active = spec.plugin.active;
plugin.instance = spec.plugin.instance;
plugin.name = spec.plugin.name;
@@ -1195,7 +1192,7 @@ void mjCBody::Compile(void) {
}
// check and process orientation alternatives for body
const char* err = alt_.Set(quat, model->degree, model->euler);
const char* err = ResolveOrientation(quat, model->degree, model->euler, alt);
if (err) {
throw mjCError(this, "error '%s' in frame alternative", err);
}
@@ -1432,10 +1429,6 @@ void mjCFrame::CopyFromSpec() {
*static_cast<mjsFrame*>(this) = spec;
mju_copy3(pos, spec.pos);
mju_copy4(quat, spec.quat);
mju_copy4(alt_.axisangle, alt.axisangle);
mju_copy(alt_.xyaxes, alt.xyaxes, 6);
mju_copy3(alt_.zaxis, alt.zaxis);
mju_copy3(alt_.euler, alt.euler);
}
@@ -1446,7 +1439,7 @@ void mjCFrame::Compile() {
}
CopyFromSpec();
const char* err = alt_.Set(quat, model->spec.degree, model->spec.euler);
const char* err = ResolveOrientation(quat, model->spec.degree, model->spec.euler, alt);
if (err) {
throw mjCError(this, "orientation specification error '%s' in site %d", err, id);
}
@@ -1746,10 +1739,6 @@ void mjCGeom::CopyFromSpec() {
hfieldname = (mjString)&hfieldname_;
meshname = (mjString)&meshname_;
material = (mjString)&material_;
mju_copy4(alt_.axisangle, alt.axisangle);
mju_copy(alt_.xyaxes, alt.xyaxes, 6);
mju_copy3(alt_.zaxis, alt.zaxis);
mju_copy3(alt_.euler, alt.euler);
plugin.active = spec.plugin.active;
plugin.instance = spec.plugin.instance;
plugin.name = spec.plugin.name;
@@ -2181,7 +2170,7 @@ void mjCGeom::Compile(void) {
// not 'fromto': try alternative
else {
const char* err = alt_.Set(quat, model->degree, model->euler);
const char* err = ResolveOrientation(quat, model->degree, model->euler, alt);
if (err) {
throw mjCError(this, "orientation specification error '%s' in geom %d", err, id);
}
@@ -2355,10 +2344,6 @@ void mjCSite::CopyFromSpec() {
material_ = spec_material_;
userdata = (mjDoubleVec)&userdata_;
material = (mjString)&material_;
mju_copy4(alt_.axisangle, alt.axisangle);
mju_copy(alt_.xyaxes, alt.xyaxes, 6);
mju_copy3(alt_.zaxis, alt.zaxis);
mju_copy3(alt_.euler, alt.euler);
}
@@ -2430,7 +2415,7 @@ void mjCSite::Compile(void) {
// alternative orientation
else {
const char* err = alt_.Set(quat, model->degree, model->euler);
const char* err = ResolveOrientation(quat, model->degree, model->euler, alt);
if (err) {
throw mjCError(this, "orientation specification error '%s' in site %d", err, id);
}
@@ -2514,10 +2499,6 @@ void mjCCamera::CopyFromSpec() {
targetbody_ = spec_targetbody_;
userdata = (mjDoubleVec)&userdata_;
targetbody = (mjString)&targetbody_;
mju_copy4(alt_.axisangle, alt.axisangle);
mju_copy(alt_.xyaxes, alt.xyaxes, 6);
mju_copy3(alt_.zaxis, alt.zaxis);
mju_copy3(alt_.euler, alt.euler);
}
@@ -2534,7 +2515,7 @@ void mjCCamera::Compile(void) {
userdata_.resize(model->nuser_cam);
// process orientation specifications
const char* err = alt_.Set(quat, model->degree, model->euler);
const char* err = ResolveOrientation(quat, model->degree, model->euler, alt);
if (err) {
throw mjCError(this, "orientation specification error '%s' in camera %d", err, id);
}
+4 -17
View File
@@ -30,7 +30,6 @@
// forward declarations of all mjC/X classes
class mjCError;
class mjCAlternative;
class mjCBase;
class mjCBody;
class mjCFrame;
@@ -82,13 +81,10 @@ class [[nodiscard]] mjCError {
// alternative specifications of frame orientation
class mjCAlternative : public mjsOrientation {
public:
mjCAlternative(); // constuctor
const char* Set(double* quat, // set frame quat
bool degree, // angle format: degree/radian
const char* sequence); // euler sequence format: "xyz"
};
const char* ResolveOrientation(double* quat, // set frame quat
bool degree, // angle format: degree/radian
const char* sequence, // euler sequence format: "xyz"
const mjsOrientation& orient);
@@ -223,10 +219,6 @@ class mjCBase : public mjCBase_ {
// Describes a rigid body
class mjCBody_ : public mjCBase {
public:
mjCAlternative alt_;
mjCAlternative ialt_;
protected:
// variables computed by 'Compile' and 'AddXXX'
int parentid; // parent index in global array
@@ -340,7 +332,6 @@ class mjCBody : public mjCBody_, private mjsBody {
class mjCFrame_ : public mjCBase {
protected:
bool compiled; // frame already compiled
mjCAlternative alt_;
};
class mjCFrame : public mjCFrame_, private mjsFrame {
@@ -433,7 +424,6 @@ class mjCGeom_ : public mjCBase {
bool inferinertia; // true if inertia should be computed from geom
protected:
mjCAlternative alt_;
bool visual_; // true: geom does not collide and is unreferenced
int matid; // id of geom's material
mjCMesh* mesh; // geom's mesh
@@ -513,8 +503,6 @@ class mjCGeom : public mjCGeom_, private mjsGeom {
class mjCSite_ : public mjCBase {
protected:
mjCAlternative alt_;
// variable-size data
std::string material_;
std::vector<double> userdata_;
@@ -565,7 +553,6 @@ class mjCCamera_ : public mjCBase {
protected:
mjCBody* body; // camera's body
int targetbodyid; // id of target body; -1: none
mjCAlternative alt_;
std::string targetbody_;
std::string spec_targetbody_;
std::vector<double> userdata_;
+3 -3
View File
@@ -20,7 +20,6 @@
#include <mujoco/mjmodel.h>
#include "user/user_api.h"
#include "user/user_objects.h"
#include "user/user_util.h"
#include "xml/xml_native_reader.h"
#include "xml/xml_urdf.h"
@@ -633,9 +632,10 @@ void mjXURDF::Origin(XMLElement* origin_elem, double* pos, double* quat) {
ReadAttr(temp, "xyz", 3, pos, text);
// orientation
mjCAlternative alt;
mjsOrientation alt;
mjs_defaultOrientation(alt);
if (ReadAttr(temp, "rpy", 3, alt.euler, text)) {
alt.Set(quat, 0, "XYZ");
mjs_resolveOrientation(quat, 0, "XYZ", &alt);
}
}
}