19
19
20
20
"""
21
21
import argparse
22
- import json
23
22
import pickle
24
23
import sys
25
24
import numpy as np
@@ -66,16 +65,43 @@ def main():
66
65
args = parser .parse_args ()
67
66
68
67
with open (args .logfile , "rb" ) as fh :
69
- # log = json.load(fh)
70
68
log = pickle .load (fh )
71
69
72
70
initial_object_pose = move_cube .Pose .from_json (args .initial_pose )
73
71
goal_pose = move_cube .Pose .from_json (args .goal_pose )
74
72
73
+ # verify that the initial object pose matches with the one in the log file
74
+ try :
75
+ np .testing .assert_array_almost_equal (
76
+ initial_object_pose .position , log ["initial_object_pose" ].position ,
77
+ err_msg = ("Given initial object position does not match with log file." )
78
+ )
79
+ np .testing .assert_array_almost_equal (
80
+ initial_object_pose .orientation , log ["initial_object_pose" ].orientation ,
81
+ err_msg = ("Given initial object orientation does not match with log file." )
82
+ )
83
+ except AssertionError as e :
84
+ print ("Failed." , file = sys .stderr )
85
+ print (e , file = sys .stderr )
86
+ sys .exit (1 )
87
+
75
88
platform = trifinger_platform .TriFingerPlatform (
76
89
visualization = False , initial_object_pose = initial_object_pose
77
90
)
78
91
92
+ # verify that the robot is initialized to the same position as in the log
93
+ # file
94
+ initial_robot_position = platform .get_robot_observation (0 ).position
95
+ try :
96
+ np .testing .assert_array_almost_equal (
97
+ initial_robot_position , log ["initial_robot_position" ],
98
+ err_msg = ("Initial robot position does not match with log file." )
99
+ )
100
+ except AssertionError as e :
101
+ print ("Failed." , file = sys .stderr )
102
+ print (e , file = sys .stderr )
103
+ sys .exit (1 )
104
+
79
105
# verify that the number of logged actions matches with the episode length
80
106
n_actions = len (log ["actions" ])
81
107
assert (
@@ -84,14 +110,11 @@ def main():
84
110
85
111
accumulated_reward = 0
86
112
for logged_action in log ["actions" ]:
87
- action = platform .Action ()
88
- action .torque = np .array (logged_action ["torque" ])
89
- action .position = np .array (logged_action ["position" ])
90
- action .position_kp = np .array (logged_action ["position_kp" ])
91
- action .position_kd = np .array (logged_action ["position_kd" ])
113
+ action = logged_action ["action" ]
92
114
93
115
t = platform .append_desired_action (action )
94
116
117
+ robot_obs = platform .get_robot_observation (t )
95
118
cube_pose = platform .get_object_pose (t )
96
119
reward = - move_cube .evaluate_state (
97
120
goal_pose , cube_pose , args .difficulty
@@ -100,20 +123,47 @@ def main():
100
123
101
124
assert logged_action ["t" ] == t
102
125
126
+ np .testing .assert_array_almost_equal (
127
+ robot_obs .position , logged_action ["robot_observation" ].position ,
128
+ err_msg = ("Step %d: Recorded robot position does not match with"
129
+ " the one achieved by the replay" % t )
130
+ )
131
+ np .testing .assert_array_almost_equal (
132
+ robot_obs .torque , logged_action ["robot_observation" ].torque ,
133
+ err_msg = ("Step %d: Recorded robot torque does not match with"
134
+ " the one achieved by the replay" % t )
135
+ )
136
+ np .testing .assert_array_almost_equal (
137
+ robot_obs .velocity , logged_action ["robot_observation" ].velocity ,
138
+ err_msg = ("Step %d: Recorded robot velocity does not match with"
139
+ " the one achieved by the replay" % t )
140
+ )
141
+
142
+ np .testing .assert_array_almost_equal (
143
+ cube_pose .position , logged_action ["object_pose" ].position ,
144
+ err_msg = ("Step %d: Recorded object position does not match with"
145
+ " the one achieved by the replay" % t )
146
+ )
147
+ np .testing .assert_array_almost_equal (
148
+ cube_pose .orientation , logged_action ["object_pose" ].orientation ,
149
+ err_msg = ("Step %d: Recorded object orientation does not match with"
150
+ " the one achieved by the replay" % t )
151
+ )
152
+
103
153
cube_pose = platform .get_object_pose (t )
104
- final_pose = log ["final_object_pose" ]
154
+ final_pose = log ["final_object_pose" ][ "pose" ]
105
155
106
156
print ("Accumulated Reward:" , accumulated_reward )
107
157
108
158
# verify that actual and logged final object pose match
109
159
try :
110
160
np .testing .assert_array_almost_equal (
111
- cube_pose .position , final_pose [ " position" ] , decimal = 3 ,
161
+ cube_pose .position , final_pose . position , decimal = 3 ,
112
162
err_msg = ("Recorded object position does not match with the one"
113
163
" achieved by the replay" )
114
164
)
115
165
np .testing .assert_array_almost_equal (
116
- cube_pose .orientation , final_pose [ " orientation" ] , decimal = 3 ,
166
+ cube_pose .orientation , final_pose . orientation , decimal = 3 ,
117
167
err_msg = ("Recorded object orientation does not match with the one"
118
168
" achieved by the replay" )
119
169
)
0 commit comments