def __init__(self): self.interface = controller.Car_Interface() self.pedal = None self.amount = 0 self.TIME_UNIT = self.interface.dt self.img = PIL.Image.open("car.png")
def __init__(self): self.interface = controller.Car_Interface() self.pedal_type = None self.amount = 0.0 self.TIME_UNIT = self.interface.dt
def __init__(self, mode, car_model="simple"): self.mode = mode self.car_model = car_model ''' Initialize the interface that will be used to manage motion dynamics. ''' self.interface = controller.Car_Interface(car_model) ''' If we are testing system ID then we will initialize an instance of the controller model, which we will interact with side by side along with the actual interface. ''' if (self.mode == "sysID_testing"): self.interface_model = controller_model.Car_Interface(car_model) ''' pedal_type intitialized to None peda_type can later be "accelerate", "brake", or "release" amount is relevant for both "accelerate" and "brake" and represents the magnitude of pedal depression. TIME_UNIT is a constant and represents how often we update the car's state. ''' self.pedal_type = None self.amount = 0.0 self.TIME_UNIT = self.interface.dt ''' Build up is used to allow for increasing pedal depression the longer you hold a control. That is when you press as you hold "accelerate" or "brake" the pedal depression will increase from 0 to 1 over time. When we are doing SystemID we will not follow the build up principle and apply random depression quantities, to make sure we are covering all possible scenarios. ''' if (not (self.mode == "sysID_data" or self.mode == "sysID_testing")): self.build_up = 0 self.bu_to_amt = lambda: 1 - 1 / ((self.build_up / 20) + 1) ''' If we are collecting data for System ID we intialize a file path for where we will save the data points (including reference to the internal car model). If there is a preexisting data points file we will load it and add to it, as opposed to starting from scratch. We will also keep track how long ago we last saved the collected data. ''' if (self.mode == "sysID_data"): self.data_points_file_path = f"Car Interface Weeks 2-3/SystemID/{car_model}_data_points.json" if (os.path.exists(self.data_points_file_path)): self.data_points = json.load( open(self.data_points_file_path, "r")) else: self.data_points = [] self.saved_data = 0 ''' If we are testing System ID we will keep track of a rolling average of the discrepancy between the actual controller and the controller model. The average will be taken over the last ERROR_WINDOW times. The maximum average error will be tracked as well. ''' if (self.mode == "sysID_testing"): self.ERROR_WINDOW = 100 self.errors = [] self.max_mean_error = None