@@ -146,7 +146,7 @@ def add_mount(self, mount: MountModel):
146146 """
147147 Mounts @mount to arm.
148148
149- Throws error if robot already has a mount or if mount type i\s incorrect.
149+ Throws error if robot already has a mount or if mount type is incorrect.
150150
151151 Args:
152152 mount (MountModel): mount MJCF model
@@ -187,19 +187,25 @@ def add_mobile_base(self, mobile_base: MobileBaseModel):
187187 offset = self .base_offset - mobile_base .top_offset
188188 mobile_base ._elements ["root_body" ].set ("pos" , array_to_string (offset ))
189189
190- # if the mount is mobile, the robot should be "merged" into the mount,
191- # so that when the mount moves the robot moves along with it
190+ # Keep robot0_base as the root, but move all its content (geoms, inertial, arms) to mobile base support
192191 merge_body = self .root_body
193192 root = find_elements (root = self .worldbody , tags = "body" , attribs = {"name" : merge_body }, return_first = True )
193+
194+ # Store all direct children of robot0_base (arms, geoms, inertial, etc.)
195+ all_root_children = list (root ) # Make a copy of all children
196+
197+ # Append mobile base bodies to robot0_base (not to worldbody)
194198 for body in mobile_base .worldbody :
195199 root .append (body )
196- arm_root = find_elements (root = self .worldbody , tags = "body" , return_first = False )[1 ]
197200
201+ # Find the mount's support body where everything should attach
198202 mount_support = find_elements (
199203 root = self .worldbody , tags = "body" , attribs = {"name" : mobile_base .correct_naming ("support" )}, return_first = True
200204 )
201- mount_support .append (deepcopy (arm_root ))
202- root .remove (arm_root )
205+ # Move ALL content from robot0_base to the mobile base support (arms, geoms, inertial)
206+ for child in all_root_children :
207+ mount_support .append (deepcopy (child ))
208+ root .remove (child )
203209 self .merge_assets (mobile_base )
204210 for one_actuator in mobile_base .actuator :
205211 self .actuator .append (one_actuator )
0 commit comments