suboptimumg.vehicle.powertrain.motor#

class suboptimumg.vehicle.powertrain.motor.Motor(vehicle_model)[source]#

Bases: object

Models motor torque output, efficiency, and power limits.

Notes

The efficiency map, rpm/torque normalization parameters, and the power-limit grids are caches at construction time. Call rebuild_derived_data if motor parameters are mutated.

Parameters:

vehicle_model (VehicleModel)

calculate_max_ground_force_and_motor_power(v, ratio)[source]#

Calculates force and power output by the motor.

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)

Return type:

tuple[float, float]

Notes

The torque the motor can deliver is constrained by two things: the static torque curve tau_curve(rpm), and the DC-bus power limit pow_lim, via tau * omega / eta_elec(rpm, tau) <= pow_lim, which is circular in tau because eta_elec depends on tau. When use_efficiency_lut is True this is resolved by an inverse lookup cached by rebuild_derived_data.

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.

electrical_efficiency(rpm, torque)[source]#

Loss factor between DC bus and motor shaft.

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

Notes

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.

eval_efficiency_map(rpm, torque)[source]#

Evaluate the 2D efficiency map at a given (rpm, torque) point.

Parameters:
  • rpm (float) – Motor RPM

  • torque (float) – Motor torque

Returns:

Motor efficiency (0.66 to 0.99)

Return type:

float

Notes

Inputs outside the fitted rpm/torque range are clamped to the nearest in-range value before evaluating the polynomial, and the result is scaled down by an exponential penalty based on how far outside the range the original inputs were.

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.

Returns:

Combined chain and differential efficiency (0.0 to 1.0)

Return type:

float

Notes

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).

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

Notes

Equals electrical_efficiency * mechanical_efficiency when in ‘indiv’ mode. In ‘sys’ mode the lumped system_efficiency parameter is used directly. Diff efficiency is currently fixed at 100% (TODO).

rebuild_derived_data()[source]#

Rebuild the cached efficiency map and power-limit table.

Return type:

None

v_to_rpm(v, ratio)[source]#

Convert vehicle velocity to motor RPM given the gear ratio.

Parameters:
  • v (float) – Velocity of the vehicle (m/s)

  • ratio (float) – Gear ratio

Returns:

Motor RPM

Return type:

float