Skip to content

Commit

Permalink
Merge pull request #213 from Balint-H/myochal-mani-p2
Browse files Browse the repository at this point in the history
MyoChallenge Manipulation Track Metric
  • Loading branch information
Vittorio-Caggiano authored Aug 27, 2024
2 parents 3fe5c31 + 3281da5 commit 76f3925
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions myosuite/envs/myo/myochallenge/bimanual_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _setup(self,

# check whether the object experience force over max force
self.over_max = False
self.max_force = max_force
self.max_force = 0

self.touch_history = []

Expand Down Expand Up @@ -177,7 +177,8 @@ def get_obs_dict(self, sim):

current_force = sim.data.sensordata[0]
if current_force > self.max_force:
self.over_max = True
self.max_force = current_force
obs_dict['max_force'] = np.array([self.max_force])

obs_vec = self._obj_label_to_obs(touching_objects)
obs_dict["touching_body"] = obs_vec
Expand Down Expand Up @@ -236,7 +237,8 @@ def get_reward_dict(self, obs_dict):
("pass_err", pass_dist + np.log(pass_dist + 1e-3)),
# Must keys
("sparse", 0),
("solved", self.check_solve(goal_dis)),
("goal_dist", goal_dis),
("solved", goal_dis < self.proximity_th),
("done", False),
)
)
Expand All @@ -258,12 +260,6 @@ def step(self, a, **kwargs):
- self.sim.model.actuator_ctrlrange[robotic_act_ind, 0]) / 2.0)
return super().step(processed_controls, **kwargs)

def check_solve(self, goal_dis):
if goal_dis > 0.01:
return False
if self.over_max == True:
return False
return True

def get_metrics(self, paths, successful_steps=5):
"""
Expand All @@ -280,15 +276,19 @@ def get_metrics(self, paths, successful_steps=5):
num_success += 1
score = num_success / num_paths

times = np.mean([np.round(p['env_infos']['obs_dict']['time'][-1], 2) for p in paths])
times = np.mean([np.round(p['env_infos']['obs_dict']['time'][-1], 5) for p in paths])
max_force = np.mean([np.round(p['env_infos']['obs_dict']['max_force'][-1], 5) for p in paths])
goal_dist = np.mean([np.mean(p['env_infos']['rwd_dict']['goal_dist']) for p in paths])

# average activations over entire trajectory (can be shorter than horizon, if done) realized
effort = -1.0 * np.mean([np.mean(p['env_infos']['rwd_dict']['act_reg']) for p in paths])
effort = -1.0 * np.mean([np.mean(p['env_infos']['rwd_dict']['act']) for p in paths])

metrics = {
'score': score,
'time': times,
'effort': effort,
'peak force': max_force,
'goal dist': goal_dist,
}
return metrics

Expand Down

0 comments on commit 76f3925

Please sign in to comment.