Beispiel #1
0
        //  ╔╦╗╔═╗╔╦╗╔═╗   ╔═╗═╗ ╦╔╦╗╦═╗╦ ╦╔╦╗╔═╗  ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
        //   ║ ║╣ ║║║╠═╝───║╣ ╔╩╦╝ ║ ╠╦╝║ ║ ║║║╣   ├─┤│   │ ││ ││││└─┐
        //   ╩ ╚═╝╩ ╩╩     ╚═╝╩ ╚═ ╩ ╩╚═╚═╝═╩╝╚═╝  ┴ ┴└─┘ ┴ ┴└─┘┘└┘└─┘
        /// <summary>
        /// Apply ActionTemperature write action to this cursor.
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public bool ApplyAction(ActionTemperature action)
        {
            if (action.relative)
            {
                this.partTemperature[action.robotPart] += action.temperature;
            }
            else
            {
                this.partTemperature[action.robotPart] = action.temperature;
            }

            return(true);
        }
Beispiel #2
0
        //  ╔╦╗╔═╗╔╦╗╔═╗   ╔═╗═╗ ╦╔╦╗╦═╗╦ ╦╔╦╗╔═╗  ┌─┐┌─┐┌┬┐┬┌─┐┌┐┌┌─┐
        //   ║ ║╣ ║║║╠═╝───║╣ ╔╩╦╝ ║ ╠╦╝║ ║ ║║║╣   ├─┤│   │ ││ ││││└─┐
        //   ╩ ╚═╝╩ ╩╩     ╚═╝╩ ╚═ ╩ ╩╚═╚═╝═╩╝╚═╝  ┴ ┴└─┘ ┴ ┴└─┘┘└┘└─┘
        /// <summary>
        /// Apply ActionTemperature write action to this cursor.
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public bool ApplyAction(ActionTemperature action)
        {
            if (action.relative)
            {
                this.partTemperature[action.robotPart] += action.temperature;
            }
            else
            {
                this.partTemperature[action.robotPart] = action.temperature;
            }

            if (_logRelativeActions && action.relative)
            {
                logger.Verbose("Temperature set to " + this.partTemperature[action.robotPart]);
            }

            return(true);
        }
Beispiel #3
0
        //  ╦ ╦╔╦╗╦╦  ╔═╗
        //  ║ ║ ║ ║║  ╚═╗
        //  ╚═╝ ╩ ╩╩═╝╚═╝
        internal bool GenerateInstructionDeclaration(
            Action action, RobotCursor cursor,
            out string declaration)
        {
            string dec = null;

            switch (action.Type)
            {
            case ActionType.Speed:
                dec = string.Format(CultureInfo.InvariantCulture,
                                    "G1 F{0}",
                                    Math.Round(60.0 * cursor.speed, Geometry.STRING_ROUND_DECIMALS_MM));
                break;

            case ActionType.Translation:
            case ActionType.Transformation:
                dec = string.Format("G1 {0}{1}",
                                    GetPositionTargetValue(cursor),
                                    cursor.isExtruding ? " " + GetExtrusionTargetValue(cursor) : "");
                break;

            // Only available in MakerBot? http://reprap.org/wiki/G-code#M70:_Display_message
            case ActionType.Message:
                ActionMessage am = (ActionMessage)action;
                dec = string.Format("M70 P1000 ({0})",
                                    am.message);
                break;

            // In GCode, this is called "Dwell"
            case ActionType.Wait:
                ActionWait aw = (ActionWait)action;
                dec = string.Format(CultureInfo.InvariantCulture,
                                    "G4 P{0}",
                                    aw.millis);
                break;

            case ActionType.Comment:
                ActionComment ac = (ActionComment)action;
                dec = string.Format("{0} {1}",
                                    commChar,
                                    ac.comment);
                break;

            // Untested, but oh well...
            // http://reprap.org/wiki/G-code#M42:_Switch_I.2FO_pin
            case ActionType.IODigital:
                ActionIODigital aiod = (ActionIODigital)action;
                if (!aiod.isDigit)
                {
                    dec = $"{commChar} ERROR on \"{aiod}\": only integer pin names allowed";
                }
                else
                {
                    dec = $"M42 P{aiod.pinNum} S{(aiod.on ? "1" : "0")}";
                }
                break;


            case ActionType.IOAnalog:
                ActionIOAnalog aioa = (ActionIOAnalog)action;
                if (!aioa.isDigit)
                {
                    dec = $"{commChar} ERROR on \"{aioa}\": only integer pin names allowed";
                }
                else if (aioa.value < 0 || aioa.value > 255)
                {
                    dec = $"{commChar} ERROR on \"{aioa.ToString()}\": value out of range [0..255]";
                }
                else
                {
                    //dec = $"M42 P{aioa.pinNum} S{Math.Round(aioa.value, 0)}";
                    dec = string.Format(CultureInfo.InvariantCulture,
                                        "M42 P{0} S{1}",
                                        aioa.pinNum,
                                        Math.Round(aioa.value, 0));
                }
                break;

            case ActionType.Temperature:
                ActionTemperature at = (ActionTemperature)action;
                //dec = $"{tempToGCode[new Tuple<RobotPartType, bool>(at.robotPart, at.wait)]} S{Math.Round(cursor.partTemperature[at.robotPart], Geometry.STRING_ROUND_DECIMALS_TEMPERATURE)}";
                dec = string.Format(CultureInfo.InvariantCulture,
                                    "{0} S{1}",
                                    tempToGCode[new Tuple <RobotPartType, bool>(at.robotPart, at.wait)],
                                    Math.Round(cursor.partTemperature[at.robotPart], Geometry.STRING_ROUND_DECIMALS_TEMPERATURE));
                break;

            case ActionType.Extrusion:
            case ActionType.ExtrusionRate:
                dec = $"{commChar} {action.ToString()}";      // has no direct G-code, simply annotate it as a comment
                break;

            case ActionType.Initialization:
                ActionInitialization ai = (ActionInitialization)action;
                if (ai.initialize == true)
                {
                    StartCodeBoilerplate(cursor);
                }
                else
                {
                    EndCodeBoilerplate(cursor);
                }

                break;

            case ActionType.CustomCode:
                ActionCustomCode acc = action as ActionCustomCode;
                if (!acc.isDeclaration)
                {
                    dec = $"{acc.statement}";
                }
                break;

            // If action wasn't implemented before, then it doesn't apply to this device
            default:
                dec = $"{commChar} ACTION \"{action}\" NOT APPLICABLE TO THIS DEVICE";
                break;

                //case ActionType.Rotation:
                //case ActionType.Zone:
                //case ActionType.Joints:
                //case ActionType.Attach:
                //case ActionType.Detach:
                //    dec = string.Format("; ACTION \"{0}\" NOT IMPLEMENTED IN THIS DEVICE", action);
                //    break;
            }

            // Add trailing comments or ids if speficied
            if (ADD_ACTION_STRING && action.Type != ActionType.Comment)
            {
                dec = string.Format("{0}  {1} [{2}]",
                                    dec,
                                    commChar,
                                    action.ToString());
            }
            else if (ADD_ACTION_ID)
            {
                dec = string.Format("{0}  {1} [{2}]",
                                    dec,
                                    commChar,
                                    action.Id);
            }

            declaration = dec;
            return(dec != null);
        }