suboptimumg.vehicle.powertrain.powertrain#
- class suboptimumg.vehicle.powertrain.powertrain.Motor(vehicle_model)[source]#
Bases:
object- Parameters:
vehicle_model (VehicleModel)
- build_power_limit_table(n_rpm=200)[source]#
Precompute the DC-power-limited max motor torque at each rpm.
At a given rpm, the binding DC constraint is
τ · ω / η_elec(rpm, τ) ≤ pow_lim, which is implicit in τ because η_elec depends on τ via the LUT. We invert this once by bisecting τ in [0, τ_curve(rpm)] at each rpm in a fixed grid, then look the result up with np.interp at runtime.At rpm=0 there is no power binding (ω=0 ⇒ P_DC=0 for any τ), so the static torque curve dominates. Where the static curve already fits under pow_lim, no inversion is needed.
Rebuild this table if pow_lim, moc_efficiency, or the LUT itself changes after construction.
- Parameters:
n_rpm (int) – Number of RPM points to precompute between 0 and max_rpm. Default is 200.
- calculate_max_ground_force_and_motor_power(v, ratio)[source]#
Calculates force and power output by the motor.
The torque the motor can deliver is constrained by two things:
the static torque curve τ_curve(rpm), and
the DC-bus power limit pow_lim, via
τ · ω / η_elec(rpm, τ) ≤ pow_lim, which is circular in τ because η_elec depends on τ. When use_efficiency_lut is True this is resolved by an inverse lookup built once at init in build_power_limit_table().
Only chain/diff efficiencies sit between shaft and wheel, so the wheel torque uses mechanical_efficiency() (not the full chain). The inverter and motor losses are upstream of the shaft and affect battery draw, not wheel torque.
- Parameters:
v (float) – Velocity of the vehicle (m/s)
ratio (float) – Gear ratio
- Returns:
ground_force (float) – Force at the ground (N)
motor_power (float) – Motor shaft power output (W)
- electrical_efficiency(rpm, torque)[source]#
Loss factor between DC bus and motor shaft.
Covers the inverter (moc_efficiency) and the motor itself. When an efficiency LUT is in use and both rpm and torque are supplied, the motor’s contribution is pulled from the (rpm, torque) map; otherwise the scalar motor_efficiency is used.
- Parameters:
rpm (float) – Motor RPM (used if LUT is enabled)
torque (float) – Motor torque (used if LUT is enabled)
- Returns:
Motor efficiency * MOC efficiency
- Return type:
float
- eval_efficiency_map(rpm, torque)[source]#
Evaluate 2D efficiency map (input \((motor rpm, motor torque)\)) with edge clamping and distance penalty for OOB.
- Parameters:
rpm (float) – Motor RPM
torque (float) – Motor torque
- Returns:
Motor efficiency (0.66 to 0.99)
- Return type:
float
- fit_efficiency_data(points, degv, degt)[source]#
Fit a 2D polynomial z = f(x, y) to data points [[x, y, z], …]
- Parameters:
points (list of lists) – Each inner list is [rpm, torque, efficiency] for a data point.
degv (int) – Degree of the polynomial in the rpm (x) direction.
degt (int) – Degree of the polynomial in the torque (y) direction.
- Returns:
Coefficient matrix C[i,j] for x^i y^j
- Return type:
npt.NDArray
- get_torque_at_rpm(motor_rpm)[source]#
Get motor torque at a given RPM using piecewise function.
The torque curve has three regions: 1. Flat region (0 to fw_rpm): constant max torque 2. Linear decay (fw_rpm to max_rpm): torque decreases linearly 3. Zero region (above max_rpm): no torque
- Parameters:
motor_rpm (float) – Motor RPM
- Returns:
Motor torque at the given RPM (Nm)
- Return type:
float
- mechanical_efficiency()[source]#
Loss factor between motor shaft and wheel.
Only the components that physically sit downstream of the shaft act here: the chain/belt and the diff. The inverter and motor losses are electrical and do not reduce wheel torque; they show up as extra DC current draw and are accounted for in electrical_efficiency().
- powertrain_efficiency(rpm, torque)[source]#
Full DC-bus-to-ground efficiency, used by callers converting between battery power and wheel power (or vice versa).
Equals electrical_efficiency * mechanical_efficiency when in ‘indiv’ mode. In ‘sys’ mode the lumped system_efficiency parameter is used directly.
- Parameters:
rpm (float) – Motor RPM (used if efficiency_method is ‘indiv’)
torque (float) – Motor torque (used if efficiency_method is ‘indiv’)
- Returns:
Overall powertrain efficiency (0.0 to 1.0)
- Return type:
float
- class suboptimumg.vehicle.powertrain.powertrain.Powertrain(vehicle_model)[source]#
Bases:
object- Parameters:
vehicle_model (VehicleModel)