Skip to content

How to randomize the initial state of the robot in simulation? #351

Discussion options

You must be logged in to vote

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}$:

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.s…

Replies: 1 comment

Comment options

You must be logged in to vote
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
Labels
None yet
1 participant