Attention
This challenge has ended!
This documentation is only for the Real Robot Challenge 2020 which has ended. Following challenges have their own documentation, see the challenge website for more information.
Getting Started¶
The TriFingerPlatform Class¶
The TriFingerPlatform
class contains the pyBullet simulation of the
TriFinger robot and provides an interface that is mostly identical with that of
the real robot. This way, transitioning from simulation to real robot later
should only require very few changes in your code.
#!/usr/bin/env python3
"""Simple demo on how to use the TriFingerPlatform interface."""
import time
import numpy as np
import rrc_simulation
if __name__ == "__main__":
platform = rrc_simulation.TriFingerPlatform(visualization=True)
# Move the fingers to random positions
while True:
position = platform.spaces.robot_position.gym.sample()
finger_action = platform.Action(position=position)
# apply action for a few steps, so the fingers can move to the target
# position and stay there for a while
for _ in range(100):
t = platform.append_desired_action(finger_action)
# sleep after each step so that the visualization happens in real
# time
time.sleep(platform.get_time_step())
# show the latest observations
robot_observation = platform.get_robot_observation(t)
print("Finger0 Joint Positions: %s" % robot_observation.position[:3])
cube_pose = platform.get_object_pose(t)
print("Cube Position (x, y, z): %s" % cube_pose.position)
For a documentation on the full API see The TriFingerPlatform Class.
Gym Environment¶
We provide a basic Gym environment for the challenge task. It is registered as
rrc_simulation.gym_wrapper:real_robot_challenge_phase_1-v1
.
Below is a simple demo showing how the environment is used to run a “random policy” for one episode.
#!/usr/bin/env python3
"""Demo on how to run the simulation using the Gym environment
This demo creates a CubeEnv environment and runs one episode with random
initialization using a dummy policy which uses random actions.
"""
import gym
from rrc_simulation.gym_wrapper.envs import cube_env
class RandomPolicy:
"""Dummy policy which uses random actions."""
def __init__(self, action_space):
self.action_space = action_space
def predict(self, observation):
return self.action_space.sample()
def main():
# Use a random initializer with difficulty 1
initializer = cube_env.RandomInitializer(difficulty=1)
env = gym.make(
"rrc_simulation.gym_wrapper:real_robot_challenge_phase_1-v1",
initializer=initializer,
action_type=cube_env.ActionType.POSITION,
frameskip=100,
visualization=True,
)
policy = RandomPolicy(env.action_space)
observation = env.reset()
is_done = False
while not is_done:
action = policy.predict(observation)
observation, reward, is_done, info = env.step(action)
print("Reward at final step: {:.3f}".format(reward))
if __name__ == "__main__":
main()
The environment uses the same reward function that will also be used to evaluate submissions at the end of this phase of the challenge.
See the full API documentation for more details.
You may use this environment as is for your training but you may also implement your own one. If you only want to change parts, you can use a copy of our environment as a base for your custom one. You can find the file in the rrc_simulation repository at:
python/rrc_simulation/gym_wrapper/envs/cube_env.py