Skip to content

reaching_goal_reward

ReachingGoalReward

Bases: BaseRewardFunction

Reaching goal reward Success reward for reaching the goal with the robot's end-effector

Parameters:

Name Type Description Default
robot_idn int

robot identifier to evaluate point goal with. Default is 0, corresponding to the first robot added to the scene

0
r_reach float

reward for succeeding to reach the goal

10.0
distance_tol float

Distance (m) tolerance between goal position and @robot_idn's robot eef position that is accepted as a success

0.1
Source code in OmniGibson/omnigibson/reward_functions/reaching_goal_reward.py
class ReachingGoalReward(BaseRewardFunction):
    """
    Reaching goal reward
    Success reward for reaching the goal with the robot's end-effector

    Args:
        robot_idn (int): robot identifier to evaluate point goal with. Default is 0, corresponding to the first
            robot added to the scene
        r_reach (float): reward for succeeding to reach the goal
        distance_tol (float): Distance (m) tolerance between goal position and @robot_idn's robot eef position
            that is accepted as a success
    """

    def __init__(self, robot_idn=0, r_reach=10.0, distance_tol=0.1):
        # Store internal vars
        self._robot_idn = robot_idn
        self._r_reach = r_reach
        self._distance_tol = distance_tol

        # Run super
        super().__init__()

    def _step(self, task, env, action):
        # Sparse reward is received if distance between robot_idn robot's eef and goal is below the distance threshold
        rewards = th.zeros(env.num_envs, dtype=th.float32)
        infos = [dict() for _ in range(env.num_envs)]
        for env_idx in range(env.num_envs):
            robot = env.scenes[env_idx].robots[self._robot_idn]
            eef_pos = robot.get_eef_position()
            dist = T.l2_distance(eef_pos, task.get_goal_pos(env_idx))
            if dist < self._distance_tol:
                rewards[env_idx] = self._r_reach
        return rewards, infos