6
6
import matplotlib .pyplot as plt
7
7
8
8
from pytransform3d import rotations
9
- from core .RobotController import RobotController
10
9
11
10
from pathlib import Path
12
11
import h5py
20
19
class Player :
21
20
def __init__ (self , dt = 1 / 60 ):
22
21
self .dt = dt
23
- self .controller = None
24
22
self .head_mat = None
25
23
self .left_wrist_mat = None
26
24
self .right_wrist_mat = None
@@ -91,14 +89,11 @@ def __init__(self, dt=1/60):
91
89
cam_target = gymapi .Vec3 (0 , 0 , 1 )
92
90
self .gym .viewer_camera_look_at (self .viewer , None , cam_pos , cam_target )
93
91
94
- self .controller = RobotController ()
95
- self .controller .load_config ('h1_inspire.yml' )
96
-
97
92
plt .figure (figsize = (12 , 6 ))
98
93
plt .ion ()
99
94
100
- def step (self , action , left_img , right_img , control_mode = 'qpos' ):
101
- qpos = self .convert_h1_qpos (action , control_mode )
95
+ def step (self , action , left_img , right_img ):
96
+ qpos = self .convert_h1_qpos (action )
102
97
states = np .zeros (qpos .shape , dtype = gymapi .DofState .dtype )
103
98
states ['pos' ] = qpos
104
99
self .gym .set_actor_dof_states (self .env , self .robot_handle , states , gymapi .STATE_POS )
@@ -124,63 +119,34 @@ def end(self):
124
119
self .gym .destroy_sim (self .sim )
125
120
plt .close ()
126
121
127
- def convert_h1_qpos (self , action , control_mode ):
122
+ def convert_h1_qpos (self , action ):
128
123
'''
129
124
left_arm_indices = [13, 14, 15, 16, 17, 18, 19]
130
125
right_arm_indices = [32, 33, 34, 35, 36, 37, 38]
131
126
left_hand_indices = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
132
127
right_hand_indices = [39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]
133
128
'''
134
- if control_mode == 'ee' :
135
- left_wrist_mat = np .eye (4 )
136
- left_wrist_mat [0 :3 , 3 ] = action [0 :3 ]
137
- left_wrist_mat [0 :3 , 0 :3 ] = rotations .active_matrix_from_intrinsic_euler_zyx (action [3 :6 ])
138
-
139
- right_wrist_mat = np .eye (4 )
140
- right_wrist_mat [0 :3 , 3 ] = action [12 :15 ]
141
- right_wrist_mat [0 :3 , 0 :3 ] = rotations .active_matrix_from_intrinsic_euler_zyx (action [15 :18 ])
142
-
143
- self .controller .update (np .eye (4 ), left_wrist_mat , right_wrist_mat , np .zeros ((25 ,3 )), np .zeros ((25 ,3 )))
144
- qpos = self .controller .qpos
145
-
146
- # left hand actions
147
- qpos [20 :22 ] = action [6 ]
148
- qpos [22 :24 ] = action [7 ]
149
- qpos [24 :26 ] = action [8 ]
150
- qpos [26 :28 ] = action [9 ]
151
- qpos [28 ] = action [10 ]
152
- qpos [29 :32 ] = action [11 ] * np .array ([1 , 1.6 , 2.4 ])
153
-
154
- # right hand actions
155
- qpos [39 :41 ] = action [18 ]
156
- qpos [41 :43 ] = action [19 ]
157
- qpos [43 :45 ] = action [20 ]
158
- qpos [45 :47 ] = action [21 ]
159
- qpos [47 ] = action [22 ]
160
- qpos [48 :51 ] = action [23 ] * np .array ([1 , 1.6 , 2.4 ])
161
- elif control_mode == 'qpos' :
162
- qpos = np .zeros (51 )
163
- qpos [13 :20 ] = action [0 :7 ]
164
-
165
- # left hand actions
166
- qpos [20 :22 ] = action [7 ]
167
- qpos [22 :24 ] = action [8 ]
168
- qpos [24 :26 ] = action [9 ]
169
- qpos [26 :28 ] = action [10 ]
170
- qpos [28 ] = action [11 ]
171
- qpos [29 :32 ] = action [12 ] * np .array ([1 , 1.6 , 2.4 ])
172
-
173
- qpos [32 :39 ] = action [13 :20 ]
174
-
175
- # right hand actions
176
- qpos [39 :41 ] = action [20 ]
177
- qpos [41 :43 ] = action [21 ]
178
- qpos [43 :45 ] = action [22 ]
179
- qpos [45 :47 ] = action [23 ]
180
- qpos [47 ] = action [24 ]
181
- qpos [48 :51 ] = action [25 ] * np .array ([1 , 1.6 , 2.4 ])
182
- else :
183
- raise NotImplementedError ('Invalid control mode' )
129
+ qpos = np .zeros (51 )
130
+ qpos [13 :20 ] = action [0 :7 ]
131
+
132
+ # left hand actions
133
+ qpos [20 :22 ] = action [7 ]
134
+ qpos [22 :24 ] = action [8 ]
135
+ qpos [24 :26 ] = action [9 ]
136
+ qpos [26 :28 ] = action [10 ]
137
+ qpos [28 ] = action [11 ]
138
+ qpos [29 :32 ] = action [12 ] * np .array ([1 , 1.6 , 2.4 ])
139
+
140
+ qpos [32 :39 ] = action [13 :20 ]
141
+
142
+ # right hand actions
143
+ qpos [39 :41 ] = action [20 ]
144
+ qpos [41 :43 ] = action [21 ]
145
+ qpos [43 :45 ] = action [22 ]
146
+ qpos [45 :47 ] = action [23 ]
147
+ qpos [47 ] = action [24 ]
148
+ qpos [48 :51 ] = action [25 ] * np .array ([1 , 1.6 , 2.4 ])
149
+
184
150
return qpos
185
151
186
152
if __name__ == '__main__' :
0 commit comments