Initialize a flexcomp object in PyMJCF
@quagla arbeitet bereits daran.
Seit 08.1.2024.
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
Mujoco 3.0 introduced flexcomp object for modelling deformable obejcts.
However trying to create a Prop using
class Cloth(prop.Prop):
"""Simple cloth prop that consists of a MuJoco flexcomp."""
def _build(self, *args, **kwargs):
del args, kwargs
mjcf_root = mjcf.RootElement()
mjcf_root.extension.add('plugin', plugin="mujoco.elasticity.shell")
# Props need to contain a body called prop_root
mjcf_root.worldbody.add('body', name='prop_root')
cloth_object = mjcf.from_file('cloth.xml')
mjcf_root.attach(cloth_object)
super()._build('cloth', mjcf_root)
Errors out as flexcomp is not recoginzed as part of schema.
I modified schema.xml(which is part of mjcf under dm_control) and after adding all the tags and attibutes that I am using in an xml such as below
<mujoco model="cloth">
<extension>
<plugin plugin="mujoco.elasticity.shell"/>
</extension>
<worldbody>
<body name="cloth">
<flexcomp type="grid" count="10 5 1" spacing=".025 .025 .025" mass="0.1"
name="cloth" radius="0.001">
<contact condim="6" solref="0.001"/>
<edge equality="true" damping="0.1"/>
<plugin plugin="mujoco.elasticity.shell">
<config key="poisson" value="0"/>
<config key="thickness" value="10e-3"/>
<!--Units are in Pa (SI)-->
<config key="young" value="3e4"/>
</plugin>
</flexcomp>
</body>
</worldbody>
</mujoco>
I can get the xml to be parsed and get a Prop object. I looked at composite as an example and copied over the spec as described in mujoco XML reference.
However I cannot get the simulation to run and it fails at this line self._qp_mapper = _CartesianVelocityMapper(qp_params) in dm_robotics/moma/effectors/cartesian_6d_velocity_effector.py. The error is Process finished with exit code 139 (interrupted by signal 11:SIGSEGV) which just sounds like it crashed
I cannot understand why. The whole file which I am running is
"""Minimal working example of the dm_robotics Panda model."""
import dm_env
import numpy as np
from dm_env import specs
from dm_robotics.panda import environment
from dm_robotics.panda import parameters as params
from dm_robotics.panda import run_loop, utils
from dm_robotics.panda import arm_constants
import math
from dm_control import mjcf
from dm_robotics.moma import entity_initializer, prop
from dm_control.composer.variation import distributions, rotations
class Ball(prop.Prop):
"""Simple ball prop that consists of a MuJoco sphere geom."""
def _build(self, *args, **kwargs):
del args, kwargs
mjcf_root = mjcf.RootElement()
# Props need to contain a body called prop_root
body = mjcf_root.worldbody.add('body', name='prop_root')
body.add('geom',
type='sphere',
size=[0.04],
solref=[0.01, 0.5],
mass=1,
rgba=(1, 0, 0, 1))
super()._build('ball', mjcf_root)
class Cloth(prop.Prop):
"""Simple cloth prop that consists of a MuJoco flexcomp."""
def _build(self, *args, **kwargs):
del args, kwargs
mjcf_root = mjcf.RootElement()
mjcf_root.extension.add('plugin', plugin="mujoco.elasticity.shell")
# Props need to contain a body called prop_root
mjcf_root.worldbody.add('body', name='prop_root')
cloth_object = mjcf.from_file('cloth.xml')
mjcf_root.attach(cloth_object)
super()._build('cloth', mjcf_root)
class Agent:
"""The agent produces a trajectory tracing the path of an eight
in the x/y control frame of the robot using end-effector velocities.
"""
def __init__(self, spec: specs.BoundedArray) -> None:
self._spec = spec
def step(self, timestep: dm_env.TimeStep) -> np.ndarray:
"""Computes velocities in the x/y plane parameterized in time."""
time = timestep.observation['time'][0]
r = 0.1
vel_x = r * math.cos(time) # Derivative of x = sin(t)
vel_y = r * ((math.cos(time) * math.cos(time)) -
(math.sin(time) * math.sin(time)))
action = np.zeros(shape=self._spec.shape, dtype=self._spec.dtype)
# The action space of the Cartesian 6D effector corresponds
# to the linear and angular velocities in x, y and z directions
# respectively
action[0] = vel_x
action[1] = vel_y
return action
if __name__ == '__main__':
# We initialize the default configuration for logging
# and argument parsing. These steps are optional.
utils.init_logging()
parser = utils.default_arg_parser()
args = parser.parse_args()
# Use RobotParams to customize Panda robots added to the environment.
robot_params = params.RobotParams(robot_ip=args.robot_ip, actuation=arm_constants.Actuation.CARTESIAN_VELOCITY)
panda_env = environment.PandaEnvironment(robot_params)
ball = Ball()
cloth = Cloth()
props = [ball, cloth]
panda_env.add_props(props)
initialize_props = entity_initializer.prop_initializer.PropPlacer(
props,
position=distributions.Uniform(-.5, .5),
quaternion=rotations.UniformQuaternion())
panda_env.add_entity_initializers([initialize_props])
with panda_env.build_task_environment() as env:
# Print the full action, observation and reward specification
utils.full_spec(env)
# Initialize the agent
agent = Agent(env.action_spec())
# Run the environment and agent either in headless mode or inside the GUI.
if args.gui:
app = utils.ApplicationWithPlot()
app.launch(env, policy=agent.step)
else:
run_loop.run(env, agent, [], max_steps=1000, real_time=True)
Which is just a modification of the basic example in [dm_robotics_panda] (https://github.com/JeanElsner/dm_robotics_panda)
Commenting out creating of Cloth and adding to props list works fine.
- Vorherrschende Sprache
- Python
- Sterne
- 4.7k
- Forks
- 765
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus google-deepmind/dm_control
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
google-deepmind/dm_control#552 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
google-deepmind/dm_control#540 · 1 Kommentar ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
google-deepmind/dm_control#537 · 1 Kommentar ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
google-deepmind/dm_control#529 ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
google-deepmind/dm_control#527 · 1 Kommentar ·
Alle Issues in google-deepmind/dm_control
Ähnliche Issues
-
agent-ready documentation needs-triage
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
documentation
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
-
instance instance add
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
searxng/searx-instances#939 · 1 Kommentar ·
-
area-deployment area-integrations triage:bot-seen
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 86/100