/// <summary>
        /// Takes manual input parameters for a set of commands for motorized printhead droplet printing and outputs the commands to the serial port.
        /// </summary>
        /// <param name="xDistance"></param>
        /// <param name="yDistance"></param>
        /// <param name="zDistance"></param>
        /// <param name="interpolateDistance"></param>
        /// <param name="eDispensePerDroplet"></param>
        public void ProcessManualMotorDropletPrintCommand(double xDistance, double yDistance, double zDistance, double interpolateDistance, double eDispensePerDroplet)
        {
            PrintheadModel printheadModel = _printerModel.FindPrinthead(_realTimeStatusDataModel.ActivePrintheadModel.Name);
            MotorizedPrintheadTypeModel motorizedPrintheadTypeModel = (MotorizedPrintheadTypeModel)printheadModel.PrintheadTypeModel;
            double emmPerStep = motorizedPrintheadTypeModel.MmPerStep;
            RealTimeStatusMotorizedPrintheadModel realTimeStatusMotorizedPrintheadModel = (RealTimeStatusMotorizedPrintheadModel)_realTimeStatusDataModel.ActivePrintheadModel;
            double    eMaxSpeed          = realTimeStatusMotorizedPrintheadModel.MaxSpeed;
            double    eAcceleration      = realTimeStatusMotorizedPrintheadModel.Acceleration;
            double    xmmPerStep         = (xDistance != 0) ? _printerModel.AxisModelList[0].MmPerStep : double.MaxValue;
            double    ymmPerStep         = (yDistance != 0) ? _printerModel.AxisModelList[1].MmPerStep : double.MaxValue;
            AxisModel zAxisModel         = _printerModel.FindAxis(_realTimeStatusDataModel.ZRealTimeStatusAxisModel.Name);
            double    zmmPerStep         = (zDistance != 0) ? _printerModel.FindAxis(zAxisModel.Name).MmPerStep : double.MaxValue;
            bool      zDirectionInverted = (zAxisModel != null) ? zAxisModel.IsDirectionInverted : false;

            double unused      = 0;
            string printString = GCodeLinesConverter.GCodeLinesListToString(
                WriteG00.WriteMotorizedDropletPrint(
                    emmPerStep, xmmPerStep, ymmPerStep, zmmPerStep,
                    eDispensePerDroplet, 0, xDistance, 0, yDistance, 0, zDistance,
                    _printerModel.AxisModelList[0].IsDirectionInverted, _printerModel.AxisModelList[1].IsDirectionInverted, zDirectionInverted, motorizedPrintheadTypeModel.IsDirectionInverted,
                    ref unused, ref unused, ref unused, ref unused,
                    null, new DropletModel(interpolateDistance)));

            _serialCommunicationOutgoingMessagesModel.QueueNextProspectiveOutgoingMessage(printString);
        }
Exemple #2
0
        public RealTimeStatusMotorizedPrintheadViewModel(RealTimeStatusMotorizedPrintheadModel RealTimeStatusMotorizedPrintheadModel) : base(RealTimeStatusMotorizedPrintheadModel)
        {
            _realTimeStatusMotorizedPrintheadModel = RealTimeStatusMotorizedPrintheadModel;
            base._imageSource = "/Resources/General/ValvePrinthead.png";

            UpdateProperties();
        }
        /// <summary>
        /// Set the new center as the origin (position 0) and adjust the max and min range around such.
        /// </summary>
        /// <param name="commandSet"></param>
        /// <returns></returns>
        private List <string> InterpretSetOrigin(string commandSet)
        {
            //Remove "*Origin" from the beginning of the string.
            commandSet = commandSet.Substring(6);

            if (commandSet.Contains("E"))
            {
                if (_realTimeStatusDataModel.ActivePrintheadType == PrintheadType.Motorized)
                {
                    RealTimeStatusMotorizedPrintheadModel realTimeStatusMotorizedPrintheadModel = (RealTimeStatusMotorizedPrintheadModel)_realTimeStatusDataModel.ActivePrintheadModel;
                    MotorizedPrintheadTypeModel           motorizedPrintheadTypeModel           = (MotorizedPrintheadTypeModel)_printerModel.FindPrinthead(realTimeStatusMotorizedPrintheadModel.Name).PrintheadTypeModel;

                    double previousEPosition = realTimeStatusMotorizedPrintheadModel.Position;

                    motorizedPrintheadTypeModel.MaxPosition       -= previousEPosition;
                    motorizedPrintheadTypeModel.MinPosition       -= previousEPosition;
                    realTimeStatusMotorizedPrintheadModel.Position = 0;
                }
            }

            if (commandSet.Contains("X"))
            {
                AxisModel xAxisModel = _printerModel.AxisModelList[0];

                double previousXPosition = _realTimeStatusDataModel.XRealTimeStatusAxisModel.Position;

                xAxisModel.MaxPosition -= previousXPosition;
                xAxisModel.MinPosition -= previousXPosition;
                _realTimeStatusDataModel.XRealTimeStatusAxisModel.Position = 0;
            }

            if (commandSet.Contains("Y"))
            {
                AxisModel yAxisModel = _printerModel.AxisModelList[1];

                double previousYPosition = _realTimeStatusDataModel.YRealTimeStatusAxisModel.Position;

                yAxisModel.MaxPosition -= previousYPosition;
                yAxisModel.MinPosition -= previousYPosition;
                _realTimeStatusDataModel.YRealTimeStatusAxisModel.Position = 0;
            }

            if (commandSet.Contains("Z"))
            {
                AxisModel zAxisModel = _printerModel.FindAxis(_realTimeStatusDataModel.ZRealTimeStatusAxisModel.Name);

                double previousZPosition = _realTimeStatusDataModel.ZRealTimeStatusAxisModel.Position;

                zAxisModel.MaxPosition -= previousZPosition;
                zAxisModel.MinPosition -= previousZPosition;
                _realTimeStatusDataModel.ZRealTimeStatusAxisModel.Position = 0;
            }

            OnCommandSetMinMaxPositionChanged();
            OnCommandSetMinMaxPositionChanged();

            //No commands to return.
            return(null);
        }
        /// <summary>
        /// Takes manual input parameters for a motor print without movement command and outputs the command to the serial port.
        /// </summary>
        /// <param name="eDistance"></param>
        public void ProcessManualMotorPrintWithoutMovementCommand(double eDistance)
        {
            MotorizedPrintheadTypeModel motorizedPrintheadTypeModel = (MotorizedPrintheadTypeModel)_printerModel.FindPrinthead(_realTimeStatusDataModel.ActivePrintheadModel.Name).PrintheadTypeModel;
            double emmPerStep = motorizedPrintheadTypeModel.MmPerStep;
            RealTimeStatusMotorizedPrintheadModel realTimeStatusMotorizedPrintheadModel = (RealTimeStatusMotorizedPrintheadModel)_realTimeStatusDataModel.ActivePrintheadModel;

            double unused      = 0;
            string printString = GCodeLinesConverter.GCodeLinesListToString(
                WriteG00.WriteMotorizedPrintWithoutMovement(eDistance, emmPerStep, motorizedPrintheadTypeModel.IsDirectionInverted, ref unused, null));

            _serialCommunicationOutgoingMessagesModel.QueueNextProspectiveOutgoingMessage(printString);
        }
        /// <summary>
        /// Record the parameters from a Motorized Printhead Print With Movement command.
        /// </summary>
        /// <param name="taskQueuedMessage"></param>
        /// <param name="eStepsTaken"></param>
        /// <param name="xStepsTaken"></param>
        /// <param name="yStepsTaken"></param>
        /// <param name="zStepsTaken"></param>
        public void RecordMotorizedPrintWithMovement(int eStepsTaken, int xStepsTaken, int yStepsTaken, int zStepsTaken)
        {
            if (_activePrintheadType == PrintheadType.Motorized)
            {
                MotorizedPrintheadTypeModel motorizedPrintheadTypeModel = (MotorizedPrintheadTypeModel)_printerModel.FindPrinthead(_activePrintheadModel.Name).PrintheadTypeModel;
                double emmPerStep = motorizedPrintheadTypeModel.MmPerStep;
                double xmmPerStep = _printerModel.AxisModelList[0].MmPerStep;
                double ymmPerStep = _printerModel.AxisModelList[1].MmPerStep;
                double zmmPerStep = _printerModel.FindAxis(_zRealTimeStatusAxisModel.Name).MmPerStep;

                //Record data.
                RealTimeStatusMotorizedPrintheadModel motorizedPrintheadModel = (RealTimeStatusMotorizedPrintheadModel)_activePrintheadModel;

                //Record positions.
                if (eStepsTaken != 0)
                {
                    motorizedPrintheadModel.Position         += (motorizedPrintheadTypeModel.IsDirectionInverted == false) ? (double)(eStepsTaken * emmPerStep) : (double)(eStepsTaken * -1 * emmPerStep);
                    motorizedPrintheadModel.LimitSwitchStatus = LimitSwitchStatus.NoLimit;
                }

                if (xStepsTaken != 0)
                {
                    _xRealTimeStatusAxisModel.Position         += (_printerModel.AxisModelList[0].IsDirectionInverted == false) ? (double)(xStepsTaken * xmmPerStep) : (double)(xStepsTaken * -1 * xmmPerStep);
                    _xRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.NoLimit;
                }

                if (yStepsTaken != 0)
                {
                    _yRealTimeStatusAxisModel.Position         += (_printerModel.AxisModelList[1].IsDirectionInverted == false) ? (double)(yStepsTaken * ymmPerStep) : (double)(yStepsTaken * -1 * ymmPerStep);
                    _yRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.NoLimit;
                }

                if (zStepsTaken != 0)
                {
                    _zRealTimeStatusAxisModel.Position         += (_printerModel.FindAxis(_zRealTimeStatusAxisModel.Name).IsDirectionInverted == false) ? (double)(zStepsTaken * zmmPerStep) : (double)(zStepsTaken * -1 * zmmPerStep);
                    _zRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.NoLimit;
                }

                //Notify other classes.
                OnRecordMotorizedPrintWithMovementExecuted();
            }
        }
        /// <summary>
        /// Record the parameters from a Motorized Printhead Print without Movement command.
        /// </summary>
        /// <param name="ePosition"></param>
        public void RecordMotorizedPrintWithoutMovement(double eStepsTaken)
        {
            if (_activePrintheadType == PrintheadType.Motorized)
            {
                MotorizedPrintheadTypeModel motorizedPrintheadTypeModel = (MotorizedPrintheadTypeModel)_printerModel.FindPrinthead(_activePrintheadModel.Name).PrintheadTypeModel;
                double emmPerStep = motorizedPrintheadTypeModel.MmPerStep;

                //Record data.
                RealTimeStatusMotorizedPrintheadModel motorizedPrintheadModel = (RealTimeStatusMotorizedPrintheadModel)_activePrintheadModel;

                if (eStepsTaken != 0)
                {
                    motorizedPrintheadModel.Position         += (motorizedPrintheadTypeModel.IsDirectionInverted == false) ? (double)(eStepsTaken * emmPerStep) : (double)(eStepsTaken * -1 * emmPerStep);
                    motorizedPrintheadModel.LimitSwitchStatus = LimitSwitchStatus.NoLimit;
                }

                //Notify other classes.
                OnRecordMotorizedPrintWithoutMovementExecuted();
            }
        }
        /// <summary>
        /// Sets the minimum and/or maximum position of actuator-based equipment as its current position.
        /// </summary>
        /// <param name="commandSet"></param>
        /// <returns></returns>
        private List <string> InterpretSetMinMaxPosition(string commandSet)
        {
            //Remove "*SetMinMaxPos" from the beginning of the command set.
            commandSet = commandSet.Substring(12);

            for (int index = 0; index < commandSet.Length; index++)
            {
                switch (commandSet[index])
                {
                case 'E':
                    if (_realTimeStatusDataModel.ActivePrintheadType == PrintheadType.Motorized)
                    {
                        //Set the current position as the parameter value.
                        RealTimeStatusMotorizedPrintheadModel realTimeStatusMotorizedPrintheadModel = (RealTimeStatusMotorizedPrintheadModel)_realTimeStatusDataModel.ActivePrintheadModel;
                        MotorizedPrintheadTypeModel           motorizedPrintheadTypeModel           = (MotorizedPrintheadTypeModel)_printerModel.FindPrinthead(_realTimeStatusDataModel.ActivePrintheadModel.Name).PrintheadTypeModel;
                        double ePreviousPosition = realTimeStatusMotorizedPrintheadModel.Position;
                        realTimeStatusMotorizedPrintheadModel.Position = ParseDouble(commandSet.Substring(index));
                        double ePositionDifference = realTimeStatusMotorizedPrintheadModel.Position - ePreviousPosition;

                        //Set the Min or Max Position property as the parameter value.
                        //Adjust the Min and Max positions such that the distance between Max and Min Position remains the same.
                        switch (commandSet[index + 1])
                        {
                        case 'N':
                            motorizedPrintheadTypeModel.MinPosition  = realTimeStatusMotorizedPrintheadModel.Position;
                            motorizedPrintheadTypeModel.MaxPosition += ePositionDifference;
                            break;

                        case 'M':
                            motorizedPrintheadTypeModel.MaxPosition  = realTimeStatusMotorizedPrintheadModel.Position;
                            motorizedPrintheadTypeModel.MinPosition += ePositionDifference;
                            break;

                        default:
                            //Set position value only.
                            //Do nothing here.
                            break;
                        }
                    }
                    break;

                case 'X':
                    //Set the current position as the parameter value.
                    RealTimeStatusAxisModel xRealTimeStatusAxisModel = _realTimeStatusDataModel.XRealTimeStatusAxisModel;
                    AxisModel xAxisModel        = _printerModel.AxisModelList[0];
                    double    xPreviousPosition = xRealTimeStatusAxisModel.Position;
                    xRealTimeStatusAxisModel.Position = ParseDouble(commandSet.Substring(index));
                    double xPositionDifference = xRealTimeStatusAxisModel.Position - xPreviousPosition;

                    //Set the Min or Max Position property as the parameter value.
                    //Adjust the Min and Max positions such that the distance between Max and Min Position remains the same.
                    switch (commandSet[index + 1])
                    {
                    case 'N':
                        xAxisModel.MinPosition  = xRealTimeStatusAxisModel.Position;
                        xAxisModel.MaxPosition += xPositionDifference;
                        break;

                    case 'M':
                        xAxisModel.MaxPosition  = xRealTimeStatusAxisModel.Position;
                        xAxisModel.MinPosition += xPositionDifference;
                        break;

                    default:
                        //Set position value only.
                        //Do nothing here.
                        break;
                    }
                    break;

                case 'Y':
                    //Set the current position as the parameter value.
                    RealTimeStatusAxisModel yRealTimeStatusAxisModel = _realTimeStatusDataModel.YRealTimeStatusAxisModel;
                    AxisModel yAxisModel        = _printerModel.AxisModelList[1];
                    double    yPreviousPosition = yRealTimeStatusAxisModel.Position;
                    yRealTimeStatusAxisModel.Position = ParseDouble(commandSet.Substring(index));
                    double yPositionDifference = yRealTimeStatusAxisModel.Position - yPreviousPosition;

                    //Set the Min or Max Position property as the parameter value.
                    //Adjust the Min and Max positions such that the distance between Max and Min Position remains the same.
                    switch (commandSet[index + 1])
                    {
                    case 'N':
                        yAxisModel.MinPosition  = yRealTimeStatusAxisModel.Position;
                        yAxisModel.MaxPosition += yPositionDifference;
                        break;

                    case 'M':
                        yAxisModel.MaxPosition  = yRealTimeStatusAxisModel.Position;
                        yAxisModel.MinPosition += yPositionDifference;
                        break;

                    default:
                        //Set position value only.
                        //Do nothing here.
                        break;
                    }
                    break;

                case 'Z':
                    //Set the current position as the parameter value.
                    RealTimeStatusAxisModel zRealTimeStatusAxisModel = _realTimeStatusDataModel.ZRealTimeStatusAxisModel;
                    AxisModel zAxisModel        = _printerModel.FindAxis(zRealTimeStatusAxisModel.Name);
                    double    zPreviousPosition = zRealTimeStatusAxisModel.Position;
                    zRealTimeStatusAxisModel.Position = ParseDouble(commandSet.Substring(index));
                    double zPositionDifference = zRealTimeStatusAxisModel.Position - zPreviousPosition;

                    //Set the Min or Max Position property as the parameter value.
                    //Adjust the Min and Max positions such that the distance between Max and Min Position remains the same.
                    switch (commandSet[index + 1])
                    {
                    case 'N':
                        zAxisModel.MinPosition  = zRealTimeStatusAxisModel.Position;
                        zAxisModel.MaxPosition += zPositionDifference;
                        break;

                    case 'M':
                        zAxisModel.MaxPosition  = zRealTimeStatusAxisModel.Position;
                        zAxisModel.MinPosition += zPositionDifference;
                        break;

                    default:
                        //Set position value only.
                        //Do nothing here.
                        break;
                    }

                    break;
                }
            }

            OnCommandSetPositionChanged();
            OnCommandSetMinMaxPositionChanged();

            //No commands to return.
            return(null);
        }
        /// <summary>
        /// Record the parameters from a Limit Switch status message.
        /// </summary>
        /// <param name="xLimit"></param>
        /// <param name="yLimit"></param>
        /// <param name="zLimit"></param>
        /// <param name="eLimit"></param>
        /// <param name="xStepsTaken"></param>
        /// <param name="yStepsTaken"></param>
        /// <param name="zStepsTaken"></param>
        /// <param name="eStepsTaken"></param>
        public void RecordLimit(bool xLimit, bool yLimit, bool zLimit, bool eLimit, int xStepsTaken, int yStepsTaken, int zStepsTaken, int eStepsTaken)
        {
            //E
            if (_activePrintheadType == PrintheadType.Motorized)
            {
                //mm Per Step.
                MotorizedPrintheadTypeModel motorizedPrintheadTypeModel = (MotorizedPrintheadTypeModel)_printerModel.FindPrinthead(_activePrintheadModel.Name).PrintheadTypeModel;
                eStepsTaken = (motorizedPrintheadTypeModel.IsDirectionInverted == false) ? eStepsTaken : (-1 * eStepsTaken);
                double emmPerStep = motorizedPrintheadTypeModel.MmPerStep;

                //Update Position.
                RealTimeStatusMotorizedPrintheadModel realTimeStatusMotorizedPrintheadTypeModel = (RealTimeStatusMotorizedPrintheadModel)_activePrintheadModel;
                realTimeStatusMotorizedPrintheadTypeModel.Position += (double)(eStepsTaken * -1 * emmPerStep);

                //Update Max/Min Position and Limit.
                if (eLimit == true)
                {
                    if (eStepsTaken > 0)
                    {
                        motorizedPrintheadTypeModel.MaxPosition = realTimeStatusMotorizedPrintheadTypeModel.Position;
                        realTimeStatusMotorizedPrintheadTypeModel.LimitSwitchStatus = LimitSwitchStatus.UpperLimit;
                    }
                    else if (eStepsTaken < 0)
                    {
                        motorizedPrintheadTypeModel.MinPosition = realTimeStatusMotorizedPrintheadTypeModel.Position;
                        realTimeStatusMotorizedPrintheadTypeModel.LimitSwitchStatus = LimitSwitchStatus.LowerLimit;
                    }
                }
            }

            AxisModel xAxisModel = _printerModel.AxisModelList[0];
            AxisModel yAxisModel = _printerModel.AxisModelList[1];
            AxisModel zAxisModel = _printerModel.FindAxis(_zRealTimeStatusAxisModel.Name);

            //mm Per Step.
            double xmmPerStep = xAxisModel.MmPerStep;
            double ymmPerStep = yAxisModel.MmPerStep;
            double zmmPerStep = (zAxisModel != null) ? _printerModel.FindAxis(_zRealTimeStatusAxisModel.Name).MmPerStep : 0;

            //Record positions.
            if (xStepsTaken != 0)
            {
                xStepsTaken = (_printerModel.AxisModelList[0].IsDirectionInverted == false) ? xStepsTaken : (-1 * xStepsTaken);
                _xRealTimeStatusAxisModel.Position += (double)(xStepsTaken * xmmPerStep);
            }

            if (yStepsTaken != 0)
            {
                yStepsTaken = (_printerModel.AxisModelList[1].IsDirectionInverted == false) ? yStepsTaken : (-1 * yStepsTaken);
                _yRealTimeStatusAxisModel.Position += (double)(yStepsTaken * ymmPerStep);
            }

            if (zStepsTaken != 0)
            {
                zStepsTaken = (_printerModel.FindAxis(_zRealTimeStatusAxisModel.Name).IsDirectionInverted == false) ? zStepsTaken : (-1 * zStepsTaken);
                _zRealTimeStatusAxisModel.Position += (double)(zStepsTaken * zmmPerStep);
            }

            //Set Max Positions and Limits.
            if (xLimit == true)
            {
                if (xStepsTaken > 0)
                {
                    xAxisModel.MaxPosition = _xRealTimeStatusAxisModel.Position;
                    _xRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.UpperLimit;
                }
                else if (xStepsTaken < 0)
                {
                    xAxisModel.MinPosition = _xRealTimeStatusAxisModel.Position;
                    _xRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.LowerLimit;
                }
            }

            if (yLimit == true)
            {
                if (yStepsTaken > 0)
                {
                    yAxisModel.MaxPosition = _yRealTimeStatusAxisModel.Position;
                    _yRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.UpperLimit;
                }
                else if (yStepsTaken < 0)
                {
                    yAxisModel.MinPosition = _yRealTimeStatusAxisModel.Position;
                    _yRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.LowerLimit;
                }
            }

            if (zLimit == true)
            {
                if (zStepsTaken > 0)
                {
                    if (_shouldZCalibrate == true)
                    {
                        zAxisModel.MaxPosition = _zRealTimeStatusAxisModel.Position;
                        _shouldZCalibrate      = false;
                    }
                    _zRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.UpperLimit;
                }
                else if (zStepsTaken < 0)
                {
                    //The minimum Position of Z Axes are always zero.
                    //If the lower limit of a Z Axis is hit, then adjust the Max Position such that the range remains the same.
                    if (_shouldZCalibrate == true)
                    {
                        zAxisModel.MaxPosition = zAxisModel.MaxPosition + _zRealTimeStatusAxisModel.Position;
                        zAxisModel.MinPosition = 0;
                        _shouldZCalibrate      = false;
                    }
                    _zRealTimeStatusAxisModel.LimitSwitchStatus = LimitSwitchStatus.LowerLimit;
                }
            }

            //Notify other classes.
            OnRecordLimitExecuted();
        }