Simulate docking process of between robots using the Weld equality #2323
-
IntroHi! I am a graduate student at Beijing Institute of Technology, and I am using MuJoCo to simulate the docking/connecting process between two floating robots in space, using the weld equality constraint to constrain them together. My setupmujoco3.2.6, Python API, window10 x64 My questionIn my simulation, the weld equality is added during runtime using the add_equality() function with setting 2 sites. Because the moment and configuration of docking may vary, and here says that 'the frames of the two sites will be aligned by the constraint, regardless of their position in the default configuration'. So, my question is:
Minimal model and/or code that explain my questionModel: minimal XML<mujoco model="simple_demo">
<option timestep="0.0001"/>
<option gravity="0 0 0"/>
<worldbody>
<light name="light" pos="0 0 10"/>
<body name="obj_1" pos="0 0 0" euler="0 90 0">
<joint name="free_1" type="free"/>
<geom name="capsule_1_1" type="capsule" size="0.05 0.3" mass="0.2" rgba="1 0 0 1"/>
<body name="interface_1" pos="0 0 0.5">
<joint name="joint_1" type="hinge" axis="0 1 0" pos="0 0 -0.15"/>
<geom name="capsule_1_2" type="capsule" size="0.05 0.1" mass="0.1" rgba="1 0 0 1"/>
<site name="site_1" quat="1 0 0 0"/>
</body>
</body>
<body name="obj_2" pos="1.3 0 0" euler="0 -90 0">
<joint name="free_2" type="free"/>
<geom name="capsule_2_1" type="capsule" size="0.05 0.3" mass="0.2" rgba="1 1 0 1"/>
<body name="interface_2" pos="0 0 0.5">
<joint name="joint_2" type="hinge" axis="0 1 0" pos="0 0 -0.15"/>
<geom name="capsule_2_2" type="capsule" size="0.05 0.1" mass="0.1" rgba="1 1 0 1"/>
<site name="site_2" quat="1 0 0 0"/>
</body>
</body>
</worldbody>
<actuator>
<position name="motor_1" joint="joint_1"/>
<position name="motor_2" joint="joint_2"/>
</actuator>
<equality>
<!-- <weld name="connection_12" body1="interface_1" body2="interface_2"/>-->
</equality>
</mujoco>
Code: import mujoco
import mujoco.viewer
from math import pi
with open('simple_demo.xml', 'r') as f:
xml = f.read()
model = mujoco.MjModel.from_xml_string(xml)
data = mujoco.MjData(model)
spec = mujoco.MjSpec.from_string(xml)
delta = 0.00001
with mujoco.viewer.launch_passive(model, data) as viewer:
viewer.sync()
while viewer.is_running():
if data.time > 20:
idx = [index for index, obj in enumerate(spec.equalities) if obj.name == 'connection_12']
if len(idx) == 0:
# spec.add_equality(name='connection_12', type=mujoco.mjtEq.mjEQ_WELD, objtype=mujoco.mjtObj.mjOBJ_SITE,
# name1='site_1', name2='site_2')
spec.add_equality(name='connection_12', type=mujoco.mjtEq.mjEQ_WELD, objtype=mujoco.mjtObj.mjOBJ_SITE,
name1='site_1', name2='site_2',
solimp=[0.9, 0.99, 1e-6, 0.9, 6], solref=[0.0001, 1e6]) # tuned parameter
model = spec.compile()
if data.actuator('motor_1').ctrl < pi/2:
data.actuator('motor_1').ctrl += delta
mujoco.mj_step(model, data)
viewer.sync() Confirmations
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
When loading just your XML in I think the issue might be that adding the weld via MjSpec does not calculate the offsets to satisfy the constraint at q0, while the MJCF compiler does. If you do want to dynamically add the weld via MjSpec, you might need to calculate and set the relevant |
Beta Was this translation helpful? Give feedback.
-
I don't think you sites are aligned properly, the frames are rotated. Do you know that you can visualize site frames? It's covered in the simulate tutorial video. |
Beta Was this translation helpful? Give feedback.
-
Build weld joint using sites assuming these two site are overlapping. It would be better using bodies two define weld joint and define their relative pose in |
Beta Was this translation helpful? Give feedback.
Build weld joint using sites assuming these two site are overlapping. It would be better using bodies two define weld joint and define their relative pose in
eq_data
.