예제 #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();
        }
예제 #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();
        }
예제 #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);
            });
        }
예제 #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);
        }
예제 #5
0
파일: ServoHat.cs 프로젝트: mciec/ServoHat
 /// <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);
예제 #6
0
 static void MoveToAngle(ServoMotor Servo, int Angle)
 {
     Servo.WriteAngle(Angle);
 }