Ejemplo n.º 1
0
        /// <summary>
        /// Returns a string of converted g-code for Valve Printhead printing with continuous Axis movement.
        /// </summary>
        /// <param name="xmmPerStep"></param>
        /// <param name="ymmPerStep"></param>
        /// <param name="zmmPerStep"></param>
        /// <param name="xDistance"></param>
        /// <param name="yDistance"></param>
        /// <param name="zDistance"></param>
        /// <param name="xInvertDirection"></param>
        /// <param name="yInvertDirection"></param>
        /// <param name="zInvertDirection"></param>
        /// <param name="xRemainder"></param>
        /// <param name="yRemainder"></param>
        /// <param name="zRemainder"></param>
        /// <returns></returns>
        public static List <ConvertedGCodeLine> WriteValveContinuousPrint(double xmmPerStep, double ymmPerStep, double zmmPerStep,
                                                                          double xDistance, double yDistance, double zDistance,
                                                                          bool xInvertDirection, bool yInvertDirection, bool zInvertDirection,
                                                                          ref double xRemainder, ref double yRemainder, ref double zRemainder)
        {
            //The return GCode.
            List <ConvertedGCodeLine> convertedGCodeLinesList = new List <ConvertedGCodeLine>();

            if (((xDistance) != 0) || ((yDistance) != 0) || ((zDistance) != 0))
            {
                string convertedGCodeLine = SerialCommands.ValvePrintWithMovement;

                //Calculate the number of steps for each axis.
                //If steps == 0, then do not print a command for that axis.
                convertedGCodeLine += G00Calculator.WriteSteps('X', xDistance, xmmPerStep, xInvertDirection, ref xRemainder);
                convertedGCodeLine += G00Calculator.WriteSteps('Y', yDistance, ymmPerStep, yInvertDirection, ref yRemainder);
                convertedGCodeLine += G00Calculator.WriteSteps('Z', zDistance, zmmPerStep, zInvertDirection, ref zRemainder);

                //Catch the corner case where there is movement that is less than one step.
                if (convertedGCodeLine != SerialCommands.ValvePrintWithMovement)
                {
                    convertedGCodeLinesList.Add(new ConvertedGCodeLine(convertedGCodeLine));
                }
                return(convertedGCodeLinesList);
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a string of converted GCode for Motorized Printhead printing with continuous Axis movement.
        /// </summary>
        /// <param name="xmmPerStep"></param>
        /// <param name="ymmPerStep"></param>
        /// <param name="zmmPerStep"></param>
        /// <param name="xDistance"></param>
        /// <param name="yDistance"></param>
        /// <param name="zDistance"></param>
        /// <param name="xInvertDirection"></param>
        /// <param name="yInvertDirection"></param>
        /// <param name="zInvertDirection"></param>
        /// <param name="xRemainder"></param>
        /// <param name="yRemainder"></param>
        /// <param name="zRemainder"></param>
        /// <returns></returns>
        public static List <ConvertedGCodeLine> WriteAxesMovement(
            double xmmPerStep, double ymmPerStep, double zmmPerStep,
            double xDistance, double yDistance, double zDistance,
            bool xInvertDirection, bool yInvertDirection, bool zInvertDirection,
            ref double xRemainder, ref double yRemainder, ref double zRemainder)
        {
            //The return GCode.
            List <ConvertedGCodeLine> convertedGCodeLinesList = new List <ConvertedGCodeLine>();
            string convertedGCodeLine = "";

            if (((xDistance) != 0) || ((yDistance) != 0) || ((zDistance) != 0))
            {
                convertedGCodeLine += SerialCommands.AxesMovement;

                //Output commands that will be sent through the serial port.
                convertedGCodeLine += G00Calculator.WriteSteps('X', xDistance, xmmPerStep, xInvertDirection, ref xRemainder);
                convertedGCodeLine += G00Calculator.WriteSteps('Y', yDistance, ymmPerStep, yInvertDirection, ref yRemainder);
                convertedGCodeLine += G00Calculator.WriteSteps('Z', zDistance, zmmPerStep, zInvertDirection, ref zRemainder);
            }

            if (convertedGCodeLine != SerialCommands.AxesMovement) //If there are steps to take...
            {
                convertedGCodeLinesList.Add(new ConvertedGCodeLine(convertedGCodeLine));
                return(convertedGCodeLinesList);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a converted g-code line for a motorized print without movement.
        /// </summary>
        /// <param name="eDistance"></param>
        /// <param name="emmPerStep"></param>
        /// <param name="invertDirection"></param>
        /// <param name="eRemainder"></param>
        /// <returns></returns>
        public static List <ConvertedGCodeLine> WriteMotorizedPrintWithoutMovement(double eDistance, double emmPerStep, bool invertDirection, ref double eRemainder, CoordinateModel eModiPrintCoord)
        {
            //The return GCode.
            List <ConvertedGCodeLine> convertedGCodeLinesList = new List <ConvertedGCodeLine>();

            if (eDistance != 0)
            {
                string printLine = SerialCommands.MotorPrintWithoutMovement;
                printLine += G00Calculator.WriteSteps('E', eDistance, emmPerStep, invertDirection, ref eRemainder);

                //EModiPrintCoord can be passed into this method as a null object if this step is not required.
                if (eModiPrintCoord != null)
                {
                    eModiPrintCoord.SetCoord(eDistance, false);
                }

                convertedGCodeLinesList.Add(new ConvertedGCodeLine(printLine));
                return(convertedGCodeLinesList);
            }

            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a string of converted g-code for Motorized Printhead printing with continuous Axis movement.
        /// </summary>
        /// <param name="emmPerStep"></param>
        /// <param name="xmmPerStep"></param>
        /// <param name="ymmPerStep"></param>
        /// <param name="zmmPerStep"></param>
        /// <param name="eDistancePerMmMovement"></param>
        /// <param name="xDistance"></param>
        /// <param name="yDistance"></param>
        /// <param name="zDistance"></param>
        /// <param name="eInvertDirection"></param>
        /// <param name="xInvertDirection"></param>
        /// <param name="yInvertDirection"></param>
        /// <param name="zInvertDirection"></param>
        /// <param name="eRemainder"></param>
        /// <param name="xRemainder"></param>
        /// <param name="yRemainder"></param>
        /// <param name="zRemainder"></param>
        /// <param name="eModiPrintCoord"></param>
        /// <returns></returns>
        public static List <ConvertedGCodeLine> WriteMotorizedContinuousPrint(
            double emmPerStep, double xmmPerStep, double ymmPerStep, double zmmPerStep,
            double eDistancePerMmMovement, double xDistance, double yDistance, double zDistance,
            bool eInvertDirection, bool xInvertDirection, bool yInvertDirection, bool zInvertDirection,
            ref double eRemainder, ref double xRemainder, ref double yRemainder, ref double zRemainder,
            CoordinateModel eModiPrintCoord)
        {
            //The return GCode.
            List <ConvertedGCodeLine> convertedGCodeLinesList = new List <ConvertedGCodeLine>();

            if (((eDistancePerMmMovement) != 0) || ((xDistance) != 0) || ((yDistance) != 0) || ((zDistance) != 0))
            {
                string convertedGCodeLine = "";
                convertedGCodeLine += SerialCommands.MotorPrintWithMovement;

                //Calculate the distance that the Printhead's motor will move.
                double movementDistance = Math.Sqrt(xDistance * xDistance + yDistance * yDistance + zDistance * zDistance);
                double eDistance        = eDistancePerMmMovement * movementDistance;

                //Output commands that will be sent through the serial port.
                convertedGCodeLine += G00Calculator.WriteSteps('X', xDistance, xmmPerStep, xInvertDirection, ref xRemainder);
                convertedGCodeLine += G00Calculator.WriteSteps('Y', yDistance, ymmPerStep, yInvertDirection, ref yRemainder);
                convertedGCodeLine += G00Calculator.WriteSteps('Z', zDistance, zmmPerStep, zInvertDirection, ref zRemainder);
                convertedGCodeLine += G00Calculator.WriteSteps('E', eDistance, emmPerStep, eInvertDirection, ref eRemainder);

                //EModiPrintCoord can be passed into this method as a null object if this step is not required.
                if (eModiPrintCoord != null)
                {
                    eModiPrintCoord.SetCoord(eDistance, false);
                }

                convertedGCodeLinesList.Add(new ConvertedGCodeLine(convertedGCodeLine));
                return(convertedGCodeLinesList);
            }

            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns a list of relative positions that should be droplet printed.
        /// Positions are relative and in units of mm.
        /// Movement by relative PreDistance values should be executed before droplet printing.
        /// PreDistance values should be an array of 3 where the XPreDistance value is in the 0th index, Y in 1st, Z in 2nd.
        /// If return value or PreDistances are null, then no printing or movement is required.
        /// </summary>
        /// <param name="xDistance"></param>
        /// <param name="yDistance"></param>
        /// <param name="zDistance"></param>
        /// <returns></returns>
        public List <double[]> PrintPosition(double xDistance, double yDistance, double zDistance)
        {
            //All position values in this function are relative to the starting point of movements.
            //Rounding is used here to prevent errors incurred from using floating point values.

            xDistance = Math.Round(xDistance, 8);
            yDistance = Math.Round(yDistance, 8);
            zDistance = Math.Round(zDistance, 8);

            double          distanceToPrint    = Math.Round(_interpolateDistance - _distanceTravelled, 8);                        //Distance until the next droplet in mm.
            double          movementDistance   = Math.Round(G00Calculator.CalculateDistance(xDistance, yDistance, zDistance), 8); //Total distance travelled in this movement.
            List <double[]> printDistancesList = new List <double[]>();                                                           //Relative coordinates to print in units of mm.

            //Is this the first droplet?
            //If so, then a droplet needs to be deposited at the beginning of the first movement.
            if (_firstDroplet == true)
            {
                double[] printCoord = new double[3];
                printCoord[0] = printCoord[1] = printCoord[2] = 0;

                printDistancesList.Add(printCoord);

                _firstDroplet = false;
            }

            //Movement is too short for the interpolation.
            //No print happens.
            if (distanceToPrint > movementDistance)
            {
                _distanceTravelled += movementDistance;
                _preDistance[0]    += xDistance;
                _preDistance[1]    += yDistance;
                _preDistance[2]    += zDistance;
                return(null);
            }
            //Movement is exactly the length needed for the next droplet.
            //The print happens at the end of the movement.
            else if (distanceToPrint == movementDistance)
            {
                _distanceTravelled = 0;

                double[] printCoord = new double[3];
                printCoord[0] = _preDistance[0] + xDistance;
                printCoord[1] = _preDistance[1] + yDistance;
                printCoord[2] = _preDistance[2] + zDistance;

                _preDistance[0] = _preDistance[1] = _preDistance[2] = 0;

                printDistancesList.Add(printCoord);
                return(printDistancesList);
            }
            //Movement is longer than the length needed for the next droplet.
            //One or multiple prints happen in the middle of the movement.
            else if (distanceToPrint < movementDistance)
            {
                double percentMovementTravelled = 0; //Percentage of the movement that needs to be traversed until the next droplet.
                double xPrintPosition           = 0; //Last position printed at.
                double yPrintPosition           = 0;
                double zPrintPosition           = 0;

                for (percentMovementTravelled = Math.Abs(distanceToPrint / movementDistance);
                     Math.Round(percentMovementTravelled, 8) <= 1;
                     percentMovementTravelled += (_interpolateDistance / movementDistance))
                {
                    xPrintPosition = percentMovementTravelled * xDistance;
                    yPrintPosition = percentMovementTravelled * yDistance;
                    zPrintPosition = percentMovementTravelled * zDistance;

                    double[] printCoord = { xPrintPosition + _preDistance[0], yPrintPosition + _preDistance[1], zPrintPosition + _preDistance[2] };
                    printDistancesList.Add(printCoord);
                }

                _preDistance[0]    = xDistance - xPrintPosition;
                _preDistance[1]    = yDistance - yPrintPosition;
                _preDistance[2]    = zDistance - zPrintPosition;
                _distanceTravelled = G00Calculator.CalculateDistance(_preDistance[0], _preDistance[1], _preDistance[2]);
                return(printDistancesList);
            }

            //Should not reach this point.
            return(null);
        }