From 595d3af4f4e49e7f57be4f3574a6190bb908091d Mon Sep 17 00:00:00 2001 From: Bart Moyaers Date: Mon, 17 Feb 2020 10:26:41 +0100 Subject: [PATCH] add target_link to Strike goal --- .../pybullet/gym/pybullet_envs/deep_mimic/env/goals.py | 8 ++++++-- .../deep_mimic/env/pybullet_deep_mimic_env.py | 7 ++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/pybullet/gym/pybullet_envs/deep_mimic/env/goals.py b/examples/pybullet/gym/pybullet_envs/deep_mimic/env/goals.py index 5f7646c28..6b12c420f 100644 --- a/examples/pybullet/gym/pybullet_envs/deep_mimic/env/goals.py +++ b/examples/pybullet/gym/pybullet_envs/deep_mimic/env/goals.py @@ -4,6 +4,7 @@ import random import math import pybullet as pb import numpy +from pybullet_envs.deep_mimic.env.humanoid_link_ids import HumanoidLinks class RandomBounds: def __init__(self, lower_bound: float, upper_bound: float): @@ -65,13 +66,15 @@ class Strike(Goal): height_RB: RandomBounds, rot_RB: RandomBounds, hit_range = 0.2, - follow_rot = True): + follow_rot = True, + target_link = HumanoidLinks.rightAnkle): self.follow_rot = follow_rot self.is_hit_prev = False self.distance_RB = distance_RB self.height_RB = height_RB self.rot_RB = rot_RB self.hit_range = hit_range + self.target_link = target_link super().__init__(GoalType.Strike) def generateGoalData(self, @@ -133,7 +136,8 @@ class Grab(Strike): height_RB = RandomBounds(0.8, 1.1) rot_RB = RandomBounds(3.14159 - 0.5, 3.14159 + 0.5) hit_range = 0.1 - super().__init__(distance_RB, height_RB, rot_RB, hit_range=hit_range, follow_rot=False) + target_link = HumanoidLinks.rightWrist + super().__init__(distance_RB, height_RB, rot_RB, hit_range=hit_range, follow_rot=False, target_link=target_link) class TargetHeadingGoal(Goal): def __init__(self): diff --git a/examples/pybullet/gym/pybullet_envs/deep_mimic/env/pybullet_deep_mimic_env.py b/examples/pybullet/gym/pybullet_envs/deep_mimic/env/pybullet_deep_mimic_env.py index eb51f20d5..a60747cf7 100644 --- a/examples/pybullet/gym/pybullet_envs/deep_mimic/env/pybullet_deep_mimic_env.py +++ b/examples/pybullet/gym/pybullet_envs/deep_mimic/env/pybullet_deep_mimic_env.py @@ -257,10 +257,7 @@ class PyBulletDeepMimicEnv(Env): goal_weight = 0.3 if self.goal.goal_type == GoalType.Strike: - if self.goal.__class__ == Kick: - linkPos, linkOrient = self._humanoid.getLinkPositionAndOrientation(HumanoidLinks.rightAnkle) - else: #elif type(self.goal) == Grab: - linkPos, linkOrient = self._humanoid.getLinkPositionAndOrientation(HumanoidLinks.rightWrist) + linkPos, linkOrient = self._humanoid.getLinkPositionAndOrientation(self.goal.target_link) reward = mimic_weight * reward + goal_weight * self.calcStrikeGoalReward(linkPos) return reward @@ -292,7 +289,7 @@ class PyBulletDeepMimicEnv(Env): #print("pybullet_deep_mimic_env:update timeStep=",timeStep," t=",self.t) self._pybullet_client.setTimeStep(timeStep) self._humanoid._timeStep = timeStep - self.updateGoal(self._humanoid.getLinkPositionAndOrientation(HumanoidLinks.rightAnkle)[0]) + self.updateGoal(self._humanoid.getLinkPositionAndOrientation(self.goal.target_link)[0]) if self.target_id is not None: # TODO: check goal type self.updateDrawStrikeGoal()