Move mjCWrap type to mjsWrap.
PiperOrigin-RevId: 821851540 Change-Id: I53382a8a21312a96aea46eec130f43e7cad70f92
This commit is contained in:
committed by
Copybara-Service
parent
88ac02dad3
commit
59f14485e0
@@ -120,7 +120,7 @@ bool IsNullPose(const T pos[3], const T quat[4]) {
|
||||
// get body id from wrap object
|
||||
int GetBodyIdFromWrap(const mjCWrap* wrap) {
|
||||
if (!wrap || !wrap->obj) return -1;
|
||||
switch (wrap->type) {
|
||||
switch (wrap->Type()) {
|
||||
case mjWRAP_SITE:
|
||||
return static_cast<mjCSite*>(wrap->obj)->Body()->id;
|
||||
case mjWRAP_CYLINDER:
|
||||
@@ -3606,10 +3606,10 @@ void mjCModel::CopyObjects(mjModel* m) {
|
||||
|
||||
// set wraps
|
||||
for (int j=0; j < (int)pte->path.size(); j++) {
|
||||
m->wrap_type[adr+j] = pte->path[j]->type;
|
||||
m->wrap_type[adr+j] = pte->path[j]->Type();
|
||||
m->wrap_objid[adr+j] = pte->path[j]->obj ? pte->path[j]->obj->id : -1;
|
||||
m->wrap_prm[adr+j] = (mjtNum)pte->path[j]->prm;
|
||||
if (pte->path[j]->type == mjWRAP_SPHERE || pte->path[j]->type == mjWRAP_CYLINDER) {
|
||||
if (pte->path[j]->Type() == mjWRAP_SPHERE || pte->path[j]->Type() == mjWRAP_CYLINDER) {
|
||||
m->wrap_prm[adr+j] = (mjtNum)pte->path[j]->sideid;
|
||||
}
|
||||
}
|
||||
|
||||
+30
-20
@@ -6138,8 +6138,8 @@ void mjCTendon::CopyFromSpec() {
|
||||
|
||||
// clear precompiled
|
||||
for (int i=0; i < path.size(); i++) {
|
||||
if (path[i]->type == mjWRAP_CYLINDER) {
|
||||
path[i]->type = mjWRAP_SPHERE;
|
||||
if (path[i]->Type() == mjWRAP_CYLINDER) {
|
||||
path[i]->spec.type = mjWRAP_SPHERE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6175,7 +6175,7 @@ void mjCTendon::WrapSite(std::string wrapname, std::string_view wrapinfo) {
|
||||
wrap->info = wrapinfo;
|
||||
|
||||
// set parameters, add to path
|
||||
wrap->type = mjWRAP_SITE;
|
||||
wrap->spec.type = mjWRAP_SITE;
|
||||
wrap->name = wrapname;
|
||||
wrap->id = (int)path.size();
|
||||
path.push_back(wrap);
|
||||
@@ -6190,7 +6190,7 @@ void mjCTendon::WrapGeom(std::string wrapname, std::string sidesite, std::string
|
||||
wrap->info = wrapinfo;
|
||||
|
||||
// set parameters, add to path
|
||||
wrap->type = mjWRAP_SPHERE; // replace with cylinder later if needed
|
||||
wrap->spec.type = mjWRAP_SPHERE; // replace with cylinder later if needed
|
||||
wrap->name = wrapname;
|
||||
wrap->sidesite = sidesite;
|
||||
wrap->id = (int)path.size();
|
||||
@@ -6206,7 +6206,7 @@ void mjCTendon::WrapJoint(std::string wrapname, double coef, std::string_view wr
|
||||
wrap->info = wrapinfo;
|
||||
|
||||
// set parameters, add to path
|
||||
wrap->type = mjWRAP_JOINT;
|
||||
wrap->spec.type = mjWRAP_JOINT;
|
||||
wrap->name = wrapname;
|
||||
wrap->prm = coef;
|
||||
wrap->id = (int)path.size();
|
||||
@@ -6222,7 +6222,7 @@ void mjCTendon::WrapPulley(double divisor, std::string_view wrapinfo) {
|
||||
wrap->info = wrapinfo;
|
||||
|
||||
// set parameters, add to path
|
||||
wrap->type = mjWRAP_PULLEY;
|
||||
wrap->spec.type = mjWRAP_PULLEY;
|
||||
wrap->prm = divisor;
|
||||
wrap->id = (int)path.size();
|
||||
path.push_back(wrap);
|
||||
@@ -6253,7 +6253,7 @@ void mjCTendon::ResolveReferences(const mjCModel* m) {
|
||||
for (int i=0; i < path.size(); i++) {
|
||||
std::string pname = path[i]->name;
|
||||
std::string psidesite = path[i]->sidesite;
|
||||
if (path[i]->type == mjWRAP_PULLEY) {
|
||||
if (path[i]->Type() == mjWRAP_PULLEY) {
|
||||
npulley++;
|
||||
}
|
||||
try {
|
||||
@@ -6280,6 +6280,11 @@ void mjCTendon::ResolveReferences(const mjCModel* m) {
|
||||
|
||||
// compiler
|
||||
void mjCTendon::Compile(void) {
|
||||
// compile all wraps in the path
|
||||
for (mjCWrap* wrap : path) {
|
||||
wrap->Compile();
|
||||
}
|
||||
|
||||
CopyFromSpec();
|
||||
|
||||
// resize userdata
|
||||
@@ -6297,7 +6302,7 @@ void mjCTendon::Compile(void) {
|
||||
}
|
||||
|
||||
// determine type
|
||||
bool spatial = (path[0]->type != mjWRAP_JOINT);
|
||||
bool spatial = (path[0]->Type() != mjWRAP_JOINT);
|
||||
|
||||
// require at least two objects in spatial path
|
||||
if (spatial && sz < 2) {
|
||||
@@ -6318,7 +6323,7 @@ void mjCTendon::Compile(void) {
|
||||
// fixed
|
||||
if (!spatial) {
|
||||
// make sure all objects are joints
|
||||
if (path[i]->type != mjWRAP_JOINT) {
|
||||
if (path[i]->Type() != mjWRAP_JOINT) {
|
||||
throw mjCError(this, "tendon '%s' (id = %d): spatial object found in fixed path at pos %d",
|
||||
name.c_str(), id, i);
|
||||
}
|
||||
@@ -6332,10 +6337,10 @@ void mjCTendon::Compile(void) {
|
||||
name.c_str(), id);
|
||||
}
|
||||
|
||||
switch (path[i]->type) {
|
||||
switch (path[i]->Type()) {
|
||||
case mjWRAP_PULLEY:
|
||||
// pulley should not follow other pulley
|
||||
if (i > 0 && path[i-1]->type == mjWRAP_PULLEY) {
|
||||
if (i > 0 && path[i-1]->Type() == mjWRAP_PULLEY) {
|
||||
throw mjCError(this, "tendon '%s' (id = %d): consecutive pulleys (pos %d)",
|
||||
name.c_str(), id, i);
|
||||
}
|
||||
@@ -6348,15 +6353,15 @@ void mjCTendon::Compile(void) {
|
||||
|
||||
case mjWRAP_SITE:
|
||||
// site needs a neighbor that is not a pulley
|
||||
if ((i == 0 || path[i-1]->type == mjWRAP_PULLEY) &&
|
||||
(i == sz-1 || path[i+1]->type == mjWRAP_PULLEY)) {
|
||||
if ((i == 0 || path[i-1]->Type() == mjWRAP_PULLEY) &&
|
||||
(i == sz-1 || path[i+1]->Type() == mjWRAP_PULLEY)) {
|
||||
throw mjCError(this,
|
||||
"tendon '%s' (id = %d): site %d needs a neighbor that is not a pulley",
|
||||
name.c_str(), id, i);
|
||||
}
|
||||
|
||||
// site cannot be repeated
|
||||
if (i < sz-1 && path[i+1]->type == mjWRAP_SITE && path[i]->obj->id == path[i+1]->obj->id) {
|
||||
if (i < sz-1 && path[i+1]->Type() == mjWRAP_SITE && path[i]->obj->id == path[i+1]->obj->id) {
|
||||
throw mjCError(this,
|
||||
"tendon '%s' (id = %d): site %d is repeated",
|
||||
name.c_str(), id, i);
|
||||
@@ -6367,7 +6372,7 @@ void mjCTendon::Compile(void) {
|
||||
case mjWRAP_SPHERE:
|
||||
case mjWRAP_CYLINDER:
|
||||
// geom must be bracketed by sites
|
||||
if (i == 0 || i == sz-1 || path[i-1]->type != mjWRAP_SITE || path[i+1]->type != mjWRAP_SITE) {
|
||||
if (i == 0 || i == sz-1 || path[i-1]->Type() != mjWRAP_SITE || path[i+1]->Type() != mjWRAP_SITE) {
|
||||
throw mjCError(this,
|
||||
"tendon '%s' (id = %d): geom at pos %d not bracketed by sites",
|
||||
name.c_str(), id, i);
|
||||
@@ -6442,7 +6447,7 @@ mjCWrap::mjCWrap(mjCModel* _model, mjCTendon* _tendon) {
|
||||
tendon = _tendon;
|
||||
|
||||
// clear variables
|
||||
type = mjWRAP_NONE;
|
||||
spec.type = mjWRAP_NONE;
|
||||
obj = nullptr;
|
||||
sideid = -1;
|
||||
prm = 0;
|
||||
@@ -6450,6 +6455,7 @@ mjCWrap::mjCWrap(mjCModel* _model, mjCTendon* _tendon) {
|
||||
|
||||
// point to local
|
||||
PointToLocal();
|
||||
CopyFromSpec();
|
||||
}
|
||||
|
||||
|
||||
@@ -6478,7 +6484,9 @@ void mjCWrap::PointToLocal() {
|
||||
spec.info = &info;
|
||||
}
|
||||
|
||||
|
||||
void mjCWrap::CopyFromSpec() {
|
||||
*static_cast<mjsWrap*>(this) = spec;
|
||||
}
|
||||
|
||||
void mjCWrap::NameSpace(const mjCModel* m) {
|
||||
name = m->prefix + name + m->suffix;
|
||||
@@ -6487,13 +6495,15 @@ void mjCWrap::NameSpace(const mjCModel* m) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mjCWrap::Compile(void) {
|
||||
CopyFromSpec();
|
||||
}
|
||||
|
||||
void mjCWrap::ResolveReferences(const mjCModel* m) {
|
||||
mjCBase *pside;
|
||||
|
||||
// handle wrap object types
|
||||
switch (type) {
|
||||
switch (spec.type) {
|
||||
case mjWRAP_JOINT: // joint
|
||||
// find joint by name
|
||||
obj = m->FindObject(mjOBJ_JOINT, name);
|
||||
@@ -6516,7 +6526,7 @@ void mjCWrap::ResolveReferences(const mjCModel* m) {
|
||||
|
||||
// set/check geom type
|
||||
if (((mjCGeom*)obj)->type == mjGEOM_CYLINDER) {
|
||||
type = mjWRAP_CYLINDER;
|
||||
spec.type = mjWRAP_CYLINDER;
|
||||
} else if (((mjCGeom*)obj)->type != mjGEOM_SPHERE) {
|
||||
throw mjCError(this,
|
||||
"geom '%s' in tendon %d, wrap %d is not sphere or cylinder",
|
||||
|
||||
@@ -1705,7 +1705,6 @@ class mjCTendon : public mjCTendon_, private mjsTendon {
|
||||
|
||||
class mjCWrap_ : public mjCBase {
|
||||
public:
|
||||
mjtWrap type; // wrap object type
|
||||
int sideid; // side site id; -1 if not applicable
|
||||
double prm; // parameter: divisor, coefficient
|
||||
std::string sidesite; // name of side site
|
||||
@@ -1719,9 +1718,11 @@ class mjCWrap : public mjCWrap_, private mjsWrap {
|
||||
mjsWrap spec;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec();
|
||||
void PointToLocal();
|
||||
void ResolveReferences(const mjCModel* m);
|
||||
void NameSpace(const mjCModel* m);
|
||||
mjtWrap Type() const { return spec.type; }
|
||||
|
||||
mjCBase* obj; // wrap object pointer
|
||||
|
||||
@@ -1730,6 +1731,8 @@ class mjCWrap : public mjCWrap_, private mjsWrap {
|
||||
mjCWrap(const mjCWrap& other); // copy constructor
|
||||
mjCWrap& operator=(const mjCWrap& other); // copy assignment
|
||||
|
||||
void Compile(void); // compiler
|
||||
|
||||
mjCTendon* tendon; // tendon owning this wrap
|
||||
};
|
||||
|
||||
|
||||
@@ -715,7 +715,7 @@ void mjXWriter::OneEquality(XMLElement* elem, const mjCEquality* equality, mjCDe
|
||||
|
||||
// write tendon
|
||||
void mjXWriter::OneTendon(XMLElement* elem, const mjCTendon* tendon, mjCDef* def) {
|
||||
bool fixed = (tendon->GetWrap(0) && tendon->GetWrap(0)->type == mjWRAP_JOINT);
|
||||
bool fixed = (tendon->GetWrap(0) && tendon->GetWrap(0)->Type() == mjWRAP_JOINT);
|
||||
|
||||
// regular
|
||||
if (!writingdefaults) {
|
||||
@@ -1886,14 +1886,14 @@ void mjXWriter::Tendon(XMLElement* root) {
|
||||
continue;
|
||||
}
|
||||
XMLElement* elem = InsertEnd(section,
|
||||
tendon->GetWrap(0)->type == mjWRAP_JOINT ? "fixed" : "spatial");
|
||||
tendon->GetWrap(0)->Type() == mjWRAP_JOINT ? "fixed" : "spatial");
|
||||
OneTendon(elem, tendon, model->def_map[tendon->classname]);
|
||||
|
||||
// write wraps
|
||||
XMLElement* wrapelem;
|
||||
for (int j=0; j < tendon->NumWraps(); j++) {
|
||||
const mjCWrap* wrap = tendon->GetWrap(j);
|
||||
switch (wrap->type) {
|
||||
switch (wrap->Type()) {
|
||||
case mjWRAP_JOINT:
|
||||
wrapelem = InsertEnd(elem, "joint");
|
||||
WriteAttrTxt(wrapelem, "joint", wrap->obj->name);
|
||||
|
||||
Reference in New Issue
Block a user