Amend bugs
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from isaaclab.assets import ArticulationCfg
|
from isaaclab.assets import ArticulationCfg
|
||||||
from isaaclab.envs import ManagerBasedRLEnvCfg, ManagerBasedRLEnv
|
from isaaclab.envs import ManagerBasedRLEnvCfg, ManagerBasedRLEnv
|
||||||
@@ -10,7 +12,6 @@ from isaaclab.envs.mdp import JointPositionActionCfg
|
|||||||
from isaaclab.managers import SceneEntityCfg
|
from isaaclab.managers import SceneEntityCfg
|
||||||
from isaaclab.utils import configclass
|
from isaaclab.utils import configclass
|
||||||
from rl_game.get_up.env.t1_env import T1SceneCfg
|
from rl_game.get_up.env.t1_env import T1SceneCfg
|
||||||
import isaaclab.utils.math as math_utils
|
|
||||||
|
|
||||||
import isaaclab.envs.mdp as mdp
|
import isaaclab.envs.mdp as mdp
|
||||||
|
|
||||||
@@ -184,51 +185,6 @@ def strict_feet_contact_reward(env: ManagerBasedRLEnv, sensor_cfg: SceneEntityCf
|
|||||||
|
|
||||||
return (~all_feet_cond).float() # 返回1表示违规
|
return (~all_feet_cond).float() # 返回1表示违规
|
||||||
|
|
||||||
|
|
||||||
def reset_root_state_symmetric(
|
|
||||||
env: ManagerBasedRLEnv,
|
|
||||||
env_ids: torch.Tensor,
|
|
||||||
asset_cfg: SceneEntityCfg,
|
|
||||||
pose_range: dict,
|
|
||||||
velocity_range: dict
|
|
||||||
):
|
|
||||||
"""随机对称采样:让机器人随机以 趴/躺/左倾/右倾 及其组合姿态重置"""
|
|
||||||
robot = env.scene[asset_cfg.name]
|
|
||||||
num_resets = len(env_ids)
|
|
||||||
device = env.device
|
|
||||||
|
|
||||||
# 1. 采样 Euler 角 (roll, pitch, yaw)
|
|
||||||
# 我们先在 positive range 内采样
|
|
||||||
def get_rand(key):
|
|
||||||
low, high = pose_range[key]
|
|
||||||
return (high - low) * torch.rand(num_resets, device=device) + low
|
|
||||||
|
|
||||||
roll = get_rand("roll")
|
|
||||||
pitch = get_rand("pitch")
|
|
||||||
yaw = (pose_range["yaw"][1] - pose_range["yaw"][0]) * torch.rand(num_resets, device=device) + pose_range["yaw"][0]
|
|
||||||
|
|
||||||
# 2. 核心:随机符号化 (Random Sign)
|
|
||||||
# 50% 概率保持正,50% 概率变负。Roll 和 Pitch 独立随机。
|
|
||||||
roll_sign = (torch.randint(0, 2, (num_resets,), device=device) * 2 - 1).float()
|
|
||||||
pitch_sign = (torch.randint(0, 2, (num_resets,), device=device) * 2 - 1).float()
|
|
||||||
|
|
||||||
roll *= roll_sign
|
|
||||||
pitch *= pitch_sign
|
|
||||||
|
|
||||||
# 3. 应用到状态
|
|
||||||
quat = math_utils.quat_from_euler_xyz(roll, pitch, yaw)
|
|
||||||
|
|
||||||
# 获取默认状态并叠加随机位置偏移 (x, y, z)
|
|
||||||
root_states = robot.data.default_root_state[env_ids].clone()
|
|
||||||
for i, key in enumerate(["x", "y", "z"]):
|
|
||||||
low, high = pose_range[key]
|
|
||||||
root_states[:, i] += (high - low) * torch.rand(num_resets, device=device) + low
|
|
||||||
|
|
||||||
root_states[:, 3:7] = quat
|
|
||||||
|
|
||||||
# 4. 写入仿真 (同时清除速度,确保是静态开始)
|
|
||||||
robot.write_root_state_to_sim(root_states, env_ids)
|
|
||||||
|
|
||||||
# --- 2. 配置类 ---
|
# --- 2. 配置类 ---
|
||||||
|
|
||||||
T1_JOINT_NAMES = [
|
T1_JOINT_NAMES = [
|
||||||
@@ -258,12 +214,12 @@ class T1ObservationCfg:
|
|||||||
@configclass
|
@configclass
|
||||||
class T1EventCfg:
|
class T1EventCfg:
|
||||||
reset_robot_rotation = EventTerm(
|
reset_robot_rotation = EventTerm(
|
||||||
func=reset_root_state_symmetric, # 使用上面那个通用的函数
|
func=mdp.reset_root_state_uniform,
|
||||||
params={
|
params={
|
||||||
"asset_cfg": SceneEntityCfg("robot"),
|
"asset_cfg": SceneEntityCfg("robot"),
|
||||||
"pose_range": {
|
"pose_range": {
|
||||||
"roll": (0, 1.57), # 左右侧卧
|
"roll": (0, 1.57) * random.choice([1, -1]) , # 左右侧卧
|
||||||
"pitch": (1.4, 1.6), # 仰卧/俯卧
|
"pitch": (1.4, 1.6) * random.choice([1, -1]) , # 仰卧/俯卧
|
||||||
"yaw": (-3.14, 3.14), # 全向旋转
|
"yaw": (-3.14, 3.14), # 全向旋转
|
||||||
"x": (0.0, 0.0),
|
"x": (0.0, 0.0),
|
||||||
"y": (0.0, 0.0),
|
"y": (0.0, 0.0),
|
||||||
|
|||||||
Reference in New Issue
Block a user