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]
          )
  
      # Reward for not falling
      ret_r = 36
  
      vel_penalty = (
          state_desc["body_vel"]["pelvis"][0] - self.target_v
      ) ** 2 + (state_desc["body_vel"]["pelvis"][2] - 0) ** 2
  
      origin_action_l2_penalty = np.linalg.norm(action)
      action_l2_penalty = max(
          self.act_penalty_lowerbound, origin_action_l2_penalty
      )
  
      ret_r = (
          ret_r
          - vel_penalty * self.vel_penalty_coeff
          - action_l2_penalty * self.act_penalty_coeff
      )
  
      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": origin_action_l2_penalty,
      }
      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 FixedTargetSpeedReward obj's underlying member method code with example usage: obj.reward_shaping(state_desc, r2_reward, done, action) and returns: info