Skip to content

Commit

Permalink
Added sync mode flag. Improved debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
deval-maker committed Nov 22, 2020
1 parent ecadadc commit 0c33189
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
22 changes: 12 additions & 10 deletions carla_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ def __del__(self):


class CarlaEnv(object):
def __init__(self, town="Town03", port=2000, **kwargs):
def __init__(self, town="Town03", port=2000, sync=True, num_players=1, **kwargs):
self._client = carla.Client("localhost", port)
self._client.set_timeout(30.0)

self.sync = sync
self.num_players = num_players
set_sync_mode(self._client, False)

# self._town_name = town
Expand All @@ -189,7 +190,9 @@ def _set_weather(self, weather_string):
self.weather = weather
self._world.set_weather(weather)

def reset(self, weather="random", n_vehicles=0, n_pedestrians=0, seed=0):
def reset(
self, weather="random", n_vehicles=0, n_pedestrians=0, seed=0, set_weather=False
):
is_ready = False

while not is_ready:
Expand All @@ -198,12 +201,11 @@ def reset(self, weather="random", n_vehicles=0, n_pedestrians=0, seed=0):
self._clean_up()
### make this a multi agent thing(take num_agents as args)
### Initialize the ActorClass object inside this and add to a list called self._players
num_agents = NUM_AGENTS
self._spawn_players(self._map.get_spawn_points(), num_agents)
# self._spawn_player(np.random.choice(self._map.get_spawn_points()))
# self._setup_sensors()
self._spawn_players(self._map.get_spawn_points(), self.num_players)

if set_weather:
self._set_weather(weather)

self._set_weather(weather)
self._pedestrian_pool = PedestrianPool(self._client, n_pedestrians)
self._vehicle_pool = VehiclePool(self._client, n_vehicles)

Expand Down Expand Up @@ -238,8 +240,8 @@ def ready(self, ticks=10):
def step(self, control=None):
# if control is not None:
# self._player.apply_control(control)

# self._world.tick()
if self.sync:
self._world.tick()
self._tick += 1
self._pedestrian_pool.tick()
for player in self._players:
Expand Down
25 changes: 18 additions & 7 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

from carla_env import CarlaEnv

SYNCMODE = True
NUM_PLAYERS = 2

if __name__ == "__main__":
print("Run.py")
env = CarlaEnv()
print("Env activated")
env.reset()
for i in tqdm(range(10000)):
# print("IN Step ", i)
env.step()
# time.sleep(0.2)
if not SYNCMODE:
env = CarlaEnv(sync=SYNCMODE, num_players=NUM_PLAYERS)
print("Env activated")
env.reset()
for i in tqdm(range(10000)):
# print("IN Step ", i)
env.step()
# time.sleep(0.2)
else:
with CarlaEnv(sync=SYNCMODE, num_players=NUM_PLAYERS) as env:
print("Env activated")
env.reset()
for i in tqdm(range(10000)):
# print("IN Step ", i)
env.step()
14 changes: 12 additions & 2 deletions stars_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


PIXELS_PER_WORLD = 5.5
DEBUG_MAP_VIEW = False
DEBUG_MAP_VIEW = True


class StarsAgent:
Expand Down Expand Up @@ -241,7 +241,7 @@ def run_step(self):
velocity = self.player.get_velocity()
speed = np.linalg.norm([velocity.x, velocity.y, velocity.z])

DT = 2.5 # speed-time window for rerouting
DT = 3.5 # speed-time window for rerouting

if self.player.get_location().distance(
self.cur_target.transform.location
Expand All @@ -255,6 +255,16 @@ def run_step(self):
target = self.transform_target_waypoint(self.cur_target)

if DEBUG_MAP_VIEW:

self.world.debug.draw_point(
self.cur_target.transform.location, life_time=2
)
self.world.debug.draw_point(
self.player.get_location(),
color=carla.Color(0, 0, 255),
life_time=1,
)

out_points, heatmap = self.model(
topdown.cuda()[None], target.unsqueeze(0), debug=True
)
Expand Down

0 comments on commit 0c33189

Please sign in to comment.