Rename detach_default and detach_body to delete in the mjSpec bindings.
PiperOrigin-RevId: 773674361 Change-Id: I3977060e19e9ff0afc65ad91693c017958576b78
This commit is contained in:
committed by
Copybara-Service
parent
e23b39fbfa
commit
a2acd2d4ed
+4
-5
@@ -603,11 +603,10 @@ Lists of all elements in a spec can be accessed using named properties, using th
|
||||
|
||||
Element removal
|
||||
^^^^^^^^^^^^^^^
|
||||
For elements that can have children (bodies and defaults), the methods ``spec.detach_body(body)`` and
|
||||
``spec.detach_default(def)`` remove, respectively, ``body`` and ``def`` from the spec, together with all of their
|
||||
children. When detaching body subtrees, all elements which reference elements in the subtree, will also be removed. For
|
||||
all other elements, the method ``delete()`` removes the corresponding element from the spec, e.g.
|
||||
``spec.delete(spec.geom('my_geom'))`` will remove the geom named "my_geom" and all of the elements that reference it.
|
||||
The method ``delete()`` removes the corresponding element from the spec, e.g. ``spec.delete(spec.geom('my_geom'))`` will
|
||||
remove the geom named "my_geom" and all of the elements that reference it. For elements that can have children (bodies
|
||||
and defaults), ``delete`` removes also all of their children. When detaching body subtrees, all elements which reference
|
||||
elements in the subtree, will also be removed.
|
||||
|
||||
Tree traversal
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
+4
-4
@@ -1827,7 +1827,7 @@
|
||||
"\n",
|
||||
"# Remove all bodies in the list from the spec\n",
|
||||
"for body in delete_list:\n",
|
||||
" spec.detach_body(body)\n",
|
||||
" spec.delete(body)\n",
|
||||
"\n",
|
||||
"# # Add another humanoid\n",
|
||||
"spec_humanoid = mj.MjSpec.from_file(humanoid_file)\n",
|
||||
@@ -1900,8 +1900,8 @@
|
||||
"shoulder_right = torso.add_frame(pos=arm_right.pos)\n",
|
||||
"\n",
|
||||
"# Remove the arms\n",
|
||||
"spec.detach_body(arm_left)\n",
|
||||
"spec.detach_body(arm_right)\n",
|
||||
"spec.delete(arm_left)\n",
|
||||
"spec.delete(arm_right)\n",
|
||||
"\n",
|
||||
"# Add new legs\n",
|
||||
"shoulder_left.attach_body(leg_left, 'shoulder', 'left')\n",
|
||||
@@ -1942,7 +1942,7 @@
|
||||
"arm_right = spec.body('upper_arm_right')\n",
|
||||
"torso = spec.body('torso')\n",
|
||||
"shoulder_right = torso.add_frame(pos=arm_right.pos, quat=[0, 0.8509035, 0, 0.525322])\n",
|
||||
"spec.detach_body(arm_right)\n",
|
||||
"spec.delete(arm_right)\n",
|
||||
"\n",
|
||||
"# Attach Franka arm to humanoid\n",
|
||||
"franka_arm = franka.body('fr3_link2')\n",
|
||||
|
||||
@@ -396,7 +396,7 @@ PYBIND11_MODULE(_specs, m) {
|
||||
return mjs_addDefault(spec->ptr, classname.c_str(), parent);
|
||||
},
|
||||
py::return_value_policy::reference_internal);
|
||||
mjSpec.def("detach_default", [](MjSpec& self, raw::MjsDefault& def) {
|
||||
mjSpec.def("delete", [](MjSpec& self, raw::MjsDefault& def) {
|
||||
if (mjs_delete(self.ptr, def.element) != 0) {
|
||||
throw pybind11::value_error(mjs_getError(self.ptr));
|
||||
}
|
||||
@@ -407,7 +407,7 @@ PYBIND11_MODULE(_specs, m) {
|
||||
return mjs_getSpecDefault(self.ptr);
|
||||
},
|
||||
py::return_value_policy::reference_internal);
|
||||
mjSpec.def("detach_body", [](MjSpec& self, raw::MjsBody& body) {
|
||||
mjSpec.def("delete", [](MjSpec& self, raw::MjsBody& body) {
|
||||
mjs_delete(self.ptr, body.element);
|
||||
});
|
||||
mjSpec.def(
|
||||
|
||||
@@ -604,7 +604,7 @@ class SpecsTest(absltest.TestCase):
|
||||
|
||||
# test delete default
|
||||
def1 = spec.find_default('def1')
|
||||
spec.detach_default(def1)
|
||||
spec.delete(def1)
|
||||
def1 = spec.find_default('def1')
|
||||
self.assertIsNone(def1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user