public void Update() { if (InActualRpm <= 0.0) { OutGain = MinimumGain; return; } if (InActualRpm >= MaximumRpm) { OutGain = 1.0; } else { var ratio = (InTargetRpm - InActualRpm) / MaximumRpm + 1.0; OutGain = Math.Max(Math.Min(ratio, MaximumGain), MinimumGain); } DebugForm.SetText(DebugForm.GovernerRatio, OutGain.ToString("F3")); DebugForm.SetText(DebugForm.ActualRpm, InActualRpm.ToString("0000")); DebugForm.SetText(DebugForm.TargetRpm, InTargetRpm.ToString("0000")); }
public void Update(double deltaTime) { var absoluteVelocity = AtsSimulationEnvironment.Instance.CurrentStates.AbsoluteVelocity; OutEngineDelayTp = DefaultEngineDelayTp; BacklashDelay.U = 1.0f - BacklashRand.Next(0, Math.Max(100 - (int)(AtsSimulationEnvironment.Instance.CurrentStates.MainCircuitCurrent * 2.0), 0)) / 100.0f; BacklashDelay.Tp = 70.0; BacklashDelay.Calculate(AtsSimulationEnvironment.Instance.DeltaTime); if (OutRpm >= EngineBlowUpRpm) { // Engine blow up. InNotch = 0; } if (absoluteVelocity < 5.0f) { CurrentReverserPosition = InReverser; } if (absoluteVelocity <= EngineBrakeEndVelocity) { IsEnabledEngineBrake = false; } else { IsEnabledEngineBrake = true; } switch (InNotch) { case 0: if (InEngineBrake && IsEnabledEngineBrake) { OrderedDrivingState = DrivingState.Brake; break; } OrderedDrivingState = DrivingState.Neutral; break; default: if (OrderedDrivingState != DrivingState.Neutral) { break; } OrderedDrivingState = DrivingState.Drive; break; } switch (CurrentReverserPosition) { case 0: ForwardClutch.InEngaged = false; BackwardClutch.InEngaged = false; break; case 1: if (!BackwardClutch.OutEngaged) { ForwardClutch.InEngaged = true; } BackwardClutch.InEngaged = false; break; case -1: ForwardClutch.InEngaged = false; if (!ForwardClutch.OutEngaged) { BackwardClutch.InEngaged = true; } break; } ForwardClutch.Update(deltaTime); BackwardClutch.Update(deltaTime); if (!ForwardClutch.OutEngaged && !BackwardClutch.OutEngaged) { OrderedDrivingState = DrivingState.Neutral; AtsSimulationEnvironment.Instance.PanelOperations["FwLp"] = 0; AtsSimulationEnvironment.Instance.PanelOperations["BwLp"] = 0; } else if (ForwardClutch.OutEngaged) { AtsSimulationEnvironment.Instance.PanelOperations["FwLp"] = 1; AtsSimulationEnvironment.Instance.PanelOperations["BwLp"] = 0; } else if (BackwardClutch.OutEngaged) { AtsSimulationEnvironment.Instance.PanelOperations["FwLp"] = 0; AtsSimulationEnvironment.Instance.PanelOperations["BwLp"] = 1; } switch (OrderedDrivingState) { case DrivingState.Neutral: CurrentDrivingState = DrivingState.Neutral; break; case DrivingState.Drive: if (CurrentDrivingState == DrivingState.Neutral) { if (absoluteVelocity < TransitionVelocityPositive[(int)GearPositionState.Hensoku]) { OrderedGearPosition = GearPositionState.Hensoku; } else if (absoluteVelocity < TransitionVelocityPositive[(int)GearPositionState.Mission1]) { OrderedGearPosition = GearPositionState.Mission1; } else { OrderedGearPosition = GearPositionState.Mission2; } CcsSyncingState = SynchingState.WaitOperation; CurrentDrivingState = DrivingState.Synching; } break; case DrivingState.Brake: if (CurrentDrivingState == DrivingState.Neutral) { CcsSyncingState = SynchingState.WaitOperation; CurrentDrivingState = DrivingState.Synching; if (absoluteVelocity < TransitionVelocityNegative[(int)GearPositionState.Mission2]) { OrderedGearPosition = GearPositionState.Mission1; } else { OrderedGearPosition = GearPositionState.Mission2; } } break; } var notch = InNotch; var gear1Rpm = absoluteVelocity / TransitionVelocityPositive[(int)GearPositionState.Mission1] * MaximumGear1Rpm;; var gear2Rpm = absoluteVelocity / MaximumGear2Velocity * MaximumGear2Rpm; var gear1TargetFuelCurrent = absoluteVelocity / TransitionVelocityPositive[(int)GearPositionState.Mission1]; var gear2TargetFuelCurrent = absoluteVelocity / MaximumGear2Velocity; // CCS switch (CurrentDrivingState) { case DrivingState.Neutral: Gear1Clutch.InEngaged = false; Gear2Clutch.InEngaged = false; OutNotch = notch; OutFuelInjectionCurrent = 0.0; break; case DrivingState.Synching: OutNotch = 0; OutFuelInjectionCurrent = 0.0; switch (CcsSyncingState) { case SynchingState.WaitOperation: CcsSyncingState = SynchingState.DisengageAllGearClutch; break; case SynchingState.DisengageAllGearClutch: Gear1Clutch.InEngaged = false; Gear2Clutch.InEngaged = false; CcsSyncingState = SynchingState.WaitDisengagingAllGearClutch; break; case SynchingState.WaitDisengagingAllGearClutch: Gear1Clutch.InEngaged = false; Gear2Clutch.InEngaged = false; if (Gear1Clutch.OutEngaged || Gear2Clutch.OutEngaged) { break; } CcsSyncingState = SynchingState.EngageMissionClutch; break; case SynchingState.EngageMissionClutch: switch (OrderedGearPosition) { case GearPositionState.Hensoku: MissionClutch.InEngaged = false; break; case GearPositionState.Mission1: case GearPositionState.Mission2: MissionClutch.InEngaged = true; break; } CcsSyncingState = SynchingState.WaitEngagingMissionClutch; break; case SynchingState.WaitEngagingMissionClutch: switch (OrderedGearPosition) { case GearPositionState.Hensoku: MissionClutch.InEngaged = false; break; case GearPositionState.Mission1: case GearPositionState.Mission2: MissionClutch.InEngaged = true; break; } if (MissionClutch.InEngaged != MissionClutch.OutEngaged) { break; } switch (OrderedGearPosition) { case GearPositionState.Mission1: case GearPositionState.Mission2: break; default: break; } CcsSyncingState = SynchingState.Sync; break; case SynchingState.Sync: switch (OrderedGearPosition) { case GearPositionState.Hensoku: CcsSyncingState = SynchingState.EngageGearClutchForHensoku; break; case GearPositionState.Mission1: OutFuelInjectionCurrent = gear1TargetFuelCurrent; if (InRpm < gear1Rpm - 100.0) { break; } CcsSyncingState = SynchingState.WaitSyncing; break; case GearPositionState.Mission2: OutFuelInjectionCurrent = gear2TargetFuelCurrent; if (InRpm < gear2Rpm - 100.0) { break; } CcsSyncingState = SynchingState.WaitSyncing; break; } break; case SynchingState.WaitSyncing: var diffRpm = 0.0; switch (OrderedGearPosition) { case GearPositionState.Mission1: diffRpm = InRpm - gear1Rpm; OutFuelInjectionCurrent = gear1TargetFuelCurrent; break; case GearPositionState.Mission2: diffRpm = InRpm - gear2Rpm; OutFuelInjectionCurrent = gear2TargetFuelCurrent; break; } if (diffRpm >= 100.0) { break; } CurrentTime = 0.0; CcsSyncingState = SynchingState.EngageGearClutch; break; case SynchingState.EngageGearClutchForHensoku: Gear1Clutch.InEngaged = true; CcsSyncingState = SynchingState.WaitEngagingGearClutchForHensoku; break; case SynchingState.WaitEngagingGearClutchForHensoku: Gear1Clutch.InEngaged = true; if (!Gear1Clutch.OutEngaged) { break; } CurrentDrivingState = DrivingState.Drive; CcsSyncingState = SynchingState.WaitOperation; break; case SynchingState.EngageGearClutch: switch (OrderedGearPosition) { case GearPositionState.Hensoku: case GearPositionState.Mission1: Gear1Clutch.InEngaged = true; Gear2Clutch.InEngaged = false; OutFuelInjectionCurrent = gear1TargetFuelCurrent; break; case GearPositionState.Mission2: Gear1Clutch.InEngaged = false; Gear2Clutch.InEngaged = true; OutFuelInjectionCurrent = gear2TargetFuelCurrent; break; } CcsSyncingState = SynchingState.WaitEngagingGearClutch; break; case SynchingState.WaitEngagingGearClutch: CurrentTime += deltaTime; switch (OrderedGearPosition) { case GearPositionState.Hensoku: case GearPositionState.Mission1: Gear1Clutch.InEngaged = true; Gear2Clutch.InEngaged = false; OutFuelInjectionCurrent = gear1TargetFuelCurrent; break; case GearPositionState.Mission2: Gear1Clutch.InEngaged = false; Gear2Clutch.InEngaged = true; OutFuelInjectionCurrent = gear2TargetFuelCurrent; break; } if (CurrentTime > 500.0) { OutNotch = TransmissionSyncingStabilizeNotch; } if (!Gear1Clutch.OutEngaged && !Gear2Clutch.OutEngaged) { break; } CurrentTime = 0.0; CcsSyncingState = SynchingState.Stabilize; break; case SynchingState.Stabilize: CurrentTime += deltaTime; if (OrderedDrivingState == DrivingState.Brake) { CcsSyncingState = SynchingState.WaitOperation; CurrentDrivingState = DrivingState.Brake; break; } if (CurrentTime > 300.0) { OutNotch = TransmissionSyncingStabilizeNotch; if (InNotch >= TransmissionSyncingReductionConditionNotch) { if (CurrentTime < 1500.0) { OutNotch = TransmissionSyncingReductionNotch; } else { CcsSyncingState = SynchingState.WaitOperation; CurrentDrivingState = DrivingState.Drive; OutNotch = InNotch; } } else { CcsSyncingState = SynchingState.WaitOperation; CurrentDrivingState = DrivingState.Drive; OutNotch = InNotch; } } break; } break; case DrivingState.Drive: var lastGearPosition = OrderedGearPosition; switch (CurrentGearPosition) { case GearPositionState.Hensoku: if (absoluteVelocity >= TransitionVelocityPositive[(int)GearPositionState.Hensoku]) { OrderedGearPosition = GearPositionState.Mission1; } break; case GearPositionState.Mission1: if (absoluteVelocity >= TransitionVelocityPositive[(int)GearPositionState.Mission1]) { OrderedGearPosition = GearPositionState.Mission2; } else if (absoluteVelocity <= TransitionVelocityNegative[(int)GearPositionState.Mission1]) { OrderedGearPosition = GearPositionState.Hensoku; } break; case GearPositionState.Mission2: if (absoluteVelocity <= TransitionVelocityNegative[(int)GearPositionState.Mission2]) { OrderedGearPosition = GearPositionState.Mission1; } break; } if (lastGearPosition != OrderedGearPosition) { CurrentDrivingState = DrivingState.Synching; } OutNotch = notch; OutFuelInjectionCurrent = 0.0; break; case DrivingState.Brake: OutFuelInjectionCurrent = 0.0; break; } if ((ForwardClutch.InEngaged && (ForwardClutch.InEngaged != ForwardClutch.OutEngaged)) || (BackwardClutch.InEngaged && (BackwardClutch.InEngaged != BackwardClutch.OutEngaged))) { OutFuelInjectionCurrent = FuelController.FuelValueOnCutOff + 0.03; } MissionClutch.Update(deltaTime); Gear1Clutch.Update(deltaTime); Gear2Clutch.Update(deltaTime); if (!MissionClutch.OutEngaged && Gear1Clutch.OutEngaged) { CurrentGearPosition = GearPositionState.Hensoku; } else if (Gear1Clutch.OutEngaged) { CurrentGearPosition = GearPositionState.Mission1; } else if (Gear2Clutch.OutEngaged) { CurrentGearPosition = GearPositionState.Mission2; } else { CurrentGearPosition = GearPositionState.Neutral; OutNotch *= 2; } OutReverserPosition = CurrentReverserPosition; switch (CurrentDrivingState) { case DrivingState.Neutral: case DrivingState.Synching: case DrivingState.Drive: OutNotch = Math.Min(OutNotch, AtsSimulationEnvironment.Instance.ControlHandle.MaximumTractionPosition); OutTractionPosition = TractionPositionTable[(int)CurrentGearPosition][OutNotch]; break; case DrivingState.Brake: OutNotch = 0; OutTractionPosition = TractionPositionTable[(int)CurrentGearPosition][9];; break; } switch (CurrentGearPosition) { case GearPositionState.Neutral: OutRpm = InRpm; OutTransferGearNoiseVolume = 0.0; Converter.InVelocity = AtsSimulationEnvironment.Instance.CurrentStates.AbsoluteVelocity; Converter.Reset(InRpm * 0.9); Converter.Update(deltaTime); break; case GearPositionState.Hensoku: Converter.InVelocity = AtsSimulationEnvironment.Instance.CurrentStates.AbsoluteVelocity; Converter.InRpm = InRpm; Converter.Update(deltaTime); OutRpm = Converter.OutRpm; if (InRpm < FuelController.FuelTable[1] * MaximumRpm) { OutEngineDelayTp = 500.0; } break; case GearPositionState.Mission1: OutRpm = gear1Rpm; OutTransferGearNoiseVolume = 1.0f * (float)BacklashDelay.Y; Converter.InVelocity = AtsSimulationEnvironment.Instance.CurrentStates.AbsoluteVelocity; Converter.Reset(OutRpm); break; case GearPositionState.Mission2: OutRpm = gear2Rpm; OutTransferGearNoiseVolume = 1.0f * (float)BacklashDelay.Y; Converter.InVelocity = AtsSimulationEnvironment.Instance.CurrentStates.AbsoluteVelocity; Converter.Reset(OutRpm); break; } AtsSimulationEnvironment.Instance.PanelOperations["ExBLp"] = CurrentDrivingState == DrivingState.Brake ? 1 : 0; DebugForm.SetText(DebugForm.MissionClutch, MissionClutch.OutEngaged ? "直結" : "変速"); DebugForm.SetText(DebugForm.Gear1Clutch, Gear1Clutch.OutEngaged ? "ON" : "OFF"); DebugForm.SetText(DebugForm.Gear2Clutch, Gear2Clutch.OutEngaged ? "ON" : "OFF"); DebugForm.SetText(DebugForm.ForwardClutch, ForwardClutch.OutEngaged ? "ON" : "OFF"); DebugForm.SetText(DebugForm.BackwardClutch, BackwardClutch.OutEngaged ? "ON" : "OFF"); DebugForm.SetText(DebugForm.CurrentDrivingState, CurrentDrivingState.ToString()); DebugForm.SetText(DebugForm.CcsSyncingState, CcsSyncingState.ToString()); }