예제 #1
0
        public override float Update(float elapsedSeconds)
        {
            if (TCSEmergencyBraking())
            {
                allowConnect = true;
            }
            if (client == null && allowConnect)
            {
                TcpClient c = new TcpClient();
                c.Connect("127.0.0.1", 5090);
                client = new TCPClient(c);
                client.WriteLine("register(train_brake)");
                client.WriteLine("register(emergency_pushb)");
                client.WriteLine("register(power)");
                client.WriteLine("register(speed)");
            }
            if (client != null)
            {
                string line = client.ReadLine();
                while (line != null)
                {
                    string val = line.Substring(line.IndexOf('=') + 1);
                    if (line.StartsWith("train_brake="))
                    {
                        Value = float.Parse(val.Replace('.', ','));
                    }
                    else if (line.StartsWith("emergency_pushb="))
                    {
                        EBPB = val != "0" && val != "false";
                    }
                    else if (line.StartsWith("power="))
                    {
                        power = val == "1" || val == "true";
                    }
                    else if (line.StartsWith("speed="))
                    {
                        speed = MpS.FromKpH(float.Parse(val.Replace('.', ',')));
                    }
                    line = client.ReadLine();
                }
            }
            if (UpdateValue() == 1)
            {
                if (Value > 0.9)
                {
                    Value = 1;
                    SetUpdateValue(0);
                }
                else
                {
                    float prev = Value;
                    Value += elapsedSeconds / 3;
                    if (Value >= 0.9 && prev < 0.9)
                    {
                        Value = 0.93f;
                        SetUpdateValue(0);
                    }
                }
            }
            if (UpdateValue() == -1)
            {
                float prev = Value;
                Value -= elapsedSeconds / 3;
                if (Value <= 0)
                {
                    Value = 0;
                    SetUpdateValue(0);
                }
            }
            if (speed < 6 || !power)
            {
                dynavail = false;
            }
            else if (Value == 0)
            {
                dynavail = true;
            }
            if (EBPB || EmergencyBrakingPushButton() || TCSEmergencyBraking() || Value > 0.95f)
            {
                CurrentState = State.Emergency;
            }
            else if (TCSFullServiceBraking() || Value > 0.90f)
            {
                CurrentState = State.FullBrake;
            }
            else if (Value > 0.01)
            {
                CurrentState = State.Apply;
            }
            else
            {
                CurrentState = State.Release;
            }
            if (Value < 0.01)
            {
                applyValue = 0;
            }
            else
            {
                applyValue = Math.Min(Math.Max((Value - 0.01f) / 0.89f * 0.85f + 0.15f, 0.15f), 1);
            }
            float MaxDynForce        = DynamicBrakeForce(speed);
            float TargetForce        = applyValue;
            float TargetDynamicForce = CurrentState == State.Emergency ? 0 : Math.Min(TargetForce, MaxDynForce);
            float TargetAirForce     = TargetForce - TargetDynamicForce;

            dynamicBrakeValue = MaxDynForce == 0 ? 0 : TargetDynamicForce / MaxDynForce;
            airBrakeValue     = Math.Max(TargetAirForce, 0);
            if (client != null)
            {
                client.WriteLine("dynamic_brake=" + dynamicBrakeValue.ToString().Replace(',', '.'));
            }
            SetCurrentValue(Value);
            return(CurrentValue());
        }
예제 #2
0
 public override void Update(float elapsedClockSeconds)
 {
     if (clientConnect == null)
     {
         c             = new TcpClient();
         clientConnect = c.ConnectAsync("127.0.0.1", 5090);
     }
     if (client == null && clientConnect.IsCompleted)
     {
         client = new TCPClient(c);
     }
     Convertidor_Estático.Update(ClockTime());
     elapsedTime += elapsedClockSeconds;
     if (elapsedTime > 0.5)
     {
         SpeedMpS         = (DistanceM() - PreviousDistance) / elapsedTime;
         Acceleration     = (SpeedMpS - PreviousSpeed) / elapsedTime;
         PreviousSpeed    = SpeedMpS;
         PreviousDistance = DistanceM();
         elapsedTime      = 0;
     }
     RealLineVoltageV = LineVoltageV();
     if (CurrentPantographState() == PantographState.Down)
     {
         if (!Rele_minima.Triggered)
         {
             Contactor_bateria = true;
         }
         if (!Rele_minima.Started)
         {
             Rele_minima.Start();
         }
     }
     if ((CurrentPantographState() == PantographState.Up && PreviousState != PantographState.Up) || Battery.VoltageV >= 69)
     {
         Rele_minima.Stop();
     }
     PreviousState = CurrentPantographState();
     if (CurrentPantographState() == PantographState.Up && Convertidor_Estático.State != PowerSupplyState.PowerOn && !Rele_minima.Started)
     {
         Rele_minima.Start();
     }
     if (Rele_minima.Triggered)
     {
         Contactor_bateria = false;
     }
     if (CurrentCircuitBreakerState() == CircuitBreakerState.Open || RealLineVoltageV < 2700 || RealLineVoltageV > 3300 || Convertidor_Estático.State != PowerSupplyState.PowerOn)
     {
         SetCurrentState(PowerSupplyState.PowerOff);
     }
     else
     {
         SetCurrentState(PowerSupplyState.PowerOn);
     }
     if (Contactor_bateria && Battery.VoltageV > 56)
     {
         SetCurrentAuxiliaryState(PowerSupplyState.PowerOn);
     }
     else
     {
         SetCurrentAuxiliaryState(PowerSupplyState.PowerOff);
     }
     if (Convertidor_Estático.State != PowerSupplyState.PowerOn && CurrentAuxiliaryState() == PowerSupplyState.PowerOn && Contactor_bateria)
     {
         Battery.Get(1800f, elapsedClockSeconds);
     }
     if (Convertidor_Estático.State == PowerSupplyState.PowerOn && Contactor_bateria)
     {
         Cargador_Batería.Charge(ref Battery, ClockTime());
     }
     SetFilterVoltageV(CurrentCircuitBreakerState() == CircuitBreakerState.Closed ? RealLineVoltageV : Battery.VoltageV);
     SetPantographVoltageV(FilterVoltageV());
     if (client != null)
     {
         client.WriteLine("power=" + ((CurrentState() == PowerSupplyState.PowerOn) ? "1" : "0"));
         client.WriteLine("line_voltage=" + RealLineVoltageV.ToString().Replace(',', '.'));
     }
 }
예제 #3
0
 public override float Update(float elapsedSeconds)
 {
     if (TCSEmergencyBraking())
     {
         allowConnect = true;
     }
     if (client == null && allowConnect)
     {
         TcpClient c = new TcpClient();
         c.Connect("127.0.0.1", 5090);
         client = new TCPClient(c);
         client.WriteLine("register(train_brake)");
         client.WriteLine("register(emergency_pushb)");
         client.WriteLine("register(power)");
         client.WriteLine("register(speed)");
     }
     if (client != null)
     {
         string line = client.ReadLine();
         while (line != null)
         {
             string val = line.Substring(line.IndexOf('=') + 1);
             if (line.StartsWith("train_brake="))
             {
                 Value = float.Parse(val.Replace('.', ','));
             }
             else if (line.StartsWith("emergency_pushb="))
             {
                 EBPB = val != "0" && val != "false";
             }
             else if (line.StartsWith("power="))
             {
                 power = val == "1" || val == "true";
             }
             else if (line.StartsWith("speed="))
             {
                 speed = MpS.FromKpH(float.Parse(val.Replace('.', ',')));
             }
             line = client.ReadLine();
         }
     }
     if (UpdateValue() == 1)
     {
         if (Value > 0.9)
         {
             Value = 1;
             SetUpdateValue(0);
         }
         else
         {
             float prev = Value;
             Value += elapsedSeconds / 3;
             if (Value >= 0.9 && prev < 0.9)
             {
                 Value = 0.93f;
                 SetUpdateValue(0);
             }
         }
     }
     if (UpdateValue() == -1)
     {
         float prev = Value;
         Value -= elapsedSeconds / 3;
         if (Value <= 0)
         {
             Value = 0;
             SetUpdateValue(0);
         }
     }
     if (EBPB || EmergencyBrakingPushButton() || TCSEmergencyBraking() || Value > 0.95f)
     {
         CurrentState = State.Emergency;
     }
     else if (TCSFullServiceBraking() || Value > 0.90f)
     {
         CurrentState = State.FullBrake;
     }
     else if (Value > 0.01)
     {
         CurrentState = State.Apply;
     }
     else
     {
         CurrentState = State.Release;
     }
     if (Value < 0.01)
     {
         applyValue = 0;
     }
     else
     {
         applyValue = Math.Min(Math.Max(Value * 0.9f, 0), 1);
     }
     airBrakeValue = applyValue;
     SetCurrentValue(Value);
     return(CurrentValue());
 }