Ejemplo n.º 1
0
        public void AllUnitsImplementToStringForNorwegian()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

                Assert.AreEqual("1 °", Angle.FromDegrees(1).ToString());
                Assert.AreEqual("1 m²", Area.FromSquareMeters(1).ToString());
                Assert.AreEqual("1 V", ElectricPotential.FromVolts(1).ToString());
                Assert.AreEqual("1 m³/s", Flow.FromCubicMetersPerSecond(1).ToString());
                Assert.AreEqual("1 N", Force.FromNewtons(1).ToString());
                Assert.AreEqual("1 m", Length.FromMeters(1).ToString());
                Assert.AreEqual("1 kg", Mass.FromKilograms(1).ToString());
                Assert.AreEqual("1 Pa", Pressure.FromPascals(1).ToString());
                Assert.AreEqual("1 r/s", RotationalSpeed.FromRevolutionsPerSecond(1).ToString());
                Assert.AreEqual("1 K", Temperature.FromKelvins(1).ToString());
                Assert.AreEqual("1 N·m", Torque.FromNewtonMeters(1).ToString());
                Assert.AreEqual("1 m³", Volume.FromCubicMeters(1).ToString());
            }
            finally
            {
                Thread.CurrentThread.CurrentUICulture = originalCulture;
            }
        }
        public void CompareToThrowsOnTypeMismatch()
        {
            RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1);

// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            revolutionpersecond.CompareTo(new object());
        }
        public void EqualsIsImplemented()
        {
            RotationalSpeed v = RotationalSpeed.FromRevolutionsPerSecond(1);

            Assert.IsTrue(v.Equals(RotationalSpeed.FromRevolutionsPerSecond(1)));
            Assert.IsFalse(v.Equals(RotationalSpeed.Zero));
        }
        public void CompareToThrowsOnNull()
        {
            RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1);

// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            revolutionpersecond.CompareTo(null);
        }
        public void RevolutionPerSecondToRotationalSpeedUnits()
        {
            RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1);

            Assert.AreEqual(RevolutionsPerMinuteInOneRevolutionPerSecond, revolutionpersecond.RevolutionsPerMinute, RevolutionsPerMinuteTolerance);
            Assert.AreEqual(RevolutionsPerSecondInOneRevolutionPerSecond, revolutionpersecond.RevolutionsPerSecond, RevolutionsPerSecondTolerance);
        }
        public void As()
        {
            var revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1);

            Assert.AreEqual(RevolutionsPerMinuteInOneRevolutionPerSecond, revolutionpersecond.As(RotationalSpeedUnit.RevolutionPerMinute), RevolutionsPerMinuteTolerance);
            Assert.AreEqual(RevolutionsPerSecondInOneRevolutionPerSecond, revolutionpersecond.As(RotationalSpeedUnit.RevolutionPerSecond), RevolutionsPerSecondTolerance);
        }
        public void ConversionRoundTrip()
        {
            RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1);

            Assert.AreEqual(1, RotationalSpeed.FromRevolutionsPerMinute(revolutionpersecond.RevolutionsPerMinute).RevolutionsPerSecond, RevolutionsPerMinuteTolerance);
            Assert.AreEqual(1, RotationalSpeed.FromRevolutionsPerSecond(revolutionpersecond.RevolutionsPerSecond).RevolutionsPerSecond, RevolutionsPerSecondTolerance);
        }
Ejemplo n.º 8
0
        public void AllUnitsImplementToStringForRussian()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru-RU");

                Assert.AreEqual("1 °", Angle.FromDegrees(1).ToString());
                Assert.AreEqual("1 м²", Area.FromSquareMeters(1).ToString());
                Assert.AreEqual("1 В", ElectricPotential.FromVolts(1).ToString());
                Assert.AreEqual("1 м³/с", Flow.FromCubicMetersPerSecond(1).ToString());
                Assert.AreEqual("1 Н", Force.FromNewtons(1).ToString());
                Assert.AreEqual("1 м", Length.FromMeters(1).ToString());
                Assert.AreEqual("1 кг", Mass.FromKilograms(1).ToString());
                Assert.AreEqual("1 Па", Pressure.FromPascals(1).ToString());
                Assert.AreEqual("1 об/с", RotationalSpeed.FromRevolutionsPerSecond(1).ToString());
                Assert.AreEqual("1 K", Temperature.FromKelvins(1).ToString());
                Assert.AreEqual("1 Н·м", Torque.FromNewtonMeters(1).ToString());
                Assert.AreEqual("1 м³", Volume.FromCubicMeters(1).ToString());
            }
            finally
            {
                Thread.CurrentThread.CurrentUICulture = originalCulture;
            }
        }
        public void CompareToIsImplemented()
        {
            RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1);

            Assert.AreEqual(0, revolutionpersecond.CompareTo(revolutionpersecond));
            Assert.Greater(revolutionpersecond.CompareTo(RotationalSpeed.Zero), 0);
            Assert.Less(RotationalSpeed.Zero.CompareTo(revolutionpersecond), 0);
        }
        public void ArithmeticOperators()
        {
            RotationalSpeed v = RotationalSpeed.FromRevolutionsPerSecond(1);

            Assert.AreEqual(-1, -v.RevolutionsPerSecond, RevolutionsPerSecondTolerance);
            Assert.AreEqual(2, (RotationalSpeed.FromRevolutionsPerSecond(3) - v).RevolutionsPerSecond, RevolutionsPerSecondTolerance);
            Assert.AreEqual(2, (v + v).RevolutionsPerSecond, RevolutionsPerSecondTolerance);
            Assert.AreEqual(10, (v * 10).RevolutionsPerSecond, RevolutionsPerSecondTolerance);
            Assert.AreEqual(10, (10 * v).RevolutionsPerSecond, RevolutionsPerSecondTolerance);
            Assert.AreEqual(2, (RotationalSpeed.FromRevolutionsPerSecond(10) / 5).RevolutionsPerSecond, RevolutionsPerSecondTolerance);
            Assert.AreEqual(2, RotationalSpeed.FromRevolutionsPerSecond(10) / RotationalSpeed.FromRevolutionsPerSecond(5), RevolutionsPerSecondTolerance);
        }
Ejemplo n.º 11
0
        public void ConversionRoundTrip()
        {
            RotationalSpeed radianpersecond = RotationalSpeed.FromRadiansPerSecond(1);

            Assert.AreEqual(1, RotationalSpeed.FromCentiradiansPerSecond(radianpersecond.CentiradiansPerSecond).RadiansPerSecond, CentiradiansPerSecondTolerance);
            Assert.AreEqual(1, RotationalSpeed.FromDeciradiansPerSecond(radianpersecond.DeciradiansPerSecond).RadiansPerSecond, DeciradiansPerSecondTolerance);
            Assert.AreEqual(1, RotationalSpeed.FromMicroradiansPerSecond(radianpersecond.MicroradiansPerSecond).RadiansPerSecond, MicroradiansPerSecondTolerance);
            Assert.AreEqual(1, RotationalSpeed.FromMilliradiansPerSecond(radianpersecond.MilliradiansPerSecond).RadiansPerSecond, MilliradiansPerSecondTolerance);
            Assert.AreEqual(1, RotationalSpeed.FromNanoradiansPerSecond(radianpersecond.NanoradiansPerSecond).RadiansPerSecond, NanoradiansPerSecondTolerance);
            Assert.AreEqual(1, RotationalSpeed.FromRadiansPerSecond(radianpersecond.RadiansPerSecond).RadiansPerSecond, RadiansPerSecondTolerance);
            Assert.AreEqual(1, RotationalSpeed.FromRevolutionsPerMinute(radianpersecond.RevolutionsPerMinute).RadiansPerSecond, RevolutionsPerMinuteTolerance);
            Assert.AreEqual(1, RotationalSpeed.FromRevolutionsPerSecond(radianpersecond.RevolutionsPerSecond).RadiansPerSecond, RevolutionsPerSecondTolerance);
        }
        public void EqualityOperators()
        {
            RotationalSpeed a = RotationalSpeed.FromRevolutionsPerSecond(1);
            RotationalSpeed b = RotationalSpeed.FromRevolutionsPerSecond(2);

// ReSharper disable EqualExpressionComparison
            Assert.True(a == a);
            Assert.True(a != b);

            Assert.False(a == b);
            Assert.False(a != a);
// ReSharper restore EqualExpressionComparison
        }
        public void ComparisonOperators()
        {
            RotationalSpeed oneRevolutionPerSecond  = RotationalSpeed.FromRevolutionsPerSecond(1);
            RotationalSpeed twoRevolutionsPerSecond = RotationalSpeed.FromRevolutionsPerSecond(2);

            Assert.True(oneRevolutionPerSecond < twoRevolutionsPerSecond);
            Assert.True(oneRevolutionPerSecond <= twoRevolutionsPerSecond);
            Assert.True(twoRevolutionsPerSecond > oneRevolutionPerSecond);
            Assert.True(twoRevolutionsPerSecond >= oneRevolutionPerSecond);

            Assert.False(oneRevolutionPerSecond > twoRevolutionsPerSecond);
            Assert.False(oneRevolutionPerSecond >= twoRevolutionsPerSecond);
            Assert.False(twoRevolutionsPerSecond < oneRevolutionPerSecond);
            Assert.False(twoRevolutionsPerSecond <= oneRevolutionPerSecond);
        }
Ejemplo n.º 14
0
        public void AllUnitsImplementToStringForInvariantCulture()
        {
            Assert.AreEqual("1 °", Angle.FromDegrees(1).ToString());
            Assert.AreEqual("1 m²", Area.FromSquareMeters(1).ToString());
            Assert.AreEqual("1 V", ElectricPotential.FromVolts(1).ToString());
            Assert.AreEqual("1 m³/s", Flow.FromCubicMetersPerSecond(1).ToString());
            Assert.AreEqual("1 N", Force.FromNewtons(1).ToString());
            Assert.AreEqual("1 m", Length.FromMeters(1).ToString());
            Assert.AreEqual("1 kg", Mass.FromKilograms(1).ToString());
            Assert.AreEqual("1 Pa", Pressure.FromPascals(1).ToString());
            Assert.AreEqual("1 r/s", RotationalSpeed.FromRevolutionsPerSecond(1).ToString());
            Assert.AreEqual("1 K", Temperature.FromKelvins(1).ToString());
            Assert.AreEqual("1 N·m", Torque.FromNewtonMeters(1).ToString());
            Assert.AreEqual("1 m³", Volume.FromCubicMeters(1).ToString());

            Assert.AreEqual("2 ft 3 in", Length.FromFeetInches(2, 3).FeetInches.ToString());
            Assert.AreEqual("3 st 7 lb", Mass.FromStonePounds(3, 7).StonePounds.ToString());
        }
Ejemplo n.º 15
0
 /// <inheritdoc cref="RotationalSpeed.FromRevolutionsPerSecond(double)"/>
 public static RotationalSpeed RevolutionsPerSecond(this double value) => RotationalSpeed.FromRevolutionsPerSecond(value);
Ejemplo n.º 16
0
 /// <inheritdoc cref="RotationalSpeed.FromRevolutionsPerSecond(double?)"/>
 public static RotationalSpeed?RevolutionsPerSecond(this float?value) => RotationalSpeed.FromRevolutionsPerSecond(value);
Ejemplo n.º 17
0
 /// <inheritdoc cref="RotationalSpeed.FromRevolutionsPerSecond(double?)"/>
 public static RotationalSpeed?RevolutionsPerSecond(this decimal?value) => RotationalSpeed.FromRevolutionsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value));
        public void EqualsReturnsFalseOnNull()
        {
            RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1);

            Assert.IsFalse(revolutionpersecond.Equals(null));
        }
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            RotationalSpeed revolutionpersecond = RotationalSpeed.FromRevolutionsPerSecond(1);

            Assert.IsFalse(revolutionpersecond.Equals(new object()));
        }
 public void NumberToRevolutionsPerSecondTest() =>
 Assert.Equal(RotationalSpeed.FromRevolutionsPerSecond(2), 2.RevolutionsPerSecond());
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            // nema17 - 24v datasheet
            var MOTOR_TYPE    = "nema17";
            var MOTOR_VOLTAGE = ElectricPotentialDc.FromVoltsDc(24);
            var SPEED_MAX     = RotationalSpeed.FromRevolutionsPerMinute(200);
            var TORQUE_MAX    = Torque.FromNewtonMeters(0.4);
            // problem data
            var MASS           = Mass.FromKilograms(2);
            var LEVER_ARM_LEN  = Length.FromCentimeters(1);
            var ROUND_CNT      = Angle.FromRevolutions(1d);
            var EXECUTION_TIME = Duration.FromSeconds(2);
            // config
            var TIME_STEP = Duration.FromMilliseconds(1);

            // speed required to achieve given ROUND_CNT in EXECUTION_TIME without cruise
            var minTargetSpeed = 2 * ROUND_CNT / EXECUTION_TIME;

            if (minTargetSpeed > SPEED_MAX)
            {
                System.Console.WriteLine($"W: given position {ROUND_CNT} round cannot established due to speed_max:{SPEED_MAX.RevolutionsPerSecond} rps vs actual required target speed:{minTargetSpeed.RevolutionsPerSecond} rps");
                return;
            }

            // s:target speed
            var s = minTargetSpeed;

            // d:duration
            var d = EXECUTION_TIME;

            var minHoldingTorque = Torque.FromKilogramForceCentimeters(MASS.Kilograms * LEVER_ARM_LEN.Centimeters);

            if (minHoldingTorque > TORQUE_MAX)
            {
                System.Console.WriteLine($"W: given mass {MASS} at lever arm distance {LEVER_ARM_LEN} generate {minHoldingTorque.KilogramForceCentimeters} kgfcm torque versus max {TORQUE_MAX.KilogramForceCentimeters} kgfcm");
                return;
            }

            var minDynAccel = RotationalAcceleration.FromRevolutionsPerSecondSquared(4 * s.RevolutionsPerSecond / d.Seconds);
            var I           = MassMomentOfInertia.FromKilogramSquareCentimeters(MASS.Kilograms * Pow(LEVER_ARM_LEN.Centimeters, 2));
            // torque            = inertia * angularaccel
            // F:[M*L*T-2]*r:[L] = I:[M*L2]*a:[T-2]
            // [M*L2*T-2]        = [M*L2*T-2]
            var minDynTorque = Torque.FromKilogramForceMeters(I.KilogramSquareMeters * minDynAccel.RadiansPerSecondSquared);

            if (minDynTorque > TORQUE_MAX)
            {
                System.Console.WriteLine($"W: accelerating given mass {MASS} at angaccel {minDynAccel} generates torque {minDynTorque.NewtonCentimeters} Ncm great than max {TORQUE_MAX.NewtonCentimeters} Ncm");
                return;
            }

            var srcPathfilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "template.xlsx");
            var dstPathfilename = "output.xlsx";

            File.Copy(srcPathfilename, dstPathfilename, true);
            using (var wb = new ClosedXML.Excel.XLWorkbook(dstPathfilename))
            {
                var ws = wb.Worksheets.First();

                IXLCell cell = null;

                Action <int, int, object> setCell = (r, c, val) =>
                {
                    cell       = ws.Cell(r, c);
                    cell.Value = val;
                };

                Action <int, int, object> setCellBold = (r, c, val) =>
                {
                    cell       = ws.Cell(r, c);
                    cell.Value = val;
                    cell.Style.Font.SetBold();
                };

                var row       = 1;
                int col       = 1;
                var colTime   = col++;
                var colAccel  = col++;
                var colSpeed  = col++;
                var colPosRot = col++;

                setCellBold(row, colTime, "TIME (s)");
                setCellBold(row, colAccel, "ACCEL (rps2)");
                setCellBold(row, colSpeed, "SPEED (rps)");
                setCellBold(row, colPosRot, "POS (rot)");
                ++row;

                var t    = Duration.FromSeconds(0);
                var tMax = t + EXECUTION_TIME;

                var halfTMax = tMax / 2;

                ws.Cell("MotorType").Value                 = MOTOR_TYPE;
                ws.Cell("MotorSpeedMax").Value             = SPEED_MAX;
                ws.Cell("MotorTorqueMaxAtSpeedMax").Value  = TORQUE_MAX;
                ws.Cell("MotorVoltage").Value              = MOTOR_VOLTAGE;
                ws.Cell("ProblemDuration").Value           = EXECUTION_TIME;
                ws.Cell("ProblemLoadLeverArmLength").Value = LEVER_ARM_LEN;
                ws.Cell("ProblemLoadMass").Value           = MASS;
                ws.Cell("ProblemRevolutions").Value        = ROUND_CNT;
                ws.Cell("ResultingTorque").Value           = minDynTorque.ToUnit(TorqueUnit.NewtonMeter);
                ws.Cell("ResultingAccel").Value            = minDynAccel;
                ws.Cell("ResultingSpeedMax").Value         = minTargetSpeed.ToUnit(RotationalSpeedUnit.RevolutionPerMinute);

                var tEps = Duration.FromNanoseconds(1);
                while (t.LessThanOrEqualsTol(tEps, tMax))
                {
                    setCell(row, colTime, t.Seconds);

                    var accel = RotationalAcceleration.FromRevolutionsPerSecondSquared(0);
                    var speed = RotationalSpeed.FromRevolutionsPerSecond(0);
                    var pos   = Angle.FromRevolutions(0);

                    if (t.LessThanOrEqualsTol(tEps, halfTMax))
                    {
                        accel = RotationalAcceleration.FromRevolutionsPerSecondSquared(
                            2 * s.RevolutionsPerSecond / d.Seconds * (1 - Cos(4 * PI * t / d)));

                        speed = RotationalSpeed.FromRevolutionsPerSecond(
                            2 * s.RevolutionsPerSecond / d.Seconds * (t - d * Sin(4 * PI * t / d) / (4 * PI)).Seconds);

                        pos = s * d * (Cos(4 * PI * t / d) - 1) / (8 * Pow(PI, 2)) + (s * t) * (t / d);
                    }

                    if (t.GreatThanOrEqualsTol(tEps, halfTMax))
                    {
                        var th = t - d / 2;

                        accel = RotationalAcceleration.FromRevolutionsPerSecondSquared(
                            2 * s.RevolutionsPerSecond / d.Seconds * (Cos(4 * PI * th / d) - 1));

                        speed = RotationalSpeed.FromRevolutionsPerSecond(
                            2 * s.RevolutionsPerSecond * Sin(4 * PI * th / d) / (4 * PI)
                            - (2 * s * th / d - s).RevolutionsPerSecond);

                        pos = s * d * (1 - Cos(4 * PI * th / d)) / (8 * Pow(PI, 2)) - (s * th) * (th / d) + s * th + s * d / 4;
                    }

                    setCell(row, colAccel, accel.RevolutionsPerSecondSquared);
                    setCell(row, colSpeed, speed.RevolutionsPerSecond);
                    setCell(row, colPosRot, pos.Revolutions);

                    ++row;
                    t += TIME_STEP;
                }

                wb.Save();
            }
        }
Ejemplo n.º 22
0
 public static RotationalSpeed ToRotationalSpeedFromCircumference(this Speed linearSpeed,
                                                                  Length circumference)
 {
     return(RotationalSpeed.FromRevolutionsPerSecond(linearSpeed.MetersPerSecond / circumference.Meters));
 }
Ejemplo n.º 23
0
 public static RotationalSpeed?RevolutionsPerSecond <T>(this T?value) where T : struct => RotationalSpeed.FromRevolutionsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value));
 /// <inheritdoc cref="RotationalSpeed.FromRevolutionsPerSecond(UnitsNet.QuantityValue)" />
 public static RotationalSpeed RevolutionsPerSecond <T>(this T value) =>
 RotationalSpeed.FromRevolutionsPerSecond(Convert.ToDouble(value));