示例#1
0
        public void Step(int steps, Direction direction, StepStyle stepstyle)
        {
            var s_per_s = (int)(secPerStep * 1000);

            if (stepstyle == StepStyle.Interleave)
            {
                s_per_s = s_per_s / 2;
            }


            //this.logger.WriteLn(String.Format("{0} millisec per step", s_per_s));

            for (var s = 0; s < steps; s++)
            {
                this.OneStep(direction, stepstyle);
                syncDelay.Sleep(5);
            }
        }
示例#2
0
        public int OneStep(Direction dir, StepStyle style)
        {
            switch (style)
            {
            case StepStyle.Single:
                if ((currentstep / (MICROSTEPS / 2)) % 2 != 0)
                {
                    //# we're at an odd step, weird
                    if (dir == Direction.Forward)
                    {
                        currentstep += MICROSTEPS / 2;
                    }
                    else
                    {
                        currentstep -= MICROSTEPS / 2;
                    }
                }
                else
                {
                    // go to next even step
                    if (dir == Direction.Forward)
                    {
                        currentstep += MICROSTEPS;
                    }
                    else
                    {
                        currentstep -= MICROSTEPS;
                    }
                }
                break;

            case StepStyle.Double:
                if ((currentstep / (MICROSTEPS / 2) % 2) == 0)
                {
                    //# we're at an even step, weird
                    if (dir == Direction.Forward)
                    {
                        currentstep += MICROSTEPS / 2;
                    }
                    else
                    {
                        currentstep -= MICROSTEPS / 2;
                    }
                }
                else
                {
                    // go to next odd step
                    if (dir == Direction.Forward)
                    {
                        currentstep += MICROSTEPS;
                    }
                    else
                    {
                        currentstep -= MICROSTEPS;
                    }
                }
                break;

            case StepStyle.Interleave:
                if (dir == Direction.Forward)
                {
                    currentstep += MICROSTEPS / 2;
                }
                else
                {
                    currentstep -= MICROSTEPS / 2;
                }
                break;
            }

            //go to next 'step' and wrap around
            currentstep += MICROSTEPS * MICROSTEPS_PER_INTERLEAVE_STEP;
            currentstep %= MICROSTEPS * MICROSTEPS_PER_INTERLEAVE_STEP;

            this.driver.SetPwm(pwmA, 4096, 0);
            this.driver.SetPwm(pwmB, 4096, 0);

            //set up coil energizing!
            bool[][] step2coils =
            {
                new bool[] { true,  false, false, false },
                new bool[] { true,  true,  false, false },
                new bool[] { false, true,  false, false },
                new bool[] { false, true,  true,  false },
                new bool[] { false, false, true,  false },
                new bool[] { false, false, true,  true  },
                new bool[] { false, false, false, true  },
                new bool[] { true,  false, false, true  }
            };

            var coils = step2coils[currentstep / MICROSTEPS_PER_INTERLEAVE_STEP];

            // print "coils state = " + str(coils)
            driver.SetPin(ain2, coils[0]);
            driver.SetPin(bin1, coils[1]);
            driver.SetPin(ain1, coils[2]);
            driver.SetPin(bin2, coils[3]);

            return(currentstep);
        }
示例#3
0
        public int OneStep(Direction dir, StepStyle style)
        {
            switch (style)
            {
                case StepStyle.Single:
                    if ((currentstep / (MICROSTEPS / 2)) % 2 != 0)
                    {
                        //# we're at an odd step, weird
                        if (dir == Direction.Forward)
                        {
                            currentstep += MICROSTEPS / 2;
                        }
                        else
                        {
                            currentstep -= MICROSTEPS / 2;
                        }
                    }
                    else
                    {
                        // go to next even step
                        if (dir == Direction.Forward)
                        {
                            currentstep += MICROSTEPS;
                        }
                        else
                        {
                            currentstep -= MICROSTEPS;
                        }
                    }
                    break;
                case StepStyle.Double:
                    if ((currentstep / (MICROSTEPS / 2) % 2) == 0)
                    {
                        //# we're at an even step, weird
                        if (dir == Direction.Forward)
                        {
                            currentstep += MICROSTEPS / 2;
                        }
                        else
                        {
                            currentstep -= MICROSTEPS / 2;
                        }
                    }
                    else
                    {
                        // go to next odd step
                        if (dir == Direction.Forward)
                        {
                            currentstep += MICROSTEPS;
                        }
                        else
                        {
                            currentstep -= MICROSTEPS;
                        }
                    }
                    break;
                case StepStyle.Interleave:
                    if (dir == Direction.Forward)
                    {
                        currentstep += MICROSTEPS / 2;
                    }
                    else
                    {
                        currentstep -= MICROSTEPS / 2;
                    }
                    break;
            }

            //go to next 'step' and wrap around
            currentstep += MICROSTEPS * MICROSTEPS_PER_INTERLEAVE_STEP;
            currentstep %= MICROSTEPS * MICROSTEPS_PER_INTERLEAVE_STEP;

            this.driver.SetPwm(pwmA, 4096, 0);
            this.driver.SetPwm(pwmB, 4096, 0);

            //set up coil energizing!
            bool[][] step2coils = {
                new bool[]{true,    false,  false,  false },
                new bool[]{true,    true,   false,  false },
                new bool[]{false,   true,   false,  false },
                new bool[]{false,   true,   true,   false },
                new bool[]{false,   false,  true,   false },
                new bool[]{false,   false,  true,   true },
                new bool[]{ false,  false,  false,  true },
                new bool[]{ true,   false,  false,  true }
            };

            var coils = step2coils[currentstep / MICROSTEPS_PER_INTERLEAVE_STEP];

            // print "coils state = " + str(coils)
            driver.SetPin(ain2, coils[0]);
            driver.SetPin(bin1, coils[1]);
            driver.SetPin(ain1, coils[2]);
            driver.SetPin(bin2, coils[3]);

            return currentstep;
        }
示例#4
0
        public void Step(int steps, Direction direction, StepStyle stepstyle)
        {
            var s_per_s = (int)(secPerStep * 1000);

            if (stepstyle == StepStyle.Interleave)
            {
                s_per_s = s_per_s / 2;
            }

            //this.logger.WriteLn(String.Format("{0} millisec per step", s_per_s));

            for (var s = 0; s < steps; s++)
            {
                this.OneStep(direction, stepstyle);
                syncDelay.Sleep(5);
            }
        }