Skip to content

Commit

Permalink
fewer magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
tawnkramer committed Oct 20, 2018
1 parent 32c373e commit 269ac8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 9 additions & 3 deletions donkey_gym/envs/donkey_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ class DonkeyEnv(gym.Env):
"render.modes": ["human", "rgb_array"],
}

ACTION = ["steer", "throttle"]
ACTION_NAMES = ["steer", "throttle"]
STEER_LIMIT_LEFT = -1.0
STEER_LIMIT_RIGHT = 1.0
THROTTLE_MIN = 0.0
THROTTLE_MAX = 5.0
VAL_PER_PIXEL = 255

def __init__(self, level, time_step=0.05, frame_skip=2):

Expand Down Expand Up @@ -67,10 +72,11 @@ def __init__(self, level, time_step=0.05, frame_skip=2):
self.viewer = DonkeyUnitySimContoller(level=level, time_step=time_step, port=port)

# steering and throttle
self.action_space = spaces.Box(low=np.array([-1.0, 0.0]), high=np.array([1.0, 5.0]), dtype=np.float32 )
self.action_space = spaces.Box(low=np.array([self.STEER_LIMIT_LEFT, self.THROTTLE_MIN]),
high=np.array([self.STEER_LIMIT_RIGHT, self.THROTTLE_MAX]), dtype=np.float32 )

# camera sensor data
self.observation_space = spaces.Box(0, 255, self.viewer.get_sensor_size(), dtype=np.uint8)
self.observation_space = spaces.Box(0, self.VAL_PER_PIXEL, self.viewer.get_sensor_size(), dtype=np.uint8)

# simulation related variables.
self.seed()
Expand Down
13 changes: 11 additions & 2 deletions examples/ppo_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ def _init():

if __name__ == "__main__":

# Initialize the donkey environment
# where env_name one of:
env_list = [
"donkey-warehouse-v0",
"donkey-generated-roads-v0",
"donkey-avc-sparkfun-v0",
"donkey-generated-track-v0"
]

parser = argparse.ArgumentParser(description='ppo_train')
parser.add_argument('--sim', type=str, default="sim_path", help='path to unity simulator. maybe be left at manual if you would like to start the sim on your own.')
parser.add_argument('--headless', type=int, default=0, help='1 to supress graphics')
parser.add_argument('--port', type=int, default=9091, help='port to use for tcp')
parser.add_argument('--test', action="store_true", help='load the trained model and play')
parser.add_argument('--multi', action="store_true", help='start multiple sims at once')
parser.add_argument('--env_name', type=str, default='donkey-generated-track-v0', help='name of donkey sim environment', choices=env_list)


args = parser.parse_args()

if args.sim == "sim_path" and args.multi:
Expand All @@ -54,7 +63,7 @@ def _init():
os.environ['DONKEY_SIM_PORT'] = str(args.port)
os.environ['DONKEY_SIM_HEADLESS'] = str(args.headless)

env_id = "donkey-generated-track-v0"
env_id = args.env_name

if args.test:

Expand Down

0 comments on commit 269ac8e

Please sign in to comment.