Skip to content

Commit

Permalink
Add "dynamic_traction_control" setting to diesel locomotives
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Dec 14, 2023
1 parent cdaaa44 commit dd03fbc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public void onTick() {
public abstract double getAppliedTractiveEffort(Speed speed);

/** Maximum force that can be between the wheels and the rails before it slips */
private double getStaticTractiveEffort(Speed speed) {
protected final double getStaticTractiveEffort(Speed speed) {
return (Config.ConfigBalance.FuelRequired ? this.getWeight() : this.getMaxWeight()) // KG
* 9.8 // M/S/S
* (slipping ? STEEL.kineticFriction(STEEL)/2 : STEEL.staticFriction(STEEL))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,15 @@ public double getAppliedTractiveEffort(Speed speed) {
double efficiency = 0.82; // Similar to a *lot* of imperial references
double speed_M_S = (Math.abs(speed.metric())/3.6);
double maxPowerAtSpeed = maxPower_W * efficiency / Math.max(0.001, speed_M_S);
return maxPowerAtSpeed * relativeRPM * getReverser();
double applied = maxPowerAtSpeed * relativeRPM * getReverser();
if (getDefinition().hasDynamicTractionControl) {
double max = getStaticTractiveEffort(speed);
if (Math.abs(applied) > max) {
return Math.copySign(max, applied);
}

}
return applied;
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class LocomotiveDieselDefinition extends LocomotiveDefinition {
private boolean hornSus;
private int notches;
private float enginePitchRange;
public boolean hasDynamicTractionControl;

public LocomotiveDieselDefinition(String defID, DataBlock data) throws Exception {
super(LocomotiveDiesel.class, defID, data);
Expand All @@ -41,6 +42,7 @@ public void loadData(DataBlock data) throws Exception {
if (!isCabCar()) {
fuelCapacity_l = properties.getValue("fuel_capacity_l").asInteger() * internal_inv_scale * 10;
fuelEfficiency = properties.getValue("fuel_efficiency_%").asInteger();
hasDynamicTractionControl = properties.getValue("dynamic_traction_control").asBoolean();
} else {
fuelCapacity_l = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ properties =
fuel_capacity_l = null # Required: How large should the fuel tank be?
fuel_efficiency_% = null # Required: How efficient does this locomotive consume fuel? Range 1-99
throttle_notches = 8 # Optional: Number of throttle notches in the cab
dynamic_traction_control = false # If the onboard computer can try to prevent wheel slip
horn_sustained = False # Optional: Should the horn repeat

sounds =
Expand Down

0 comments on commit dd03fbc

Please sign in to comment.