def controller(x: simulator.State, dt: float, time: float): global active_parking_spot, recalculate running = True for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_0: active_parking_spot = 0 elif event.key == pygame.K_1: active_parking_spot = 1 elif event.key == pygame.K_2: active_parking_spot = 2 elif event.key == pygame.K_3: active_parking_spot = 3 elif event.key == pygame.K_q: running = False recalculate = True print(f"time: {time:.1f}") if car_is_in_box(x, p_list[active_parking_spot]): if simulator.is_zero(x.speed): active_parking_spot += 1 if active_parking_spot == len(p_list): active_parking_spot = 0 visualizer.update(x.position.x, x.position.y, x.orientation, active_parking_spot) recalculate = True if ((not recalculate and simulator.is_zero(x.speed)) or time % 10 < 0.1) else False cs = mpc.get_control_signals(x, p_list[active_parking_spot], 0.3, recalculate=recalculate) if simulation_time < time or not running: x.position.x, x.position.y, x.orientation = 0, 0, 0 simulator.run(replay) cs_s.append(cs) return cs
def replay(x: simulator.State, dt: float, time: float): print(f"time: {time:.1f}") global counter running = True if counter < len(cs_s) - 1 else False for event in pygame.event.get(): if event.type == pygame.QUIT: running = False visualizer.update(x.position.x, x.position.y, x.orientation, -1, replay=True) if simulation_time < time or not running: simulator.close() visualizer.close() cs = cs_s[counter] counter += 1 return cs
def update_display(self, swap1=None, swap2=None): import visualizer visualizer.update( self, swap1, swap2) # pass the indexes to be swapped into the visualizer
def update_display(self, swap1=None, swap2=None): visualizer.update(self, swap1, swap2)
#This will loop until the user exits #This will handle everything that happens while 1: #Main loop for event in pygame.event.get(): #Pygame event loop if event.type == pygame.QUIT: exit() #exit from the exit button elif event.type == pygame.KEYDOWN: #If event is a key press if event.key == pygame.K_ESCAPE:exit() #exit by hitting the escape key. midi = midi_input.read() #use interchangably between network_midi and pygame.midi visualizer.update(midi) #Update the visualizer with the midi input pygame.display.update() #Possibly remove this if pygame display is handled in visualizer. fpsClock.tick(30) #Keep a constant framerate #Above is the bare minimum for a show. Below are extras. #This will handle midi output to the light console. If interface is possible #This will probably use usb to midi output import midi_light #This will handle the audio input analysis #This will try to mimic midi_input as close as possible to stay consistant import fft_input