Пример #1
0
        public void TickControls()
        {
            var br = Main.GetAxisIn(JoyControls.Brake);
            var th = Main.GetAxisIn(JoyControls.Throttle);

            switch (state)
            {
            case LaunchControlState.Inactive:
                if (Main.GetButtonIn(JoyControls.LaunchControl) && br > 0.05)
                {
                    Debug.WriteLine("LC activated - waiting");
                    state = LaunchControlState.Waiting;
                }
                break;

            case LaunchControlState.Waiting:
                if (th > 0.1 && br > 0.05)
                {
                    Debug.WriteLine("Revving up engine, waiting for brake to be released");
                    state = LaunchControlState.Revving;
                }
                else if (br < 0.05)
                {
                    Debug.WriteLine("Brake released,  stopped waiting");
                    state = LaunchControlState.Inactive;
                }
                break;

            case LaunchControlState.Revving:
                if (revvedUp && br < 0.05)     // engine is ready & user lets go of brake
                {
                    Debug.WriteLine("GO GO GO");
                    state = LaunchControlState.Pulling;
                }

                if (th < 0.1)     // user lets go of throttle
                {
                    Debug.WriteLine("Back to idle");
                    state = LaunchControlState.Waiting;
                }

                break;

            case LaunchControlState.Pulling:
            case LaunchControlState.Slipping:
                if (th < 0.1 || br > 0.05)
                {
                    Debug.WriteLine("aborting");
                    state = LaunchControlState.Inactive;     // abort
                }
                break;
            }
        }
Пример #2
0
        public void TickTelemetry(IDataMiner data)
        {
            var acc = (data.Telemetry.Speed - previousSpeed) /
                      (DateTime.Now.Subtract(previousTime).TotalMilliseconds / 1000);
            var pullSpeed = Main.Drivetrain.CalculateSpeedForRpm(data.Telemetry.Gear - 1, data.Telemetry.EngineRpm);

            LaunchControlActive = state != LaunchControlState.Inactive;

            switch (state)
            {
                case LaunchControlState.Inactive:
                    break;

                case LaunchControlState.Waiting:
                    _outThrottle = 0;
                    _outClutch = 1;
                    break;

                case LaunchControlState.Revving:
                    _outThrottle = RevvingProp - RevvingProp * data.Telemetry.EngineRpm / LaunchRpm;
                    _outClutch = 1;
                    revvedUp = Math.Abs(data.Telemetry.EngineRpm - LaunchRpm) < 300;
                    break;

                case LaunchControlState.Pulling:
                    _outThrottle = PullingThrottleProp - PullingThrottleProp * data.Telemetry.EngineRpm / LaunchRpm;
                    _outClutch = 1 - PullingClutchProp * previousAcc / PeakAcceleration;
                    if (_outClutch > 0.8) _outClutch = 0.8;

                    if (data.Telemetry.EngineRpm - 300 > LaunchRpm)
                        state = LaunchControlState.Slipping;
                    break;

                case LaunchControlState.Slipping:
                    // revving is less harder to do than pulling
                    // so we switch back to the revving settings, and when the wheelspin is over we go back.
                    _outThrottle = RevvingProp - RevvingProp * data.Telemetry.EngineRpm / LaunchRpm;
                    _outClutch = 1 - PullingClutchProp * previousAcc / PeakAcceleration;
                    if (_outClutch > 0.8) _outClutch = 0.8;

                    if (data.Telemetry.EngineRpm  < LaunchRpm)
                        state = LaunchControlState.Pulling;

                    break;
            }

            if (TemporaryLoadTc)
            {
                if (!tcLoaded && data.Telemetry.Gear == 1 && LaunchControlActive && Main.TractionControl.File.Contains("notc"))
                {
                    tcLoaded = true;
                    Main.Load(Main.TractionControl, "Settings/TractionControl/launch.ini");
                }

                if(tcLoaded && data.Telemetry.Gear != 1)
                {
                    tcLoaded = false;
                    Main.Load(Main.TractionControl, "Settings/TractionControl/notc.ini");
                }
            }

            if (LaunchControlActive && data.Telemetry.Speed > pullSpeed * 0.95)
            {
                Debug.WriteLine("Done pulling!");
                // We're done pulling
                state = LaunchControlState.Inactive;
            }

            if (_outThrottle > 1) _outThrottle = 1;
            if (_outThrottle < 0) _outThrottle = 0;

            if (_outClutch > 1) _outClutch = 1;
            if (_outClutch < 0) _outClutch = 0;

            previousSpeed = data.Telemetry.Speed;
            previousTime = DateTime.Now;
            previousAcc = acc*0.25 + previousAcc*0.75;

            //Debug.WriteLine(previousAcc);
        }
Пример #3
0
        public void TickControls()
        {
            var br = Main.GetAxisIn(JoyControls.Brake);
            var th = Main.GetAxisIn(JoyControls.Throttle);

            switch (state)
            {
                case LaunchControlState.Inactive:
                    if (Main.GetButtonIn(JoyControls.LaunchControl) && br > 0.05)
                    {
                        Debug.WriteLine("LC activated - waiting");
                        state = LaunchControlState.Waiting;
                    }
                    break;

                case LaunchControlState.Waiting:
                    if (th > 0.1 && br>0.05)
                    {
                        Debug.WriteLine("Revving up engine, waiting for brake to be released");
                        state = LaunchControlState.Revving;
                    }
                    else if (br < 0.05)
                    {
                        Debug.WriteLine("Brake released,  stopped waiting");
                        state = LaunchControlState.Inactive;
                    }
                    break;

                case LaunchControlState.Revving:
                    if (revvedUp && br < 0.05) // engine is ready & user lets go of brake
                    {
                        Debug.WriteLine("GO GO GO");
                        state = LaunchControlState.Pulling;
                    }

                    if (th < 0.1) // user lets go of throttle
                    {
                        Debug.WriteLine("Back to idle");
                        state = LaunchControlState.Waiting;
                    }

                    break;

                case LaunchControlState.Pulling:
                case LaunchControlState.Slipping:
                    if (th < 0.1 || br > 0.05)
                    {
                        Debug.WriteLine("aborting");
                        state = LaunchControlState.Inactive; // abort
                    }
                    break;

            }
        }
Пример #4
0
        public void TickTelemetry(IDataMiner data)
        {
            var acc = (data.Telemetry.Speed - previousSpeed) /
                      (DateTime.Now.Subtract(previousTime).TotalMilliseconds / 1000);
            var pullSpeed = Main.Drivetrain.CalculateSpeedForRpm(data.Telemetry.Gear - 1, data.Telemetry.EngineRpm);

            LaunchControlActive = state != LaunchControlState.Inactive;

            switch (state)
            {
            case LaunchControlState.Inactive:
                break;

            case LaunchControlState.Waiting:
                _outThrottle = 0;
                _outClutch   = 1;
                break;

            case LaunchControlState.Revving:
                _outThrottle = RevvingProp - RevvingProp * data.Telemetry.EngineRpm / LaunchRpm;
                _outClutch   = 1;
                revvedUp     = Math.Abs(data.Telemetry.EngineRpm - LaunchRpm) < 300;
                break;

            case LaunchControlState.Pulling:
                _outThrottle = PullingThrottleProp - PullingThrottleProp * data.Telemetry.EngineRpm / LaunchRpm;
                _outClutch   = 1 - PullingClutchProp * previousAcc / PeakAcceleration;
                if (_outClutch > 0.8)
                {
                    _outClutch = 0.8;
                }

                if (data.Telemetry.EngineRpm - 300 > LaunchRpm)
                {
                    state = LaunchControlState.Slipping;
                }
                break;

            case LaunchControlState.Slipping:
                // revving is less harder to do than pulling
                // so we switch back to the revving settings, and when the wheelspin is over we go back.
                _outThrottle = RevvingProp - RevvingProp * data.Telemetry.EngineRpm / LaunchRpm;
                _outClutch   = 1 - PullingClutchProp * previousAcc / PeakAcceleration;
                if (_outClutch > 0.8)
                {
                    _outClutch = 0.8;
                }

                if (data.Telemetry.EngineRpm < LaunchRpm)
                {
                    state = LaunchControlState.Pulling;
                }

                break;
            }

            if (TemporaryLoadTc)
            {
                if (!tcLoaded && data.Telemetry.Gear == 1 && LaunchControlActive && Main.TractionControl.File.Contains("notc"))
                {
                    tcLoaded = true;
                    Main.Load(Main.TractionControl, "Settings/TractionControl/launch.ini");
                }

                if (tcLoaded && data.Telemetry.Gear != 1)
                {
                    tcLoaded = false;
                    Main.Load(Main.TractionControl, "Settings/TractionControl/notc.ini");
                }
            }

            if (LaunchControlActive && data.Telemetry.Speed > pullSpeed * 0.95)
            {
                Debug.WriteLine("Done pulling!");
                // We're done pulling
                state = LaunchControlState.Inactive;
            }

            if (_outThrottle > 1)
            {
                _outThrottle = 1;
            }
            if (_outThrottle < 0)
            {
                _outThrottle = 0;
            }

            if (_outClutch > 1)
            {
                _outClutch = 1;
            }
            if (_outClutch < 0)
            {
                _outClutch = 0;
            }

            previousSpeed = data.Telemetry.Speed;
            previousTime  = DateTime.Now;
            previousAcc   = acc * 0.25 + previousAcc * 0.75;

            //Debug.WriteLine(previousAcc);
        }