|
| 1 | +# Copyright (C) 2020-2025 Motphys Technology Co., Ltd. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# ============================================================================== |
| 15 | + |
| 16 | +import os |
| 17 | +from dataclasses import dataclass, field |
| 18 | + |
| 19 | +from motrix_envs import registry |
| 20 | +from motrix_envs.base import EnvCfg |
| 21 | + |
| 22 | +model_file = os.path.dirname(__file__) + "/xmls/scene_flat.xml" |
| 23 | + |
| 24 | + |
| 25 | +@dataclass |
| 26 | +class NoiseConfig: |
| 27 | + level: float = 1.0 |
| 28 | + scale_joint_angle: float = 0.03 |
| 29 | + scale_joint_vel: float = 1.5 |
| 30 | + scale_gyro: float = 0.2 |
| 31 | + scale_gravity: float = 0.05 |
| 32 | + scale_linvel: float = 0.1 |
| 33 | + |
| 34 | + |
| 35 | +@dataclass |
| 36 | +class ControlConfig: |
| 37 | + # action scale: target angle = actionScale * action + defaultAngle |
| 38 | + action_scale = 0.05 |
| 39 | + |
| 40 | + |
| 41 | +@dataclass |
| 42 | +class InitState: |
| 43 | + # the initial position of the robot in the world frame |
| 44 | + pos = [0.0, 0.0, 0.42] #0.278 |
| 45 | + |
| 46 | + # the default angles for all joints. key = joint name, value = target angle [rad] |
| 47 | + default_joint_angles = { |
| 48 | + "FL_hip" : 0.1, # [rad] |
| 49 | + "FL_thigh" : 0.9, # [rad] |
| 50 | + "FL_calf" : -1.8, # [rad] |
| 51 | + "FR_hip" : -0.1, # [rad] |
| 52 | + "FR_thigh" : 0.9, # [rad] |
| 53 | + "FR_calf" : -1.8, # [rad] |
| 54 | + "RL_hip" : 0.1, # [rad] |
| 55 | + "RL_thigh" : 0.9, # [rad] |
| 56 | + "RL_calf" : -1.8, # [rad] |
| 57 | + "RR_hip" : -0.1, # [rad] |
| 58 | + "RR_thigh" : 0.9, # [rad] |
| 59 | + "RR_calf" : -1.8, # [rad] |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | +@dataclass |
| 64 | +class Commands: |
| 65 | + vel_limit = [ |
| 66 | + [-2.0, -1.0, -3.1416], # min: vel_x [m/s], vel_y [m/s], ang_vel [rad/s] |
| 67 | + [ 2.0, 1.0, 3.1416], # max |
| 68 | + ] |
| 69 | + |
| 70 | + |
| 71 | +@dataclass |
| 72 | +class Normalization: |
| 73 | + lin_vel = 2 |
| 74 | + ang_vel = 0.25 |
| 75 | + dof_pos = 1 |
| 76 | + dof_vel = 0.05 |
| 77 | + |
| 78 | + |
| 79 | +@dataclass |
| 80 | +class Asset: |
| 81 | + body_name = "base" |
| 82 | + foot_name = "foot" |
| 83 | + penalize_contacts_on = ["thigh", "calf"] |
| 84 | + terminate_after_contacts_on = [ |
| 85 | + "base_collision_0", "base_collision_1", "base_collision_2", |
| 86 | + "fl_hip_0", "fr_hip_0", "rl_hip_0", "rr_hip_0", |
| 87 | + ] |
| 88 | + ground = "floor" |
| 89 | + |
| 90 | + |
| 91 | +@dataclass |
| 92 | +class Sensor: |
| 93 | + local_linvel = "local_linvel" |
| 94 | + gyro = "gyro" |
| 95 | + |
| 96 | + |
| 97 | +@dataclass |
| 98 | +class RewardConfig: |
| 99 | + scales: dict[str, float] = field( |
| 100 | + default_factory=lambda: { |
| 101 | + "termination": -0.0, |
| 102 | + "tracking_lin_vel": 1.0, |
| 103 | + "tracking_ang_vel": 0.5, |
| 104 | + "lin_vel_z": -2.0, |
| 105 | + "ang_vel_xy": -0.05, |
| 106 | + "orientation": -0.0, |
| 107 | + "torques": -0.00001, |
| 108 | + "dof_vel": -0.0, |
| 109 | + "dof_acc": -2.5e-7, |
| 110 | + "base_height": -0.0, |
| 111 | + "feet_air_time": 1.0, |
| 112 | + "collision": -1.0 * 0, |
| 113 | + "feet_stumble": -0.0, |
| 114 | + "action_rate": -0.001, |
| 115 | + "stand_still": -0.0, |
| 116 | + "hip_pos": -1, |
| 117 | + "calf_pos": -0.3 * 0, |
| 118 | + } |
| 119 | + ) |
| 120 | + |
| 121 | + tracking_sigma: float = 0.25 |
| 122 | + max_foot_height: float = 0.1 |
| 123 | + |
| 124 | + |
| 125 | +@registry.envcfg("go2-flat-terrain-walk") |
| 126 | +@dataclass |
| 127 | +class Go2WalkNpEnvCfg(EnvCfg): |
| 128 | + max_episode_seconds: float = 20.0 |
| 129 | + model_file: str = model_file |
| 130 | + noise_config: NoiseConfig = field(default_factory=NoiseConfig) |
| 131 | + control_config: ControlConfig = field(default_factory=ControlConfig) |
| 132 | + reward_config: RewardConfig = field(default_factory=RewardConfig) |
| 133 | + init_state: InitState = field(default_factory=InitState) |
| 134 | + commands: Commands = field(default_factory=Commands) |
| 135 | + normalization: Normalization = field(default_factory=Normalization) |
| 136 | + asset: Asset = field(default_factory=Asset) |
| 137 | + sensor: Sensor = field(default_factory=Sensor) |
| 138 | + sim_dt: float = 0.01 |
| 139 | + ctrl_dt: float = 0.01 |
0 commit comments