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

Class DualControl

PythonAPI/examples/manual_control_steeringwheel.py:206–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204
205
206class DualControl(object):
207 def __init__(self, world, start_in_autopilot):
208 self._autopilot_enabled = start_in_autopilot
209 if isinstance(world.player, carla.Vehicle):
210 self._control = carla.VehicleControl()
211 world.player.set_autopilot(self._autopilot_enabled)
212 elif isinstance(world.player, carla.Walker):
213 self._control = carla.WalkerControl()
214 self._autopilot_enabled = False
215 self._rotation = world.player.get_transform().rotation
216 else:
217 raise NotImplementedError("Actor type not supported")
218 self._steer_cache = 0.0
219 world.hud.notification("Press 'H' or '?' for help.", seconds=4.0)
220
221 # initialize steering wheel
222 pygame.joystick.init()
223
224 joystick_count = pygame.joystick.get_count()
225 if joystick_count > 1:
226 raise ValueError("Please Connect Just One Joystick")
227
228 self._joystick = pygame.joystick.Joystick(0)
229 self._joystick.init()
230
231 self._parser = ConfigParser()
232 self._parser.read('wheel_config.ini')
233 self._steer_idx = int(
234 self._parser.get('G29 Racing Wheel', 'steering_wheel'))
235 self._throttle_idx = int(
236 self._parser.get('G29 Racing Wheel', 'throttle'))
237 self._brake_idx = int(self._parser.get('G29 Racing Wheel', 'brake'))
238 self._reverse_idx = int(self._parser.get('G29 Racing Wheel', 'reverse'))
239 self._handbrake_idx = int(
240 self._parser.get('G29 Racing Wheel', 'handbrake'))
241
242 def parse_events(self, world, clock):
243 for event in pygame.event.get():
244 if event.type == pygame.QUIT:
245 return True
246 elif event.type == pygame.JOYBUTTONDOWN:
247 if event.button == 0:
248 world.restart()
249 elif event.button == 1:
250 world.hud.toggle_info()
251 elif event.button == 2:
252 world.camera_manager.toggle_camera()
253 elif event.button == 3:
254 world.next_weather()
255 elif event.button == self._reverse_idx:
256 self._control.gear = 1 if self._control.reverse else -1
257 elif event.button == 23:
258 world.camera_manager.next_sensor()
259
260 elif event.type == pygame.KEYUP:
261 if self._is_quit_shortcut(event.key):
262 return True
263 elif event.key == K_BACKSPACE:

Callers 1

game_loopFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected