From f14d60e2994530f423fee6bb89d16c25ce4e0164 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Mon, 15 Oct 2018 12:01:31 +0200 Subject: [PATCH] Allow changing weather from manual_control.py --- PythonAPI/manual_control.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/PythonAPI/manual_control.py b/PythonAPI/manual_control.py index 9e8a7b987..5cc77773f 100755 --- a/PythonAPI/manual_control.py +++ b/PythonAPI/manual_control.py @@ -24,6 +24,7 @@ Use ARROWS or WASD keys for control. TAB : change camera position ` : next camera sensor [1-9] : change to camera sensor [1-9] + C : change weather R : toggle recording images to disk @@ -82,6 +83,7 @@ try: from pygame.locals import K_TAB from pygame.locals import K_UP from pygame.locals import K_a + from pygame.locals import K_c from pygame.locals import K_d from pygame.locals import K_h from pygame.locals import K_p @@ -113,6 +115,14 @@ class World(object): self.vehicle = carla_world.spawn_actor(blueprint, START_POSITION) self.camera_manager = CameraManager(self.vehicle, self.hud) self.controller = None + self._weather_presets = ["Clear Noon", "Cloudy Noon", "Wet Noon"] + + def next_weather(self): + weather_name = self._weather_presets.pop(0) + self.hud.notification('Weather: %s' % weather_name) + weather = getattr(carla.WeatherParameters, weather_name.replace(" ", "")) + self.vehicle.get_world().set_weather(weather) + self._weather_presets.append(weather_name) def tick(self, clock): self.hud.tick(self, clock) @@ -151,6 +161,8 @@ class KeyboardControl(object): world.hud.help.toggle() elif event.key == K_TAB: world.camera_manager.toggle_camera() + elif event.key == K_c: + world.next_weather() elif event.key == K_BACKQUOTE: world.camera_manager.next_sensor() elif event.key > K_0 and event.key <= K_9: @@ -258,7 +270,7 @@ class FadingText(object): class HelpText(object): def __init__(self, font, width, height): self.font = font - self.dim = (680, 460) + self.dim = (680, 480) self.pos = (0.5 * width - 0.5 * self.dim[0], 0.5 * height - 0.5 * self.dim[1]) self.seconds_left = 0 self.surface = pygame.Surface(self.dim)