Car

Introduction

Car is an object defined in car_model.py that consumes a self, m, Crr, CdA, max_force, speed_min_ms, speed_max_ms

With a Car object, we can generate the following:

  • The force required for the car to accelerate to a certain velocity , using the force_req() method

  • The maximum velocity of the car after some time, starting from a certain point in the elevation map and starting from a certain velocity, using the max_velocity() method

  • The energy used by the car to move through the course with the given elevation map and velocity profile, using the energy_used() method

The object initialization

6 parameters (excluding self)

m: Mass of the car, defaulted to 720kg

Crr: Rolling resistance coefficient of the car, defaulted to 0.0015

CdA: Drag coefficient o f the car, defaulted to 0.15

max_force: Max force of the car’s motors, defaulted to 100N

speed_min_ms: Minimum speed to travel, defaulted to 15m/s

speed_max_ms: Minimum speed to travel, defaulted to 45m/s

All values instance variables to be used in functions below, as well as

g = 9.81  # Acceleration due to gravity in m/s^2 rho = 1.225  # Density of air at room temperature

as static variable constants.

Functions

The force_req() function

  • Parameters

    • v: (float) final velocity of the car to accelerate to, (m/s)

    • vwind: (float) velocity of the wind relative to the car, (m/s)

    • v_old: (float) initial velocity of the car, (m/s)

    • theta: (float) angle that must be climbed (radians) personally don’t understand why “climb” matters and not just angle of elevation

    • timestep: (float) Time between measurements, (s)

      • usually calculated dist / ((v + old_v)/2), dist being the distance between two points in elevation profile, e_profile.

  • Returns

    • Fmotor: (float) Force of motors required to accelerate to a certain velocity in a certain time (N)

  • Note

    • If v or v_old greater than maximum speed or less than minimum speed, it is caught in the function and whatever is out of bounds is set to maximum speed or minimum speed

    • Ffric, Fdrag , Fg , Fa, and ultimately Fmotor to be all calculated inside the function, using parameters and constants

The max_velocity() function

  • Parameters

    • v_old: (float) initial speed of car, (m/s)

    • vwind: (float) velocity of the wind relative to the car, (m/s)

    • theta: (float) angle that must be climbed (radians)

    • timestep: (float) Time between measurements, (s)

  • Returns

    • max_v: (float) Maximum final velocity after a certain time (m/s)

  • Note

    • If v_old greater than maximum speed or less than minimum speed, it is caught in the function and is set to maximum speed or minimum speed

  • We believe that this function has an error.

 max_v = v_old - self.force_req(v_old, vwind=vwind, theta=theta) + self.max_force * timestep

We are doing (velocity) - (force) + (impulse) to get final velocity. What are we doing here??

The energy_used() function

  • Parameters

    • v_profile: (float list) A list of the same length as the e_profile with each element representing the average velocity (m/s) required for the car to move at each section on the e_profile

    • e_profile: (2D float list)

      • Each row represents a section of a course

      • column 0: the pitch/slope/steepness of the section (rad)

      • column 1: the length/distance of the section (m)

    • distance: (float) distance of each section (m/s)

      • we never use this in the function, as we have length of each sections already stored in e_profile. Useless parameter?

  • Returns

    • energy: (float) Total energy used if the entire v_profile was to be followed (J)

      • Calculated by summing force_req() * e_profile[point][1] (length of section at index point) for each point/section in v_profile and e_profile.

  • Note

    • If v or v_old greater than maximum speed or less than minimum speed, it is caught in the function and whatever is out of bounds is set to maximum speed or minimum speed.

    • Error if the length of v_profile and e_profile do not match

    • In the objective function (shown below) that we are trying to minimize, it basically returns the value of energy_used()function. Thus in Optimizer we are trying to minimize the return value of energy_used()

def objective(v_profile):         energy = car.energy_used(v_profile, elev_profile, distance=dist_step)           return energy / 1000000