Пример #1
0
        public void Step(uint steps, MotorDirection direction, StepType style = StepType.Single)
        {
            uint usPerStep = this.usPerStep;

            if (style == StepType.Interleave)
            {
                // corrections for interleave; interleave contains twice the steps (both single & double), so wait only halve the time
                usPerStep /= 2;
            }

            int waitTime = (int)usPerStep / 1000;

            if (waitTime <= 0)
            {
                waitTime = 1;
            }

            while (steps-- > 0)
            {
                // execute a single step
                OneStep(direction, style);

                // wait for a single step (convert us to ms)
                Util.Delay(waitTime);
            }
        }
Пример #2
0
        public void Go(int powerPercent, MotorDirection direction = MotorDirection.Forward)
        {
            var speedInPwm = GetPercentAsPwm(powerPercent);

            var channelA = direction == MotorDirection.Forward ? _controlChannel0 : _controlChannel1;
            var channelB = direction == MotorDirection.Forward ? _controlChannel1 : _controlChannel0;

            if (powerPercent == 100)
            {
                Log.Debug(m => m("DC.{0}={2}.{1} (FULL)", channelA, powerPercent, direction));
                Controller.SetFull(channelA, true);
                Controller.SetFull(channelB, false);
            }
            else if (powerPercent == 0)
            {
                Log.Debug(m => m("DC.{0}={2}.{1} (FULL OFF)", channelA, powerPercent, direction));
                Controller.SetFull(channelA, false);
                Controller.SetFull(channelB, false);
            }
            else
            {
                Log.Debug(m => m("DC.{0}={3}.{1} (pwm={2})", channelA, powerPercent, speedInPwm, direction));
                Controller.SetPwm(channelA, 0, speedInPwm);
                Controller.SetFull(channelB, false);
            }
        }
Пример #3
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            int speedA, speedB, time;

            try
            {
                speedA = Convert.ToInt32(textBoxSpeedMotorA.Text);
                speedB = Convert.ToInt32(textBoxSpeedMotorB.Text);
                time   = Convert.ToInt32(textBoxMotorTime.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                return;
            }
            if (speedA > MaxSpeed || speedA < MinSpeed)
            {
                MessageBox.Show("Please check your input - motor A!");
                return;
            }
            if (speedB > MaxSpeed || speedB < MinSpeed)
            {
                MessageBox.Show("Please check your input - motor B!");
                return;
            }
            if (time < 0)
            {
                MessageBox.Show("Please check your input - time!");
                return;
            }
            MotorDirection dirA = (MotorDirection)comboBoxMotorA.SelectedIndex;
            MotorDirection dirB = (MotorDirection)comboBoxMotorB.SelectedIndex;

            Arduino.GetInstance().Send(dirA, speedA, dirB, speedB, time);
        }
Пример #4
0
        public void Run(MotorDirection dir)
        {
            switch (dir)
            {
            case MotorDirection.Release:
                MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitA));
                MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitB));
                break;

            case MotorDirection.Forward:
                MotorShield.Instance.LatchState |= (byte)(1 << _motorBitA);
                MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitB));
                break;

            case MotorDirection.Reverse:
                MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitA));
                MotorShield.Instance.LatchState |= (byte)(1 << _motorBitB);
                break;

            default:
                throw new InvalidOperationException("Invalid motor direction specified");
            }

            MotorShield.Instance.LatchTx();
        }
Пример #5
0
        private void Run()
        {
            _tokenSource = new CancellationTokenSource();
            CancellationToken ct = _tokenSource.Token;

            var task = Task.Run(() =>
            {
                bool isRunning = true;
                while (isRunning)
                {
                    if (ct.IsCancellationRequested)
                    {
                        _controller.Write(Pin.MotorLeft, PinValue.Low);
                        _controller.Write(Pin.MotorRight, PinValue.Low);
                        _currentDirection = MotorDirection.None;
                        isRunning         = false;
                    }
                    else if (_controller.Read(Pin.HallBottom) == PinValue.High)
                    {
                        _controller.Write(Pin.MotorLeft, PinValue.Low);
                        _currentDirection = MotorDirection.None;
                    }
                    else if (_controller.Read(Pin.HallTop) == PinValue.High)
                    {
                        _controller.Write(Pin.MotorRight, PinValue.Low);
                        _currentDirection = MotorDirection.None;
                    }
                    Thread.Sleep(100);
                }
            }, _tokenSource.Token);
        }
Пример #6
0
        /// <summary>
        /// Set the motor direction
        /// </summary>
        /// <param name="dir">Direction the motor should run</param>
        public void Run(MotorDirection dir)
        {
            switch (dir)
            {
            case MotorDirection.Release:
                latchState &= (byte)(~(1 << motorBitA));
                latchState &= (byte)(~(1 << motorBitB));
                break;

            case MotorDirection.Forward:
                latchState |= (byte)(1 << motorBitA);
                latchState &= (byte)(~(1 << motorBitB));
                break;

            case MotorDirection.Reverse:
                latchState &= (byte)(~(1 << motorBitA));
                latchState |= (byte)(1 << motorBitB);
                break;

            default:
                throw new InvalidOperationException("Invalid motor direction specified");
            }

            latch_tx((byte)latchState);
        }
Пример #7
0
        public void Go(int powerPercent, MotorDirection direction = MotorDirection.Forward)
        {
            var speedInPwm = GetPercentAsPwm(powerPercent);

            var channelA = direction == MotorDirection.Forward ? _controlChannel0 : _controlChannel1;
            var channelB = direction == MotorDirection.Forward ? _controlChannel1 : _controlChannel0;

            if (powerPercent == 100)
            {
                Log.Debug(m => m("DC.{0}={2}.{1} (FULL)", channelA, powerPercent, direction));
                Controller.SetFull(channelA, true);
                Controller.SetFull(channelB, false);
            }
            else if (powerPercent == 0)
            {
                Log.Debug(m=>m("DC.{0}={2}.{1} (FULL OFF)", channelA, powerPercent, direction));
                Controller.SetFull(channelA, false);
                Controller.SetFull(channelB, false);
            }
            else
            {
                Log.Debug(m => m("DC.{0}={3}.{1} (pwm={2})", channelA, powerPercent, speedInPwm, direction));
                Controller.SetPwm(channelA, 0, speedInPwm);
                Controller.SetFull(channelB, false);
            }
        }
        public void MakeStep(StepperMotorIndex motorIndex, MotorDirection direction, SteppingMode steppingMode = SteppingMode.FullSteps)
        {
            ConfigureChannels(motorIndex);

            UpdateCurrentStep(direction);

            UpdateChannels(steppingMode);
        }
        public void MoveBackward()
        {
            IsMoving  = true;
            Direction = MotorDirection.Backward;

            motorGpioPinA.Write(GpioPinValue.High);
            motorGpioPinB.Write(GpioPinValue.Low);
        }
        public void Stop()
        {
            IsMoving  = false;
            Direction = MotorDirection.None;

            motorGpioPinA.Write(GpioPinValue.Low);
            motorGpioPinB.Write(GpioPinValue.Low);
        }
Пример #11
0
 private static void GoStraight(uint speed, int lot, MotorDirection direction)
 {
     rightDrive.Run(direction);
     leftDrive.Run(direction);
     rightDrive.SetSpeed(speed);
     leftDrive.SetSpeed(speed);
     Thread.Sleep(lot);
 }
Пример #12
0
 public SendArguements(MotorDirection argDirA, int argSpeedA, MotorDirection argDirB, int argSpeedB, int argTime)
 {
     DirA   = argDirA;
     SpeedA = argSpeedA;
     DirB   = argDirB;
     SpeedB = argSpeedB;
     Time   = argTime;
 }
Пример #13
0
        public void MotorOn(MotorDirection direction, int motorNumber)
        {
            if (direction == MotorDirection.Forward)
                SetFwd(motorNumber.ToString());
            else
                SetRwd(motorNumber.ToString());

            On(motorNumber.ToString());
        }
Пример #14
0
        public void SetMotorDirection(int motorIndex, MotorDirection value)
        {
            if (!OutputModes[motorIndex])
            {
                throw new InvalidOperationException($"O{motorIndex * 2} or O{motorIndex * 2 + 1} is not a motor");
            }

            MotorDirections[motorIndex] = value;
            SetMotorValue(motorIndex, GetMotorValue(motorIndex));
        }
Пример #15
0
        public void SetMotorValue(int motorIndex, int value, MotorDirection direction, int extension = 0)
        {
            if (extension > 0)
            {
                throw new NotImplementedException("More than one extension is not implemented right now");
            }
            ThrowWhenNotConnected();

            _masterInterface.SetMotorDirection(motorIndex, direction);
            _masterInterface.SetMotorValue(motorIndex, value);
        }
Пример #16
0
        private static sbyte GetSpeed(MotorDirection direction)
        {
            sbyte speed = 50;

            if (direction == MotorDirection.Backward)
            {
                speed = -50;
            }

            return speed;
        }
Пример #17
0
        public FtExtension(int extensionId)
        {
            ExtensionId = extensionId;

            InputValues    = new short[TxtInterface.UniversalInputs];
            InputModes     = new InputMode[TxtInterface.UniversalInputs];
            InputIsDigital = new bool[TxtInterface.UniversalInputs];

            OutputValues    = new int[TxtInterface.PwmOutputs];
            OutputModes     = new bool[TxtInterface.MotorOutputs];
            MotorDirections = new MotorDirection[TxtInterface.MotorOutputs];
        }
Пример #18
0
 private void AdvanceStep(MotorDirection direction)
 {
     _currentStep += (int)direction;
     if (_currentStep == Sequence.Length)
     {
         _currentStep = 0;
     }
     if (_currentStep == -1)
     {
         _currentStep = Sequence.Length - 1;
     }
 }
        public void Move(StepperMotorIndex motorIndex, MotorDirection direction, uint steps, SteppingMode steppingMode = SteppingMode.FullSteps)
        {
            var msDelay = RpmToMsDelay(Rpm, steppingMode);

            steps = GetTotalStepCount(steppingMode, steps);

            for (uint i = 0; i < steps; i++)
            {
                MakeStep(motorIndex, direction, steppingMode);

                Task.Delay(msDelay).Wait();
            }
        }
Пример #20
0
 public void Send(MotorDirection dirA, int speedA, MotorDirection dirB, int speedB, int time)
 {
     if (StateManager.TcpState.IsClientConnected == true)
     {
         string     data           = "Motor" + Separator + (int)dirA + Separator + speedA + Separator + (int)dirB + Separator + speedB + Separator + time + Separator + Environment.NewLine;
         TcpManager tempTcpManager = TcpManager.GetInstance();
         tempTcpManager.TcpServerSend(InterNetwork.GetInstance().GetRemoteClient(), data);
         StateManager.ArduinoState.IsBusy = true;
     }
     else
     {
         FormArduinoControlPanel.GetInstance().WriteToConsole("Error: No Client Connected !");
     }
 }
Пример #21
0
            public void SetValueOutput1(int value)
            {
                if (OutputDevice == OutputDevice.Motor)
                {
                    int outputValue = value - MaxOutput1 / 2;

                    MotorDirection direction = outputValue > 0
                        ? MotorDirection.Left
                        : MotorDirection.Right;


                    int absoluteValue = Math.Abs(outputValue);

                    if (absoluteValue > MaxOutput1)
                    {
                        absoluteValue = MaxOutput1;
                    }

                    if (FtInterfaceInstanceProvider.Instance != null)
                    {
                        if (FtInterfaceInstanceProvider.Instance.CanSendCommand())
                        {
                            try
                            {
                                FtInterfaceInstanceProvider.Instance.SetMotorValue(IndexMotor, absoluteValue, direction);
                            }
                            catch (InvalidOperationException) { }
                        }
                    }
                }
                else
                {
                    if (value > MaxOutput1)
                    {
                        value = MaxOutput1;
                    }

                    if (FtInterfaceInstanceProvider.Instance != null)
                    {
                        if (FtInterfaceInstanceProvider.Instance.CanSendCommand())
                        {
                            try
                            {
                                FtInterfaceInstanceProvider.Instance.SetOutputValue(IndexOutput1, value);
                            }
                            catch (InvalidOperationException) { }
                        }
                    }
                }
            }
        public void MoveWithSpeedAdjustment(StepperMotorIndex motorIndex, MotorDirection direction, uint steps, SteppingMode steppingMode = SteppingMode.FullSteps)
        {
            steps = GetTotalStepCount(steppingMode, steps);

            var speedRamp = SpeedRampHelper.GenerateTrapezoidalRamp(steps);

            for (uint i = 0; i < steps; i++)
            {
                MakeStep(motorIndex, direction, steppingMode);

                var msAutoDelay = RpmToMsDelay(speedRamp[i], steppingMode);

                Task.Delay(msAutoDelay).Wait();
            }
        }
Пример #23
0
        public void Start(DcMotorIndex motorIndex, MotorDirection direction)
        {
            ConfigureChannels(motorIndex);

            if (direction == MotorDirection.Forward)
            {
                pwmControllerProvider.SetPulseParameters(channels.In1, dutyCycleFullyOn, false);
                pwmControllerProvider.SetPulseParameters(channels.In2, dutyCycleFullyOff, false);
            }
            else
            {
                pwmControllerProvider.SetPulseParameters(channels.In1, dutyCycleFullyOff, false);
                pwmControllerProvider.SetPulseParameters(channels.In2, dutyCycleFullyOn, false);
            }
        }
Пример #24
0
        public void Start(DcMotorIndex motorIndex, MotorDirection direction)
        {
            ConfigureChannels(motorIndex);

            if (direction == MotorDirection.Forward)
            {
                pcaPwmDriver.SetChannelValue(channels.In1, PcaPwmDriver.FullyOn);
                pcaPwmDriver.SetChannelValue(channels.In2, PcaPwmDriver.FullyOff);
            }
            else
            {
                pcaPwmDriver.SetChannelValue(channels.In1, PcaPwmDriver.FullyOff);
                pcaPwmDriver.SetChannelValue(channels.In2, PcaPwmDriver.FullyOn);
            }
        }
Пример #25
0
        public void SetMotorDistance(int motorIndex, short speed, short distance, MotorDirection direction, int extension = 0)
        {
            if (extension > 0)
            {
                throw new NotImplementedException("More than one extension is not implemented right now");
            }
            if (speed < 0 || speed > 512)
            {
                throw new ArgumentException(String.Format("Incorrect speed value {0}. PWM Value should be from 0 to 512 (= max speed)", speed));
            }
            ThrowWhenNotConnected();

            _masterInterface.SetMotorDirection(motorIndex, direction);
            _masterInterface.SetMotorValue(motorIndex, speed);
            _motorInterface.SetMotorDistance(motorIndex, distance);
        }
Пример #26
0
        public static int RunAndWaitOnCompletion(
            McNxtMotor motor, uint tacho, MotorDirection direction)
        {
            _runningTacho = 0;
            sbyte speed = GetSpeed(direction);

            motor.Run(speed, tacho);
            WaitForMotorToFinish(motor);

            Debug.WriteLine("Real tacho {0} degrees", motor.TachoCount);

            if (motor.TachoCount == null)
                throw new NxtException("Error getting tacho count from motor.");

            return motor.TachoCount.Value;
        }
        private void DcMotorTest(DcMotorIndex motorIndex, MotorDirection direction, ushort speed)
        {
            if (dcMotor.IsInitialized)
            {
                const int msDelay = 5000;

                // Set speed, and run motor
                dcMotor.SetSpeed(motorIndex, speed);
                dcMotor.Start(motorIndex, direction);

                // Wait a specified delay
                Task.Delay(msDelay).Wait();

                // Stop motor
                dcMotor.Stop(motorIndex);
            }
        }
        private void DcMotorTest(DcMotorIndex motorIndex, MotorDirection direction, ushort speed)
        {
            if (dcMotor != null)
            {
                const int msDelay = 5000;

                // 속도 설정 및 모터 구동
                dcMotor.SetSpeed(motorIndex, speed);
                dcMotor.Start(motorIndex, direction);

                // 지정된 지연 대기
                Task.Delay(msDelay).Wait();

                // 모터 정지
                dcMotor.Stop(motorIndex);
            }
        }
Пример #29
0
        /// <summary>
        /// Move the stepper a specific number of steps
        /// </summary>
        /// <param name="steps">How many steps to move</param>
        /// <param name="dir">The direction in which to rotate</param>
        /// <param name="style">The type of stepping to perform</param>
        public void Step(uint steps, MotorDirection dir, StepType style = StepType.Single)
        {
            uint uspers = usPerStep;
            uint ret    = 0;

            if (style == StepType.Interleave)
            {
                uspers /= 2;
            }
            else if (style == StepType.Microstep)
            {
                uspers /= microsteps;
                steps  *= microsteps;
            }

            while (steps-- > 0)
            {
                ret = OneStep(dir, style);
                Thread.Sleep((int)uspers / 1000); // in ms
                stepCounter += (uspers % 1000);
                if (stepCounter >= 1000)
                {
                    Thread.Sleep(1);
                    stepCounter -= 1000;
                }
            }

            if (style == StepType.Microstep)
            {
                while ((ret != 0) && (ret != microsteps))
                {
                    ret = OneStep(dir, style);
                    Thread.Sleep((int)uspers / 1000); // in ms
                    stepCounter += (uspers % 1000);
                    if (stepCounter >= 1000)
                    {
                        Thread.Sleep(1);
                        stepCounter -= 1000;
                    }
                }
            }
        }
        private void UpdateCurrentStep(MotorDirection direction)
        {
            if (direction == MotorDirection.Forward)
            {
                CurrentStep++;
            }
            else
            {
                CurrentStep--;
            }

            if (CurrentStep < 0)
            {
                CurrentStep = (int)Steps - 1;
            }

            if (CurrentStep >= Steps)
            {
                CurrentStep = 0;
            }
        }
Пример #31
0
        public void Run(MotorDirection dir)
        {
            switch (dir)
            {
                case MotorDirection.Release:
                    MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitA));
                    MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitB));
                    break;
                case MotorDirection.Forward:
                    MotorShield.Instance.LatchState |= (byte)(1 << _motorBitA);
                    MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitB));
                    break;
                case MotorDirection.Reverse:
                    MotorShield.Instance.LatchState &= (byte)(~(1 << _motorBitA));
                    MotorShield.Instance.LatchState |= (byte)(1 << _motorBitB);
                    break;
                default:
                    throw new InvalidOperationException("Invalid motor direction specified");
            }

            MotorShield.Instance.LatchTx();
        }
Пример #32
0
        private void Drive(MotorDirection direction, int speed)
        {
            _controller.Write(Pin.MotorLeft, PinValue.Low);
            _controller.Write(Pin.MotorRight, PinValue.Low);
            _currentDirection = direction;
            _currentSpeed     = speed;
            switch (direction)
            {
            case MotorDirection.None:
                break;

            case MotorDirection.Up:
                _controller.Write(Pin.MotorLeft, PinValue.High);
                break;

            case MotorDirection.Down:
                _controller.Write(Pin.MotorRight, PinValue.High);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
        }
Пример #33
0
        public void Step(uint steps, MotorDirection direction, StepType style = StepType.Single)
        {
            uint usPerStep = this.usPerStep;

            if (style == StepType.Interleave) {
                // corrections for interleave; interleave contains twice the steps (both single & double), so wait only halve the time
                usPerStep /= 2;
            }

            int waitTime = (int)usPerStep / 1000;
            if (waitTime <= 0) {
                waitTime = 1;
            }

            while (steps-- > 0) {
                // execute a single step
                OneStep(direction, style);

                // wait for a single step (convert us to ms)
                Util.Delay(waitTime);
            }
        }
Пример #34
0
 private static void GoStraight(uint speed, int lot, MotorDirection direction)
 {
     rightDrive.Run(direction);
     leftDrive.Run(direction);
     rightDrive.SetSpeed(speed);
     leftDrive.SetSpeed(speed);
     Thread.Sleep(lot);
 }
Пример #35
0
        /// <summary>
        /// Move the stepper one step
        /// </summary>
        /// <param name="dir">The direction in which to move</param>
        /// <param name="style">The type of stepping to use</param>
        /// <returns>Current step count</returns>
        public uint OneStep(MotorDirection dir, StepType style = StepType.Single)
        {
            byte a, b, c, d;
            byte ocrb, ocra;

            ocra = ocrb = 255;
            switch (stepperPort)
            {
            /*
             * case StepperPorts.M1_M2;
             *  a = (1<<(int)MotorBits.Motor1_A);
             *  b = (1<<(int)MotorBits.Motor2_A);
             *  c = (1<<(int)MotorBits.Motor1_B);
             *  d = (1<<(int)MotorBits.Motor2_B);
             *  break;
             */
            case StepperPorts.M3_M4:
                a = (1 << (int)MotorBits.Motor3_A);
                b = (1 << (int)MotorBits.Motor4_A);
                c = (1 << (int)MotorBits.Motor3_B);
                d = (1 << (int)MotorBits.Motor4_B);
                break;

            default:
                return(0);
            }

            // next determine what sort of stepping procedure we're up to
            if (style == StepType.Single)
            {
                if ((currentStep / (microsteps / 2)) % 2 == 0) // we're at an odd step, weird. Shouldn't happen, but just in case...
                {
                    currentStep += (dir == MotorDirection.Forward) ? (uint)(microsteps / 2) : (uint)(-microsteps / 2);
                }
                else // go to the next even step
                {
                    currentStep += (dir == MotorDirection.Forward) ? (uint)(microsteps) : (uint)(-microsteps);
                }
            }

            else if (style == StepType.Double)
            {
                if ((currentStep / (microsteps / 2) % 2) != 0) // we're at an even step, weird.  Just in case...
                {
                    currentStep += (dir == MotorDirection.Forward) ? (uint)(microsteps / 2) : (uint)(-microsteps / 2);
                }
                else  // go to the next odd step
                {
                    currentStep += (dir == MotorDirection.Forward) ? (uint)(microsteps) : (uint)(-microsteps);
                }
            }

            else if (style == StepType.Interleave)
            {
                currentStep += (dir == MotorDirection.Forward) ? (uint)(microsteps) : (uint)(-microsteps);
            }

            if (style == StepType.Microstep)
            {
                if (dir == MotorDirection.Forward)
                {
                    currentStep++;
                }
                else
                {
                    // BACKWARDS
                    currentStep--;
                }

                currentStep += microsteps * 4;
                currentStep %= microsteps * 4;

                ocra = ocrb = 0;
                if ((currentStep >= 0) && (currentStep < microsteps))
                {
                    ocra = microstepCurve[microsteps - currentStep];
                    ocrb = microstepCurve[currentStep];
                }
                else if ((currentStep >= microsteps) && (currentStep < microsteps * 2))
                {
                    ocra = microstepCurve[currentStep - microsteps];
                    ocrb = microstepCurve[microsteps * 2 - currentStep];
                }
                else if ((currentStep >= microsteps * 2) && (currentStep < microsteps * 3))
                {
                    ocra = microstepCurve[microsteps * 3 - currentStep];
                    ocrb = microstepCurve[currentStep - microsteps * 2];
                }
                else if ((currentStep >= microsteps * 3) && (currentStep < microsteps * 4))
                {
                    ocra = microstepCurve[currentStep - microsteps * 3];
                    ocrb = microstepCurve[microsteps * 4 - currentStep];
                }
            }

            currentStep += microsteps * 4;
            currentStep %= microsteps * 4;

            coilA.SetDutyCycle(ocra);
            coilB.SetDutyCycle(ocrb);

            // release all
            latchState &= (byte)(~a & ~b & ~c & ~d); // all motor pins to 0

            //Serial.println(step, DEC);
            if (style == StepType.Microstep)
            {
                if ((currentStep >= 0) && (currentStep < microsteps))
                {
                    latchState |= (byte)(a | b);
                }
                if ((currentStep >= microsteps) && (currentStep < microsteps * 2))
                {
                    latchState |= (byte)(b | c);
                }
                if ((currentStep >= microsteps * 2) && (currentStep < microsteps * 3))
                {
                    latchState |= (byte)(c | d);
                }
                if ((currentStep >= microsteps * 3) && (currentStep < microsteps * 4))
                {
                    latchState |= (byte)(d | a);
                }
            }
            else
            {
                switch (currentStep / (microsteps / 2))
                {
                case 0:
                    latchState |= (byte)(a);     // energize coil 1 only
                    break;

                case 1:
                    latchState |= (byte)(a | b);     // energize coil 1+2
                    break;

                case 2:
                    latchState |= (byte)(b);     // energize coil 2 only
                    break;

                case 3:
                    latchState |= (byte)(b | c);     // energize coil 2+3
                    break;

                case 4:
                    latchState |= (byte)(c);     // energize coil 3 only
                    break;

                case 5:
                    latchState |= (byte)(c | d);     // energize coil 3+4
                    break;

                case 6:
                    latchState |= (byte)(d);     // energize coil 4 only
                    break;

                case 7:
                    latchState |= (byte)(d | a);     // energize coil 1+4
                    break;
                }
            }


            latch_tx(latchState);
            return(currentStep);
        }
Пример #36
0
 private void AdvanceStep(MotorDirection direction)
 {
     _currentStep += (int) direction;
     if (_currentStep == Sequence.Length)
     {
         _currentStep = 0;
     }
     if (_currentStep == -1)
     {
         _currentStep = Sequence.Length - 1;
     }
 }
Пример #37
0
        protected int OneStep(MotorDirection direction, StepType stepStyle = StepType.Single)
        {
            switch (stepStyle) {
                // single coil activation only uses the even stages (0, 2, 4, 6)
                case StepType.Single:
                    if (this.currentStep % 2 != 0)  // we're at an odd step
                    {
                        // add or retract 1, depending on the direction, to get back into the next/previous even stage
                        this.currentStep += direction == MotorDirection.Forward ? 1 : -1;
                    }
                    else {
                        // add or retract 2, depending on the direction, to advance to the next/previous stage
                        this.currentStep += direction == MotorDirection.Forward ? 2 : -2;
                    }
                    break;

                // double coil activation only uses the odd stages (1, 3, 5, 7)
                case StepType.Double:
                    if (this.currentStep % 2 == 0)  // we're at an even step
                    {
                        // add or retract 1, depending on the direction, to get back into the next/previous odd stage
                        this.currentStep += direction == MotorDirection.Forward ? 1 : -1;
                    }
                    else {
                        // add or retract 2, depending on the direction, to advance to the next/previous stage
                        this.currentStep += direction == MotorDirection.Forward ? 2 : -2;
                    }
                    break;

                // interleave coil activation uses all stages (0, 1, 2, 3, 4, 5, 6, 7)
                case StepType.Interleave:
                    // add or retract 1, depending on the direction, to advance to the next/previous stage
                    this.currentStep += direction == MotorDirection.Forward ? 1 : -1;
                    break;
            }

            // ensure we stay within the 0-7 range
            this.currentStep += 8;
            this.currentStep %= 8;

            switch (this.currentStep) {
                case 0:                         // energize coil 1A
                    this.portCoil1B.Write(false);
                    this.portCoil2A.Write(false);
                    this.portCoil2B.Write(false);
                    this.portCoil1A.Write(true);
                    break;
                case 1:                         // energize coil 1A + 2A
                    this.portCoil1A.Write(true);
                    this.portCoil1B.Write(false);
                    this.portCoil2A.Write(true);
                    this.portCoil2B.Write(false);
                    break;
                case 2:                         // energize coil 2A
                    this.portCoil1A.Write(false);
                    this.portCoil1B.Write(false);
                    this.portCoil2B.Write(false);
                    this.portCoil2A.Write(true);
                    break;
                case 3:                         // energize coil 1B + 2A
                    this.portCoil1A.Write(false);
                    this.portCoil1B.Write(true);
                    this.portCoil2A.Write(true);
                    this.portCoil2B.Write(false);
                    break;
                case 4:                         // energize coil 1B
                    this.portCoil1A.Write(false);
                    this.portCoil2A.Write(false);
                    this.portCoil2B.Write(false);
                    this.portCoil1B.Write(true);
                    break;
                case 5:                         // energize coil 1B + 2B
                    this.portCoil1A.Write(false);
                    this.portCoil1B.Write(true);
                    this.portCoil2A.Write(false);
                    this.portCoil2B.Write(true);
                    break;
                case 6:                         // energize coil 2B
                    this.portCoil1A.Write(false);
                    this.portCoil1B.Write(false);
                    this.portCoil2A.Write(false);
                    this.portCoil2B.Write(true);
                    break;
                case 7:                         // energize coil 1A + 2B
                    this.portCoil1A.Write(true);
                    this.portCoil1B.Write(false);
                    this.portCoil2A.Write(false);
                    this.portCoil2B.Write(true);
                    break;
            }

            return this.currentStep;
        }
Пример #38
0
 public void SetMotorValue(int motorIndex, int value, MotorDirection direction, int extension = 0)
 {
 }
Пример #39
0
        protected int OneStep(MotorDirection direction, StepType stepStyle = StepType.Single)
        {
            switch (stepStyle)
            {
            // single coil activation only uses the even stages (0, 2, 4, 6)
            case StepType.Single:
                if (this.currentStep % 2 != 0)      // we're at an odd step
                {
                    // add or retract 1, depending on the direction, to get back into the next/previous even stage
                    this.currentStep += direction == MotorDirection.Forward ? 1 : -1;
                }
                else
                {
                    // add or retract 2, depending on the direction, to advance to the next/previous stage
                    this.currentStep += direction == MotorDirection.Forward ? 2 : -2;
                }
                break;

            // double coil activation only uses the odd stages (1, 3, 5, 7)
            case StepType.Double:
                if (this.currentStep % 2 == 0)      // we're at an even step
                {
                    // add or retract 1, depending on the direction, to get back into the next/previous odd stage
                    this.currentStep += direction == MotorDirection.Forward ? 1 : -1;
                }
                else
                {
                    // add or retract 2, depending on the direction, to advance to the next/previous stage
                    this.currentStep += direction == MotorDirection.Forward ? 2 : -2;
                }
                break;

            // interleave coil activation uses all stages (0, 1, 2, 3, 4, 5, 6, 7)
            case StepType.Interleave:
                // add or retract 1, depending on the direction, to advance to the next/previous stage
                this.currentStep += direction == MotorDirection.Forward ? 1 : -1;
                break;
            }

            // ensure we stay within the 0-7 range
            this.currentStep += 8;
            this.currentStep %= 8;

            switch (this.currentStep)
            {
            case 0:                             // energize coil 1A
                this.portCoil1B.Write(false);
                this.portCoil2A.Write(false);
                this.portCoil2B.Write(false);
                this.portCoil1A.Write(true);
                break;

            case 1:                             // energize coil 1A + 2A
                this.portCoil1A.Write(true);
                this.portCoil1B.Write(false);
                this.portCoil2A.Write(true);
                this.portCoil2B.Write(false);
                break;

            case 2:                             // energize coil 2A
                this.portCoil1A.Write(false);
                this.portCoil1B.Write(false);
                this.portCoil2B.Write(false);
                this.portCoil2A.Write(true);
                break;

            case 3:                             // energize coil 1B + 2A
                this.portCoil1A.Write(false);
                this.portCoil1B.Write(true);
                this.portCoil2A.Write(true);
                this.portCoil2B.Write(false);
                break;

            case 4:                             // energize coil 1B
                this.portCoil1A.Write(false);
                this.portCoil2A.Write(false);
                this.portCoil2B.Write(false);
                this.portCoil1B.Write(true);
                break;

            case 5:                             // energize coil 1B + 2B
                this.portCoil1A.Write(false);
                this.portCoil1B.Write(true);
                this.portCoil2A.Write(false);
                this.portCoil2B.Write(true);
                break;

            case 6:                             // energize coil 2B
                this.portCoil1A.Write(false);
                this.portCoil1B.Write(false);
                this.portCoil2A.Write(false);
                this.portCoil2B.Write(true);
                break;

            case 7:                             // energize coil 1A + 2B
                this.portCoil1A.Write(true);
                this.portCoil1B.Write(false);
                this.portCoil2A.Write(false);
                this.portCoil2B.Write(true);
                break;
            }

            return(this.currentStep);
        }