@@ -64,6 +64,7 @@ def __init__(self, headless=False):
6464 self ._setup_simulator (headless = headless )
6565 # Setup the interface
6666 self ._setup_interface ()
67+ self ._init_pose ()
6768 # Setup the Mink for solving the inverse kinematics
6869 self ._setup_mink ()
6970 self .state_machine = SimpleStateMachine (max_states = 8 )
@@ -116,20 +117,19 @@ def _setup_simulator(self, headless=False):
116117 )
117118 self .simulator .add_object (table_config )
118119
119- # Add closet
120- closet_config = MeshConfig (
121- prim_path = "/World/Closet " ,
120+ # Add bucket
121+ bucket_config = MeshConfig (
122+ prim_path = "/World/bucket " ,
122123 mjcf_path = Path ()
123124 .joinpath (self .simulator .synthnova_assets_directory )
124125 .joinpath ("synthnova_assets" )
125126 .joinpath ("objects" )
126- .joinpath ("closet " )
127- .joinpath ("closet .xml" ),
127+ .joinpath ("bucket " )
128+ .joinpath ("bucket .xml" ),
128129 position = [0.65 , - 0.1 , 0.55 ],
129- orientation = [0 , 0 , 0.70711 , - 0.70711 ],
130- scale = [0.2 , 0.2 , 0.2 ]
130+ orientation = [0 , 0 , 0 , 1 ],
131131 )
132- self .simulator .add_object (closet_config )
132+ self .simulator .add_object (bucket_config )
133133
134134 # Add cube
135135 cube_config = CuboidConfig (
@@ -144,9 +144,9 @@ def _setup_simulator(self, headless=False):
144144 # Initialize the simulator
145145 self .simulator .initialize ()
146146
147- closet_state = self .simulator .get_object_state ("/World/Closet " )
148- self .closet_position = closet_state ["position" ]
149- self .closet_orientation = closet_state ["orientation" ]
147+ bucket_state = self .simulator .get_object_state ("/World/bucket " )
148+ self .bucket_position = bucket_state ["position" ]
149+ self .bucket_orientation = bucket_state ["orientation" ]
150150
151151
152152 def _setup_interface (self ):
@@ -226,33 +226,29 @@ def _setup_mink(self):
226226 model = self .simulator .model ._model
227227 self .mink_config = mink .Configuration (model )
228228
229- # Create tasks
230- self .tasks = [
231- mink .FrameTask (
229+ # Create tasks as dictionary
230+ self .tasks = {
231+ "torso" : mink .FrameTask (
232232 frame_name = self .robot .namespace + "torso_base_link" ,
233233 frame_type = "body" ,
234- position_cost = 0.0 ,
235- orientation_cost = 10.0 ,
234+ position_cost = 1e6 ,
235+ orientation_cost = 1e6 ,
236236 ),
237- mink .PostureTask (model , cost = 1.0 ),
238- mink .FrameTask (
237+ "posture" : mink .PostureTask (model , cost = 1.0 ),
238+ "chassis" : mink .FrameTask (
239239 frame_name = self .robot .namespace + "omni_chassis_base_link" ,
240240 frame_type = "body" ,
241- position_cost = 100.0 ,
242- orientation_cost = 100.0 ,
241+ position_cost = 1e6 ,
242+ orientation_cost = 1e6 ,
243243 ),
244- ]
245-
246- # Create arm tasks
247- self .arm_tasks = {
248- "left" : mink .FrameTask (
244+ "left_arm" : mink .FrameTask (
249245 frame_name = self .robot .namespace + "left_gripper_tcp" ,
250246 frame_type = "site" ,
251247 position_cost = 50.0 ,
252248 orientation_cost = 50.0 ,
253249 lm_damping = 1.0 ,
254250 ),
255- "right " : mink .FrameTask (
251+ "right_arm " : mink .FrameTask (
256252 frame_name = self .robot .namespace + "right_gripper_tcp" ,
257253 frame_type = "site" ,
258254 position_cost = 50.0 ,
@@ -272,8 +268,28 @@ def _setup_mink(self):
272268 self .solver = "daqp"
273269 self .rate_limiter = RateLimiter (frequency = 1000 , warn = False )
274270
275- for task in self .tasks :
276- task .set_target_from_configuration (self .mink_config )
271+ # Set targets for torso, posture, and chassis tasks
272+ # for task_name in ["torso", "posture", "chassis"]:
273+ # self.tasks[task_name].set_target_from_configuration(self.mink_config)
274+
275+ # Set target for chassis
276+ chassis_target = mink .SE3 .from_rotation_and_translation (
277+ rotation = mink .SO3 (wxyz = xyzw_to_wxyz (self .robot .get_orientation ())),
278+ translation = self .robot .get_position ()
279+ )
280+ self .tasks ["chassis" ].set_target (chassis_target )
281+
282+ # Set target for torso
283+ import mujoco
284+ torso_body_id = mujoco .mj_name2id (self .simulator .model ._model , mujoco .mjtObj .mjOBJ_BODY , self .robot .namespace + "torso_base_link" )
285+ torso_target = mink .SE3 .from_rotation_and_translation (
286+ rotation = mink .SO3 (wxyz = self .simulator .data .xquat [torso_body_id ]),
287+ translation = self .simulator .data .xpos [torso_body_id ]
288+ )
289+ self .tasks ["torso" ].set_target (torso_target )
290+
291+ # Set target for posture
292+ self .tasks ["posture" ].set_target_from_configuration (self .mink_config )
277293
278294 def solve_ik (self ,
279295 left_target_position = None ,
@@ -291,42 +307,42 @@ def solve_ik(self,
291307 right_target_position: Target position for right arm [x, y, z]
292308 right_target_orientation: Target orientation for right arm as quaternion [x, y, z, w]
293309 """
294- active_tasks = self .tasks .copy ()
295-
296- if left_target_position is not None :
297- if left_target_orientation is not None :
298- target = mink .SE3 .from_rotation_and_translation (
299- rotation = mink .SO3 (wxyz = xyzw_to_wxyz (left_target_orientation )),
300- translation = left_target_position
301- )
302- self .arm_tasks ["left" ].set_target (target )
303- active_tasks .append (self .arm_tasks ["left" ])
304-
305- if right_target_position is not None :
306- if right_target_orientation is not None :
307- target = mink .SE3 .from_rotation_and_translation (
308- rotation = mink .SO3 (wxyz = xyzw_to_wxyz (right_target_orientation )),
309- translation = right_target_position
310- )
311- self .arm_tasks ["right" ].set_target (target )
312- active_tasks .append (self .arm_tasks ["right" ])
313-
310+
311+ # Set targets for left and right arm
312+ if left_target_position is not None and left_target_orientation is not None :
313+ target = mink .SE3 .from_rotation_and_translation (
314+ rotation = mink .SO3 (wxyz = xyzw_to_wxyz (left_target_orientation )),
315+ translation = left_target_position
316+ )
317+ self .tasks ["left_arm" ].set_target (target )
318+ if right_target_position is not None and right_target_orientation is not None :
319+ target = mink .SE3 .from_rotation_and_translation (
320+ rotation = mink .SO3 (wxyz = xyzw_to_wxyz (right_target_orientation )),
321+ translation = right_target_position
322+ )
323+ self .tasks ["right_arm" ].set_target (target )
324+
325+ # Collect all tasks
326+ tasks = [self .tasks ["torso" ], self .tasks ["posture" ], self .tasks ["chassis" ]]
327+ if left_target_position is not None and left_target_orientation is not None :
328+ tasks .append (self .tasks ["left_arm" ])
329+ if right_target_position is not None and right_target_orientation is not None :
330+ tasks .append (self .tasks ["right_arm" ])
331+
314332 # Solve IK
315333 vel = mink .solve_ik (
316334 self .mink_config ,
317- active_tasks ,
335+ tasks ,
318336 self .rate_limiter .dt ,
319337 self .solver ,
320338 0.01 ,
321339 limits = [self .velocity_limit ] if limit_velocity else None
322340 )
323341
324- self .mink_config .integrate_inplace (vel , self .rate_limiter .dt * 0.1 )
325-
326- # Update robot joint positions
342+ self .mink_config .integrate_inplace (vel , self .rate_limiter .dt * 0.02 )
327343 joint_positions = self .mink_config .q
328344
329- # Use joint_positions to update leg, head, left_arm, and right_arm
345+ # Extract joint positions for each module
330346 left_arm_joint_indexes = self .interface .left_arm .joint_indexes
331347 left_arm_joint_positions = joint_positions [left_arm_joint_indexes ]
332348 right_arm_joint_indexes = self .interface .right_arm .joint_indexes
@@ -342,39 +358,18 @@ def solve_ik(self,
342358 "head" : head_joint_positions ,
343359 "leg" : leg_joint_positions
344360 }
345-
361+
346362 def _init_pose (self ):
347- # Init head pose
348- head = [0.0 , 0.0 ]
349- self ._move_joints_to_target (self .interface .head , head )
350-
351- # Init leg pose
352- leg = [0.43 , 1.48 , 1.07 , 0.0 ]
353- self ._move_joints_to_target (self .interface .leg , leg )
354-
355- # Init left arm pose
356- left_arm = [
357- - 0.716656506061554 ,
358- - 1.538102626800537 ,
359- - 0.03163932263851166 ,
360- - 1.379408597946167 ,
361- - 1.4995604753494263 ,
362- 0.0332450270652771 ,
363- - 1.0637063884735107
364- ]
365- self ._move_joints_to_target (self .interface .left_arm , left_arm )
366-
367- # Init right arm pose
368- right_arm = [
369- - 0.058147381991147995 ,
370- - 1.4785659313201904 ,
371- 0.0999724417924881 ,
372- 2.097979784011841 ,
373- - 1.3999720811843872 ,
374- 0.009971064515411854 ,
375- - 1.0999830961227417
376- ]
377- self ._move_joints_to_target (self .interface .right_arm , right_arm )
363+ # Initialize robot pose
364+ poses = {
365+ self .interface .head : [0.0 , 0.0 ],
366+ self .interface .leg : [0.2 , 0.756 , 0.53 , 0.0 ],
367+ self .interface .left_arm : [- 0.4654513936071508 , 1.4785659313201904 , - 0.6235712173907869 , 2.097979784011841 , 1.3999720811843872 , - 0.009971064515411854 , 1.0999830961227417 ],
368+ self .interface .right_arm : [0.4654513936071508 , - 1.4785659313201904 , 0.6235712173907869 , - 2.097979784011841 , - 1.3999720811843872 , 0.009971064515411854 , - 1.0999830961227417 ]
369+ }
370+
371+ for module , pose in poses .items ():
372+ module .set_joint_positions (pose , immediate = True )
378373
379374 def _move_joints_to_target (self , module , target_positions , steps = 100 ):
380375 """Move joints from current position to target position smoothly."""
@@ -428,9 +423,9 @@ def pick_and_place_callback(self):
428423
429424 def init_state ():
430425 """Ready to pick"""
431- left_target_position = np .array ([0.4 , 0.3 , 0.8 ])
426+ left_target_position = np .array ([0.5 , 0.3 , 0.7 ])
432427 left_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
433- right_target_position = np .array ([0.4 , - 0.3 , 0.8 ])
428+ right_target_position = np .array ([0.5 , - 0.3 , 0.7 ])
434429 right_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
435430
436431 # Solve IK for left arm
@@ -467,7 +462,7 @@ def move_to_pre_pick_state():
467462 self .state_first_entry = False
468463 left_target_position = self .cube_position + np .array ([0 , 0 , 0.15 ])
469464 left_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
470- right_target_position = np .array ([0.4 , - 0.3 , 0.8 ])
465+ right_target_position = np .array ([0.5 , - 0.3 , 0.7 ])
471466 right_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
472467
473468 # Solve IK for left arm
@@ -503,7 +498,7 @@ def move_to_pick_state():
503498 self .state_first_entry = False
504499 left_target_position = self .cube_position + np .array ([0 , 0 , 0.03 ])
505500 left_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
506- right_target_position = np .array ([0.4 , - 0.3 , 0.8 ])
501+ right_target_position = np .array ([0.5 , - 0.3 , 0.7 ])
507502 right_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
508503
509504 # Solve IK for left arm
@@ -538,9 +533,9 @@ def grasp_state():
538533 def move_to_pre_place_state ():
539534 """Move to place position"""
540535
541- left_target_position = self .cube_position + np .array ([0 , 0 , 0.4 ])
536+ left_target_position = self .cube_position + np .array ([- 0.1 , 0 , 0.4 ])
542537 left_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
543- right_target_position = np .array ([0.4 , - 0.3 , 0.7 ])
538+ right_target_position = np .array ([0.5 , - 0.3 , 0.7 ])
544539 right_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
545540
546541 # Solve IK for left arm
@@ -569,13 +564,13 @@ def move_to_pre_place_state():
569564 def move_to_place_state ():
570565 """Move to place position"""
571566 if self .state_first_entry :
572- closet_state = self .simulator .get_object_state ("/World/Closet " )
573- self .closet_position = closet_state ["position" ].copy ()
567+ bucket_state = self .simulator .get_object_state ("/World/bucket " )
568+ self .bucket_position = bucket_state ["position" ].copy ()
574569 self .state_first_entry = False
575570
576- left_target_position = self .closet_position + np .array ([0 , 0 , 0.3 ])
571+ left_target_position = self .bucket_position + np .array ([0 , 0 , 0.3 ])
577572 left_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
578- right_target_position = np .array ([0.4 , - 0.3 , 0.7 ])
573+ right_target_position = np .array ([0.5 , - 0.3 , 0.7 ])
579574 right_target_orientation = np .array ([0 , 0.7071 , 0 , 0.7071 ])
580575
581576 # Solve IK for left arm
0 commit comments