示例#1
0
        public void MoveZRail(PrinterControl.StepperDir dir, int steps)
        {
            double secondsElapsed = 1;
            double waitCounter    = 0;
            double waitTime;

            for (int i = 0; i < steps; i++)
            {
                waitTime = (1 / (secondsElapsed * 4 * 400)) * 1000000;

                if (waitTime < 70)
                {
                    waitTime = 70;
                }

                printer.StepStepper(dir);

                printer.WaitMicroseconds((long)waitTime);

                waitCounter += (int)waitTime;

                if (waitCounter >= 1000000)
                {
                    secondsElapsed += 1;
                    waitCounter     = 0;
                }
            }
        }
示例#2
0
 public void MoveZrail(float millimeters, PrinterControl.StepperDir direction)
 {
     if (millimeters > 0)
     {
         var stepsToStep  = Convert.ToInt32(millimeters * 400);
         var delay        = 0;
         var totalDelay   = 0;
         var stepperSpeed = 1;
         for (int i = 0; i != stepsToStep; i++)
         {
             totalDelay += delay;
             if (totalDelay >= 1100000)
             {
                 stepperSpeed = IncreaseStepperSpeed(stepperSpeed);
                 totalDelay   = 0;
             }
             delay = CalculateStepperDelay(stepperSpeed);
             printer.WaitMicroseconds(delay);
             printer.StepStepper(direction);
         }
     }
 }
示例#3
0
        public void StepOnce(PrinterControl.StepperDir dir)
        {
            // ResetSteps() must be called as soon as you are done using this function
            waitTimeOnce = (1 / (secondsElapsedOnce * 4 * 400)) * 1000000;

            if (waitTimeOnce < 70)
            {
                waitTimeOnce = 70;
            }

            printer.StepStepper(dir);

            printer.WaitMicroseconds((long)waitTimeOnce);

            waitCounterOnce += waitTimeOnce;

            if (waitCounterOnce >= 1000000)
            {
                secondsElapsedOnce += 1;
                waitCounterOnce     = 0;
            }
        }
        // Set the Z height of the platform - Zero is at the bottom, against the resin tray
        void SetZ(float Z)
        {
            if (plateZ < 0)
            {
                RetractPlate();
            }

            float curZ = plateZ;

            PrinterControl.StepperDir dir = PrinterControl.StepperDir.STEP_UP;
            float diffZ = Z - curZ;

            ResetAccelStepper();

            if (diffZ < 0)
            {
                dir = PrinterControl.StepperDir.STEP_DOWN;
            }

            diffZ = Math.Abs(diffZ);
            int numSteps = (int)(diffZ * PrinterControl.STEPS_PER_MM);

            for (int i = 0; i < numSteps; i++)
            {
                printer.StepStepper(dir);

                WaitForNextStep();

                if (printer.LimitSwitchPressed())
                {
                    break;
                }
            }

            plateZ = Z;
        }
示例#5
0
        public void movementWithSpeed(PrinterControl printer, PrinterControl.StepperDir dir, float distance)
        {
            float velocity         = 0;
            float distanceTraveled = 0;

            while (currentLocation == -1 && !(printer.LimitSwitchPressed()))
            {
                velocity += Acceleration;
                //Thread.Sleep(1000);
                for (var i = 0; i < velocity; i++)
                {
                    for (var j = 0; j < 400; j++)
                    {
                        if (printer.LimitSwitchPressed())
                        {
                            break;
                        }
                        printer.StepStepper(dir);
                        distanceTraveled += (float)(1.0 / 400);
                    }
                    if (printer.LimitSwitchPressed())
                    {
                        break;
                    }
                }

                //printer.StepStepper(dir);
            }
            if (((dir == PrinterControl.StepperDir.STEP_DOWN) && (currentLocation - distance > 0) && (!printer.LimitSwitchPressed() || (currentLocation != -1))))
            {
                while (distanceTraveled < distance)
                {
                    if (velocity < maxVelocity && (velocity + Acceleration < maxVelocity))
                    {
                        velocity += Acceleration;
                    }
                    else if (velocity < maxVelocity && (maxVelocity - velocity < Acceleration)) //allows us to reach max velocity without overshooting
                    {
                        velocity = maxVelocity;
                    }
                    //Thread.Sleep(1000);
                    for (var i = 0; i < velocity; i++)
                    {
                        for (var j = 0; j < 400; j++)
                        {
                            if (distanceTraveled >= distance || (printer.LimitSwitchPressed() && (currentLocation == -1)))
                            {
                                break;
                            }
                            printer.StepStepper(dir);
                            distanceTraveled += (float)(1.0 / 400);
                        }
                        if (distanceTraveled >= distance || printer.LimitSwitchPressed())
                        {
                            break;
                        }
                    }/*
                      * if (distanceTraveled + velocity < distance) //if we wont over shoot
                      * {
                      * distanceTraveled += velocity;
                      * }
                      * else //this happens if we're close but the velocity will over shoot it should move the rest of the way without overshooting
                      * {
                      * //distanceTraveled += (velocity - distance);
                      * velocity = 0;
                      * }
                      */
                }
                currentLocation -= distanceTraveled;
            }
            if ((dir == PrinterControl.StepperDir.STEP_UP) && currentLocation + distance < 100 && !printer.LimitSwitchPressed())
            {
                while (distanceTraveled < distance)
                {
                    if (velocity < maxVelocity && (velocity + Acceleration < maxVelocity))
                    {
                        velocity += Acceleration;
                    }
                    else if (velocity < maxVelocity && (maxVelocity - velocity < Acceleration))
                    {
                        velocity = maxVelocity;
                    }
                    // Thread.Sleep(1000);
                    for (var i = 0; i < velocity; i++)
                    {
                        for (var j = 0; j < 400; j++)
                        {
                            if (distanceTraveled >= distance || printer.LimitSwitchPressed())
                            {
                                break;
                            }
                            printer.StepStepper(dir);
                            distanceTraveled += (float)(1.0 / 400);
                        }
                        if (distanceTraveled >= distance || printer.LimitSwitchPressed())
                        {
                            break;
                        }
                    }
                }
                currentLocation += distanceTraveled;
            }
        }