Exemple #1
0
        private void UpdateState(IEvent @event)
        {
            switch (@event)
            {
            case RpmChanged rpmChanged:
                CurrentRpm = rpmChanged.NewRpm;
                break;

            case GasPressureChanged gasPressure:
                LastGasPressure = gasPressure.PedalPressure;
                break;

            case GearChanged gearChanged:
                CurrentGear = gearChanged.EnteredGear;
                break;

            case EconomicModeEntered _:
                ResponsivenessMode = ResponsivenessMode.Economic;
                break;

            case ComfortModeEntered _:
                ResponsivenessMode = ResponsivenessMode.Comfort;
                break;

            case SportModeEntered _:
                ResponsivenessMode = ResponsivenessMode.Sport;
                break;
            }
        }
Exemple #2
0
        public void GreaterThan_ShouldReturnFalse_WhenComparingLesserValueWithGreaterValue()
        {
            var lesser  = new Rpm(1000d);
            var greater = new Rpm(2000d);

            var result = lesser > greater;

            result.Should().BeFalse();
        }
Exemple #3
0
        public void GreaterThan_ShouldReturnTrue_WhenComparingGreaterValueWithLesserValue()
        {
            var lesser  = new Rpm(1000d);
            var greater = new Rpm(2000d);

            var result = greater > lesser;

            result.Should().BeTrue();
        }
Exemple #4
0
 public KickdownDetectionProcess(IKickdownCharacteristics kickdownCharacteristics, IGearshiftService gearshiftService)
 {
     _kickdownCharacteristics = kickdownCharacteristics;
     _gearshiftService        = gearshiftService;
     ResponsivenessMode       = ResponsivenessMode.Economic;
     CurrentGear     = new Gear(0);
     LastGasPressure = new PedalPressure(0.0);
     CurrentRpm      = new Rpm(0.0);
 }
Exemple #5
0
        public SuggestedAction GetSuggestedActionFor(Gear currentGear, Rpm rpm)
        {
            if (_innerProgram.GetSuggestedActionFor(currentGear, rpm) == SuggestedAction.Retain)
            {
                return(SuggestedAction.Downshift);
            }

            return(SuggestedAction.Retain);
        }
        public ShiftpointRange(Rpm lowerShiftPoint, Rpm upperShiftPoint)
        {
            if (lowerShiftPoint.Value > upperShiftPoint.Value)
            {
                throw new DomainRuleViolatedException("Upper shiftpoint value cannot be lower than lower shiftpoint value");
            }

            LowerShiftPoint = lowerShiftPoint;
            UpperShiftPoint = upperShiftPoint;
        }
        public void SendsRpmEventOnChange()
        {
            var rpm = new Rpm(2137d);

            _providerMock.Setup(x => x.GetCurrentRpm()).Returns(rpm);

            _reporter.TryToReport();

            _eventBusMock.Verify(x => x.SendEvent(It.Is <RpmChanged>(y => y.NewRpm == rpm)), Times.Once);
        }
Exemple #8
0
        public void QueriesTheProgramAboutReceivedFps()
        {
            var rpm = new Rpm(2000);

            _programMock.Setup(x => x.GetSuggestedActionFor(It.IsAny <Gear>(), rpm)).Returns(SuggestedAction.Retain);
            _gearshifter.SetProgram(_programMock.Object);

            _gearshifter.HandleRpmChange(new Rpm(2000));

            _programMock.Verify(x => x.GetSuggestedActionFor(It.IsAny <Gear>(), rpm));
        }
Exemple #9
0
 public int GetHashCodeWithMembers()
 {
     unchecked
     {
         var hashCode = 397;
         hashCode = (hashCode * 397) ^ Type.GetHashCode();
         hashCode = (hashCode * 397) ^ (Model?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ Rpm.GetHashCode();
         hashCode = (hashCode * 397) ^ Capacity.GetHashCode();
         return(hashCode);
     }
 }
        public void Accelerate_ShouldUpshift_WhenCurrentRpmIsGreaterThanUpshiftBoundary()
        {
            var currentRpm = new Rpm(3000d);

            _externalSystems.GetCurrentRpm().Returns(currentRpm);

            var threshold = new Threshold(0.8d);

            Sut().Accelerate(threshold);

            _gearShifter.Received(1).Upshift();
            _gearShifter.DidNotReceive().Downshift();
        }
        public void Accelerate_ShouldNotUpshiftAndNotDownShift_WhenCurrentRpmIsBetweenShiftBoundaries()
        {
            var currentRpm = new Rpm(1500d);

            _externalSystems.GetCurrentRpm().Returns(currentRpm);

            var threshold = new Threshold(0.8d);

            Sut().Accelerate(threshold);

            _gearShifter.DidNotReceive().Upshift();
            _gearShifter.DidNotReceive().Downshift();
        }
Exemple #12
0
        public void QueriesTheProgramGivingTheGearFromGearbox()
        {
            var rpm = new Rpm(2000);

            _gearboxMock.Setup(x => x.CurrentGear).Returns(new Gear(3));

            _programMock.Setup(x => x.GetSuggestedActionFor(new Gear(3), It.IsAny <Rpm>())).Returns(SuggestedAction.Retain);
            _gearshifter.SetProgram(_programMock.Object);

            _gearshifter.HandleRpmChange(new Rpm(2000));

            _programMock.Verify(x => x.GetSuggestedActionFor(It.IsAny <Gear>(), rpm));
        }
Exemple #13
0
        public void Accelerate_ShouldDownshift_WhenCurrentRpmIsLesserThanDownshiftBoundary()
        {
            var currentRpm = new Rpm(1000d);

            _externalSystems.GetCurrentRpm().Returns(currentRpm);

            var shiftBoundaries = GetShiftBoundaries(1500d, 3000d);

            Sut().Accelerate(shiftBoundaries);

            _gearShifter.Received(1).Downshift();
            _gearShifter.DidNotReceive().Upshift();
        }
Exemple #14
0
        public void Accelerate_ShouldNotUpshift_WhenCurrentRpmIsGreaterThanUpshiftBoundaryNotModifiedByFactor()
        {
            var currentRpm = new Rpm(3000d + 1);

            _externalSystems.GetCurrentRpm().Returns(currentRpm);

            var shiftBoundaries = GetShiftBoundaries(1500d, 3000d);

            Sut().Accelerate(shiftBoundaries);

            _gearShifter.DidNotReceive().Upshift();
            _gearShifter.DidNotReceive().Downshift();
        }
Exemple #15
0
        public void HandleRpmChange(Rpm rpm)
        {
            var suggestedAction = Program.GetSuggestedActionFor(Gearbox.CurrentGear, rpm);

            if (suggestedAction == SuggestedAction.Upshift)
            {
                Gearbox.Upshift();
            }

            if (suggestedAction == SuggestedAction.Downshift)
            {
                Gearbox.Downshift();
            }
        }
        public SuggestedAction GetSuggestedActionFor(Gear currentGear, Rpm rpm)
        {
            if (rpm.Value < Range.LowerShiftPoint.Value)
            {
                return(SuggestedAction.Downshift);
            }

            if (rpm.Value > Range.UpperShiftPoint.Value)
            {
                return(SuggestedAction.Upshift);
            }

            return(SuggestedAction.Retain);
        }
Exemple #17
0
        public SuggestedAction GetSuggestedActionFor(Gear currentGear, Rpm rpm)
        {
            if (currentGear.Value > TargetedGear.Value)
            {
                return(SuggestedAction.Downshift);
            }

            if (currentGear.Value < TargetedGear.Value)
            {
                return(SuggestedAction.Upshift);
            }

            return(SuggestedAction.Retain);
        }
        public void Accelerate_ShouldUpshiftAndMakeSound_WhenCurrentRpmIsGreaterThanUpshiftBoundaryModifiedByFactor()
        {
            var currentRpm = new Rpm(3000d * _rpmUpShiftFactorValue + 1);

            _externalSystems.GetCurrentRpm().Returns(currentRpm);

            var shiftBoundaries = GetShiftBoundaries(1500d, 3000d);

            Sut().Accelerate(shiftBoundaries);

            _gearShifter.Received().Upshift();
            _gearShifter.DidNotReceive().Downshift();

            _externalSystems.Received().MakeSound(Arg.Any <SoundVolume>());
        }
        public void WhenTwoDifferentValuesSendsTwoEvents()
        {
            var firstRpm  = new Rpm(2137d);
            var secondRpm = new Rpm(1728d);

            _providerMock.SetupSequence(x => x.GetCurrentRpm())
            .Returns(firstRpm)
            .Returns(secondRpm);

            _reporter.TryToReport();
            _reporter.TryToReport();

            _eventBusMock.Verify(x => x.SendEvent(It.Is <RpmChanged>(y => y.NewRpm == firstRpm)), Times.Once);
            _eventBusMock.Verify(x => x.SendEvent(It.Is <RpmChanged>(y => y.NewRpm == secondRpm)), Times.Once);
        }
Exemple #20
0
        public void ChangesBehaviourAlongWithChangedProgram()
        {
            var rpm = new Rpm(2000);

            _programMock.Setup(x => x.GetSuggestedActionFor(It.IsAny <Gear>(), rpm)).Returns(SuggestedAction.Upshift);
            _gearshifter.SetProgram(_programMock.Object);
            _gearshifter.HandleRpmChange(new Rpm(2000));

            var secondProgramMock = new Mock <IShiftingProgram>();

            secondProgramMock.Setup(x => x.GetSuggestedActionFor(It.IsAny <Gear>(), rpm)).Returns(SuggestedAction.Downshift);
            _gearshifter.SetProgram(secondProgramMock.Object);
            _gearshifter.HandleRpmChange(new Rpm(2000));

            _gearboxMock.Verify(x => x.Upshift());
            _gearboxMock.Verify(x => x.Downshift());
        }
        public void NegotiatedFollowRpmProgramReflectsTheDemand()
        {
            var negotiator = new Negotiator();

            negotiator.Issue(_dummyFollowRpmDemand);

            var program = negotiator.Negotiate();

            var rpmInTheMiddleOfDemandedRange = new Rpm((_dummyFollowRpmDemand.ShiftpointRange.LowerShiftPoint.Value +
                                                         _dummyFollowRpmDemand.ShiftpointRange.UpperShiftPoint.Value) /
                                                        2);

            var rpmBelowDemandedRange = new Rpm(_dummyFollowRpmDemand.ShiftpointRange.LowerShiftPoint.Value - 1);

            var rpmAboveDemandedRange = new Rpm(_dummyFollowRpmDemand.ShiftpointRange.UpperShiftPoint.Value + 1);

            var anyGear = new Gear(2);

            Assert.AreEqual(SuggestedAction.Retain, program.GetSuggestedActionFor(anyGear, rpmInTheMiddleOfDemandedRange));
            Assert.AreEqual(SuggestedAction.Downshift, program.GetSuggestedActionFor(anyGear, rpmBelowDemandedRange));
            Assert.AreEqual(SuggestedAction.Upshift, program.GetSuggestedActionFor(anyGear, rpmAboveDemandedRange));
        }
        /// <summary>
        ///     Output of Maximum Torque Lookup Table in MATLAB Model
        /// </summary>
        public void CalculateTorque()
        {
            // Save the Throttle Input locally because we can't change the pedal press
            var throttlePercentage = ThrottleInput;

            // Get list of possible RPM and Throttle Percentage values
            var possibleRpm      = new List <double>();
            var possibleThrottle = new List <double>();

            foreach (var key in Setup.EngineTorque.Keys)
            {
                possibleRpm.Add(key.Rpm);
                possibleThrottle.Add(key.ThrottlePercentage);
            }

            // Remove duplicates from lists
            possibleRpm      = possibleRpm.Distinct().ToList();
            possibleThrottle = possibleThrottle.Distinct().ToList();

            // Ensure that RPM and Throttle Percentage are within limits
            Rpm = Helpers.SaturationDynamic(possibleRpm.First(), possibleRpm.Last(), Rpm);
            throttlePercentage = Helpers.SaturationDynamic(possibleThrottle.First(), possibleThrottle.Last(), throttlePercentage);

            // If Max RPM and Max Throttle
            if (Rpm.Equals(possibleRpm.Last()) && throttlePercentage.Equals(possibleThrottle.Last()))
            {
                Torque = Setup.EngineTorque[new Setup.EngineTorqueKey(Rpm, throttlePercentage)];

                return;
            }

            // If Max RPM
            if (Rpm.Equals(possibleRpm.Last()))
            {
                CalculateTorqueForConstantRpmOrThrottle(possibleThrottle, Rpm, throttlePercentage, isRpm: true);

                return;
            }

            // If Max Throttle
            if (throttlePercentage.Equals(possibleThrottle.Last()))
            {
                CalculateTorqueForConstantRpmOrThrottle(possibleRpm, throttlePercentage, Rpm, isRpm: false);

                return;
            }

            // Calculate RPM and Throttle Breakpoints
            var upperRpmBreakpoint = possibleRpm.Find(x => Rpm < x);
            var lowerRpmBreakpoint = possibleRpm[possibleRpm.IndexOf(upperRpmBreakpoint) - 1];

            var upperThrottleBreakpoint = possibleThrottle.Find(x => throttlePercentage < x);
            var lowerThrottleBreakpoint = possibleThrottle[possibleThrottle.IndexOf(upperThrottleBreakpoint) - 1];

            // Get torque values for RPM-Throttle bounds
            var torqueForLowerRpmLowerThrottle = Setup.EngineTorque[new Setup.EngineTorqueKey(lowerRpmBreakpoint, lowerThrottleBreakpoint)];
            var torqueForLowerRpmUpperThrottle = Setup.EngineTorque[new Setup.EngineTorqueKey(lowerRpmBreakpoint, upperThrottleBreakpoint)];
            var torqueForUpperRpmLowerThrottle = Setup.EngineTorque[new Setup.EngineTorqueKey(upperRpmBreakpoint, lowerThrottleBreakpoint)];
            var torqueForUpperRpmUpperThrottle = Setup.EngineTorque[new Setup.EngineTorqueKey(upperRpmBreakpoint, upperThrottleBreakpoint)];

            // Interpolation
            var torqueRpmInterpolation = torqueForLowerRpmLowerThrottle +
                                         (torqueForUpperRpmLowerThrottle - torqueForLowerRpmLowerThrottle) /
                                         (upperRpmBreakpoint - lowerRpmBreakpoint) * (Rpm - lowerRpmBreakpoint);

            var torqueThrottleInterpolation = torqueForLowerRpmUpperThrottle +
                                              (torqueForUpperRpmUpperThrottle - torqueForLowerRpmUpperThrottle) /
                                              (upperRpmBreakpoint - lowerRpmBreakpoint) * (Rpm - lowerRpmBreakpoint);

            Torque = torqueRpmInterpolation +
                     (torqueThrottleInterpolation - torqueRpmInterpolation) / (upperThrottleBreakpoint - lowerThrottleBreakpoint) *
                     (throttlePercentage - lowerThrottleBreakpoint);
        }
Exemple #23
0
 public RpmReporter(IEventBus eventBus, IRpmSensor rpmSensor)
 {
     _eventBus       = eventBus;
     _rpmSensor      = rpmSensor;
     LastReportedRpm = new Rpm(0);
 }
Exemple #24
0
 public GearShiftBoundaries(Rpm downshiftBoundary, Rpm upshiftBoundary)
 {
     DownshiftBoundary = downshiftBoundary ?? throw new ArgumentNullException(nameof(downshiftBoundary));
     UpshiftBoundary   = upshiftBoundary ?? throw new ArgumentNullException(nameof(upshiftBoundary));
 }
        public SuggestedKickdownAction GetActionFor(ResponsivenessMode responsivenessMode, PedalPressure pedalPressure, Rpm currentRpm)
        {
            switch (responsivenessMode)
            {
            case ResponsivenessMode.Comfort:
                if (pedalPressure.Value > SingularKickdownThresholdInComfortMode && currentRpm.Value >= SingularKickdownRpmInComfortMode)
                {
                    return(SuggestedKickdownAction.Singular);
                }
                break;

            case ResponsivenessMode.Sport:
                if (pedalPressure.Value >= DoubleKickdownThresholdInSportsMode && currentRpm.Value >= DoubleKickdownRpmInSportMode)
                {
                    return(SuggestedKickdownAction.Double);
                }
                else if (pedalPressure.Value >= SingularKickdownThresholdInSportsMode && currentRpm.Value >= SingularKickdownRpmInSportMode)
                {
                    return(SuggestedKickdownAction.Singular);
                }
                break;
            }

            return(SuggestedKickdownAction.None);
        }
 public SuggestedAction GetSuggestedActionFor(Gear currentGear, Rpm rpm)
 {
     return(SuggestedAction.Retain);
 }