Initialize a flexcomp object in PyMJCF
@quagla y travaille déjà.
Depuis le 8/1/2024.
Évaluation
Cette issue n'a pas encore été évaluée.
Description
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.
- Langage dominant
- Python
- Étoiles
- 4.7k
- Forks
- 765
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de google-deepmind/dm_control
-
Difficulté 3/5 1-2 jours Accessibilité débutants 76/100
google-deepmind/dm_control#552 ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
google-deepmind/dm_control#540 · 1 commentaire ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
google-deepmind/dm_control#537 · 1 commentaire ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
google-deepmind/dm_control#529 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
google-deepmind/dm_control#527 · 1 commentaire ·
Toutes les issues de google-deepmind/dm_control
Issues similaires
-
agent-ready documentation needs-triage
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
-
documentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
-
Add https://search.jeremyh.xyz/ Ouverteinstance instance add
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
searxng/searx-instances#939 · 1 commentaire ·
-
area-deployment area-integrations triage:bot-seen
Difficulté 2/5 Une demi-journée Accessibilité débutants 86/100