How to randomize the initial state of the robot in simulation? #351
Answered
by
stephane-caron
stephane-caron
asked this question in
Software
-
The training script of the PPO balancer randomizes initial states in parallel environments, but the whole script altogether is hard to parse. What is a simple way to randomize the initial state of my Upkie in simulation? |
Beta Was this translation helpful? Give feedback.
Answered by
stephane-caron
May 29, 2024
Replies: 1 comment
-
Here is a small balancer where we randomize the initial vertical position import gymnasium as gym
import numpy as np
from upkie.utils.robot_state import RobotState, RobotStateRandomization
with gym.make(
"UpkieGroundVelocity-v3",
init_state=RobotState(
position_base_in_world=np.array([0.0, 0.0, 0.8]),
randomization=RobotStateRandomization(
z=0.4,
v_z=0.1,
),
),
) as env:
env.reset() # connects to the spine at first call
action = np.zeros(env.action_space.shape)
for step in range(1_000_000):
observation, _, _, _, _ = env.step(action)
pitch = observation[0]
action[0] = 10.0 * pitch # 1D action: [ground_velocity] |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
stephane-caron
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a small balancer where we randomize the initial vertical position$z_0 \in [0.4, 1.2] \textrm{ m}$ and velocity $\dot{z}_0 \in [-0.1, 0.1] \textrm{ m/s}$ :