Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manipulating Individual Joint Stiffness of a Elastic Cable #1678

Closed
lololchen opened this issue May 19, 2024 · 1 comment
Closed

Manipulating Individual Joint Stiffness of a Elastic Cable #1678

lololchen opened this issue May 19, 2024 · 1 comment
Assignees
Labels
question Request for help or information

Comments

@lololchen
Copy link

lololchen commented May 19, 2024

Hi, I'm a student trying to use elasticity plugin to simulate the melting deformation of polymer material.

Goal: Change Each Joint Stiffness Individually at Runtime
In order to model the time-varying material properties (softening -> solidification), I'm aiming to manipulate the individual joint stiffness of a composite cable generated by the elasticity plugin. My initial attempts are inspired by this issue: Combining Composites · Issue #1226

image

Trial 1: Move Plugin into Bodies
In the first trial, I moved the plugin into each body based on the hint from Issue #1226. I was hoping that I could manipulate each "elasticity joint" individually. Unfortunately, none of the plugins in the bodies seem to be working properly (middle of the diagram).

minimal XML
<mujoco model="Cable">
  <compiler angle="radian" meshdir="asset/" texturedir="asset/"/>
  <size memory="2M"/>
  <visual>
    <global elevation="-30"/>
    <map stiffness="700" fogstart="1" fogend="15" zfar="40" haze="1" shadowscale="0.5"/>
    <rgba haze="0.15 0.25 0.35 1"/>
  </visual>
  <statistic meansize="0.05" extent="1" center="0 0 0.3"/>
  <extension>
    <plugin plugin="mujoco.elasticity.cable">
      <!--instance name="composite">
        <config key="twist" value="1e7"/>
        <config key="bend" value="1e7"/>
        <config key="vmax" value="2"/>
      </instance-->
    </plugin>
  </extension>
  <custom>
    <text name="composite_" data="rope_"/>
  </custom>
  <asset>
    <texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072"/>
    <texture type="2d" name="texplane" builtin="checker" mark="cross" rgb1="0.2 0.3 0.4" rgb2="0.1 0.15 0.2" markrgb="0.8 0.8 0.8" width="512" height="512"/>
    <material name="matplane" texture="texplane" texuniform="true" texrepeat="10 10" reflectance="0.3"/>
  </asset>
  <worldbody>
    <geom name="ground" size="0 0 1" type="plane" condim="1" material="matplane"/>
    <light pos="0 0 2" dir="0 0 -1" castshadow="false" diffuse="0.4 0.4 0.4" specular="0.1 0.1 0.1"/>
    <light pos="0 0 4" dir="0 0 -1" directional="true" diffuse="0.8 0.8 0.8" specular="0.2 0.2 0.2"/>
    <body name="B_first" pos="0 0 0.6">
      <geom name="G0" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.72603 1 1"/>
      <site name="S_first" pos="0 0 0" group="3"/>
      <plugin plugin="mujoco.elasticity.cable"> <!-- move plugin into every bodies -->
        <config key="twist" value="1e7"/>
        <config key="bend" value="1e7"/>
        <config key="vmax" value="2"/>
      </plugin>
      <body name="B_1" pos="0.1 0 0">
        <joint name="J_1" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
        <geom name="G1" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.528786 1 1"/>
        <plugin plugin="mujoco.elasticity.cable">
          <config key="twist" value="1e7"/>
          <config key="bend" value="1e7"/>
          <config key="vmax" value="2"/>
        </plugin>
        <body name="B_2" pos="0.1 0 0">
          <joint name="J_2" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
          <geom name="G2" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.173589 1 1"/>
          <plugin plugin="mujoco.elasticity.cable">
            <config key="twist" value="1e7"/>
            <config key="bend" value="1e7"/>
            <config key="vmax" value="2"/>
          </plugin>
          <body name="B_3" pos="0.1 0 0">
            <joint name="J_3" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
            <geom name="G3" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.103106 1 1"/>
            <plugin plugin="mujoco.elasticity.cable">
              <config key="twist" value="1e7"/>
              <config key="bend" value="1e7"/>
              <config key="vmax" value="2"/>
            </plugin>
            <body name="B_4" pos="0.1 0 0">
              <joint name="J_4" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
              <geom name="G4" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.301404 1 1"/>
              <plugin plugin="mujoco.elasticity.cable">
                <config key="twist" value="1e8"/>
                <config key="bend" value="1e8"/>
                <config key="vmax" value="2"/>
              </plugin>
              <body name="B_5" pos="0.1 0 0">
                <joint name="J_5" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                <geom name="G5" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.421312 1 1"/>
                <plugin plugin="mujoco.elasticity.cable">
                  <config key="twist" value="1e8"/>
                  <config key="bend" value="1e8"/>
                  <config key="vmax" value="2"/>
                </plugin>
                <body name="B_6" pos="0.1 0 0">
                  <joint name="J_6" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                  <geom name="G6" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.46278 1 1"/>
                  <plugin plugin="mujoco.elasticity.cable">
                    <config key="twist" value="1e8"/>
                    <config key="bend" value="1e8"/>
                    <config key="vmax" value="2"/>
                  </plugin>
                  <body name="B_7" pos="0.1 0 0">
                    <joint name="J_7" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                    <geom name="G7" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.42578 1 1"/>
                    <plugin plugin="mujoco.elasticity.cable">
                      <config key="twist" value="1e8"/>
                      <config key="bend" value="1e8"/>
                      <config key="vmax" value="2"/>
                    </plugin>
                    <body name="B_8" pos="0.1 0 0">
                      <joint name="J_8" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                      <geom name="G8" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.310339 1 1"/>
                      <plugin plugin="mujoco.elasticity.cable">
                        <config key="twist" value="1e8"/>
                        <config key="bend" value="1e8"/>
                        <config key="vmax" value="2"/>
                      </plugin>
                      <body name="B_last" pos="0.1 0 0">
                        <joint name="J_last" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                        <geom name="G9" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.233015 1 1"/>
                        <site name="S_last" pos="0.1 0 0" group="3"/>
                        <plugin plugin="mujoco.elasticity.cable">
                          <config key="twist" value="1e8"/>
                          <config key="bend" value="1e8"/>
                          <config key="vmax" value="2"/>
                        </plugin>
                      </body>
                    </body>
                  </body>
                </body>
              </body>
            </body>
          </body>
        </body>
      </body>
    </body>
    <body name="slider" pos="1 0 0.6">
      <joint pos="0 0 0" axis="1 0 0" type="slide" damping="0.1"/>
      <geom size="0.01"/>
    </body>
  </worldbody>

<!-- for complete code pls refer to the file -->  

</mujoco>

Trial 2: Create Multiple Instances
As a workaround, I tried to create multiple instances of the plugin. In this example, two instances are implemented to create two sections of cable with different mechanical properties. Within each section, the model seems to work with proper stiffness. However, at the transition between the sections of the cable, the elasticity plugin seems to be deactivated and this joint is too soft (right side of the diagram).

minimal XML
<mujoco model="Cable">
  <compiler angle="radian" meshdir="asset/" texturedir="asset/"/>
  <size memory="2M"/>
  <visual>
    <global elevation="-30"/>
    <map stiffness="700" fogstart="1" fogend="15" zfar="40" haze="1" shadowscale="0.5"/>
    <rgba haze="0.15 0.25 0.35 1"/>
  </visual>
  <statistic meansize="0.05" extent="1" center="0 0 0.3"/>
  <extension>
    <plugin plugin="mujoco.elasticity.cable">
      <instance name="composite_soft"> <!-- 1st instance -->
        <config key="twist" value="1e7"/>
        <config key="bend" value="1e7"/>
        <config key="vmax" value="2"/>
      </instance>
      <instance name="composite_stiff"> <!-- 2nd instance -->
        <config key="twist" value="1e8"/>
        <config key="bend" value="1e8"/>
        <config key="vmax" value="2"/>
      </instance>
    </plugin>
  </extension>
  <custom>
    <text name="composite_" data="rope_"/>
  </custom>
  <asset>
    <texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072"/>
    <texture type="2d" name="texplane" builtin="checker" mark="cross" rgb1="0.2 0.3 0.4" rgb2="0.1 0.15 0.2" markrgb="0.8 0.8 0.8" width="512" height="512"/>
    <material name="matplane" texture="texplane" texuniform="true" texrepeat="10 10" reflectance="0.3"/>
  </asset>
  <worldbody>
    <geom name="ground" size="0 0 1" type="plane" condim="1" material="matplane"/>
    <light pos="0 0 2" dir="0 0 -1" castshadow="false" diffuse="0.4 0.4 0.4" specular="0.1 0.1 0.1"/>
    <light pos="0 0 4" dir="0 0 -1" directional="true" diffuse="0.8 0.8 0.8" specular="0.2 0.2 0.2"/>
    <body name="B_first" pos="0 0 0.6">
      <geom name="G0" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.72603 1 1"/>
      <site name="S_first" pos="0 0 0" group="3"/>
      <plugin instance="composite_soft"/>
      <body name="B_1" pos="0.1 0 0">
        <joint name="J_1" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
        <geom name="G1" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.528786 1 1"/>
        <plugin instance="composite_soft"/>
        <body name="B_2" pos="0.1 0 0">
          <joint name="J_2" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
          <geom name="G2" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.173589 1 1"/>
          <plugin instance="composite_soft"/>
          <body name="B_3" pos="0.1 0 0">
            <joint name="J_3" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
            <geom name="G3" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.103106 1 1"/>
            <plugin instance="composite_soft"/>
            <body name="B_4" pos="0.1 0 0">
              <joint name="J_4" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
              <geom name="G4" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.301404 1 1"/>
              <plugin instance="composite_stiff"/>
              <body name="B_5" pos="0.1 0 0">
                <joint name="J_5" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                <geom name="G5" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.421312 1 1"/>
                <plugin instance="composite_stiff"/>
                <body name="B_6" pos="0.1 0 0">
                  <joint name="J_6" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                  <geom name="G6" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.46278 1 1"/>
                  <plugin instance="composite_stiff"/>
                  <body name="B_7" pos="0.1 0 0">
                    <joint name="J_7" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                    <geom name="G7" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.42578 1 1"/>
                    <plugin instance="composite_stiff"/>
                    <body name="B_8" pos="0.1 0 0">
                      <joint name="J_8" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                      <geom name="G8" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.310339 1 1"/>
                      <plugin instance="composite_stiff"/>
                      <body name="B_last" pos="0.1 0 0">
                        <joint name="J_last" pos="0 0 0" type="ball" group="3" actuatorfrclimited="false" armature="0.001" damping="0.015"/>
                        <geom name="G9" size="0.05 0.01 0.01" pos="0.05 0 0" type="box" condim="1" rgba="0 0.233015 1 1"/>
                        <site name="S_last" pos="0.1 0 0" group="3"/>
                        <plugin instance="composite_stiff"/>
                      </body>
                    </body>
                  </body>
                </body>
              </body>
            </body>
          </body>
        </body>
      </body>
    </body>
    <body name="slider" pos="1 0 0.6">
      <joint pos="0 0 0" axis="1 0 0" type="slide" damping="0.1"/>
      <geom size="0.01"/>
    </body>
  </worldbody>
  
<!-- for complete code pls refer to the file -->  

</mujoco>

Over-inflated in Box Geom
Additionally, when using elasticity.cable with box geom, I noticed that the deformable skin seems to inflate too much and is 200% thick. After loading the model, saving the XML, and then manually reducing the inflate value by half, the visualization looks more correct. Is there a reason why elasticity.cable is coded to inflate like that?

I would be so grateful if anyone could help me understand why these two trials didn't work and provide some helpful hints for an elegant way to manipulate the individual joint stiffness of a composite body. Thanks so much in advance!

cable_issue.zip

@lololchen lololchen added the question Request for help or information label May 19, 2024
@quagla
Copy link
Collaborator

quagla commented May 28, 2024

Hi, I don't see a quick solution that doesn't involve a little custom coding. We already build a stiffness vector that in principle allows for a varying stiffness along the cable, see https://github.com/google-deepmind/mujoco/blob/main/plugin/elasticity/cable.cc#L198 however we populate it with a constant stiffness. You could hard code your desired stiffness in those lines and compile it from source. If you have ideas on how to expose a custom stiffness to the XML, please let us know - or try it yourself and send a pull request :)

For the skin, there is no reason for the default parameters to be like that.

@quagla quagla closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Request for help or information
Projects
None yet
Development

No branches or pull requests

2 participants