예제 #1
0
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard.ServoTest starting");

            try
            {
                AdcController adc        = AdcController.GetDefault();
                AdcChannel    adcChannel = adc.OpenChannel(0);

#if POSITIONAL
                ServoMotor servo = new ServoMotor("TIM5", ServoMotor.ServoType.Positional, PinNumber('A', 0));
                servo.ConfigurePulseParameters(0.1, 2.3);
#endif
#if CONTINUOUS
                ServoMotor servo = new ServoMotor("TIM5", ServoMotor.ServoType.Continuous, PinNumber('A', 0));
                servo.ConfigurePulseParameters(0.1, 2.3);
#endif

                while (true)
                {
                    double value = adcChannel.ReadRatio();

#if POSITIONAL
                    double position = Map(value, 0.0, 1.0, 0.0, 180);
#endif
#if CONTINUOUS
                    double position = Map(value, 0.0, 1.0, -100.0, 100.0);
#endif
                    Debug.WriteLine($"Value: {value:F2} Position: {position:F1}");

                    servo.Set(position);

                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }