MCPcopy Create free account
hub / github.com/OpenDriveLab/TCP / HumanInterface

Class HumanInterface

scenario_runner/srunner/autoagents/human_agent.py:34–88  ·  view source on GitHub ↗

Class to control a vehicle manually for debugging purposes

Source from the content-addressed store, hash-verified

32
33
34class HumanInterface(object):
35
36 """
37 Class to control a vehicle manually for debugging purposes
38 """
39
40 def __init__(self, parent):
41 self.quit = False
42 self._parent = parent
43 self._width = 800
44 self._height = 600
45 self._throttle_delta = 0.05
46 self._steering_delta = 0.01
47 self._surface = None
48
49 pygame.init()
50 pygame.font.init()
51 self._clock = pygame.time.Clock()
52 self._display = pygame.display.set_mode((self._width, self._height), pygame.HWSURFACE | pygame.DOUBLEBUF)
53 pygame.display.set_caption("Human Agent")
54
55 def run(self):
56 """
57 Run the GUI
58 """
59 while not self._parent.agent_engaged and not self.quit:
60 time.sleep(0.5)
61
62 controller = KeyboardControl()
63 while not self.quit:
64 self._clock.tick_busy_loop(20)
65 controller.parse_events(self._parent.current_control, self._clock)
66 # Process events
67 pygame.event.pump()
68
69 # process sensor data
70 input_data = self._parent.sensor_interface.get_data()
71 image_center = input_data['Center'][1][:, :, -2::-1]
72 image_left = input_data['Left'][1][:, :, -2::-1]
73 image_right = input_data['Right'][1][:, :, -2::-1]
74 image_rear = input_data['Rear'][1][:, :, -2::-1]
75
76 top_row = np.hstack((image_left, image_center, image_right))
77 bottom_row = np.hstack((0 * image_rear, image_rear, 0 * image_rear))
78 comp_image = np.vstack((top_row, bottom_row))
79 # resize image
80 image_rescaled = cv2.resize(comp_image, dsize=(self._width, self._height), interpolation=cv2.INTER_CUBIC)
81
82 # display image
83 self._surface = pygame.surfarray.make_surface(image_rescaled.swapaxes(0, 1))
84 if self._surface is not None:
85 self._display.blit(self._surface, (0, 0))
86 pygame.display.flip()
87
88 pygame.quit()
89
90
91class HumanAgent(AutonomousAgent):

Callers 1

setupMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected