Skip to content

Commit

Permalink
define simple action and observation space
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeMartins96 committed Aug 12, 2020
1 parent a99b190 commit 97bf70f
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
grsim_ssl/__pycache__/*
*.pyc
gym_ssl.egg-info/
pb/*
4 changes: 2 additions & 2 deletions gym_ssl/grsim_ssl/grSimClient.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import socket
import pb.messages_robocup_ssl_wrapper_pb2 as wrapper_pb2
import pb.grSim_Packet_pb2 as packet_pb2
import gym_ssl.grsim_ssl.pb.messages_robocup_ssl_wrapper_pb2 as wrapper_pb2
import gym_ssl.grsim_ssl.pb.grSim_Packet_pb2 as packet_pb2


class grSimClient:
Expand Down
55 changes: 55 additions & 0 deletions gym_ssl/grsim_ssl/grSimSSL_env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
import gym
import math
import numpy as np

from gym_ssl.grsim_ssl.grSimClient import grSimClient


class GrSimSSLEnv(gym.Env):
"""
Using cartpole env description as base example for our documentation
Description:
A pole is attached by an un-actuated joint to a cart, which moves along
a frictionless track. The pendulum starts upright, and the goal is to
prevent it from falling over by increasing and reducing the cart's
velocity.
Source:
This environment corresponds to the version of the cart-pole problem
described by Barto, Sutton, and Anderson
Observation:
Type: Box(3)
Num Observation Min Max
0 id 0 Blue Team Robot X -Inf Inf
1 id 0 Blue Team Robot Y -Inf Inf
2 id 0 Blue Team Robot Angle -3.1416 3.1416
Actions:
Type: Box(3)
Num Action Min Max
0 id 0 Blue Team Robot Vx -1 1
1 id 0 Blue Team Robot Vy -1 1
2 id 0 Blue Team Robot Omega -1 1
Note: The amount the velocity that is reduced or increased is not
fixed; it depends on the angle the pole is pointing. This is because
the center of gravity of the pole increases the amount of energy needed
to move the cart underneath it
Reward:
Reward is 1 for every step taken, including the termination step
Starting State:
All observations are assigned a uniform random value in [-0.05..0.05]
Episode Termination:
Pole Angle is more than 12 degrees.
Cart Position is more than 2.4 (center of the cart reaches the edge of
the display).
Episode length is greater than 200.
Solved Requirements:
Considered solved when the average return is greater than or equal to
195.0 over 100 consecutive trials.
"""

def __init__(self):
self.client = grSimClient()

self.action_space = gym.spaces.Box(low=-1, high=1, shape=(3,), dtype=np.float32)
# Observation Space thresholds
obsSpaceThresholds = np.array([np.finfo(np.float32).max,
np.finfo(np.float32).max,
math.pi], dtype=np.float32)
self.observation_space = gym.spaces.Box(low=-obsSpaceThresholds, high=obsSpaceThresholds)

print('Environment initialized')

def step(self):
print('step sucessful!')
return self.observation_space.sample()
def reset(self):
print('Environment reset')
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions gym_ssl/grsim_ssl/pb/grSim_Packet_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gym_ssl/grsim_ssl/pb/messages_robocup_ssl_wrapper_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import gym
import gym_ssl

env = gym.make('grSimSSL-v0')
env.step()
env.reset()
print(env.action_space.sample())
print(env.observation_space.sample())

0 comments on commit 97bf70f

Please sign in to comment.