Robot body positions in body frame
(sim_data, motion_loader, t)
| 470 | |
| 471 | |
| 472 | def robot_body_pos_b(sim_data, motion_loader, t): |
| 473 | """Robot body positions in body frame""" |
| 474 | # Get robot anchor pose |
| 475 | robot_anchor_pos = sim_data.body(motion_loader.anchor_body_name).xpos.copy().reshape(1, 3) |
| 476 | robot_anchor_quat = sim_data.body(motion_loader.anchor_body_name).xquat.copy().reshape(1, 4) |
| 477 | |
| 478 | # Get all robot body poses |
| 479 | robot_body_positions = [] |
| 480 | robot_body_orientations = [] |
| 481 | |
| 482 | for body_name in motion_loader.body_names: |
| 483 | body_pos = sim_data.body(body_name).xpos.copy().reshape(1, 3) |
| 484 | body_quat = sim_data.body(body_name).xquat.copy().reshape(1, 4) |
| 485 | robot_body_positions.append(body_pos) |
| 486 | robot_body_orientations.append(body_quat) |
| 487 | |
| 488 | robot_body_pos = np.concatenate(robot_body_positions, axis=0) # [14, 3] |
| 489 | robot_body_quat = np.concatenate(robot_body_orientations, axis=0) # [14, 4] |
| 490 | |
| 491 | # Transform to body frame - expand robot_anchor to match robot_body shape |
| 492 | robot_anchor_pos_expanded = robot_anchor_pos.repeat(len(motion_loader.body_names), axis=0) # [14, 3] |
| 493 | robot_anchor_quat_expanded = robot_anchor_quat.repeat(len(motion_loader.body_names), axis=0) # [14, 4] |
| 494 | |
| 495 | pos_b, _ = subtract_frame_transforms( |
| 496 | torch.from_numpy(robot_anchor_pos_expanded).float(), |
| 497 | torch.from_numpy(robot_anchor_quat_expanded).float(), |
| 498 | torch.from_numpy(robot_body_pos).float(), |
| 499 | torch.from_numpy(robot_body_quat).float(), |
| 500 | ) |
| 501 | |
| 502 | return np.array(pos_b, dtype=np.float32).flatten() # [42] |
| 503 | |
| 504 | |
| 505 | def robot_body_ori_b(sim_data, motion_loader, t): |
no outgoing calls
no test coverage detected