Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MyoChallenge Manipulation Track Metric #213

Merged
merged 5 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading