Ejemplo n.º 1
0
        //================================================================================================//
        /// <summary>
        /// Initialization when simulation starts with moving train
        /// <\summary>
        ///
        public override void InitializeMoving()
        {
            base.InitializeMoving();
            WheelSpeedMpS       = SpeedMpS;
            DynamicBrakePercent = -1;
            ThrottleController.SetValue(Train.MUThrottlePercent / 100);

            Pantographs.InitializeMoving();
            PowerSupply.InitializeMoving();
        }
Ejemplo n.º 2
0
 //================================================================================================//
 /// <summary>
 /// The method copes with the strange parameters that some british gear-based DMUs have: throttle
 /// values arrive up to 1000%, and conversely GearBoxMaxTractiveForceForGears are divided by 10.
 /// Apparently MSTS works well with such values. This method recognizes such case and corrects such values.
 /// </summary>
 protected void NormalizeParams()
 {
     // check for wrong GearBoxMaxTractiveForceForGears parameters
     if (GearBox != null && GearBox.mstsParams != null && GearBox.mstsParams.GearBoxMaxTractiveForceForGearsN.Count > 0)
     {
         if (ThrottleController != null && ThrottleController.MaximumValue > 1 && MaxForceN / GearBox.mstsParams.GearBoxMaxTractiveForceForGearsN[0] > 3)
         // Tricky things have been made with this .eng file, see e.g Cravens 105; let's correct them
         {
             for (int i = 0; i < GearBox.mstsParams.GearBoxMaxTractiveForceForGearsN.Count; i++)
             {
                 GearBox.mstsParams.GearBoxMaxTractiveForceForGearsN[i] *= ThrottleController.MaximumValue;
             }
         }
         ThrottleController.Normalize(ThrottleController.MaximumValue);
         // correct also .cvf files
         if (CabViewList.Count > 0)
         {
             foreach (var cabView in CabViewList)
             {
                 if (cabView.CVFFile != null && cabView.CVFFile.CabViewControls != null && cabView.CVFFile.CabViewControls.Count > 0)
                 {
                     foreach (var control in cabView.CVFFile.CabViewControls)
                     {
                         if (control is CVCDiscrete && control.ControlType == CABViewControlTypes.THROTTLE && (control as CVCDiscrete).Values.Count > 0 && (control as CVCDiscrete).Values[(control as CVCDiscrete).Values.Count - 1] > 1)
                         {
                             var discreteControl = (CVCDiscrete)control;
                             for (var i = 0; i < discreteControl.Values.Count; i++)
                             {
                                 discreteControl.Values[i] /= ThrottleController.MaximumValue;
                             }
                             if (discreteControl.MaxValue > 0)
                             {
                                 discreteControl.MaxValue = discreteControl.Values[discreteControl.Values.Count - 1];
                             }
                         }
                     }
                 }
             }
         }
         ThrottleController.MaximumValue = 1;
     }
     // Check also for very low DieselEngineIdleRPM
     if (IdleRPM < 10)
     {
         IdleRPM = Math.Max(150, MaxRPM / 10);
     }
 }
Ejemplo n.º 3
0
        private void History_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                var idx = e.NewStartingIndex;

                foreach (var item in e.NewItems.OfType <DataPacket>())
                {
                    ThrottleController.PushData(new Int32DataPoint(idx), new Int32DataPoint(item.Throttle));
                    idx++;
                }
            }
            else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
            {
                ThrottleController.ClearCommand.Execute(null);
                ThrottleController.PushData(new Int32DataPoint(0), new Int32DataPoint(0));
            }
        }
Ejemplo n.º 4
0
        public void Run()
        {
            ThrottleConfig config = new ThrottleConfig(new int[] { 10, 20 })
            {
                RejectionFactor = 3,
                TokenExpiration = TimeSpan.FromSeconds(5)
            };

            controller = new ThrottleController(config);
            controller.Start();

            value1 = 0;
            value2 = 0;
            Timer timer = new Timer(50);

            timer.Enabled  = true;
            timer.Elapsed += (source, stat) => QueueWorkItems(controller);
            Thread.Sleep(TimeSpan.FromMinutes(10));
        }
Ejemplo n.º 5
0
        //================================================================================================//
        /// <summary>
        /// Set starting conditions  when initial speed > 0
        ///

        public override void InitializeMoving()
        {
            base.InitializeMoving();
            WheelSpeedMpS       = SpeedMpS;
            DynamicBrakePercent = -1;
            if (DieselEngines[0].GearBox != null && GearBoxController != null)
            {
                DieselEngines[0].GearBox.InitializeMoving();
                DieselEngines[0].InitializeMoving();
                if (IsLeadLocomotive())
                {
                    Train.MUGearboxGearIndex      = DieselEngines[0].GearBox.CurrentGearIndex + 1;
                    Train.AITrainGearboxGearIndex = DieselEngines[0].GearBox.CurrentGearIndex + 1;
                }
                GearBoxController.CurrentNotch = Train.MUGearboxGearIndex;
                GearboxGearIndex = DieselEngines[0].GearBox.CurrentGearIndex + 1;
                GearBoxController.SetValue((float)GearBoxController.CurrentNotch);
            }
            ThrottleController.SetValue(Train.MUThrottlePercent / 100);
        }
Ejemplo n.º 6
0
        public void SetEditMode(WaterfallController ctrl, ModuleWaterfallFX mod)
        {
            showWindow        = true;
            control           = ctrl;
            fxMod             = mod;
            newControllerName = ctrl.name;
            controllerFlag    = controllerTypes.ToList().IndexOf(ctrl.linkedTo);
            windowMode        = ControllerPopupMode.Modify;
            WindowPosition    = new Rect(Screen.width / 2 - 100, Screen.height / 2f - 50, 400, 100);
            eventCurve        = new FloatCurve();
            try
            {
                RandomnessController r = (RandomnessController)control;
                if (r.noiseType == "random")
                {
                    randomStrings[0] = r.range.x.ToString();
                    randomStrings[1] = r.range.y.ToString();
                }
                if (r.noiseType == "perlin")
                {
                    randomStrings[0] = r.seed.ToString();
                    randomStrings[1] = r.scale.ToString();
                    randomStrings[2] = r.speed.ToString();
                    randomStrings[3] = r.minimum.ToString();
                }
                EngineEventController e = (EngineEventController)control;
                ThrottleController    t = (ThrottleController)control;

                throttleStrings[0] = t.responseRateUp.ToString();
                throttleStrings[1] = t.responseRateDown.ToString();

                eventCurve = e.eventCurve;
            }
            catch (Exception)
            { }
            GenerateCurveThumbs();
        }
        WaterfallController CreateNewController()
        {
            if (controllerTypes[controllerFlag] == "atmosphere_density")
            {
                AtmosphereDensityController newCtrl = new AtmosphereDensityController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "custom")
            {
                CustomController newCtrl = new CustomController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "engineEvent")
            {
                EngineEventController newCtrl = new EngineEventController();
                newCtrl.name          = newControllerName;
                newCtrl.linkedTo      = controllerTypes[controllerFlag];
                newCtrl.eventName     = eventTypes[eventFlag];
                newCtrl.eventCurve    = eventCurve;
                newCtrl.eventDuration = eventDuration;
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "gimbal")
            {
                GimbalController newCtrl = new GimbalController();
                newCtrl.name     = newControllerName;
                newCtrl.axis     = axisTypes[axisFlag];
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "light")
            {
                LightController newCtrl = new LightController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "mach")
            {
                MachController newCtrl = new MachController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "random")
            {
                RandomnessController newCtrl = new RandomnessController();
                newCtrl.name      = newControllerName;
                newCtrl.range     = randomRange;
                newCtrl.scale     = perlinScale;
                newCtrl.minimum   = perlinMin;
                newCtrl.seed      = perlinSeed;
                newCtrl.speed     = perlinSpeed;
                newCtrl.noiseType = randTypes[randFlag];
                newCtrl.linkedTo  = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "rcs")
            {
                RCSController newCtrl = new RCSController();
                newCtrl.name             = newControllerName;
                newCtrl.linkedTo         = controllerTypes[controllerFlag];
                newCtrl.responseRateUp   = rampRateUp;
                newCtrl.responseRateDown = rampRateDown;
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "throttle")
            {
                ThrottleController newCtrl = new ThrottleController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];

                newCtrl.responseRateUp   = rampRateUp;
                newCtrl.responseRateDown = rampRateDown;
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "thrust")
            {
                ThrustController newCtrl = new ThrustController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else
            {
                return(null);
            }
        }