MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / KeyboardControl

Class KeyboardControl

PythonAPI/examples/manual_control_rss.py:244–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242
243
244class KeyboardControl(object):
245 def __init__(self, world, args):
246 self._autopilot_enabled = args.autopilot
247 self._world = world
248 self._restrictor = None
249 self._restrictorEnabled = True
250 if isinstance(world.player, carla.Vehicle):
251 self._control = carla.VehicleControl()
252 world.player.set_autopilot(self._autopilot_enabled)
253 self._restrictor = carla.RssRestrictor()
254 elif isinstance(world.player, carla.Walker):
255 self._control = carla.WalkerControl()
256 self._autopilot_enabled = False
257 self._rotation = world.player.get_transform().rotation
258 else:
259 raise NotImplementedError("Actor type not supported")
260 self._steer_cache = 0.0
261 world.hud.notification("Press 'H' or '?' for help.", seconds=4.0)
262
263 def parse_events(self, client, world, clock):
264 for event in pygame.event.get():
265 if event.type == pygame.QUIT:
266 return True
267 elif event.type == pygame.KEYUP:
268 if self._is_quit_shortcut(event.key):
269 return True
270 elif event.key == K_BACKSPACE:
271 world.restart()
272 elif event.key == K_F1:
273 world.hud.toggle_info()
274 elif event.key == K_h or (event.key == K_SLASH and pygame.key.get_mods() & KMOD_SHIFT):
275 world.hud.help.toggle()
276 elif event.key == K_TAB:
277 world.camera_manager.toggle_camera()
278 elif event.key == K_c and pygame.key.get_mods() & KMOD_SHIFT:
279 world.next_weather(reverse=True)
280 elif event.key == K_c:
281 world.next_weather()
282 elif event.key == K_BACKQUOTE:
283 world.camera_manager.next_sensor()
284 elif event.key > K_0 and event.key <= K_9:
285 world.camera_manager.set_sensor(event.key - 1 - K_0)
286 elif event.key == K_r and not (pygame.key.get_mods() & KMOD_CTRL):
287 world.camera_manager.toggle_recording()
288 elif event.key == K_r and (pygame.key.get_mods() & KMOD_CTRL):
289 if (world.recording_enabled):
290 client.stop_recorder()
291 world.recording_enabled = False
292 world.hud.notification("Recorder is OFF")
293 else:
294 client.start_recorder("manual_recording.rec")
295 world.recording_enabled = True
296 world.hud.notification("Recorder is ON")
297 elif event.key == K_p and (pygame.key.get_mods() & KMOD_CTRL):
298 # stop recorder
299 client.stop_recorder()
300 world.recording_enabled = False
301 # work around to fix camera at start of replaying

Callers 1

game_loopFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected