| | import tensorflow as tf |
| |
|
| | from data.utils import clean_task_instruction, euler_to_rotation_matrix, rotation_matrix_to_ortho6d |
| |
|
| |
|
| | def process_step(step: dict) -> dict: |
| | """ |
| | Unify the action format and clean the task instruction. |
| | |
| | DO NOT use python list, use tf.TensorArray instead. |
| | """ |
| | |
| | action_dict = step['action'] |
| |
|
| | |
| | |
| | |
| | |
| | |
| | eef_pos_vel = action_dict[:3] |
| | eef_ang_vel = action_dict[3:6] |
| | |
| | |
| | grip_pos = 1 - tf.clip_by_value(action_dict[-1:], 0, 1) |
| | |
| | |
| |
|
| | |
| | step['action'] = {} |
| | action = step['action'] |
| | |
| | arm_action = tf.concat([eef_pos_vel, eef_ang_vel, grip_pos], axis=0) |
| | action['arm_concat'] = arm_action |
| | |
| |
|
| | |
| | action['format'] = tf.constant( |
| | "eef_vel_x,eef_vel_y,eef_vel_z,eef_angular_vel_roll,eef_angular_vel_pitch,eef_angular_vel_yaw,gripper_joint_0_pos") |
| |
|
| | |
| | |
| | state = step['observation'] |
| | |
| | |
| | eef_pos = state['state'][:3] |
| | eef_ang = state['state'][3:6] |
| | eef_ang = euler_to_rotation_matrix(eef_ang) |
| | eef_ang = rotation_matrix_to_ortho6d(eef_ang) |
| | |
| | grip_pos = state['state'][-2:] |
| |
|
| | |
| | state['arm_concat'] = tf.concat([ |
| | grip_pos,eef_pos,eef_ang], axis=0) |
| | |
| |
|
| | |
| | state['format'] = tf.constant( |
| | "gripper_joint_0_pos,gripper_joint_1_pos,eef_pos_x,eef_pos_y,eef_pos_z,eef_angle_0,eef_angle_1,eef_angle_2,eef_angle_3,eef_angle_4,eef_angle_5") |
| |
|
| | |
| | |
| | replacements = { |
| | '_': ' ', |
| | '1f': ' ', |
| | '4f': ' ', |
| | '-': ' ', |
| | '50': ' ', |
| | '55': ' ', |
| | '56': ' ', |
| | |
| | } |
| | instr = step['language_instruction'] |
| | |
| | step['observation'] = state |
| | step['observation']['natural_language_instruction'] = instr |
| |
|
| | return step |
| |
|
| |
|
| | if __name__ == "__main__": |
| | pass |
| |
|