Spaces:
Runtime error
Runtime error
File size: 6,238 Bytes
6299d2b 2ec5014 0a92014 3ffd15b 0a92014 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
'''Ant
Action Space Box(-1.0, 1.0, (8,), float32)
Observation Space Box(-inf, inf, (27,), float64)
'''
class BasicLevelTranslator:
def __init__(self):
pass
def translate(self, state):
(
torso_z_coordinate,
torso_x_orientation,
torso_y_orientation,
torso_z_orientation,
torso_w_orientation,
front_left_hip_angle,
front_left_link_angle,
front_right_hip_angle,
front_right_link_angle,
back_left_hip_angle,
back_left_link_angle,
back_right_hip_angle,
back_right_link_angle,
torso_x_velocity,
torso_y_velocity,
torso_z_velocity,
torso_x_angular_velocity,
torso_y_angular_velocity,
torso_z_angular_velocity,
front_left_hip_angular_velocity,
front_left_link_angular_velocity,
front_right_hip_angular_velocity,
front_right_link_angular_velocity,
back_left_hip_angular_velocity,
back_left_link_angular_velocity,
back_right_hip_angular_velocity,
back_right_link_angular_velocity,
) = state[:27]
res = (
f"Torso Z-coordinate: {torso_z_coordinate:.2f}, "
f"Torso X-orientation: {torso_x_orientation:.2f}, "
f"Torso Y-orientation: {torso_y_orientation:.2f}, "
f"Torso Z-orientation: {torso_z_orientation:.2f}, "
f"Torso W-orientation: {torso_w_orientation:.2f}, "
f"Front Left Hip Angle: {front_left_hip_angle:.2f}, "
f"Front Left Link Angle: {front_left_link_angle:.2f}, "
f"Front Right Hip Angle: {front_right_hip_angle:.2f}, "
f"Front Right Link Angle: {front_right_link_angle:.2f}, "
f"Back Left Hip Angle: {back_left_hip_angle:.2f}, "
f"Back Left Link Angle: {back_left_link_angle:.2f}, "
f"Back Right Hip Angle: {back_right_hip_angle:.2f}, "
f"Back Right Link Angle: {back_right_link_angle:.2f}, "
f"Torso X Velocity: {torso_x_velocity:.2f}, "
f"Torso Y Velocity: {torso_y_velocity:.2f}, "
f"Torso Z Velocity: {torso_z_velocity:.2f}, "
f"Torso X Angular Velocity: {torso_x_angular_velocity:.2f}, "
f"Torso Y Angular Velocity: {torso_y_angular_velocity:.2f}, "
f"Torso Z Angular Velocity: {torso_z_angular_velocity:.2f}, "
f"Front Left Hip Angular Velocity: {front_left_hip_angular_velocity:.2f}, "
f"Front Left Link Angular Velocity: {front_left_link_angular_velocity:.2f}, "
f"Front Right Hip Angular Velocity: {front_right_hip_angular_velocity:.2f}, "
f"Front Right Link Angular Velocity: {front_right_link_angular_velocity:.2f}, "
f"Back Left Hip Angular Velocity: {back_left_hip_angular_velocity:.2f}, "
f"Back Left Link Angular Velocity: {back_left_link_angular_velocity:.2f}, "
f"Back Right Hip Angular Velocity: {back_right_hip_angular_velocity:.2f}, "
f"Back Right Link Angular Velocity: {back_right_link_angular_velocity:.2f}"
)
return res
class GameDescriber:
def __init__(self, args):
self.is_only_local_obs = args.is_only_local_obs == 1
self.max_episode_len = args.max_episode_len
self.action_desc_dict = {
}
self.reward_desc_dict = {
}
def translate_terminate_state(self, state, episode_len, max_episode_len):
return ""
def translate_potential_next_state(self, state, action):
return ""
def describe_goal(self):
return "The goal is to coordinate the four legs of the ant robot to move forward."
def describe_game(self):
return (
"In the Ant environment, you control a 3D robot called the ant. The ant has a torso with four legs, "
"each consisting of two links and connected by hinge joints. Your objective is to apply torques to "
"the eight hinge joints to coordinate the four legs and make the ant move forward in the positive x-direction. "
"The environment provides observations of the ant's body parts and velocities, including the torso and leg angles, "
"orientations, and velocities. The episode ends when the ant becomes unhealthy, which can be due to various conditions."
)
def describe_action(self):
return (
"Your next move: \n Please choose your action which applies torques at the eight hinge joints of the ant. It be a list of eight numerical values and each value is within the range of [-1,1]."
)
class BasicStateSequenceTranslator(BasicLevelTranslator):
def translate(self, infos, is_current=False):
descriptions = []
if is_current:
state_desc = BasicLevelTranslator().translate(infos[-1]['state'])
return state_desc
for i, info in enumerate(infos):
assert 'state' in info, "info should contain state information"
state_desc = BasicLevelTranslator().translate(info['state'])
action_desc = (
"Take Action: "
"Apply Front Left Hip Torque: {:.2f}, "
"Apply Front Left Link Torque: {:.2f}, "
"Apply Front Right Hip Torque: {:.2f}, "
"Apply Front Right Link Torque: {:.2f}, "
"Apply Back Left Hip Torque: {:.2f}, "
"Apply Back Left Link Torque: {:.2f}, "
"Apply Back Right Hip Torque: {:.2f}, "
"Apply Back Right Link Torque: {:.2f}"
).format(
info['action'][0], info['action'][1], info['action'][2], info['action'][3],
info['action'][4], info['action'][5], info['action'][6], info['action'][7]
)
reward_desc = f"Result: Reward of {info['reward']:.2f}, "
next_state_desc = BasicLevelTranslator().translate(info['next_state'])
descriptions.append(f"{state_desc}.\\n {action_desc} \\n {reward_desc} \\n Transit to {next_state_desc}")
return descriptions |