コード例 #1
0
    def __init__(self, model="simple"):
        if (model != "simple" and model != "complex"):
            raise Exception(
                f"Illegal argument model can only be 'simple' or 'complex' not {model}"
            )

        self.model = model

        #Variables to keep track of the car's current state
        self.position = 0
        self.velocity = 0
        self.accel = 0

        self.steering_angle = 0

        self.gear = None

        #Constants corresponding to the car pedals
        self.ACCELERATOR = 0
        self.BRAKE = 1

        #Constants corrsponding to car gears
        self.FORWARD = 0
        self.REVERSE = 1
        '''
        PART OF WEEK 2 HW

        FILL IN ESTIMATED COEFFICIENTS BELOW (Delete exception too)
        All except for the brake_weight should be positive.
        '''
        #Coefficients corresponding to the motion dynamics
        self.rolling_bias = None
        self.friction_constant = None

        self.accelerator_weight = None
        self.brake_weight = None
        raise Exception(
            "You forgot to input SystemID learned weights in the Controller Model"
        )
        '''
        If approximating the complex internal model we use a FCN
        to model the acceleration as a function of the pedal depressions
        and velocity.  Since the weights for the this model will be in the
        SystemID directory we include it in the file path.
        The model has 3 inputs (accelerator depression, brake depression, velocity)
        '''
        if (self.model == "complex"):
            self.complex_accel_fcn = nn.fcn(
                model_name=self.complex_weights_fp(), num_inputs=3)

        #Variables to keep track of time (seconds)
        self.T = 0

        #Corresponds to simulations internal discrete time step (15fps)
        self.dt = 1 / 15
コード例 #2
0
    def __init__(self, car_model, estimator_type):
        '''
        Allowable combinations of car_model and estimator_type are
        ("simple", "fcn")
        ("simple", "analytical")
        ("complex", "fcn")

        No analytical solution for complex internal model.
        '''
        if (estimator_type not in {"analytical", "fcn"}):
            raise Exception(
                f"Illegal estimator_type, f{estimator_type}, must be 'analytical' or 'fcn'"
            )

        if (car_model not in {"simple", "complex"}):
            raise Exception(
                f"Illegal estimator_type, f{estimator_type}, must be 'simple' or 'complex'"
            )

        if (estimator_type == 'analytical' and car_model == 'complex'):
            raise Exception("No analytical estimator for complex car model")

        self.estimator_type = estimator_type
        '''
        If using a fcn load parameters from Brakind Distance directory
        two inputs (intitial velocity, stopping distance), output must be between 0 and 1
        '''
        if (estimator_type == "fcn"):
            self.fcn = nn.fcn(model_name=os.path.join(self.bd_fp(),
                                                      f"{car_model}_bd"),
                              num_inputs=2,
                              out_range=(0, 1))
        '''
        If using analytical approach get coefficients from controller
        model (pedal weights, friction constant, and rolling bias)
        '''
        if (estimator_type == "analytical"):
            ci = controller_model.Car_Interface()
            self.brake_weight = ci.brake_weight
            self.rolling_bias = ci.rolling_bias
            self.friction_constant = ci.friction_constant
コード例 #3
0
        self.rolling_bias = 0.009929075478129247
        self.friction_constant = 0.10974291535061839

        self.accelerator_weight = 0.10000558634381539
        self.brake_weight = -0.2499897051771736

>>>>>>> e85aa159abb29b9eba779ce605b479a4dfa30407
        '''
        If approximating the complex internal model we use a FCN
        to model the acceleration as a function of the pedal depressions
        and velocity.  Since the weights for the this model will be in the
        SystemID directory we include it in the file path.
        The model has 3 inputs (accelerator depression, brake depression, velocity)
        '''
        if (self.model == "complex"):
            self.complex_accel_fcn = nn.fcn(model_name = self.complex_weights_fp(), num_inputs = 3)

        #Variables to keep track of time (seconds)
        self.T = 0

        #Corresponds to simulations internal discrete time step (15fps)
        self.dt = 1 / 15

    #Depress the specified pedal by the specified amount for one dt time step
    def apply_control(self, pedal, amount):
        if (self.gear is None):
            raise Exception("Please set gear before applying control")

        if (pedal not in [None, self.ACCELERATOR, self.BRAKE]):
            raise Exception(f"Invalid pedal provided, {pedal}")