public void TestMovementTwoPin(Direction direction)
        {
            var pin1 = new Mock <IGpioPin>();
            var pin2 = new Mock <IGpioPin>();

            Assert.Throws <Exception>(() =>
                                      new StepperMotor(0, pin1.Object, pin2.Object));
            var stepper = new StepperMotor(200, pin1.Object, pin2.Object);

            stepper.Move(1, direction);
            if (direction == Direction.Clockwise)
            {
                pin1.VerifySet(x => x.PinValue = false, Times.Exactly(1));
                pin2.VerifySet(x => x.PinValue = true, Times.Exactly(1));
            }
            else
            {
                pin1.VerifySet(x => x.PinValue = false, Times.Exactly(1));
                pin2.VerifySet(x => x.PinValue = false, Times.Exactly(1));
            }
            stepper.Move(1, direction);
            if (direction == Direction.Clockwise)
            {
                pin1.VerifySet(x => x.PinValue = true, Times.Exactly(1));
                pin2.VerifySet(x => x.PinValue = true, Times.Exactly(2));
            }
            else
            {
                pin1.VerifySet(x => x.PinValue = true, Times.Exactly(1));
                pin2.VerifySet(x => x.PinValue = false, Times.Exactly(2));
            }
        }
        private object SetStepperPosition(object [] arguments)
        {
            string id       = (string)arguments[0];
            double position = Convert.ToDouble(arguments[1]);
            bool?  right    = null;

            if (arguments.Length > 2)
            {
                int r = Convert.ToInt32(arguments[2]);
                if (r < 0)
                {
                    right = false;
                }
                else if (r > 0)
                {
                    right = false;
                }
            }
            int?speed = 10;

            if (arguments.Length > 3)
            {
                speed = Convert.ToInt32(arguments[3]);
            }
            StepperMotor motor = GetMotor(id);

            motor.SetPosition(position, null, right, speed);
            return(true);
        }
        public void TestMovementTiming(int revsPerMinute)
        {
            var pin1 = new Mock <IGpioPin>();
            var pin2 = new Mock <IGpioPin>();

            var stepper = new StepperMotor(200, pin1.Object, pin2.Object);

            var timer = new Stopwatch();

            timer.Start();
            stepper.SetSpeed(revsPerMinute);
            var expectedDelay = revsPerMinute == 10 ? 30 : 15;

            stepper.Move(1, Direction.Clockwise);
            var elapsed1 = timer.ElapsedMilliseconds;

            Assert.InRange(elapsed1, 0, expectedDelay);

            stepper.Move(1, Direction.Clockwise);
            var elapsed2 = timer.ElapsedMilliseconds;

            Assert.InRange(elapsed2, elapsed1 + expectedDelay - 1, elapsed1 + 35);

            stepper.Move(10, Direction.Clockwise);
            var elapsed3 = timer.ElapsedMilliseconds;

            Assert.InRange(elapsed3, elapsed2 + expectedDelay * 10 - 1, elapsed2 + expectedDelay * 10 + 5);

            stepper.Move(5, Direction.Anticlockwise);
            var elapsed4 = timer.ElapsedMilliseconds;

            Assert.InRange(elapsed4, elapsed3 + 5 * expectedDelay - 1, elapsed3 + 5 * expectedDelay + 5);
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref="DualAxisSequencer" /> class.
 /// </summary>
 /// <param name="firstAxis">The first axis.</param>
 /// <param name="secondAxis">The second axis.</param>
 public DualAxisSequencer(StepperMotor firstAxis, StepperMotor secondAxis)
 {
     this.firstAxis           = firstAxis;
     this.secondAxis          = secondAxis;
     firstAxis.MotorStopped  += FirstAxisMotorStopped;
     secondAxis.MotorStopped += SecondAxisMotorStopped;
 }
        private object ZeroStepper(object [] arguments)
        {
            string       id    = (string)arguments[0];
            StepperMotor motor = GetMotor(id);

            motor.Zero();
            return(true);
        }
示例#6
0
        /// <summary>
        ///   Handles the axis stopped event for an axis.
        ///   Picks a new random position and starts a new move.
        /// </summary>
        /// <param name="axis">The axis that has stopped.</param>
        static void HandleAxisStoppedEvent(StepperMotor axis)
        {
            // Be careful, both axes appear to run on the same thread, so using Thread.Sleep() here will affect both.
            //Thread.Sleep(3000); // Wait a short time before starting the next move.
            var randomTarget = randomGenerator.Next(LimitOfTravel);

            //Debug.Print("Starting move to " + randomTarget);
            axis.MoveToTargetPosition(randomTarget);
        }
        private object SetPauseStepper(object [] arguments)
        {
            string       id    = (string)arguments[0];
            bool         pause = (bool)arguments[1];
            StepperMotor motor = GetMotor(id);

            motor.SetPause(pause);
            return(true);
        }
        public void TestSpeedException()
        {
            var pin1 = new Mock <IGpioPin>();
            var pin2 = new Mock <IGpioPin>();

            var stepper = new StepperMotor(200, pin1.Object, pin2.Object);

            Assert.Throws <Exception>(() => stepper.SetSpeed(-1));
            Assert.Throws <Exception>(() => stepper.SetSpeed(0));
        }
        private StepperMotor GetMotor(string id)
        {
            StepperMotor result = null;

            if (!_motors.TryGetValue(id, out result))
            {
                throw new Exception(string.Format("Brak silnika o identyfikatorze '{0}'.", id));
            }
            return(result);
        }
示例#10
0
 // END CUT HERE
 // BEGIN CUT HERE
 public static void Main()
 {
     try {
     StepperMotor ___test = new StepperMotor();
     ___test.run_test(-1);
     } catch(Exception e) {
     //Console.WriteLine(e.StackTrace);
     Console.WriteLine(e.ToString());
     }
 }
        private void InitializeStepperMotor()
        {
            stepperMotor = new StepperMotor(pwmDriver);

            StepperRpm = stepperMotor.Rpm;

            // Stepper motor test. Uncomment the following line to move stepper motor
            // by 200 steps forward, and then backwards.
            // StepperMotorTest(StepperMotorIndex.SM2, SteppingMode.FullSteps);
        }
示例#12
0
// END CUT HERE
// BEGIN CUT HERE
    public static void Main()
    {
        try {
            StepperMotor ___test = new StepperMotor();
            ___test.run_test(-1);
        } catch (Exception e) {
//Console.WriteLine(e.StackTrace);
            Console.WriteLine(e.ToString());
        }
    }
示例#13
0
        public Plotter(ILogger logger)
        {
            this.logger = logger;
            syncDelay.Calibrate();

            this.motorDriver = new PwmDriverPCA9685(logger, 0x60, 1600);
            this.servoDriver = new PwmDriverPCA9685(logger, 0x41, 50);
            this.motorX      = new StepperMotor(logger, motorDriver, 1, 40);
            this.motorY      = new StepperMotor(logger, motorDriver, 2, 40);

            this.servo = new Servo(logger, servoDriver);
        }
示例#14
0
        public void TestDispose()
        {
            var pin1 = new Mock <IGpioPin>();
            var pin2 = new Mock <IGpioPin>();

            using (var stepper = new StepperMotor(200, pin1.Object, pin2.Object))
            {
            }

            pin1.VerifySet(x => x.PinValue = false, Times.Once);
            pin2.VerifySet(x => x.PinValue = false, Times.Once);
        }
        /// <summary>
        ///   Handles the axis stopped event for an axis. Picks a new random position and starts a
        ///   new move.
        /// </summary>
        /// <param name="axis">The axis that has stopped.</param>
        static void HandleAxisStoppedEvent(StepperMotor axis)
        {
            // Be careful, both axes appear to run on the same thread, so using Thread.Sleep() here will affect both.
            //Thread.Sleep(3000); // Wait a short time before starting the next move.
            var randomTarget = randomGenerator.Next(LimitOfTravel);

            if (axis is InstantaneousStepperMotor)
            {
                var distance    = Math.Abs(randomTarget - axis.Position);
                var targetSpeed = distance / 5.0; // Try to get there in 5 deconds.
                axis.MaximumSpeed = targetSpeed > MaxSpeed ? MaxSpeed : targetSpeed;
            }
            //Debug.Print("Starting move to " + randomTarget);
            axis.MoveToTargetPosition(randomTarget);
        }
示例#16
0
        public void Init()
        {
            Servo   = new ServoMotor(PwmDevice, PwmChannel.C1, 150, 600);
            DcMotor = new DcMotor(PwmDevice, PwmChannel.C4, PwmChannel.C5);

            Stepper = new StepperMotor(
                PwmDevice
                , PwmChannel.C11
                , PwmChannel.C10
                , PwmChannel.C9
                , PwmChannel.C8);

            Stepper.RotationCompleted += OnStepperCompleted;

            Led0 = new Led(PwmDevice, PwmChannel.C0);
        }
示例#17
0
        public void TestNbrSteps()
        {
            var pin1 = new Mock <IGpioPin>();
            var pin2 = new Mock <IGpioPin>();

            var stepper = new StepperMotor(200, pin1.Object, pin2.Object);

            stepper.Move(5, Direction.Clockwise);

            pin1.VerifySet(x => x.PinValue = It.IsAny <bool>(), Times.Exactly(5));
            pin2.VerifySet(x => x.PinValue = It.IsAny <bool>(), Times.Exactly(5));

            stepper.Move(15, Direction.Anticlockwise);

            pin1.VerifySet(x => x.PinValue = It.IsAny <bool>(), Times.Exactly(20));
            pin2.VerifySet(x => x.PinValue = It.IsAny <bool>(), Times.Exactly(20));
        }
示例#18
0
        public void TestInitialPosition()
        {
            var pin1   = new Mock <IGpioPin>();
            var pin2   = new Mock <IGpioPin>();
            var signal = new Mock <IGpioPin>();

            var stepper = new StepperMotor(200, pin1.Object, pin2.Object);

            var result1 = stepper.SetInitialPosition(Direction.Anticlockwise, signal.Object, 10);

            Assert.False(result1);
            signal.VerifyGet(x => x.PinValue, Times.Exactly(10));
            pin1.VerifySet(x => x.PinValue = It.IsAny <bool>(), Times.Exactly(10));

            signal.Setup(x => x.PinValue).Returns(true);

            var result2 = stepper.SetInitialPosition(Direction.Clockwise, signal.Object, 100);

            Assert.True(result2);

            signal.VerifyGet(x => x.PinValue, Times.Exactly(11));
            pin1.VerifySet(x => x.PinValue = It.IsAny <bool>(), Times.Exactly(10));
        }
 /// <summary>
 ///   Receives the MotorStopped event from the second axis and signals any waiting threads.
 /// </summary>
 /// <param name="axis">The axis.</param>
 void SecondAxisMotorStopped(StepperMotor axis)
 {
     SequenceComplete.Set(); // Unblock waiting threads
 }
 /// <summary>
 ///   Received the MotorStopped event from the first axis and starts the second axis.
 /// </summary>
 /// <param name="axis">The axis.</param>
 void FirstAxisMotorStopped(StepperMotor axis)
 {
     secondAxis.MoveToTargetPosition(secondTarget);
 }
 static void ConditionalUpdateDiagnosticLed(StepperMotor axis)
 {
     LedState = !LedState;
     Led.Write(LedState);
 }
        public static void Main()
        {
            // shield-specific setup. Uncomment one of the shield #define lines above.
#if UseOnboardLedForDiagnostics
            Led = new OutputPort(Pins.ONBOARD_LED, false);
#endif
#if AdafruitV1Shield
            var adafruitMotorShieldV1 = new AdafruitV1MotorShield();
            adafruitMotorShieldV1.InitializeShield();
            StepperM1M2 = adafruitMotorShieldV1.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2);
            StepperM3M4 = adafruitMotorShieldV1.GetFullSteppingStepperMotor(3, 4);
#elif AdafruitV2Shield
            var adafruitMotorShieldV2 = new SparkfunArdumoto();  // use shield at default I2C address.
            adafruitMotorShieldV2.InitializeShield();
            StepperM1M2 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2);
            StepperM3M4 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 3, 4);
#elif SparkfunArduMotoShield
            var shield = new SparkfunArdumoto();
            shield.InitializeShield();
            var phase1 = shield.GetHBridge(Connector.A, TargetDevice.Netduino);
            var phase2 = shield.GetHBridge(Connector.B, TargetDevice.Netduino);
            StepperM1M2 = shield.GetMicrosteppingStepperMotor(MicrostepsPerStep, phase1, phase2);
#elif LedSimulatorShield
            var StepperM1M2 = LedMotorSimulator.GetSimulatedStepperMotor(Pins.GPIO_PIN_D0,
                                                                         PWMChannels.PWM_ONBOARD_LED,
                                                                         Pins.GPIO_PIN_D1,
                                                                         PWMChannels.PWM_PIN_D6);
#else
            throw new ApplicationException("Uncomment one of the shield #define statements");
#endif

            // Create the stepper motor axes and link them to the shield driver.
            axis1 = new InstantaneousStepperMotor(LimitOfTravel, StepperM1M2)
            {
                MaximumSpeed = MaxSpeed
                               //RampTime = RampTime
            };

            axis1.BeforeStep += UpdateDiagnosticLed;

            speed     = 1.0;
            direction = +1;

            var fasterButton = new InterruptPort(Pins.GPIO_PIN_D1,
                                                 true,
                                                 Port.ResistorMode.PullUp,
                                                 Port.InterruptMode.InterruptEdgeLow);
            var slowerButton = new InterruptPort(Pins.GPIO_PIN_D2,
                                                 true,
                                                 Port.ResistorMode.PullUp,
                                                 Port.InterruptMode.InterruptEdgeLow);
            var reverseButton = new InterruptPort(Pins.GPIO_PIN_D13,
                                                  true,
                                                  Port.ResistorMode.PullUp,
                                                  Port.InterruptMode.InterruptEdgeLow);
            fasterButton.OnInterrupt  += fasterButton_OnInterrupt;
            slowerButton.OnInterrupt  += slowerButton_OnInterrupt;
            reverseButton.OnInterrupt += reverseButton_OnInterrupt;
            SetMotorVelocity();
            Thread.Sleep(Timeout.Infinite);
        }
示例#23
0
 /// <summary>
 /// Предоставляет класс содержащий информацию о шаговом двигателе, который приводит в движение плечо
 /// </summary>
 /// <param name="type">Тип плеча робота-манипулятора</param>
 /// <param name="stepper">Экземпляр класса для управления шаговым двигателем</param>
 public LeverStepper(LeverType type, StepperMotor stepper)
 {
     Type    = type;
     Stepper = stepper;
 }
示例#24
0
 private void comboBox_Gripper_SelectedIndexChanged(object sender, EventArgs e)
 {
     _selectedGripper = (StepperMotor)comboBox_Gripper.SelectedItem;
 }
 /// <summary>
 ///   Toggles the Netduino's on-board led.
 /// </summary>
 /// <param name="direction">The direction.</param>
 static void UpdateDiagnosticLed(StepperMotor axis)
 {
     ConditionalUpdateDiagnosticLed(axis);
 }