Exemplo n.º 1
0
        public override void Tick(decimal DeltaTime)
        {
            if (!bEnabled)
            {
                return;
            }

            bBCState = BCStateSignal != null?BCStateSignal.GetBit() : bPowerState;

            if (Program.bComEnabled)
            {
                CountBC(DeltaTime);
            }

            bEmergency |= bBCError;

            if (bEmergency)
            {
                bInitialState     = false;
                bPowerState       = false;
                StartDelayCounter = 0;
                StopDelayCounter  = 0;
                BCDelayCounter    = 0;
            }
            else
            {
                CountDelays(DeltaTime);
                if (bCrossState)
                {
                    CountImpulsePause(DeltaTime);
                }
                else
                {
                    bPowerState = false;
                }
            }
            bFormerPowerState = bPowerState;

            if (PowerStateSignal != null)
            {
                PowerStateSignal.SetBit(bPowerState);
            }
        }
Exemplo n.º 2
0
        public override void Tick(decimal DeltaTime)
        {
            var bRecentEmergency = bEmergency;

            if (!bEnabled)
            {
                return;
            }

            var SelectedRealInputAt0kV   = !bPolarity ? RealInputAt0kV : ReverseRealInputAt0kV;
            var SelectedRealInputAt30kV  = !bPolarity ? RealInputAt30kV : ReverseRealInputAt30kV;
            var SelectedRealInputAt0mA   = !bPolarity ? RealInputAt0mA : ReverseRealInputAt0mA;
            var SelectedRealInputAtMaxmA = !bPolarity ? RealInputAtMaxmA : ReverseRealInputAtMaxmA;
            var SelectedMaxmA            = !bPolarity ? MaxmA : ReverseMaxmA;

            if (VoltageInSignal != null)
            {
                VoltageIn =
                    Program.BilinearConversion
                        (unchecked ((short)(VoltageInSignal.GetData())), SelectedRealInputAt0kV * 200,
                        SelectedRealInputAt30kV * 200, 0, 30);
            }
            if (CurrentInSignal != null)
            {
                CurrentIn =
                    Program.BilinearConversion
                        (unchecked ((short)(CurrentInSignal.GetData())), SelectedRealInputAt0mA * 200,
                        SelectedRealInputAtMaxmA * 200, 0, SelectedMaxmA);
            }
            bEmergency |= (EmergencySignal != null) && EmergencySignal.GetBit();

            if (!bRecentEmergency && bEmergency)
            {
                Program.Log("Emergency signal on " + Name, ELogType.Error);
            }

            if (bEmergency)
            {
                bInitialState = false;
                bPowerState   = false;
                // VoltageOut = 0m;
                StartDelayCounter = 0;
                StopDelayCounter  = 0;
                if (bEmergencyReset)
                {
                    EmergencyReleaseCounter += DeltaTime;
                    if (EmergencyReleaseCounter > 1)
                    {
                        EmergencyResetRelease();
                        EmergencyReleaseCounter = 0;
                    }
                }
            }
            else
            {
                CountDelays(DeltaTime);
                if (!bPowerState)
                {
                    bEmergencyReset = false;
                }
                if (!bFormerPowerState && bPowerState)
                {
                    Program.Log(Name + " launched", ELogType.Info);
                }
                if (bFormerPowerState && !bPowerState)
                {
                    Program.Log(Name + " stopped", ELogType.Info);
                }
            }
            bFormerPowerState = bPowerState;

            if (StartRampLength > 0)
            {
                if (bPowerState)
                {
                    StartRampCounter = this.Min(StartRampCounter + DeltaTime, StartRampLength);
                }
                else
                {
                    StartRampCounter = 0;
                }
                ActualVoltageOut = VoltageOut / StartRampLength * StartRampCounter;
            }
            else
            {
                ActualVoltageOut = VoltageOut;
            }

            var SelectedMinOutput = !bPolarity ? MinOutput : ReverseMinOutput;
            var SelectedMaxOutput = !bPolarity ? MaxOutput : ReverseMaxOutput;

            if (PowerStateSignal != null)
            {
                PowerStateSignal.SetBit(bPowerState);
            }
            if (EmergencyResetSignal != null)
            {
                EmergencyResetSignal.SetBit(bEmergencyReset);
            }
            if (VoltageOutSignal != null)
            {
                VoltageOutSignal.SetData
                    ((ushort)Program.BilinearConversion
                        (bPowerState ? ActualVoltageOut : 0, SelectedMinOutput, SelectedMaxOutput, 0,
                        MaxScaleOut, true));
            }
            if (PolaritySignal != null)
            {
                PolaritySignal.SetBit(!bPolarity);
            }
        }
Exemplo n.º 3
0
        public override void Tick(decimal DeltaTime)
        {
            if (!bEnabled)
            {
                return;
            }

            if (Edge1Signal != null && Edge2Signal != null)
            {
                Position = (short)(Edge2Signal.GetBit() ? 2 : (Edge1Signal.GetBit() ? 1 : 0));
            }

            if (bEmergency)
            {
                bInitialState     = false;
                bCrossState       = false;
                StartDelayCounter = 0;
                StopDelayCounter  = 0;
            }
            else
            {
                CountDelays(DeltaTime);
            }

            if (bCrossState)
            {
                if (bPowerState)
                {
                    if ((!bDesiredLocation && Position == 2) || (bDesiredLocation && Position == 1))
                    {
                        bPowerState      = false;
                        bServoState      = false;
                        bDesiredLocation = false;
                        bInitialState    = !bMoveOnce;
                        bMoveOnce        = false;
                    }
                    else
                    {
                        CleanTimeoutCounter += DeltaTime;
                        if (CleanTimeoutCounter > MaxCleanTimeout)
                        {
                            bPowerState         = false;
                            bServoState         = false;
                            bDesiredLocation    = false;
                            bEmergency          = true;
                            CleanTimeoutCounter = 0;
                        }
                    }
                }
                else
                {
                    CleanPauseCounter += DeltaTime;
                    if (CleanPauseCounter > CleanPause)
                    {
                        CleanPauseCounter -= CleanPause;
                        bPowerState        = true;
                        bServoState        = true;
                        bDesiredLocation   = (Position == 2);
                    }
                }
            }
            else
            {
                bPowerState         = false;
                bServoState         = false;
                bDesiredLocation    = false;
                CleanTimeoutCounter = 0;
            }

            if (PowerStateSignal != null)
            {
                PowerStateSignal.SetBit(bPowerState && bInitialState);
            }
            if (ServoSignal != null)
            {
                ServoSignal.SetBit(bServoState && bInitialState);
            }
            if (LocationSignal != null)
            {
                LocationSignal.SetBit(bDesiredLocation && bInitialState);
            }
        }
Exemplo n.º 4
0
        public override void Tick(decimal DeltaTime)
        {
            var bRecentEmergency = bEmergency;
            var RecentErrorCode  = ErrorCode;

            if (!bEnabled)
            {
                return;
            }

            if (Buffer != null)
            {
                Buffer.Tick(DeltaTime);
                bConnected  = Buffer.TimeSinceLastResponse <= 5 || !Program.bComEnabled;
                bEmergency |= Buffer.State > 6;
            }

            if (bEmergency)
            {
                if (!bRecentEmergency)
                {
                    Program.Log(Name + " got an error", ELogType.Error);
                }
                bInitialState     = false;
                bPowerState       = false;
                StartDelayCounter = 0;
                StopDelayCounter  = 0;
                if (Buffer != null)
                {
                    //if (Buffer.ErrorProcessStatus == EErrorProcessStatus.GotCode)
                    //{
                    ErrorCode = Buffer.ErrorCode / 10;
                    if (RecentErrorCode != ErrorCode)
                    {
                        Program.Log(Name + " received error code " + ErrorCode.ToString("F1"),
                                    ELogType.Info);
                    }
                    //}
                }
            }
            else
            {
                var bCrossState = CountDelays(DeltaTime);
                if (bCrossState.HasValue)
                {
                    bPowerState = bCrossState.Value;
                }
            }

            if (!bRecentPowerState && bPowerState)
            {
                Program.Log(Name + " launched", ELogType.Info);
            }
            if (bRecentPowerState && !bPowerState)
            {
                Program.Log(Name + " stopped", ELogType.Info);
            }

            if (Buffer != null)
            {
                Buffer.bEngineOn = bPowerState;
                var CurrentMin = CalibrationMode == EFCCalibrationMode.Scaling ?
                                 CalibrationMinFrequency : 0;
                var CurrentMax = CalibrationMode == EFCCalibrationMode.Scaling ?
                                 CalibrationMaxFrequency : 100;
                if (bPowerState)
                {
                    ConvertedOutput = (int)Program.BilinearConversion(CurrentFrequency,
                                                                      CurrentMin, CurrentMax,
                                                                      0, 0x4000, true);
                    Buffer.SW1 = (ushort)ConvertedOutput;
                }
            }
            if (PowerStateSignal != null)
            {
                PowerStateSignal.SetBit(bPowerState);
            }
            bRecentPowerState = bPowerState;
        }