Skip to content

Commit

Permalink
Merge pull request #49 from Maximellerbach/improved-tests
Browse files Browse the repository at this point in the history
Improved tests
  • Loading branch information
tawnkramer authored Sep 28, 2020
2 parents 2633a7a + 868d291 commit 85f803c
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 56 deletions.
14 changes: 7 additions & 7 deletions examples/genetic_alg/simple_gen_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ def on_agents_finished(self):

if __name__ == "__main__":

# Initialize the donkey environment
# 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",
"donkey-mountain-track-v0"
"donkey-warehouse-v0",
"donkey-generated-roads-v0",
"donkey-avc-sparkfun-v0",
"donkey-generated-track-v0",
"donkey-roboracingleague-track-v0"
]

parser = argparse.ArgumentParser(description='simple_gen_driver')
Expand All @@ -206,7 +206,7 @@ def on_agents_finished(self):
parser.add_argument('--num_agents', type=int, default=8, help='how many agents in our population')
parser.add_argument('--num_iter', type=int, default=8, help='how many generations before we stop')
parser.add_argument('--max_steps', type=int, default=200, help='how many sim steps before we stop an epoch')
parser.add_argument('--env_name', type=str, default='donkey-mountain-track-v0', help='name of donkey sim environment', choices=env_list)
parser.add_argument('--env_name', type=str, default='donkey-warehouse-v0', help='name of donkey sim environment', choices=env_list)
parser.add_argument('--in_model', type=str, help='.h5 model produced by donkeycar. expects the default linear model type.')
parser.add_argument('--out_model', type=str, default='out.h5', help='.h5 model to save.')

Expand Down
63 changes: 41 additions & 22 deletions examples/gym_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@
MAX_TIME_STEPS = 1000


def test_track(env_name, conf):
env = gym.make(env_name, conf=conf)

# make sure you have no track loaded
exit_scene(env)

simulate(env)

# exit the scene and close the env
exit_scene(env)
env.close()


def select_action(env):
#return env.action_space.sample()
return [0.0, 0.1] # enable this to test checkpoint failure
return env.action_space.sample() # taking random action from the action_space


def simulate(env):
Expand All @@ -42,6 +54,10 @@ def simulate(env):
break


def exit_scene(env):
env.viewer.exit_scene()


if __name__ == "__main__":

# Initialize the donkey environment
Expand All @@ -51,7 +67,7 @@ def simulate(env):
"donkey-generated-roads-v0",
"donkey-avc-sparkfun-v0",
"donkey-generated-track-v0",
"donkey-mountain-track-v0"
"donkey-roboracingleague-track-v0"
]

parser = argparse.ArgumentParser(description='gym_test')
Expand All @@ -61,32 +77,35 @@ def simulate(env):
help='host to use for tcp')
parser.add_argument('--port', type=int, default=9091,
help='port to use for tcp')
parser.add_argument('--env_name', type=str, default='donkey-mountain-track-v0',
help='name of donkey sim environment', choices=env_list)
parser.add_argument('--env_name', type=str, default="all",
help='name of donkey sim environment', choices=env_list+['all'])

args = parser.parse_args()

conf = {"exe_path" : args.sim,
"host" : args.host,
"port" : args.port,
conf = {
"exe_path": args.sim,
"host": args.host,
"port": args.port,

"body_style" : "donkey",
"body_rgb" : (128, 128, 128),
"car_name" : "me",
"font_size" : 100,
"body_style": "donkey",
"body_rgb": (128, 128, 128),
"car_name": "me",
"font_size": 100,

"racer_name" : "test",
"country" : "USA",
"bio" : "I am test client",
"guid" : str(uuid.uuid4()),
"racer_name": "test",
"country": "USA",
"bio": "I am test client",
"guid": str(uuid.uuid4()),

"max_cte" : 20,
}
"start_delay": 1,
"max_cte": 5,
}

env = gym.make(args.env_name, conf=conf)

simulate(env)
if args.env_name == 'all':
for env_name in env_list:
test_track(env_name, conf)

env.close()
else:
test_track(args.env_name, conf)

print("test finished")
17 changes: 7 additions & 10 deletions examples/reinforcement_learning/ddqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ def signal_handler(signal, frame):
if __name__ == "__main__":

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

parser = argparse.ArgumentParser(description='ddqn')
Expand All @@ -348,11 +348,8 @@ def signal_handler(signal, frame):
parser.add_argument('--test', action="store_true", help='agent uses learned model to navigate env')
parser.add_argument('--port', type=int, default=9091, help='port to use for websockets')
parser.add_argument('--throttle', type=float, default=0.3, help='constant throttle for driving')
parser.add_argument('--env_name', type=str, default='donkey-mountain-track-v0', help='name of donkey sim environment', choices=env_list)
parser.add_argument('--env_name', type=str, default='donkey-warehouse-v0', help='name of donkey sim environment', choices=env_list)

args = parser.parse_args()

run_ddqn(args)



18 changes: 9 additions & 9 deletions examples/reinforcement_learning/ppo_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ def _init():

if __name__ == "__main__":

# Initialize the donkey environment
# where env_name one of:
# 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",
"donkey-mountain-track-v0"
"donkey-warehouse-v0",
"donkey-generated-roads-v0",
"donkey-avc-sparkfun-v0",
"donkey-generated-track-v0",
"donkey-roboracingleague-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('--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-mountain-track-v0', help='name of donkey sim environment', choices=env_list)
parser.add_argument('--env_name', type=str, default='donkey-warehouse-v0', help='name of donkey sim environment', choices=env_list)

args = parser.parse_args()

Expand Down
4 changes: 2 additions & 2 deletions examples/test_cam_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"donkey-generated-roads-v0",
"donkey-avc-sparkfun-v0",
"donkey-generated-track-v0",
"donkey-mountain-track-v0"
"donkey-roboracingleague-track-v0"
]

parser = argparse.ArgumentParser(description='gym_test')
parser.add_argument('--sim', type=str, default="sim_path",
help='path to unity simulator. maybe be left at default if you would like to start the sim on your own.')
parser.add_argument('--port', type=int, default=9091,
help='port to use for websockets')
parser.add_argument('--env_name', type=str, default='donkey-mountain-track-v0',
parser.add_argument('--env_name', type=str, default='donkey-warehouse-v0',
help='name of donkey sim environment', choices=env_list)

args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion gym_donkeycar/envs/donkey_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DonkeyEnv(gym.Env):
STEER_LIMIT_LEFT = -1.0
STEER_LIMIT_RIGHT = 1.0
THROTTLE_MIN = 0.0
THROTTLE_MAX = 5.0
THROTTLE_MAX = 1.0
VAL_PER_PIXEL = 255

def __init__(self, level, conf):
Expand Down
9 changes: 8 additions & 1 deletion gym_donkeycar/envs/donkey_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def observe(self):
def quit(self):
self.client.stop()

def exit_scene(self):
self.handler.send_exit_scene()

def render(self, mode):
pass

Expand Down Expand Up @@ -324,7 +327,7 @@ def on_recv_scene_names(self, data):
if self.SceneToLoad in names:
self.send_load_scene(self.SceneToLoad)
else:
raise ValueError("Scene name not in scene list")
raise ValueError(f"Scene name {self.SceneToLoad} not in scene list {names}")

def send_control(self, steer, throttle):
if not self.loaded:
Expand All @@ -345,6 +348,10 @@ def send_load_scene(self, scene_name):
msg = {'msg_type': 'load_scene', 'scene_name': scene_name}
self.queue_message(msg)

def send_exit_scene(self):
msg = {'msg_type': 'exit_scene'}
self.queue_message(msg)

def send_car_config(self, body_style, body_rgb, car_name, font_size):
"""
# body_style = "donkey" | "bare" | "car01" choice of string
Expand Down
9 changes: 5 additions & 4 deletions tests/test_gym_donkeycar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import gym_donkeycar.envs

env_list = [
"donkey-warehouse-v0",
"donkey-generated-roads-v0",
"donkey-avc-sparkfun-v0",
"donkey-generated-track-v0"
"donkey-warehouse-v0",
"donkey-generated-roads-v0",
"donkey-avc-sparkfun-v0",
"donkey-generated-track-v0",
"donkey-roboracingleague-track-v0"
]

def test_load_gyms(mocker):
Expand Down

0 comments on commit 85f803c

Please sign in to comment.