Simulation not obeying gravity and collisions #2355
-
IntroHi I am trying to make a model for my robot in Mujoco My setupMujoco Version: 3.2.6 My questionIn my model, I have a robot and a cube. The end goal is to make the robot pick up the cube. I have the cube suspended in the air at the start of the simulation. When it runs the cube does not fall due to gravity it just stays there. When I rotate the robot to try and hit the cube, it also does not move (the cube). I assume this is something simple as this is my first time using Mujoco. I would appreciate any feedback. Minimal model and/or code that explain my question<mujoco model="My Robot">
<!-- Global simulation options -->
<option gravity="0 0 -9.81" />
<default>
<geom type="mesh" xyaxes="1 0 0 0 0 1" contype="1" conaffinity="1" condim="6" margin="1e-3" solref=".01 1" solimp=".99 .99 .01"/>
</default>
<!-- Mesh assets -->
<asset>
<!-- Robot Assets -->
<mesh name="base_arm_mount" file="base_arm_mount.stl" scale="0.001 0.001 0.001"/>
<mesh name="base_plate" file="Base_Plate.stl" scale="0.001 0.001 0.001"/>
<mesh name="base_pole1" file="base_pole1.stl" scale="0.001 0.001 0.001"/>
<mesh name="base_pole2" file="base_pole2.stl" scale="0.001 0.001 0.001"/>
<mesh name="base_pole3" file="base_pole3.stl" scale="0.001 0.001 0.001"/>
<mesh name="base_pole4" file="base_pole4.stl" scale="0.001 0.001 0.001"/>
<mesh name="bottom_plate_connector" file="bottom_plate_connector.stl" scale="0.001 0.001 0.001"/>
<mesh name="bottom_plate" file="bottom_plate.stl" scale="0.001 0.001 0.001"/>
<mesh name="bottom_servo_plate" file="bottom_servo_plate.stl" scale="0.001 0.001 0.001"/>
<mesh name="gripper_bottom_plate" file="gripper_bottom_plate.stl" scale="0.001 0.001 0.001"/>
<mesh name="gripper_pole1" file="gripper_Pole1.stl" scale="0.001 0.001 0.001"/>
<mesh name="gripper_pole2" file="gripper_Pole2.stl" scale="0.001 0.001 0.001"/>
<mesh name="gripper_pole3" file="gripper_Pole3.stl" scale="0.001 0.001 0.001"/>
<mesh name="gripper_pole4" file="gripper_Pole4.stl" scale="0.001 0.001 0.001"/>
<mesh name="gripper_top_plate" file="gripper_top_plate.stl" scale="0.001 0.001 0.001"/>
<mesh name="left_gripper" file="left_gripper.stl" scale="0.001 0.001 0.001"/>
<mesh name="main_arm_bottom_connector" file="main_arm_bottom_connector.stl" scale="0.001 0.001 0.001"/>
<mesh name="main_arm_bottom_rotation" file="main_arm_bottom_rotation.stl" scale="0.001 0.001 0.001"/>
<mesh name="main_arm_p1" file="main_arm_p1.stl" scale="0.001 0.001 0.001"/>
<mesh name="main_arm_p2" file="main_arm_p2.stl" scale="0.001 0.001 0.001"/>
<mesh name="main_arm_p2_gripper_rotation" file="main_arm_p2_gripper_rotation.stl" scale="0.001 0.001 0.001"/>
<mesh name="main_arm_top_rotation" file="main_arm_top_rotation.stl" scale="0.001 0.001 0.001"/>
<mesh name="right_gripper" file="right_gripper.stl" scale="0.001 0.001 0.001"/>
<!-- Cube Assets -->
<mesh name="20mm_cube" file="20mm_cube.stl" scale="0.001 0.001 0.001"/>
<mesh name="10mm_cube" file="10mm_cube.stl" scale="0.001 0.001 0.001"/>
<!-- Checker Flooring -->
<texture name="checker" type="2d" builtin="checker" width="512" height="512" rgb1="0.8 0.8 0.8" rgb2="0.2 0.2 0.2"/>
<material name="checker_mat" texture="checker" texrepeat="5 5" texuniform="true"/>
</asset>
<worldbody>
<light name="top_light" pos="0 0 1" dir="0 0 -1" diffuse="1 1 1" specular="0.1 0.1 0.1"/>
<!-- Custom Camera -->
<camera name="custom_camera" pos="0.252 -0.019 -1.092" xyaxes="0.998 0.056 -0.000 0.056 -0.998 0.017"/>
<!-- Simple ground plane -->
<geom name="floor" type="plane" pos="0 0 0" size="5 5 0.1" material="checker_mat" contype="1" conaffinity="1" />
<!-- Dummy body for fixed base -->
<body name="dummy_yaw_body" pos="0 0 0.01">
<!-- Fixed base -->
<geom name="dummy_geom" type="sphere" size="0.001"
rgba="1 1 1 0" density="1000" contype="0" conaffinity="0"/>
<!-- Robot base -->
<body name="base" pos="0 0 0">
<body name="base_structure">
<geom mesh="base_plate" contype="1" conaffinity="1"/>
<body name="base_poles">
<geom mesh="base_pole1" contype="1" conaffinity="1"/>
<geom mesh="base_pole2" contype="1" conaffinity="1"/>
<geom mesh="base_pole3" contype="1" conaffinity="1"/>
<geom mesh="base_pole4" contype="1" conaffinity="1"/>
</body>
<geom mesh="bottom_servo_plate" contype="1" conaffinity="1"/>
<body name="bottom_assembly">
<geom mesh="bottom_plate_connector" contype="1" conaffinity="1"/>
<geom mesh="bottom_plate" contype="1" conaffinity="1"/>
<geom mesh="base_arm_mount" contype="1" conaffinity="1"/>
<joint name="joint_1" pos="0.248729 0.0269 -0.595553"
axis="0 1 0" limited="true" range="-90 90" damping="1"/>
<body name="main_arm">
<geom mesh="main_arm_bottom_connector" contype="1" conaffinity="1"/>
<geom mesh="main_arm_bottom_rotation" contype="1" conaffinity="1"/>
<joint name="joint_2" type="hinge"
pos="0.23824474 -0.04370268 -0.61126763"
axis="1 0 0" limited="true"
range="-3.14 3.14" damping="1"/>
<body name="main_arm_section1">
<geom mesh="main_arm_p1" contype="1" conaffinity="1"/>
<body name="main_arm_section2">
<geom mesh="main_arm_p2" contype="1" conaffinity="1"/>
<geom mesh="main_arm_p2_gripper_rotation" contype="1" conaffinity="1"/>
<geom mesh="main_arm_top_rotation" contype="1" conaffinity="1"/>
<joint name="joint_3" type="hinge"
pos="0.23620827 -0.11626 -0.63760154"
axis="1 0 0" limited="true"
range="-90 90" damping="1"/>
<body name="gripper_housing">
<geom mesh="gripper_bottom_plate" contype="1" conaffinity="1"/>
<geom mesh="gripper_pole1" contype="1" conaffinity="1"/>
<geom mesh="gripper_pole2" contype="1" conaffinity="1"/>
<geom mesh="gripper_pole3" contype="1" conaffinity="1"/>
<geom mesh="gripper_pole4" contype="1" conaffinity="1"/>
<geom mesh="gripper_top_plate" contype="1" conaffinity="1"/>
<body name="gripper">
<body name="left_gripper_body">
<geom mesh="left_gripper" contype="1" conaffinity="1"/>
<joint name="joint_gl"
pos="0.253778 -0.0818572 -0.729863"
axis="0 1 0" limited="true"
range="-90 90" damping="1"/>
</body>
<body name="right_gripper_body">
<geom mesh="right_gripper" contype="1" conaffinity="1"/>
<joint name="joint_gr"
pos="0.235679 -0.0818572 -0.729863"
axis="0 1 0" limited="true"
range="-90 90" damping="1"/>
</body>
</body>
</body><!-- gripper_housing -->
</body><!-- main_arm_section2 -->
</body><!-- main_arm_section1 -->
</body><!-- main_arm -->
</body><!-- bottom_assembly -->
</body><!-- base_structure -->
</body><!-- base -->
</body><!-- dummy_yaw_body -->
<!-- Adding cubes -->
<body name="cube_20mm" pos="0.187 -0.054 -0.779" quat="0.9961947 0 0.0871557 0">
<!-- Define mass and inertia -->
<inertial pos="0.187 -0.054 -0.779" mass="0.005" diaginertia="1e-6 1e-6 1e-6"/>
<geom type="mesh" mesh="20mm_cube" friction="1 0.005 0.0001"
rgba="1 0 0 1" contype="1" conaffinity="1"/>
</body>
</worldbody>
<actuator>
<position name="joint_1" joint="joint_1" ctrlrange="-1 1" kp="20" kv="1"/>
<position name="joint_2" joint="joint_2" ctrlrange="0.06 1.32" kp="20" kv="1"/>
<position name="joint_3" joint="joint_3" ctrlrange="-0.78 0.78" kp="20" kv="1"/>
<position name="joint_gl" joint="joint_gl" ctrlrange="0.0157 0.754" kp="20" kv="1"/>
<position name="joint_gr" joint="joint_gr" ctrlrange="-0.754 0.0157" kp="20" kv="1"/>
</actuator>
</mujoco>
Code: import mujoco
import mujoco.viewer
import os
# Load the MuJoCo XML model
xml_file_path = "Mujoco/my_robot.xml" # Replace with the name of your XML file
model = mujoco.MjModel.from_xml_path(xml_file_path)
# Create a simulation data object
data = mujoco.MjData(model)
# Launch the viewer
viewer = mujoco.viewer.launch_passive(model, data)
'''
# Set the viewer to use the specific camera
camera_name = "custom_camera" # Replace with the name of your camera
if camera_name.encode() in model.names:
camera_id = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_CAMERA, camera_name.encode())
viewer.cam.type = mujoco.mjtCamera.mjCAMERA_FIXED
viewer.cam.fixedcamid = camera_id
else:
print(f"Camera '{camera_name}' not found in the model.")
'''
# Run the simulation
while True:
mujoco.mj_step(model, data)
viewer.sync() Confirmations
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello, this is simple to fix: you didn't add the cube any degrees of freedom. As it has no joints along which it is permitted to move, it stays as a fixed geom in its starting position. Simply add a |
Beta Was this translation helpful? Give feedback.
Hello, this is simple to fix: you didn't add the cube any degrees of freedom. As it has no joints along which it is permitted to move, it stays as a fixed geom in its starting position. Simply add a
freejoint
(or a mix of other dofs) as a child of the cube body.