Esempio n. 1
0
        static void WriteAngle(PwmChannel pwmChannel, ServoMotor servoMotor)
        {
            servoMotor.Start();

            while (true)
            {
                Console.WriteLine("Enter an angle ('Q' to quit). ");
                string?angle = Console.ReadLine();

                if (angle?.ToUpper() is "Q" || angle?.ToUpper() is null)
                {
                    break;
                }

                if (!int.TryParse(angle, out int angleValue))
                {
                    Console.WriteLine($"Can not parse {angle}.  Try again.");
                }

                servoMotor.WriteAngle(angleValue);
                Console.WriteLine($"Duty Cycle: {pwmChannel.DutyCycle * 100.0}%");
            }

            servoMotor.Stop();
        }
Esempio n. 2
0
        private static void WriteAngle(PwmChannel pwmChannel, ServoMotor servoMotor)
        {
            servoMotor.Start();

            while (true)
            {
                Console.WriteLine("Enter an angle ('Q' to quit). ");
                string angle = Console.ReadLine();

                if (angle.ToUpper() == "Q")
                {
                    break;
                }

                if (!int.TryParse(angle, out int angleValue))
                {
                    Console.WriteLine($"Can not parse {angle}.  Try again.");
                }

                servoMotor.WriteAngle(angleValue);
                Console.WriteLine($"Duty Cycle Percentage: {pwmChannel.DutyCyclePercentage}");
            }

            servoMotor.Stop();
        }
Esempio n. 3
0
        public void Exception_Should_Throw_When_Writing_Invalid_Angle(int maximumAngle, int angle)
        {
            Mock <PwmChannel> mockPwmChannel = new Mock <PwmChannel>();
            ServoMotor        servoMotor     = new ServoMotor(mockPwmChannel.Object, maximumAngle);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                servoMotor.WriteAngle(angle);
            });
        }
Esempio n. 4
0
        public void Verify_Duty_Cycle_When_Writing_Angle(
            int frequency,
            int maxiumAngle,
            int minimumPulseWidthMicroseconds,
            int maximumPulseWidthMicroseconds,
            int angle,
            double expectedDutyCycle)
        {
            Mock <PwmChannel> mockPwmChannel = new Mock <PwmChannel>();

            mockPwmChannel.SetupAllProperties();
            mockPwmChannel.Object.Frequency = frequency;
            ServoMotor servo = new ServoMotor(
                mockPwmChannel.Object,
                maxiumAngle,
                minimumPulseWidthMicroseconds,
                maximumPulseWidthMicroseconds);

            servo.WriteAngle(angle);

            Assert.Equal(expectedDutyCycle, mockPwmChannel.Object.DutyCycle, 5);
        }
Esempio n. 5
0
 /// <summary>
 /// Writes an angle to the servo motor.
 /// </summary>
 /// <param name="angle">The angle to write to the servo motor.</param>
 public void WriteAngle(double angle) => _servoMotor.WriteAngle(angle);
Esempio n. 6
0
 static void MoveToAngle(ServoMotor Servo, int Angle)
 {
     Servo.WriteAngle(Angle);
 }