Advertisement
agmike

Код тяги, торможения и сцепления

Dec 10th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.46 KB | None | 0 0
  1.     void UpdateTractionAndBraking(SPVehicleData v)
  2.     {
  3.         SPVehicleSpec vs = v.Spec;
  4.         SPAirScheme as = v.AirScheme;
  5.        
  6.         float adhesionForceCurveA = vs.AdhesionForceCurveA;
  7.         float adhesionForceCurveB = vs.AdhesionForceCurveB;
  8.         float adhesionForceCurveC = vs.AdhesionForceCurveC;
  9.         float adhesionForceCurveD = vs.AdhesionForceCurveD;
  10.         float adhesionForceCurveE = vs.AdhesionForceCurveE;
  11.         float adhesionForceCurveF = vs.AdhesionForceCurveF;
  12.  
  13.         float vehicleMass = v.Veh.GetMass();
  14.         float vehicleVelocity = v.Veh.GetVelocity();
  15.         float velocitySign = 1.0f; if (vehicleVelocity < 0.0f)  velocitySign = -1.0f;
  16.        
  17.         float vehicleVelocityKPH = velocitySign * vehicleVelocity / Train.KPH_TO_MPS;
  18.         float wheelVelocityKPH = vehicleVelocityKPH;
  19.         float slipMultiplier = 1.0f;
  20.         if (v.IsSlipping) {
  21.             wheelVelocityKPH = 0.0f;
  22.             slipMultiplier = v.SlipMultiplier;
  23.         }
  24.        
  25.         int[] brakeCylinders = vs.BrakeCylinders;
  26.         float brakeMinPressure = vs.BrakeCylinderMinPressure;
  27.         float brakeShoeCount = vs.BrakeShoeCount;
  28.         float brakeRatio = vs.BrakeGearRatio * vs.BrakeCylinderArea / brakeShoeCount;
  29.        
  30.         float brakeCurveA = vs.BrakeForceCurveA;
  31.         float brakeCurveB = vs.BrakeForceCurveB;
  32.         float brakeCurveC = vs.BrakeForceCurveC;
  33.         float brakeCurveD = vs.BrakeForceCurveD;
  34.         float brakeCurveEF = (wheelVelocityKPH + vs.BrakeForceCurveE)
  35.                              / (vs.BrakeForceCurveF * wheelVelocityKPH + vs.BrakeForceCurveE);
  36.        
  37.         float brakeForce = 0.0f;
  38.         int bc, bcCount = brakeCylinders.size();
  39.         for (bc = 0; bc < bcCount; ++bc) {
  40.             float bcPressure = as.GetPressure(brakeCylinders[bc]);
  41.             float activePressure = bcPressure - brakeMinPressure;
  42.             if (activePressure <= 0.0f)
  43.                 continue;
  44.            
  45.             float shoeAppForceKN = brakeRatio * activePressure;
  46.             float brakeCurveBCD = (brakeCurveB * shoeAppForceKN + brakeCurveC)
  47.                                   / (brakeCurveD * shoeAppForceKN + brakeCurveC);
  48.             float brakeShoeForceKN = shoeAppForceKN * brakeCurveA * brakeCurveBCD * brakeCurveEF;
  49.             brakeForce = brakeForce + 1000.0f * brakeShoeCount * brakeShoeForceKN;
  50.         }
  51.        
  52.         float tractiveWeightKN = 0.0098f * vehicleMass * vs.TractiveWeightRatio;
  53.         float tractiveWheels = vs.TractiveAxleCount * 2.0f;
  54.         float weightPerWheelKN = tractiveWeightKN / tractiveWheels;
  55.        
  56.         float defaultAdhesion = 1000.0f * tractiveWeightKN
  57.             * vs.AdhesionForceCurveA * (vs.AdhesionForceCurveB * weightPerWheelKN + vs.AdhesionForceCurveC)
  58.                                        / (vs.AdhesionForceCurveD * weightPerWheelKN + vs.AdhesionForceCurveC)
  59.                                      * (vehicleVelocityKPH + vs.AdhesionForceCurveE)
  60.                                        / (vs.AdhesionForceCurveF * vehicleVelocityKPH + vs.AdhesionForceCurveE);
  61.         float adhesionForce = slipMultiplier * defaultAdhesion * v.AdhesionMultiplier;
  62.         float customAdhesion = slipMultiplier * v.CustomAdhesion;
  63.         if (customAdhesion >= 0.0f and customAdhesion < adhesionForce)
  64.             adhesionForce = customAdhesion;
  65.         v.DefaultAdhesion = defaultAdhesion;
  66.         v.TotalAdhesion = adhesionForce;
  67.        
  68.         float traction = v.ExternalForce;
  69.         float resistance = v.ExternalResistance + brakeForce * (vs.BrakeCylindersAdditionalCount + 1.0);
  70.        
  71.         float tractionSign = 1.0f; if (traction < 0.0f) tractionSign = -1.0f;
  72.         float tractionAbs = tractionSign * traction;
  73.         float totalForceAbs = tractionAbs - resistance;
  74.         if (totalForceAbs < 0.0f)
  75.             totalForceAbs = -totalForceAbs;
  76.        
  77.         //Interface.Print("Veh " + v.Veh.GetName() + " ATR "+adhesionForce+" "+traction+" "+resistance);
  78.         if (totalForceAbs <= adhesionForce) {
  79.             v.InternalForce = traction;
  80.             v.InternalResistance = resistance;
  81.             v.IsSlipping = false;
  82.             return;
  83.         }
  84.         else if (tractionAbs > resistance) {
  85.             v.InternalForce = tractionSign * adhesionForce;
  86.             v.InternalResistance = 0.0f;
  87.         }
  88.         else {
  89.             v.InternalForce = 0.0f;
  90.             v.InternalResistance = adhesionForce;
  91.         }
  92.         v.IsSlipping = true;
  93.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement