Example #1
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D08), NamedServoConfigs.SG90);
            servo.RotateTo(0);

            rotaryEncoder          = new RotaryEncoder(Device, Device.Pins.D02, Device.Pins.D03);
            rotaryEncoder.Rotated += (s, e) =>
            {
                if (e.Direction == Meadow.Peripherals.Sensors.Rotary.RotationDirection.Clockwise)
                {
                    angle++;
                }
                else
                {
                    angle--;
                }

                if (angle > 180)
                {
                    angle = 180;
                }
                else if (angle < 0)
                {
                    angle = 0;
                }

                servo.RotateTo(angle);
            };

            led.SetColor(RgbLed.Colors.Green);
        }
Example #2
0
        void TestServo()
        {
            Console.WriteLine("TestServo...");

            while (true)
            {
                for (int i = 0; i <= servo.Config.MaximumAngle; i++)
                {
                    servo.RotateTo(i);
                    Console.WriteLine($"Rotating to {i}");
                    Thread.Sleep(40);
                }
                Thread.Sleep(2000);
                for (int i = 180; i >= servo.Config.MinimumAngle; i--)
                {
                    servo.RotateTo(i);
                    Console.WriteLine($"Rotating to {i}");
                    Thread.Sleep(40);
                }
                Thread.Sleep(2000);

                //if (servo.Angle <= servo.Config.MinimumAngle)
                //{
                //    Console.WriteLine($"Rotating to {servo.Config.MaximumAngle}");
                //    servo.RotateTo(servo.Config.MaximumAngle);
                //}
                //else
                //{
                //    Console.WriteLine($"Rotating to {servo.Config.MinimumAngle}");
                //    servo.RotateTo(servo.Config.MinimumAngle);
                //}
                //Thread.Sleep(4000);
            }
        }
Example #3
0
 /// <summary>
 /// Turns camera to selected angle
 /// </summary>
 /// <param name="verAngle">Pitch</param>
 /// <param name="horAngle">Yaw</param>
 public void SetAngle(Angle verAngle, Angle horAngle)
 {
     lock (locker)
     {
         verticalAngle   = verAngle;
         horizontalAngle = horAngle;
     }
     vertical.RotateTo(verticalAngle + angleDelta);
     horizontal.RotateTo(angleDelta - horizontalAngle);
 }
Example #4
0
        /// <summary>
        /// Allows fine tuning of servo or sets it to requested angle
        /// </summary>
        /// <param name="angle">Requested angle</param>
        public async void SetAngle(int angle)
        {
            servo.RotateTo(new Angle(angle + 90));
            await Task.Delay(500);

            servo.Stop();
        }
Example #5
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D03), NamedServoConfigs.SG90);
            servo.RotateTo(0);
            Thread.Sleep(1000);
            servo.RotateTo(180);

            button          = new PushButton(Device, Device.Pins.D04);
            button.Clicked += ButtonClicked;

            led.SetColor(RgbLed.Colors.Green);
        }
Example #6
0
 void TestServo()
 {
     while (true)
     {
         if (servo.Angle <= servo.Config.MinimumAngle)
         {
             Console.WriteLine($"Rotating to {servo.Config.MaximumAngle}");
             servo.RotateTo(servo.Config.MaximumAngle);
         }
         else
         {
             Console.WriteLine($"Rotating to {servo.Config.MinimumAngle}");
             servo.RotateTo(servo.Config.MinimumAngle);
         }
         Thread.Sleep(4000);
     }
 }
Example #7
0
        public MeadowApp()
        {
            Console.WriteLine("Initializing...");

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D04), NamedServoConfigs.SG90);
            servo.RotateTo(0);

            TestServo();
        }
        public void Kick()
        {
            Thread _animationThread = new Thread(() =>
            {
                _kickRight = !_kickRight;

                if (_kickRight)
                {
                    _servo.RotateTo(180);
                }
                else
                {
                    _servo.RotateTo(0);
                }
            });

            _animationThread.Start();
        }
        void Initialize()
        {
            var onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);

            onboardLed.SetColor(Color.Red);

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D03), NamedServoConfigs.SG90);
            servo.RotateTo(NamedServoConfigs.SG90.MaximumAngle);
            Thread.Sleep(1000);
            servo.RotateTo(NamedServoConfigs.SG90.MinimumAngle);

            button          = new PushButton(Device, Device.Pins.D04);
            button.Clicked += ButtonClicked;

            onboardLed.SetColor(Color.Green);
        }
        public void Initialize(IMeadowDevice device, IPin PwmPin)
        {
            if (initialized)
            {
                return;
            }

            servo = new Servo(device, PwmPin, NamedServoConfigs.SG90);
            servo.RotateTo(NamedServoConfigs.SG90.MinimumAngle);

            initialized = true;
        }
Example #11
0
        public MeadowApp()
        {
            var onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);

            onboardLed.SetColor(Color.Red);

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D08), NamedServoConfigs.SG90);
            servo.RotateTo(new Angle(0, AU.Degrees));

            rotaryEncoder          = new RotaryEncoder(Device, Device.Pins.D02, Device.Pins.D03);
            rotaryEncoder.Rotated += (s, e) =>
            {
                if (e.New == Meadow.Peripherals.Sensors.Rotary.RotationDirection.Clockwise)
                {
                    angle += new Angle(1, AU.Degrees);
                }
                else
                {
                    angle -= new Angle(1, AU.Degrees);
                }

                if (angle > new Angle(180, AU.Degrees))
                {
                    angle = new Angle(180, AU.Degrees);
                }
                else if (angle < new Angle(0, AU.Degrees))
                {
                    angle = new Angle(0, AU.Degrees);
                }

                servo.RotateTo(angle);
            };

            onboardLed.SetColor(Color.Green);
        }
        private async void RotateFlag()
        {
            if (IsFlagMoving)
            {
                return;
            }

            IsFlagMoving = true;

            try
            {
                await _servo.RotateTo(_upPosition);

                await Task.Delay(2000);

                await _servo.RotateTo(_downPosition, true);
            }
            finally
            {
                IsFlagMoving = false;
            }
        }
        private async void Initialize()
        {
            // create the push button
            _button = new PushButton(Device, _buttonPin, Meadow.Hardware.ResistorMode.InternalPullUp);

            _button.Clicked += OnButtonClicked;

            // create the servo object
            _servo = new Servo(Device.CreatePwmPort(_servoPin), NamedServoConfigs.SG90);

            // initialize to a known state
            await _servo.RotateTo(_downPosition, true);
        }
Example #14
0
        void Draw()
        {
            int angle = 160;
            int increment = 4;
            int x, y = 0;

            while (true)
            {
                graphics.Clear();

                DrawRadar();

                graphics.DrawLine(120, 170, 105, (float)(angle * Math.PI / 180), Color.Yellow);

                if (angle >= 180)
                {
                    increment = -4;
                }
                if (angle <= 0)
                {
                    increment = 4;
                }

                angle += increment;
                servo.RotateTo(new Angle(angle, AU.Degrees));

                graphics.DrawText(0, 0, $"{180 - angle}°", Color.Yellow);

                if (sensor.Distance != null && sensor.Distance >= new Length(0, LU.Millimeters))
                {
                    graphics.DrawText(170, 0, $"{sensor.Distance?.Millimeters}mm", Color.Yellow);
                    radarData[angle] = (float)(sensor.Distance?.Millimeters / 2);
                }
                else
                {
                    radarData[angle] = 0;
                }

                for (int i = 0; i < 180; i++)
                {
                    x = 120 + (int)(radarData[i] * MathF.Cos(i * MathF.PI / 180f));
                    y = 170 - (int)(radarData[i] * MathF.Sin(i * MathF.PI / 180f));
                    graphics.DrawCircle(x, y, 2, Color.Yellow, true);
                }

                graphics.Show();
                Thread.Sleep(100);
            }
        }
Example #15
0
        void Draw()
        {
            int angle = 160;
            int increment = 4;
            int x, y = 0;

            while (true)
            {
                graphics.Clear();

                DrawRadar();

                graphics.DrawLine(120, 170, 105, (float)(angle * Math.PI / 180), Color.Yellow);

                if (angle >= 180)
                {
                    increment = -4;
                }
                if (angle <= 0)
                {
                    increment = 4;
                }

                angle += increment;
                servo.RotateTo(angle);

                graphics.DrawText(0, 0, $"{180 - angle}°", Color.Yellow);

                if (sensor?.Conditions?.Distance != null && sensor?.Conditions?.Distance.Value >= 0)
                {
                    graphics.DrawText(170, 0, $"{sensor.Conditions.Distance.Value}mm", Color.Yellow);
                    radarData[angle] = sensor.Conditions.Distance.Value / 2;
                }
                else
                {
                    radarData[angle] = 0;
                }

                for (int i = 0; i < 180; i++)
                {
                    x = 120 + (int)(radarData[i] * MathF.Cos(i * MathF.PI / 180f));
                    y = 170 - (int)(radarData[i] * MathF.Sin(i * MathF.PI / 180f));
                    graphics.DrawCircle(x, y, 2, Color.Yellow, true);
                }

                graphics.Show();
                Thread.Sleep(100);
            }
        }
Example #16
0
        void Initialize()
        {
            var onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);

            onboardLed.SetColor(Color.Red);

            var config = new SpiClockConfiguration(
                new Frequency(48000, Frequency.UnitType.Kilohertz),
                SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(
                Device.Pins.SCK,
                Device.Pins.MOSI,
                Device.Pins.MISO, config);
            var display = new St7789(
                device: Device,
                spiBus: spiBus,
                chipSelectPin: Device.Pins.D02,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240);

            graphics             = new MicroGraphics(display);
            graphics.CurrentFont = new Font12x20();
            graphics.Rotation    = RotationType._270Degrees;

            var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);

            sensor = new Vl53l0x(Device, i2cBus);
            sensor.StartUpdating(TimeSpan.FromMilliseconds(200));

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D05), NamedServoConfigs.SG90);
            servo.RotateTo(new Angle(0, AU.Degrees));

            onboardLed.SetColor(Color.Green);
        }
Example #17
0
        public MeadowApp()
        {
            var servoConfig = new ServoConfig(
                minimumAngle: 0,
                maximumAngle: 180,
                minimumPulseDuration: 700,
                maximumPulseDuration: 3000,
                frequency: 50);

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D03), servoConfig);
            servo.RotateTo(0);

            button = new PushButton(Device, Device.Pins.D04);
            button.DebounceDuration = new TimeSpan(100);
            button.Clicked         += ButtonClicked;

            //this.changeTimer.AutoReset = true;
            this.changeTimer.Elapsed += ChangeTimer_Elapsed;
            this.changeTimer.Start();

            // Keeps the app running
            Thread.Sleep(Timeout.Infinite);
        }
Example #18
0
        void Initialize()
        {
            var led = new RgbLed(
                Device,
                Device.Pins.OnboardLedRed,
                Device.Pins.OnboardLedGreen,
                Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            var config = new SpiClockConfiguration(24000, SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(
                Device.Pins.SCK,
                Device.Pins.MOSI,
                Device.Pins.MISO, config);

            display = new St7789(device: Device, spiBus: spiBus,
                                 chipSelectPin: Device.Pins.D02,
                                 dcPin: Device.Pins.D01,
                                 resetPin: Device.Pins.D00,
                                 width: 240, height: 240);

            graphics             = new GraphicsLibrary(display);
            graphics.CurrentFont = new Font12x20();
            graphics.Rotation    = GraphicsLibrary.RotationType._270Degrees;

            var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);

            sensor = new Vl53l0x(Device, i2cBus);
            sensor.StartUpdating(200);

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D05), NamedServoConfigs.SG90);
            servo.RotateTo(0);

            led.SetColor(RgbLed.Colors.Green);
        }
        public void WaitingNetworkConnection()
        {
            _isRotating = true;

            Thread _animationThread = new Thread(() =>
            {
                int _rotationAngle = 0;

                while (_isRotating)
                {
                    while (_rotationAngle < 180)
                    {
                        if (!_isRotating)
                        {
                            break;
                        }

                        _rotationAngle++;
                        _servo.RotateTo(_rotationAngle);
                        Thread.Sleep(15);
                    }

                    while (_rotationAngle > 0)
                    {
                        if (!_isRotating)
                        {
                            break;
                        }

                        _rotationAngle--;
                        _servo.RotateTo(_rotationAngle);
                        Thread.Sleep(15);
                    }
                }
            });

            _animationThread.Start();
        }
 public void RotateTo(int degrees)
 {
     StopSweep();
     _servo.RotateTo(degrees);
 }
Example #21
0
 public void SetAngle(int angle)
 {
     servo.RotateTo(angle);
 }
Example #22
0
 void ButtonClicked(object sender, EventArgs e)
 {
     servo.RotateTo(75);
     Thread.Sleep(1000);
     servo.RotateTo(0);
 }
 void ButtonClicked(object sender, EventArgs e)
 {
     servo.RotateTo(new Angle(75, AU.Degrees));
     Thread.Sleep(1000);
     servo.RotateTo(new Angle(0, AU.Degrees));
 }
        private static void InitializeGCodeParser()
        {
            settings = new Settings();
            settings.OneStepZ_Angle_Positive = 30;
            settings.OneStepZ_Angle_Negative = 15;

            var servo = new Servo(
                PWMChannels.PWM_PIN_D10,
                new ServoConfig(0, 180, 500, 2500, 50));

            servo.RotateTo(15);
            Thread.Sleep(500);
            servo.RotateTo(35);

            var motorShield = new AdafruitMotorShield();
            IDeviceDelegateOneStep oneStepX = PrepareOneStepDelegate(motorShield, 1, OperationMode.FullStep);
            IDeviceDelegateOneStep oneStepY = PrepareOneStepDelegate(motorShield, 2, OperationMode.FullStep);
            IDeviceDelegateOneStep oneStepZ = (steps) =>
            {
                var a = servo.Angle;

                if (steps >= 0)
                {
                    servo.RotateTo(settings.OneStepZ_Angle_Negative);
                }
                else
                {
                    servo.RotateTo(settings.OneStepZ_Angle_Positive);
                }

                if (a != servo.Angle)
                {
                    Thread.Sleep(500);
                }
            };
            IDeviceDelegateStop startX = () => {  };
            IDeviceDelegateStop startY = () => {  };
            IDeviceDelegateStop startZ = () => {
                servo.RotateTo(settings.OneStepZ_Angle_Negative);
                Thread.Sleep(500);
                servo.RotateTo(settings.OneStepZ_Angle_Positive);
                Thread.Sleep(500);
                servo.RotateTo(settings.OneStepZ_Angle_Negative);
                Thread.Sleep(500);
                servo.RotateTo(settings.OneStepZ_Angle_Positive);
            };

            IDeviceDelegateStop stopX = () => { motorShield.GetStepper(2).ReleaseHoldingTorque(); };
            IDeviceDelegateStop stopY = () => { motorShield.GetStepper(1).ReleaseHoldingTorque(); };
            IDeviceDelegateStop stopZ = () => { servo.RotateTo(settings.OneStepZ_Angle_Negative); };

            var device = new XYZGantryDevice();

            device.SetStepX(oneStepX);
            device.SetStepY(oneStepY);
            device.SetStepZ(oneStepZ);
            device.SetStartX(startX);
            device.SetStartY(startY);
            device.SetStartZ(startZ);
            device.SetStopX(stopX);
            device.SetStopY(stopY);
            device.SetStopZ(stopZ);

            device.Calibrate(25f, 25f, 1);


            var machine = new GCodeMachine(device);

            parser = new GCodeParser(machine);
        }
 public void RotateTo(Angle angle)
 {
     servo.RotateTo(angle);
 }
Example #26
0
 private void ChangeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     ++this.angleIndex;
     this.angleIndex %= this.angles.Length;
     servo.RotateTo(this.angles[this.angleIndex]);
 }
 public PlayerController(Servo servo)
 {
     _servo = servo;
     _servo.RotateTo(0);
 }