class_docstr: Reward shaping wrapper for fixed target speed
class_docstr_tok: ["Reward","shaping","wrapper","for","fixed","target","speed"]
code: def reward_shaping(self, state_desc, r2_reward, done, action):
      if self.pre_state_desc is None:
          x_offset = 0
      else:
          x_offset = (
              state_desc["body_pos"]["pelvis"][0]
              - self.pre_state_desc["body_pos"]["pelvis"][0]
          )
  
      ret_r = 0
      if self.pre_state_desc is not None:
          l_foot_reward = (
              state_desc["body_pos"]["tibia_l"][0]
              - self.pre_state_desc["body_pos"]["tibia_l"][0]
          )
          r_foot_reward = (
              state_desc["body_pos"]["pros_tibia_r"][0]
              - self.pre_state_desc["body_pos"]["pros_tibia_r"][0]
          )
          ret_r = max(l_foot_reward, r_foot_reward)
  
      # penalty
      headx = state_desc["body_pos"]["head"][0]
      px = state_desc["body_pos"]["pelvis"][0]
      headz = state_desc["body_pos"]["head"][2]
      pz = state_desc["body_pos"]["pelvis"][2]
      kneer = state_desc["joint_pos"]["knee_r"][-1]
      kneel = state_desc["joint_pos"]["knee_l"][-1]
      lean_x = min(0.3, max(0, px - headx - 0.15)) * 0.05
      lean_z = min(0.3, max(0, pz - headz - 0.15)) * 0.05
      joint = sum([max(0, k - 0.1) for k in [kneer, kneel]]) * 0.03
      penalty = lean_x + lean_z + joint
  
      ret_r -= penalty * 0.15
  
      cur_vel_x = state_desc["body_vel"]["pelvis"][0]
      cur_vel_z = state_desc["body_vel"]["pelvis"][2]
      scalar_vel = math.sqrt(cur_vel_z**2 + cur_vel_x**2)
  
      info = {
          "shaping_reward": ret_r,
          "r2_reward": r2_reward,
          "x_offset_reward": x_offset,
          "scalar_vel": scalar_vel,
          "mean_action_l2_penalty": 0,
      }
      return info
  
imports: import abc
  import gym
  import math
  import numpy
  import random
  from collections import OrderedDict
  from osim.env import ProstheticsEnv
  from parl.utils import logger
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling the RunFastestReward obj's underlying member method code with example usage: obj.reward_shaping(state_desc, r2_reward, done, action) and returns: info