def decode_control(self, cod): control = VehicleControl() control.steer = 0 control.throttle = 0 control.brake = 0 control.hand_brake = False control.reverse = False if cod > 9: control.hand_brake = True if cod == 10: control.steer = -1 elif cod == 10: control.steer = -1 return control if cod == 9: control.reverse = True control.throttle = 1 return control if cod % 3 == 1: control.brake = 1 elif cod % 3 == 2: control.throttle = 1 if cod // 3 == 1: control.steer = 1 elif cod // 3 == 2: control.steer = -1 return control
def _compute_action(self, rgb_image, speed, directions=None): #shit for demo img = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2BGR) cv2.imwrite(self.img_dir + "/image_" + str(self.nr_img) + ".jpg", img) #shit for demo rgb_image = rgb_image[self._image_cut[0]:self._image_cut[1], :] steer, acc, brake = self._control_function(rgb_image, speed, directions) # This a bit biased, but is to avoid fake breaking if brake < 0.1: brake = 0.0 if acc > brake: brake = 0.0 # We limit speed to 35 km/h to avoid if speed > 10.0 and brake == 0: acc = 0.0 control = VehicleControl() control.steer = steer control.throttle = acc control.brake = brake control.hand_brake = 0 control.reverse = 0 return control
def action_joystick(self): # joystick steering_axis = self.joystick.get_axis(0) acc_axis = self.joystick.get_axis(2) brake_axis = self.joystick.get_axis(5) # print("axis 0 %f, axis 2 %f, axis 3 %f" % (steering_axis, acc_axis, brake_axis)) if (self.joystick.get_button(3)): self._rear = True if (self.joystick.get_button(2)): self._rear = False control = VehicleControl() control.steer = steering_axis control.throttle = (acc_axis + 1) / 2.0 control.brake = (brake_axis + 1) / 2.0 if control.brake < 0.001: control.brake = 0.0 control.hand_brake = 0 control.reverse = self._rear control.steer -= 0.0822 #print("steer %f, throttle %f, brake %f" % (control.steer, control.throttle, control.brake)) pygame.event.pump() return control
def _get_keyboard_control(self, keys, args): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ global flg_warning if keys[K_r]: return None control = VehicleControl() if keys[K_LEFT] or keys[K_a]: control.steer = -1.0 if keys[K_RIGHT] or keys[K_d]: control.steer = 1.0 if keys[K_UP] or keys[K_w]: control.throttle = 1.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: self._is_on_reverse = not self._is_on_reverse if keys[K_p]: self._enable_autopilot = not self._enable_autopilot if args.app == 'Control': if flg_warning == -1: control.throttle = 0.0 control.reverse = self._is_on_reverse return control
def send_control_command(client, throttle, steer, brake, hand_brake=False, reverse=False): """Send control command to CARLA client. Send control command to CARLA client. Args: client: The CARLA client object throttle: Throttle command for the sim car [0, 1] steer: Steer command for the sim car [-1, 1] brake: Brake command for the sim car [0, 1] hand_brake: Whether the hand brake is engaged reverse: Whether the sim car is in the reverse gear """ control = VehicleControl() # Clamp all values within their limits steer = np.fmax(np.fmin(steer, 1.0), -1.0) throttle = np.fmax(np.fmin(throttle, 1.0), 0) brake = np.fmax(np.fmin(brake, 1.0), 0) control.steer = steer control.throttle = throttle control.brake = brake control.hand_brake = hand_brake control.reverse = reverse client.send_control(control)
def _get_keyboard_control(self, keys): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ if keys[K_r]: return None control = VehicleControl() if keys[K_LEFT] or keys[K_a]: control.steer = -0.5 if keys[K_RIGHT] or keys[K_d]: control.steer = 0.5 if keys[K_UP] or keys[K_w]: control.throttle = 0.7 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: self._is_on_reverse = not self._is_on_reverse if keys[K_p]: self._enable_autopilot = not self._enable_autopilot if keys[K_2]: self._command = 2 if keys[K_3]: self._command = 3 if keys[K_4]: self._command = 4 if keys[K_5]: self._command = 5 control.reverse = self._is_on_reverse return control
def _get_keyboard_control(self, keys): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ if keys[K_r]: return None control = VehicleControl() if keys[K_LEFT] or keys[K_a]: self._control.steer += -0.02 self._control.steer = max(self._control.steer, -1.0) control.steer = -1.0 if keys[K_RIGHT] or keys[K_d]: self._control.steer += 0.02 self._control.steer = min(self._control.steer, 1.0) control.steer = 1.0 if keys[K_l] or keys[K_SPACE]: self._control.steer = 0 if keys[K_UP] or keys[K_w]: control.throttle = 1.0 self._control.throttle = 0.6 self._control.throttle = min(self._control.throttle, 1) self._control.brake = 0.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 self._control.brake = 1.0 self._control.throttle = 0.0 if keys[K_q]: self._is_on_reverse = not self._is_on_reverse if keys[K_p]: self._enable_autopilot = not self._enable_autopilot control.reverse = self._is_on_reverse self._control.reverse = self._is_on_reverse return control
def _control_using_agent(self, action): ''' Here we pass the action output by our agent and control the car outputs : As of now consider the agent also outputs the keys W, A, S, D, space, reverse so according to the output vector "action" For example : action = [1, 1, 0, 0, 0, 0] => it uses throttle and steer left action = [0, 0, 0, 0, 0, 1] => car will be on reverse gear ''' '''To be completed''' # if action[6]: # # if r is pressed # return None control = VehicleControl() if action[1]: control.steer = -1.0 if action[3]: control.steer = 1.0 if action[0]: control.throttle = 1.0 if action[2]: control.brake = 1.0 if action[4]: control.hand_brake = True if action[5]: self._is_on_reverse = not self._is_on_reverse control.reverse = self._is_on_reverse return control
def _get_joystick_control(self, joystick): control = VehicleControl() tmp1 = 0.6 * joystick.get_axis(1) if (tmp1 <= 0): control.throttle = -tmp1 control.brake = 0 else: control.throttle = 0 control.brake = tmp1 control.steer = joystick.get_axis(2) control.steer = 0.5 * control.steer * control.steer * control.steer # print('steer....',control.steer) #provide a stable autopilot autopilot = joystick.get_button(0) if autopilot == 1: self._enable_autopilot = not self._enable_autopilot # provide a stable reverse reverse = joystick.get_button(2) if reverse == 1: self._is_on_reverse = not self._is_on_reverse control.reverse = self._is_on_reverse return control
def _get_joystick_control(self,joystick): control = VehicleControl() tmp1 = 0.6 * joystick.get_axis(1) if (tmp1 <= 0): control.throttle = -tmp1 control.brake = 0 else: control.throttle = 0 control.brake = tmp1 control.steer = joystick.get_axis(2) control.steer = 0.5 * control.steer * control.steer * control.steer # print('steer....',control.steer) #provide a stable autopilot autopilot = joystick.get_button(0) if autopilot == 1: self._enable_autopilot = not self._enable_autopilot # provide a stable reverse reverse = joystick.get_button(2) if reverse == 1: self._is_on_reverse = not self._is_on_reverse control.reverse = self._is_on_reverse return control
def accelerate(self): control = VehicleControl() control.throttle = 1.0 if (self.too_close_to('vehicle', self.vehicle_distance_threshold)): control.throttle = self.measurements.player_measurements.autopilot_control.throttle control.reverse = self._is_on_reverse self.client.send_control(control)
def steer_right(self): control = VehicleControl() control.steer = min(control.steer + 0.01, 0.05) print(control.steer) control.reverse = self._is_on_reverse control.throttle = self.measurements.player_measurements.autopilot_control.throttle self.client.send_control(control)
def _get_keyboard_control(self, keys, measurements): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ if keys[K_p]: control = measurements.player_measurements.autopilot_control control.steer += random.uniform(-0.1, 0.1) return control if keys[K_r]: return None control = VehicleControl() if keys[K_LEFT] or keys[K_a]: control.steer = -1.0 if keys[K_RIGHT] or keys[K_d]: control.steer = 1.0 if keys[K_UP] or keys[K_w]: control.throttle = 1.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: self._is_on_reverse = not self._is_on_reverse control.reverse = self._is_on_reverse return control
def _get_keyboard_control(self, keys): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ if keys[K_r]: return None, None if keys[K_t]: self.should_display = not self.should_display return 'done', None if keys[K_m]: self.manual = True return 'done', None if keys[K_n]: self.manual = False return 'done', None if keys[K_v]: self.endnow = True return 'done', None control = VehicleControl() if keys[K_LEFT] or keys[K_a]: control.steer = -1.0 if keys[K_RIGHT] or keys[K_d]: control.steer = 1.0 if keys[K_UP] or keys[K_w]: control.throttle = 1.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: self._is_on_reverse = not self._is_on_reverse if keys[K_c]: self.manual_control = not self.manual_control if keys[K_p]: self._enable_autopilot = not self._enable_autopilot control.reverse = self._is_on_reverse reward = None if keys[K_1]: reward = -1 if keys[K_2]: reward = -0.5 if keys[K_3]: reward = -0.25 if keys[K_4]: reward = -0.1 if keys[K_5]: reward = 0 if keys[K_6]: reward = 0.1 if keys[K_7]: reward = 0.25 if keys[K_8]: reward = 0.5 if keys[K_9]: reward = 1 return control, reward
def get_control_from_a(a): control = VehicleControl() control.steer = a[0] control.throttle = a[1] control.brake = a[2] control.hand_brake = bool(a[3]) control.reverse = bool(a[4]) return control
def _get_keyboard_control(self, keys, measurements, sensor_data): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ self._at_intersection = False if keys[K_r]: return None if self._NNagent_drives: if keys[K_LEFT] or keys[K_a]: control = self.NNagent.run_step(measurements, sensor_data, 3, None) elif keys[K_RIGHT] or keys[K_d]: control = self.NNagent.run_step(measurements, sensor_data, 4, None) elif keys[K_UP] or keys[K_w]: control = self.NNagent.run_step(measurements, sensor_data, 2, None) else: control = self.NNagent.run_step(measurements, sensor_data, -1, None) if keys[K_q]: self._is_on_reverse = not self._is_on_reverse if keys[K_p]: self._enable_autopilot = True self._NNagent_drives = not self._NNagent_drives if keys[K_n]: print("Turning off") self._NNagent_drives = not self._NNagent_drives if keys[K_i]: self._at_intersection = True control.reverse = self._is_on_reverse else: control = VehicleControl() if keys[K_LEFT] or keys[K_a]: control.steer = -1.0 if keys[K_RIGHT] or keys[K_d]: control.steer = 1.0 if keys[K_UP] or keys[K_w]: control.throttle = 1.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: self._is_on_reverse = not self._is_on_reverse if keys[K_p]: self._enable_autopilot = not self._enable_autopilot if keys[K_n]: print("Turning on") self._NNagent_drives = not self._NNagent_drives self._enable_autopilot = False if keys[K_i]: self._at_intersection = True control.reverse = self._is_on_reverse return control
def _get_autopilot_control(self, measurements): control = VehicleControl() control.steer = measurements.player_measurements.autopilot_control.steer control.throttle = measurements.player_measurements.autopilot_control.throttle control.brake = measurements.player_measurements.autopilot_control.brake control.hand_brake = measurements.player_measurements.autopilot_control.hand_brake control.reverse = measurements.player_measurements.autopilot_control.reverse return control
def action_steering_wheel(self, jsInputs, jsButtons): control = VehicleControl() # Custom function to map range of inputs [1, -1] to outputs [0, 1] i.e 1 from inputs means nothing is pressed # For the steering, it seems fine as it is K1 = 1.0 # 0.55 steerCmd = K1 * math.tan(1.1 * jsInputs[self._steer_idx]) K2 = 1.6 # 1.6 throttleCmd = K2 + ( 2.05 * math.log10(-0.7 * jsInputs[self._throttle_idx] + 1.4) - 1.2) / 0.92 if throttleCmd <= 0: throttleCmd = 0 elif throttleCmd > 1: throttleCmd = 1 brakeCmd = 1.6 + (2.05 * math.log10(-0.7 * jsInputs[self._brake_idx] + 1.4) - 1.2) / 0.92 if brakeCmd <= 0: brakeCmd = 0 elif brakeCmd > 1: brakeCmd = 1 #print("Steer Cmd, ", steerCmd, "Brake Cmd", brakeCmd, "ThrottleCmd", throttleCmd) control.steer = steerCmd control.brake = brakeCmd control.throttle = throttleCmd toggle = jsButtons[self._reverse_idx] if toggle == 1: self._is_on_reverse += 1 if self._is_on_reverse % 2 == 0: control.reverse = False if self._is_on_reverse > 1: self._is_on_reverse = True if self._is_on_reverse: control.reverse = True control.hand_brake = False # jsButtons[self.handbrake_idx] return control
def _get_keyboard_control(self, keys): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ if keys[K_r]: return None control = VehicleControl() self.resetVal() ################################################### YOU CAN EDIT IT ACCORDING YOU.... if keys[K_LEFT] or keys[K_a]: self._val1 = -1 print("Left") if (pid.prev > 0): pid.prev = 0 elif keys[K_RIGHT] or keys[K_d]: self._val1 = 1 print("Right") if (pid.prev < 0): pid.prev = 0 pid.prev += self._val1 output = pid.kp * self._val1 + pid.ki * pid.prev print(output) control.steer = output #Imp Line if keys[K_UP] or keys[K_w]: self._val2 = 1 pid.prev = 0 elif keys[K_DOWN] or keys[K_s]: control.brake = 1 pid.prev = 0 ### if (self._velocity < 77): control.throttle = self._val2 #Imp Line else: control.throttle = self._val2 * 0.8 if keys[K_SPACE]: control.hand_brake = True pid.prev = 0 if keys[K_f]: self._val3 = 1 - self._val3 if keys[K_q]: self._is_on_reverse = not self._is_on_reverse pid.prev = 0 if keys[K_p]: self._enable_autopilot = not self._enable_autopilot control.reverse = self._is_on_reverse ################################################################################ #print(control) return control
def _get_keyboard_control(self, keys): control = VehicleControl() if keys[pl.K_LEFT] or keys[pl.K_a]: control.steer = -1.0 if keys[pl.K_RIGHT] or keys[pl.K_d]: control.steer = 1.0 if keys[pl.K_UP] or keys[pl.K_w]: control.throttle = 1.0 if keys[pl.K_DOWN] or keys[pl.K_s]: control.brake = 1.0 if keys[pl.K_SPACE]: control.hand_brake = True control.reverse = self._vehicle_in_reverse return control
def _get_gamepad_control(self): control = VehicleControl() gamepad = GamepadManager() control.steer = gamepad.axis_states[GamepadManager.AxisMap.LEFT_X] control.throttle = (gamepad.axis_states[GamepadManager.AxisMap.RT] + 1) / 2.0 control.brake = (gamepad.axis_states[GamepadManager.AxisMap.LT] + 1) / 2.0 if gamepad.button_states[GamepadManager.ButtonMap.X]: self._is_on_reverse = not self._is_on_reverse if gamepad.button_states[GamepadManager.ButtonMap.B]: self._enable_autopilot = not self._enable_autopilot control.reverse = self._is_on_reverse return control
def perform_action(self, data): ''' Performs action Input : Data = [image, segmentation, depth, ...] Return : control action = [throttle, steering_angle, steering_direction, brake, reverse_gear] ''' action = self.agent.select_action(data, self.memory) print("obtained action") ######################################### # TODO # Add randomness in run_step of agent ######################################### control = VehicleControl() # Car Throttle control.throttle = action[0] ################################################################ # TODO # We need to convert angle into the units which carla uses # steering direction will be a bool 0 for left and 1 for right if action[2]: control.steer = function(action[1]) else: control.steer = -1 * function(action[1]) ################################################################ # brake is a bool control.brake = action[3] # If needed there is an option for hand_brake as well # control.hand_brake # Car reverse gear if action[4]: self.carla_game._is_on_reverse = not self.carla_game._is_on_reverse control.reverse = self.carla_game._is_on_reverse print("returning control..") return control, action
def _get_XBOX_control(self, joystick): control = VehicleControl() control.throttle = 0.4 * (joystick.get_axis(5) + 1) if control.throttle > 0.6: control.throttle = 0.6 # if control.throttle <0.3: # control.throttle = 0 # elif control.throttle<0.7: # control.throttle = 0.5 # else: # control.throttle =1.0 control.brake = 0.5 * (joystick.get_axis(2) + 1) control.brake = max(0, control.brake - 0.1) control.steer = joystick.get_axis(0) if(abs(control.steer)<0.05): control.steer = 0 if control.steer <=-0.05: control.steer += 0.05 if control.steer >=0.05: control.steer -= 0.05 control.steer = 0.8 * control.steer control.reverse = self._is_on_reverse # command = joystick.get_hat(0) # if command[0] == -1: # self._command = 3 # elif command[0] == 1: # self._command = 4 # if command[1] == -1: # self._command = 5 # elif command[1] == 1: # self._command = 2 # return control if joystick.get_axis(3) > 0.5: self._command = 4 elif joystick.get_axis(3) < -0.5: self._command = 3 elif joystick.get_axis(4) > 0.5: self._command = 5 elif joystick.get_axis(4) < -0.5: self._command = 2 return control
def _get_steering_control(self): numAxes = self.js.get_numaxes() jsInputs = [float(self.js.get_axis(i)) for i in range(numAxes)] # print('Js inputs [%s]' % ', '.join(map(str, jsInputs))) control = VehicleControl() control.steer = jsInputs[0] if ((1 - jsInputs[1]) / 2) > 0.001: control.brake = (1 - jsInputs[1]) / 2 else: control.brake = 0 if ((1 - jsInputs[2]) / 2) > 0.001: control.throttle = (1 - jsInputs[2]) / 2 else: control.throttle = 0 control.hand_brake = 0.0 control.reverse = 0.0 # print(control) return control
def _get_XBOX_control(self, joystick): control = VehicleControl() control.throttle = 0.4 * (joystick.get_axis(5) + 1) if control.throttle > 0.6: control.throttle = 0.6 # if control.throttle <0.3: # control.throttle = 0 # elif control.throttle<0.7: # control.throttle = 0.5 # else: # control.throttle =1.0 control.brake = 0.5 * (joystick.get_axis(2) + 1) control.brake = max(0, control.brake - 0.1) control.steer = joystick.get_axis(0) if (abs(control.steer) < 0.05): control.steer = 0 if control.steer <= -0.05: control.steer += 0.05 if control.steer >= 0.05: control.steer -= 0.05 control.steer = 0.8 * control.steer control.reverse = self._is_on_reverse # command = joystick.get_hat(0) # if command[0] == -1: # self._command = 3 # elif command[0] == 1: # self._command = 4 # if command[1] == -1: # self._command = 5 # elif command[1] == 1: # self._command = 2 # return control if joystick.get_axis(3) > 0.5: self._command = 4 elif joystick.get_axis(3) < -0.5: self._command = 3 elif joystick.get_axis(4) > 0.5: self._command = 5 elif joystick.get_axis(4) < -0.5: self._command = 2 return control
def _on_loop(self): self._timer.tick() measurements, _ = self.client.read_data() self.pubState(measurements.player_measurements) # Print measurements every second. if self._timer.elapsed_seconds_since_lap() > 1.0: self._print_player_measurements(measurements.player_measurements) # Plot position on the map as well. self._timer.lap() if self._vehicle_control.restart: self._on_new_episode() else: control = VehicleControl() control.throttle = self._vehicle_control.accel_cmd.accel control.brake = self._vehicle_control.brake_cmd.brake control.steer = self._vehicle_control.steer_cmd.steer control.hand_brake = self._vehicle_control.hand_brake control.reverse = self._vehicle_control.reverse self.client.send_control(control)
def decode_control(self, cod): #将数字的control转换为VehicleControl() control = VehicleControl() control.steer = 0 control.throttle = 0 control.brake = 0 control.hand_brake = False control.reverse = False th, steer = cod if th > 0: control.throttle = min(th, 1.0) if th < 0: control.brake = min(-th, 1.0) control.steer = max(min(steer, 1.0), -1.0) # if cod > 9: # control.hand_brake = True # if cod == 10: # control.steer = -1 # elif cod == 11: # control.steer = 1 # return control # if cod == 9: # control.reverse = True # control.throttle = 1 # return control # if cod % 3 == 1: # control.brake = 1 # elif cod % 3 == 2: # control.throttle = 1 # if cod // 3 == 1: # control.steer = 1 # elif cod // 3 == 2: # control.steer = -1 return control
def get_keyboard_control(keys, is_on_reverse, enable_autopilot): if keys[K_r]: return None control = VehicleControl() if keys[K_LEFT] or keys[K_a]: control.steer = -1.0 if keys[K_RIGHT] or keys[K_d]: control.steer = 1.0 if keys[K_UP] or keys[K_w]: control.throttle = 1.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: is_on_reverse = not is_on_reverse if keys[K_p]: enable_autopilot = not enable_autopilot control.reverse = is_on_reverse return control, is_on_reverse, enable_autopilot
def get_keyboard_control(self, char): control = VehicleControl() if char == 'a': print 'got a' control.steer = -1.0 if char == 'd': print 'got d' control.steer = 1.0 if char == 'w': print 'got w' control.throttle = 1.0 if char == 's': print 'got s' control.brake = 1.0 if char == ' ': print 'got space' control.hand_brake = True if char == 'q': print 'got q' self._is_on_reverse = not self._is_on_reverse control.reverse = self._is_on_reverse return control
def _get_keyboard_control(self, keys): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ if keys[K_r]: return None control = VehicleControl() if keys[K_LEFT] or keys[K_a]: control.steer = -1.0 if keys[K_RIGHT] or keys[K_d]: control.steer = 1.0 if keys[K_UP] or keys[K_w]: control.throttle = 1.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: self._is_on_reverse = not self._is_on_reverse control.reverse = self._is_on_reverse return control
def _get_keyboard_control(self, keys): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ if keys[K_r]: return None control = VehicleControl() if keys[K_LEFT] or keys[K_a]: #control.steer = -1.0 if self.steer > -1 and self.steer < 0: control.steer = self.steer - .1 else: control.steer = -1 self.steer = control.steer if keys[K_RIGHT] or keys[K_d]: #control.steer = 1.0 if self.steer > 0 and self.steer < 1: control.steer = self.steer + .1 else: control.steer = 1 self.steer = control.steer if keys[K_UP] or keys[K_w]: control.throttle = 1.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: self._is_on_reverse = not self._is_on_reverse if keys[K_p]: self._enable_autopilot = not self._enable_autopilot control.reverse = self._is_on_reverse return control
def _get_keyboard_control(self, keys): """ Return a VehicleControl message based on the pressed keys. Return None if a new episode was requested. """ #returns NONE to close simulator if keys[K_r]: return None #control is set to its accurate type control = VehicleControl() #input set to manual if self._input_control == "Manual": if self._xbox_cont: #updates and checks for input from controller pygame.event.pump() #get_axis values may differ depending on controller #values weighted to be used on carla control.steer = self._joystick.get_axis(3) print(control.steer) control.throttle = (self._joystick.get_axis(5) + 1) / 2 control.brake = (self._joystick.get_axis(2) + 1) / 2 self._Manual_steer = control.steer else: if keys[K_LEFT] or keys[K_a]: control.steer = -1.0 if keys[K_RIGHT] or keys[K_d]: control.steer = 1.0 if keys[K_UP] or keys[K_w]: control.throttle = 1.0 if keys[K_DOWN] or keys[K_s]: control.brake = 1.0 #replay of previously recorded data elif self._input_control == "Replay": #read replay.csv file, _replay_frame values gives us correct row control.steer = replay.iloc[self._replay_frame, 4] control.throttle = replay.iloc[self._replay_frame, 6] #input set to autonomous, steer values from model else: control.steer = self._AI_steer control.throttle = 0.5 print(control.steer) if keys[K_l]: self._data_collection = not self._data_collection if self._data_collection: print("Data Collection ON") else: print("Data Collection OFF") time.sleep(0.05) #Check for keyboard commands to change input control device if keys[K_m]: print("Manual Control") self._input_control = "Manual" if keys[K_k]: print("Manual Control: Takeover Noted") self._takeovers += 1 self._input_control = "Manual" if keys[K_n]: print("AI Control") self._input_control = "AI" if keys[K_b]: print("Replay Control") self._input_control = "Replay" if keys[K_SPACE]: control.hand_brake = True if keys[K_q]: self._is_on_reverse = not self._is_on_reverse time.sleep(0.05) if keys[K_p]: self._enable_autopilot = not self._enable_autopilot control.reverse = self._is_on_reverse return control