コード例 #1
0
        /// <summary>
        /// Takes manual input parameters for a set axis command and outputs the command to the serial port.
        /// </summary>
        /// <param name="axisName"></param>
        /// <param name="maxSpeed"></param>
        /// <param name="acceleration"></param>
        public void ProcessManualSetAxisCommand(string axisName, double maxSpeed, double acceleration)
        {
            try
            {
                List <string> outgoingMessagesList = new List <string>();

                AxisModel axisModel = _printerModel.FindAxis(axisName);

                int limitPinID = (axisModel.AttachedLimitSwitchGPIOPinModel == null) ? GlobalValues.PinIDNull : axisModel.AttachedLimitSwitchGPIOPinModel.PinID;

                string setAxisString = _writeSetAxisModel.WriteSetAxis(axisModel.AxisID, axisModel.AttachedMotorStepGPIOPinModel.PinID, axisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                                       axisModel.StepPulseTime, limitPinID, maxSpeed, acceleration, axisModel.MmPerStep);

                //If switching Z Axes, then retract the current Z Axis first.
                if (axisModel.AxisID == 'Z')
                {
                    outgoingMessagesList.Add(SerialMessageCharacters.SerialCommandSetCharacter + "RetractZ");
                }

                outgoingMessagesList.Add(setAxisString);

                _serialCommunicationOutgoingMessagesModel.QueueNextProspectiveOutgoingMessage(outgoingMessagesList);
            }
            catch (NullReferenceException e)
            {
                _errorListViewModel.AddError("", "Actuator needs to be set in Printer Settings before setting the actuator in Control Menu.");
            }
            catch
            {
                _errorListViewModel.AddError("", "Unknown error while setting valve printhead.");
            }
        }
        /// <summary>
        /// Interpret a switch material command set and return an array of commands.
        /// </summary>
        /// <param name="commandSet"></param>
        /// <returns></returns>
        private List <string> InterpretSwitchMaterial(string commandSet)
        {
            //Remove "*SwitchMaterial" from the beginning of the command set.
            commandSet = commandSet.Substring(14);

            //Potentially pause before deactivating the current printhead.
            bool pauseBeforeDeactivating = false;

            if (commandSet.Contains('D'))
            {
                pauseBeforeDeactivating = true;
            }

            //Potentially pause after activating the next printhead.
            bool pauseBeforeActivating = false;

            if (commandSet.Contains('A'))
            {
                pauseBeforeActivating = true;
            }

            //Set of commands to be returned at the end of this method.
            List <string> returnCommands = new List <string>();

            //The name of the Material which will be switched to will be between quote characters.
            int           firstNameIndex = commandSet.IndexOf('"');
            int           nameLength     = commandSet.Substring(firstNameIndex + 1).IndexOf('"');
            string        materialName   = commandSet.Substring(firstNameIndex + 1, nameLength);
            MaterialModel materialModel  = _printModel.FindMaterialByName(materialName);

            if (materialModel == null)
            {
                _errorListViewModel.AddError("Command Set Invalid", materialName + " Not Set");
                return(null);
            }

            //References to the current and new Printheads.
            PrintheadModel currentPrintheadModel = _printerModel.FindPrinthead(_realTimeStatusDataModel.ActivePrintheadModel.Name);
            PrintheadModel newPrintheadModel     = materialModel.PrintheadModel;

            //References to the Z Axis on the current Printhead.
            AxisModel currentZAxisModel  = _printerModel.FindAxis(currentPrintheadModel.AttachedZAxisModel.Name);
            int       currentZLimitPinID = (currentZAxisModel.AttachedLimitSwitchGPIOPinModel != null) ? currentZAxisModel.AttachedLimitSwitchGPIOPinModel.PinID : GlobalValues.PinIDNull;

            //References to the XY Axes and new Z Axis.
            AxisModel xAxisModel  = _printerModel.AxisModelList[0];
            int       xLimitPinID = (xAxisModel.AttachedLimitSwitchGPIOPinModel != null) ? xAxisModel.AttachedLimitSwitchGPIOPinModel.PinID : GlobalValues.PinIDNull;
            AxisModel yAxisModel  = _printerModel.AxisModelList[1];
            int       yLimitPinID = (yAxisModel.AttachedLimitSwitchGPIOPinModel != null) ? yAxisModel.AttachedLimitSwitchGPIOPinModel.PinID : GlobalValues.PinIDNull;
            AxisModel zAxisModel  = _printerModel.FindAxis(newPrintheadModel.AttachedZAxisModel.Name);
            int       zLimitPinID = (zAxisModel.AttachedLimitSwitchGPIOPinModel != null) ? zAxisModel.AttachedLimitSwitchGPIOPinModel.PinID : GlobalValues.PinIDNull;

            //If a new Printhead is required...
            if (newPrintheadModel.Name != currentPrintheadModel.Name)
            {
                //1. Set previous Z Axis at max speeds.
                //2. Retract the previous Printhead / Z Axis.
                returnCommands.Add(_writeSetAxisModel.WriteSetAxis('Z', currentZAxisModel.AttachedMotorStepGPIOPinModel.PinID, currentZAxisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                                   currentZAxisModel.StepPulseTime, currentZLimitPinID, currentZAxisModel.MaxSpeed, currentZAxisModel.MaxAcceleration, currentZAxisModel.MmPerStep));
                List <string> retractZ = RetractZ("", currentPrintheadModel.AttachedZAxisModel);
                foreach (string command in retractZ)
                {
                    if (!String.IsNullOrWhiteSpace(command))
                    {
                        returnCommands.Add(command);
                    }
                }

                //Pause before deactivating.
                if (pauseBeforeDeactivating == true)
                {
                    returnCommands.Add(SerialMessageCharacters.SerialPrintPauseCharacter.ToString());
                }

                //3. Set new XYZ to max speeds and move to the new Offset.
                //Set associated X Axis at max speeds.
                returnCommands.Add(_writeSetAxisModel.WriteSetAxis('X', xAxisModel.AttachedMotorStepGPIOPinModel.PinID, xAxisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                                   xAxisModel.StepPulseTime, xLimitPinID, xAxisModel.MaxSpeed, xAxisModel.MaxAcceleration, xAxisModel.MmPerStep));
                //Set associated Y Axis at max speeds.
                returnCommands.Add(_writeSetAxisModel.WriteSetAxis('Y', yAxisModel.AttachedMotorStepGPIOPinModel.PinID, yAxisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                                   yAxisModel.StepPulseTime, yLimitPinID, yAxisModel.MaxSpeed, yAxisModel.MaxAcceleration, yAxisModel.MmPerStep));
                //Set associated Z Axis at max speeds.
                returnCommands.Add(_writeSetAxisModel.WriteSetAxis('Z', zAxisModel.AttachedMotorStepGPIOPinModel.PinID, zAxisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                                   zAxisModel.StepPulseTime, zLimitPinID, zAxisModel.MaxSpeed, zAxisModel.MaxAcceleration, zAxisModel.MmPerStep));
                //4.Move to the new Offset at max speeds.
                double        zPosition    = _realTimeStatusDataModel.ZRealTimeStatusAxisModel.Position;
                List <string> moveToOffset = WriteMoveToOffset(newPrintheadModel, currentPrintheadModel, zPosition, pauseBeforeActivating);
                foreach (string command in moveToOffset)
                {
                    if (!String.IsNullOrWhiteSpace(command))
                    {
                        returnCommands.Add(command);
                    }
                }
            }

            //5.Set the print speed parameters for the new Material.
            //Set associated X Axis at print speeds.
            returnCommands.Add(_writeSetAxisModel.WriteSetAxis('X', xAxisModel.AttachedMotorStepGPIOPinModel.PinID, xAxisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                               xAxisModel.StepPulseTime, xLimitPinID, materialModel.XYPrintSpeed, materialModel.XYPrintAcceleration, xAxisModel.MmPerStep));
            //Set associated Y Axis at print speeds.
            returnCommands.Add(_writeSetAxisModel.WriteSetAxis('Y', yAxisModel.AttachedMotorStepGPIOPinModel.PinID, yAxisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                               yAxisModel.StepPulseTime, yLimitPinID, materialModel.XYPrintSpeed, materialModel.XYPrintAcceleration, yAxisModel.MmPerStep));
            //Set associated Z Axis at print speeds.
            returnCommands.Add(_writeSetAxisModel.WriteSetAxis('Z', zAxisModel.AttachedMotorStepGPIOPinModel.PinID, zAxisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                               zAxisModel.StepPulseTime, zLimitPinID, materialModel.ZPrintSpeed, materialModel.ZPrintAcceleration, zAxisModel.MmPerStep));

            //6. Set the new Printhead at print speeds.
            string setNewPrinthead = _setWritePrintheadModel.SetWritePrinthead(newPrintheadModel);

            returnCommands.Add(setNewPrinthead);

            return(returnCommands);
        }
コード例 #3
0
        /// <summary>
        /// Sends outgoing commands that retracts all Z Axes and moves X and Y Axes to the limit switches.
        /// </summary>
        public void Home(double xCalibrationSpeed, double yCalibrationSpeed, double zCalibrationSpeed, double xDistanceFromCenter, double yDistanceFromCenter)
        {
            try
            {
                //Retract Z Axes.
                RetractAllZ(zCalibrationSpeed);

                //Z Axes should be in default positions.
                AxisModel zAxisModel = _printerModel.ZAxisModelList[_printerModel.ZAxisModelList.Count - 1];
                double    zPosition  = zAxisModel.MaxPosition - GlobalValues.LimitBuffer;
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(SerialMessageCharacters.SerialCommandSetCharacter + "SetMinMaxPos " + "Z" + zPosition);

                //Set X Axis to calibration speeds.
                AxisModel xAxis       = _printerModel.AxisModelList[0];
                int       xLimitPinID = (xAxis.AttachedLimitSwitchGPIOPinModel == null) ? GlobalValues.PinIDNull : xAxis.AttachedLimitSwitchGPIOPinModel.PinID;
                string    switchX     = _writeSetAxisModel.WriteSetAxis(xAxis.AxisID, xAxis.AttachedMotorStepGPIOPinModel.PinID, xAxis.AttachedMotorDirectionGPIOPinModel.PinID, xAxis.StepPulseTime,
                                                                        xLimitPinID, xCalibrationSpeed, xAxis.MaxAcceleration, xAxis.MmPerStep);
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(switchX);

                //Set Y Axis to max speeds.
                AxisModel yAxis       = _printerModel.AxisModelList[1];
                int       yLimitPinID = (yAxis.AttachedLimitSwitchGPIOPinModel == null) ? GlobalValues.PinIDNull : yAxis.AttachedLimitSwitchGPIOPinModel.PinID;
                string    switchY     = _writeSetAxisModel.WriteSetAxis(yAxis.AxisID, yAxis.AttachedMotorStepGPIOPinModel.PinID, yAxis.AttachedMotorDirectionGPIOPinModel.PinID, yAxis.StepPulseTime,
                                                                        yLimitPinID, yCalibrationSpeed, yAxis.MaxAcceleration, yAxis.MmPerStep);
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(switchY);

                //Hit the min and max limit switches on X.
                double unused    = 0;
                string xPositive = GCodeLinesConverter.GCodeLinesListToString(
                    WriteG00.WriteAxesMovement(
                        xAxis.MmPerStep, 0, 0,
                        5000, 0, 0,
                        xAxis.IsDirectionInverted, false, false,
                        ref unused, ref unused, ref unused));
                string xNegative = GCodeLinesConverter.GCodeLinesListToString(
                    WriteG00.WriteAxesMovement(
                        xAxis.MmPerStep, 0, 0,
                        -5000, 0, 0,
                        xAxis.IsDirectionInverted, false, false,
                        ref unused, ref unused, ref unused));
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(xPositive);
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(xNegative);

                //Move away from the limit switch.
                string xMoveAwayFromLimit = GCodeLinesConverter.GCodeLinesListToString(
                    WriteG00.WriteAxesMovement(
                        xAxis.MmPerStep, 0, 0,
                        GlobalValues.LimitBuffer, 0, 0,
                        xAxis.IsDirectionInverted, false, false,
                        ref unused, ref unused, ref unused));
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(xMoveAwayFromLimit);

                //Hit the min and max limit switches on Y.
                string yPositive = GCodeLinesConverter.GCodeLinesListToString(
                    WriteG00.WriteAxesMovement(
                        0, yAxis.MmPerStep, 0,
                        0, 5000, 0,
                        yAxis.IsDirectionInverted, false, false,
                        ref unused, ref unused, ref unused));
                string yNegative = GCodeLinesConverter.GCodeLinesListToString(
                    WriteG00.WriteAxesMovement(
                        0, yAxis.MmPerStep, 0,
                        0, -5000, 0,
                        yAxis.IsDirectionInverted, false, false,
                        ref unused, ref unused, ref unused));
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(yPositive);
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(yNegative);

                //Move away from the limit switch.
                string yMoveAwayFromLimit = GCodeLinesConverter.GCodeLinesListToString(
                    WriteG00.WriteAxesMovement(
                        0, yAxis.MmPerStep, 0,
                        0, GlobalValues.LimitBuffer, 0,
                        yAxis.IsDirectionInverted, false, false,
                        ref unused, ref unused, ref unused));
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(yMoveAwayFromLimit);

                //Set X Axis to max speeds.
                string switchXMax = _writeSetAxisModel.WriteSetAxis(xAxis);
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(switchXMax);

                //Set Y Axis to max speeds.
                string switchYMax = _writeSetAxisModel.WriteSetAxis(yAxis);
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(switchYMax);

                //Center the X and Y actuators.
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(SerialMessageCharacters.SerialCommandSetCharacter + "Center X" + xDistanceFromCenter + " Y" + yDistanceFromCenter);
                _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(SerialMessageCharacters.SerialCommandSetCharacter + "OriginXY");

                //At the end, switch the Z actuator to the Printhead used at the beginning of the print.
                if (_realTimeStatusDataModel.ZRealTimeStatusAxisModel.Name != "Unset")
                {
                    AxisModel zAxisFinalModel  = _printerModel.FindAxis(_realTimeStatusDataModel.ZRealTimeStatusAxisModel.Name);
                    int       zFinalLimitPinID = (zAxisFinalModel.AttachedLimitSwitchGPIOPinModel == null) ? GlobalValues.PinIDNull : zAxisFinalModel.AttachedLimitSwitchGPIOPinModel.PinID;
                    string    switchZFinal     = _writeSetAxisModel.WriteSetAxis(zAxisFinalModel.AxisID, zAxisFinalModel.AttachedMotorStepGPIOPinModel.PinID, zAxisFinalModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                                                 zAxisFinalModel.StepPulseTime, zFinalLimitPinID, zCalibrationSpeed, zAxisFinalModel.MaxAcceleration, zAxisFinalModel.MmPerStep);
                    _serialCommunicationOutgoingMessagesModel.AppendProspectiveOutgoingMessage(switchZFinal);
                }

                OnCalibrationBegun();
            }
            catch
            {
                _errorListViewModel.AddError("", "Unkown error when homing");
            }
        }