🎨 Use real variables
This commit is contained in:
@@ -8,3 +8,7 @@ pybullet
|
|||||||
websockets
|
websockets
|
||||||
msgpack
|
msgpack
|
||||||
asyncio
|
asyncio
|
||||||
|
gymnasium
|
||||||
|
stable-baselines3[extra]>=2.0.0
|
||||||
|
tensorboard
|
||||||
|
tqdm
|
||||||
@@ -41,7 +41,7 @@ class QuadrupedRobot:
|
|||||||
position, orientation = p.getBasePositionAndOrientation(self.robot_id)
|
position, orientation = p.getBasePositionAndOrientation(self.robot_id)
|
||||||
orientation = p.getEulerFromQuaternion(orientation)
|
orientation = p.getEulerFromQuaternion(orientation)
|
||||||
velocity, angular_velocity = p.getBaseVelocity(self.robot_id)
|
velocity, angular_velocity = p.getBaseVelocity(self.robot_id)
|
||||||
joint_states = p.getJointStates(self.robot_id, range(p.getNumJoints(self.robot_id)))
|
joint_states = p.getJointStates(self.robot_id, self.movable_joint_indices)
|
||||||
joint_positions = [state[0] for state in joint_states]
|
joint_positions = [state[0] for state in joint_states]
|
||||||
joint_velocities = [state[1] for state in joint_states]
|
joint_velocities = [state[1] for state in joint_states]
|
||||||
return np.concatenate(
|
return np.concatenate(
|
||||||
@@ -53,7 +53,7 @@ class QuadrupedRobot:
|
|||||||
joint_positions,
|
joint_positions,
|
||||||
joint_velocities,
|
joint_velocities,
|
||||||
]
|
]
|
||||||
)
|
).astype(np.float32)
|
||||||
|
|
||||||
def apply_action(self, action):
|
def apply_action(self, action):
|
||||||
for i, position in enumerate(action):
|
for i, position in enumerate(action):
|
||||||
@@ -71,29 +71,35 @@ class QuadrupedRobot:
|
|||||||
|
|
||||||
|
|
||||||
class QuadrupedEnv(gym.Env):
|
class QuadrupedEnv(gym.Env):
|
||||||
def __init__(self, terrain_type: TerrainType = TerrainType.FLAT, render_mode: str = "human"):
|
def __init__(
|
||||||
|
self,
|
||||||
|
terrain_type: TerrainType = TerrainType.FLAT,
|
||||||
|
render_mode: str = "human",
|
||||||
|
target_velocity: float = 0.5,
|
||||||
|
max_steps: int = 1000,
|
||||||
|
distance_limit: float = 10.0,
|
||||||
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
if render_mode == "human":
|
if render_mode == "human":
|
||||||
p.connect(p.GUI)
|
p.connect(p.GUI)
|
||||||
else:
|
else:
|
||||||
p.connect(p.DIRECT)
|
p.connect(p.DIRECT)
|
||||||
|
|
||||||
self.observation_space = gym.spaces.Box(low=-np.inf, high=np.inf, shape=(48,))
|
self.observation_space = gym.spaces.Box(low=-np.inf, high=np.inf, shape=(36,), dtype=np.float32)
|
||||||
self.action_space = gym.spaces.Box(low=-1, high=1, shape=(18,))
|
self.action_space = gym.spaces.Box(low=-1, high=1, shape=(12,), dtype=np.float32)
|
||||||
p.setAdditionalSearchPath(pybullet_data.getDataPath())
|
p.setAdditionalSearchPath(pybullet_data.getDataPath())
|
||||||
|
|
||||||
self.terrain_type = terrain_type
|
self.terrain_type = terrain_type
|
||||||
self.render_mode = render_mode
|
self.render_mode = render_mode
|
||||||
self.target_velocity = 0.5
|
self.target_velocity = target_velocity
|
||||||
self.max_steps = float("inf")
|
self.max_steps = max_steps
|
||||||
self.current_step = 0
|
self.current_step = 0
|
||||||
|
|
||||||
self._setup_world()
|
self._setup_world()
|
||||||
if render_mode == "human":
|
if render_mode == "human":
|
||||||
self.env_start_state = p.saveState()
|
self.env_start_state = p.saveState()
|
||||||
|
|
||||||
# env parameters
|
self._distance_limit = distance_limit
|
||||||
self._distance_limit = float("inf")
|
|
||||||
|
|
||||||
def _setup_world(self):
|
def _setup_world(self):
|
||||||
self.robot = QuadrupedRobot("src/resources/spot.urdf")
|
self.robot = QuadrupedRobot("src/resources/spot.urdf")
|
||||||
|
|||||||
Reference in New Issue
Block a user