How to modify configuration at reset in the gym environment? #63
-
Hi, I wonder how one could set the initial configuration (including orientations) at reset in the gym env. upkie_base_env (https://github.com/tasts-robots/upkie_locomotion/blob/main/envs/upkie_base_env.py) has a bullet interface (cf https://tasts-robots.org/doc/vulp/BulletInterface_8h_source.html) in which there's a What would be the best solution for that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The best way is to pass the initial orientation to the spine via the configuration dictionary. The orientation part was indeed not wired 😉 This is now fixed with stephane-caron/vulp#33, so that we can write examples such as this one: """Genuflect while lying on a horizontal floor."""
import gym
import numpy as np
from loop_rate_limiters import RateLimiter
import upkie.envs
nb_genuflections = 10
genuflection_steps = 200
amplitude = 1.0 # in radians
config = {
"bullet": {
"orientation_init_base_in_world": [0.707, 0.0, -0.707, 0.0], # [qw, qx, qy, qz]
"position_init_base_in_world": [0.0, 0.0, 0.1], # [x, y, z]
}
}
if __name__ == "__main__":
upkie.envs.register()
with gym.make("UpkieServosEnv-v1", config=config) as env:
observation = env.reset()
action = np.zeros(env.action_space.shape)
rate = RateLimiter(frequency=200.0)
for step in range(nb_genuflections * genuflection_steps):
observation, _, _, _ = env.step(action)
x = float(step % genuflection_steps) / genuflection_steps
y = 4.0 * x * (1.0 - x) # in [0, 1]
A = amplitude # in radians
action[[0, 1, 3, 4]] = A * y * np.array([1.0, -2.0, -1.0, 2.0])
rate.sleep() It looks like this: genuflections.mp4Hoping this helps 😃 |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! What about the joint values? Can they also be modified via the config for all resets? |
Beta Was this translation helpful? Give feedback.
The best way is to pass the initial orientation to the spine via the configuration dictionary. The orientation part was indeed not wired 😉 This is now fixed with stephane-caron/vulp#33, so that we can write examples such as this one: