Skip to content
Snippets Groups Projects
Commit 99d658ff authored by Armin Co's avatar Armin Co
Browse files

Integrated manual control into env

parent 0f51360d
Branches
Tags
No related merge requests found
...@@ -185,7 +185,6 @@ class World: ...@@ -185,7 +185,6 @@ class World:
position = transform position = transform
self.player = self.world.try_spawn_actor(blueprint, position) self.player = self.world.try_spawn_actor(blueprint, position)
start_location = self.player.get_location() start_location = self.player.get_location()
print(str(start_location))
self.collision_sensor = CollisionSensor(self.world, self.player) self.collision_sensor = CollisionSensor(self.world, self.player)
self.obstacle_sensor = ObstacleSensor(self.world, self.player) self.obstacle_sensor = ObstacleSensor(self.world, self.player)
...@@ -290,12 +289,12 @@ class CarlaEnvironment: ...@@ -290,12 +289,12 @@ class CarlaEnvironment:
client = None client = None
camera = None camera = None
allow_render = False allow_render = False
manual = False
def __init__(self, host="127.0.0.1", port=2000, render=False): def __init__(self, host="127.0.0.1", port=2000, render=False, manual=False):
pygame.init() pygame.init()
self.client = carla.Client(host, port) self.client = carla.Client(host, port)
self.client.set_timeout(5.0) self.client.set_timeout(3.0)
time.sleep(1.0)
self.client.load_world('Town07') self.client.load_world('Town07')
time.sleep(1.0) time.sleep(1.0)
self.world = World(self.client.get_world()) self.world = World(self.client.get_world())
...@@ -303,6 +302,9 @@ class CarlaEnvironment: ...@@ -303,6 +302,9 @@ class CarlaEnvironment:
self.allow_render = True self.allow_render = True
self.camera = Camera(self.world, camera_type='semantic_segmentation') self.camera = Camera(self.world, camera_type='semantic_segmentation')
# self.camera = Camera(self.world, camera_type='rgb') # self.camera = Camera(self.world, camera_type='rgb')
if manual:
self.manual = False
self.cntrl = Controller()
def reset(self): def reset(self):
self.world.reset() self.world.reset()
...@@ -315,6 +317,8 @@ class CarlaEnvironment: ...@@ -315,6 +317,8 @@ class CarlaEnvironment:
def step(self, action, render=False): def step(self, action, render=False):
if render: if render:
self.render() self.render()
if self.manual:
action = self.cntrl.get_action()
return self.world.step(action) return self.world.step(action)
def __del__(self): def __del__(self):
......
...@@ -2,41 +2,43 @@ import main ...@@ -2,41 +2,43 @@ import main
import environment_wrapper as ew import environment_wrapper as ew
import gym import gym
import copy import copy
from agents import QAgent as QAgent from agents import QAgent, DQAgent
from carla_environment import CarlaEnvironment from carla_environment import CarlaEnvironment
c = ew.Config() c = ew.Config()
c.name = 'Base' c.name = '2'
c.render = True c.render = True
c.env_type = 'Carla' c.env_type = 'Carla'
c.net_layout = [256, 128] c.net_layout = [256, 128, 128]
c.eps_decay = 0.9995 c.eps_decay = 0.9995
c.learn_rate= 0.001 c.learn_rate= 0.001
c.run_episodes = 20 c.run_episodes = 100
c.save_to = 'test/' c.save_to = 'test/'
c.load_from = 'Carla_1_256__128__128_0.9995_0.001_1'
c.load_mem = True
t = copy.deepcopy(c) # t = copy.deepcopy(c)
t.render = True # t.render = True
t.net_layout = [1024, 1024, 256, 32] # t.net_layout = [1024, 1024, 256, 32]
t.eps_decay = 0.9993 # t.eps_decay = 0.9993
t.learn_rate = 0.0005 # t.learn_rate = 0.0005
t.force_cpu = False # t.force_cpu = False
t.load_mem = True # t.load_mem = True
t.load_ann = False # t.load_ann = False
t.save_to = 'test/' # t.save_to = 'test/'
t.load_from = 'Carla_CarlaOffline_1024__1024__256__32_0.9993_0.0005_50' # t.load_from = 'Carla_CarlaOffline_1024__1024__256__32_0.9993_0.0005_50'
t.name = 'Offline' # t.name = 'Offline'
t.learn_offline = True # t.learn_offline = True
t.learn_online = True # t.learn_online = True
t.run_episodes = 500 # t.run_episodes = 500
t.offline_epochs = 100 # t.offline_epochs = 100
t.learn_iterations = 100 # t.learn_iterations = 100
t.offline_validate_every_x_iteration = -1 # t.offline_validate_every_x_iteration = -1
configuration = t configuration = c
configuration.env = CarlaEnvironment(render=configuration.render) configuration.env = CarlaEnvironment(render=configuration.render, manual=True)
configuration.conf_to_name() configuration.conf_to_name()
configuration.agent = QAgent(configuration) configuration.agent = DQAgent(configuration)
main.run(configuration) main.run(configuration)
# Start CARLA
#
# You may have to change the path to the CarlaUE4.sh
# The simulator could be installed with your package manager:
# apt install carla-simulator
#
DISPLAY= /opt/carla-simulator/CarlaUE4.sh -benchmark -fps=15 -quality-level=Low -opengl
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment