def drive(self, state, **kwargs): response = utils.get_default_response() response['gear'] = self.transmission.get_new_gear(state) extracted_state = extract_state(state, self.state_keys) if len(self.states_history) == 0: self.states_history.append( np.concatenate((extracted_state, (0, 0)))) regressor_input = self.scaler.transform( [np.concatenate((extracted_state, self.states_history[-1]))]) steer_val = self.steer_regressor.predict(regressor_input)[0] classifier_input = np.concatenate((regressor_input[0], [steer_val])) speed_action_index = self.speed_classifier.predict([classifier_input ])[0] self.states_history.append( np.array([ *extracted_state, steer_val, speed_action_index, ])) total_response = { **response, 'steer': steer_val, **self.speed_actions_labels[speed_action_index], } self.manage_start_accel(state, total_response) return total_response
def drive(self, state, **kwargs): response = utils.get_default_response() response['gear'] = self.transmission.get_new_gear(state) human_state = self.HumanInput.get_state() for k in self.hs_counter: if human_state[k]: self.hs_counter[k] += 1 else: self.hs_counter[k] = max(self.hs_counter[k] - 2, 0) if human_state['accel']: response['accel'] = 1 if human_state['brake']: response['brake'] = 1 response['accel'] = 0 if human_state['left']: response['steer'] = np.clip( self.hs_counter['left'] * 0.015, 0.0, 1.0) if human_state['right']: response['steer'] = - \ np.clip(self.hs_counter['right'] * 0.015, 0.0, 1.0) return response
def drive(self, state, **kwargs): if self.is_starting: if state['distFromStart'] < 20.: self.is_starting = False response = utils.get_default_response() response['gear'] = self.transmission.get_new_gear(state) goalSpeed = self.get_goal_speed(state['distFromStart'], **kwargs) if abs(state['trackPos']) > 1: goalSpeed = 20 if state['speedX'] > goalSpeed: if state['speedX'] > 5. + goalSpeed: response['brake'] = 1 response['accel'] = 0 else: response['accel'] = 1 if abs(state['trackPos']) < 0.2: self.precisionMode(state, response) else: targetAngle = state['trackPos'] * 90 # turningForce = abs(state['angle'] - targetAngle) * (1 / 45) * 3 if state['angle'] < targetAngle: response['steer'] = -settings['hard_turn'] else: response['steer'] = settings['hard_turn'] return response
def drive(self, state, **kwargs): response = utils.get_default_response() response['gear'] = self.transmission.get_new_gear(state) prepared_state = state_to_vector(state, keys_list=self.state_keys) state_normed = self.scaler.transform([prepared_state]) predicted_action = self.actions[self.classifier.predict_classes( state_normed)[0]] return {**response, **predicted_action}
def drive(self, state, **kwargs): response = utils.get_default_response() response['gear'] = self.transmission.get_new_gear(state) vector_before_norm = state_to_vector(state, self.state_keys) state_vector = self.scaler.transform(vector_before_norm[np.newaxis, :]) action_id = self.classifier.predict(state_vector)[0] return { **response, **self.actions[action_id], }
def drive(self, state, **kwargs): response = utils.get_default_response() response['gear'] = self.transmission.get_new_gear(state) prepared_state = state_to_vector( state, keys_list=self.state_keys ) state_normed = (prepared_state - self.X_min) / \ (self.X_max - self.X_min) predicted_action = self.actions[ self.knn.predict([state_normed])[0] ] return {**response, **predicted_action}
def drive(self, state, **kwargs): response = utils.get_default_response() response['gear'] = self.transmission.get_new_gear(state) state_vector = self.scaler.transform( [extract_state(state, self.state_keys)]) steer_val = self.steer_regressor.predict(state_vector)[0] state_vector = np.hstack((state_vector, [[steer_val]])) speed_action_index = self.speed_classifier.predict(state_vector)[0] return { **response, 'steer': steer_val, **self.speed_actions_labels[speed_action_index], }
def drive(self, state, **kwargs): response = utils.get_default_response() response['gear'] = self.transmission.get_new_gear(state) state_vector = self.scaler.transform( [extract_state(state, self.state_keys)]) steer_direction = self.steer_classifier.predict(state_vector)[0] steer_magnitude = self.steer_regressor.predict(state_vector)[0] # if steer_direction == 0 and steer_magnitude > 0.05: # print( # 'steer_direction', steer_direction, 'steer_magnitude', steer_magnitude # ) if steer_direction < 0 and steer_magnitude > 0: steer_val = 0 elif steer_direction > 0 and steer_magnitude < 0: steer_val = 0 elif steer_direction == 0: steer_val = steer_magnitude / 3 else: steer_val = steer_magnitude state_vector = np.hstack((state_vector, [[steer_val]])) speed_action_index = self.speed_classifier.predict(state_vector)[0] response = { **response, 'steer': steer_val, **self.speed_actions_labels[speed_action_index], } # self.apply_speed_limit(state, response) # self.manage_start_accel(state, response) return response