示例#1
0
 /// <summary>
 /// Apply a Push or Pop Action.
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public bool ApplyAction(ActionPushPop action)
 {
     if (action.push)
     {
         return(this.settingsBuffer.Push(this));
     }
     else
     {
         Settings s = settingsBuffer.Pop(this);
         if (s != null)
         {
             this.acceleration      = s.Acceleration;
             this.speed             = s.Speed;
             this.rotationSpeed     = s.RotationSpeed;
             this.jointSpeed        = s.JointSpeed;
             this.jointAcceleration = s.JointAcceleration;
             this.precision         = s.Precision;
             this.motionType        = s.MotionType;
             this.referenceCS       = s.RefCS;
             this.extrusionRate     = s.ExtrusionRate;
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        internal bool GenerateInstructionDeclaration(
            Action action,
            RobotCursor cursor,
            Dictionary <double, string> velNames,
            Dictionary <double, string> zoneNames,
            Dictionary <Tool, string> toolNames,
            out string declaration)
        {
            string dec = null;

            switch (action.Type)
            {
            case ActionType.Acceleration:
                bool zero = cursor.acceleration < Geometry.EPSILON;
                dec = string.Format("    WorldAccLim {0};",
                                    zero ? "\\Off" : "\\On := " + Math.Round(0.001 * cursor.acceleration, Geometry.STRING_ROUND_DECIMALS_M)).ToString(CultureInfo.InvariantCulture);
                break;

            //case ActionType.JointSpeed:
            //case ActionType.JointAcceleration:
            //    dec = string.Format("    {0} WARNING: {1}() has no effect in ABB robots.",
            //        commChar,
            //        action.Type);
            //    break;

            // @TODO: push/pop management should be done PROGRAMMATICALLY, not this CHAPUZa...
            case ActionType.PushPop:
                // Find if there was a change in acceleration, and set the corresponsing instruction...
                ActionPushPop app = action as ActionPushPop;
                if (app.push)
                {
                    break;                // only necessary for pops
                }
                if (Math.Abs(cursor.acceleration - cursor.settingsBuffer.SettingsBeforeLastPop.Acceleration) < Geometry.EPSILON)
                {
                    break;                                                                                                                   // no change
                }
                // If here, there was a change, so...
                bool zeroAcc = cursor.acceleration < Geometry.EPSILON;
                dec = string.Format("    WorldAccLim {0};",
                                    zeroAcc
                                ? "\\Off"
                                : "\\On := " + Math.Round(0.001 * cursor.acceleration,
                                                          Geometry.STRING_ROUND_DECIMALS_M)).ToString(CultureInfo.InvariantCulture);
                break;

            case ActionType.Translation:
            case ActionType.Rotation:
            case ActionType.Transformation:
                dec = string.Format("    {0} {1}, {2}, {3}, {4}\\{5};",
                                    cursor.motionType == MotionType.Joint ? "MoveJ" : "MoveL",
                                    GetRobTargetValue(cursor),
                                    velNames[cursor.speed],
                                    zoneNames[cursor.precision],
                                    cursor.tool == null ? "Tool0" : toolNames[cursor.tool],
                                    "WObj:=WObj0");
                break;

            case ActionType.Axes:
                dec = string.Format("    MoveAbsJ {0}, {1}, {2}, {3}\\{4};",
                                    GetJointTargetValue(cursor),
                                    velNames[cursor.speed],
                                    zoneNames[cursor.precision],
                                    cursor.tool == null ? "Tool0" : toolNames[cursor.tool],
                                    "WObj:=WObj0");
                break;

            case ActionType.Message:
                ActionMessage am = (ActionMessage)action;
                dec = string.Format("    TPWrite \"{0}\";",
                                    am.message.Length <= 80 ?
                                    am.message :
                                    am.message.Substring(0, 80)); // ABB strings can only be 80 chars long
                break;

            case ActionType.Wait:
                ActionWait aw = (ActionWait)action;
                dec = string.Format(CultureInfo.InvariantCulture,
                                    "    WaitTime {0};",
                                    0.001 * aw.millis);
                break;

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

            case ActionType.DefineTool:
                ActionDefineTool adt = action as ActionDefineTool;
                dec = string.Format("    {0} Tool \"{1}\" defined",      // this action has no actual RAPID instruction, just add a comment
                                    CC,
                                    adt.tool.name);
                break;

            case ActionType.AttachTool:
                ActionAttachTool aa = (ActionAttachTool)action;
                dec = string.Format("    {0} Tool \"{1}\" attached",      // this action has no actual RAPID instruction, just add a comment
                                    CC,
                                    aa.toolName);
                break;

            case ActionType.DetachTool:
                ActionDetachTool ad = (ActionDetachTool)action;
                dec = string.Format("    {0} All tools detached",      // this action has no actual RAPID instruction, just add a comment
                                    CC);
                break;

            case ActionType.IODigital:
                ActionIODigital aiod = (ActionIODigital)action;
                dec = $"    SetDO {aiod.pinName}, {(aiod.on ? "1" : "0")};";
                break;

            case ActionType.IOAnalog:
                ActionIOAnalog aioa = (ActionIOAnalog)action;
                dec = $"    SetAO {aioa.pinName}, {aioa.value};";
                break;

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

                //default:
                //    dec = string.Format("    ! ACTION \"{0}\" NOT IMPLEMENTED", action);
                //    break;
            }

            if (addActionString && action.Type != ActionType.Comment)
            {
                dec = string.Format("{0}{1}  {2} [{3}]",
                                    dec,
                                    dec == null ? "  " : "", // add indentation to align with code
                                    CC,
                                    action.ToString());
            }
            else if (addActionID)
            {
                dec = string.Format("{0}{1}  {2} [{3}]",
                                    dec,
                                    dec == null ? "  " : "", // add indentation to align with code
                                    CC,
                                    action.Id);
            }

            declaration = dec;
            return(dec != null);
        }
示例#3
0
        internal bool GenerateInstructionDeclarationFromVariable(
            Action action,
            RobotCursor cursor,
            int id,
            Dictionary <double, string> velNames,
            Dictionary <double, string> zoneNames,
            Dictionary <Tool, string> toolNames,
            out string declaration)
        {
            string dec = null;

            switch (action.type)
            {
            case ActionType.Acceleration:
                bool zero = cursor.acceleration < Geometry.EPSILON2;
                dec = string.Format("    WorldAccLim {0};",
                                    zero ? "\\Off" : "\\On := " + Math.Round(0.001 * cursor.acceleration, Geometry.STRING_ROUND_DECIMALS_M));
                break;

            case ActionType.JointSpeed:
            case ActionType.JointAcceleration:
                dec = string.Format("    {0} WARNING: {1}() has no effect in ABB robots.",
                                    commChar,
                                    action.type);
                break;

            // @TODO: push/pop management should be done PROGRAMMATICALLY, not this CHAPUZA...
            case ActionType.PushPop:
                // Find if there was a change in acceleration, and set the corresponsing instruction...
                ActionPushPop app = action as ActionPushPop;
                if (app.push)
                {
                    break;                // only necessary for pops
                }
                if (Math.Abs(cursor.acceleration - cursor.settingsBuffer.SettingsBeforeLastPop.Acceleration) < Geometry.EPSILON2)
                {
                    break;                                                                                                                    // no change
                }
                // If here, there was a change, so...
                bool zeroAcc = cursor.acceleration < Geometry.EPSILON2;
                dec = string.Format("    WorldAccLim {0};",
                                    zeroAcc ? "\\Off" : "\\On := " + Math.Round(0.001 * cursor.acceleration, Geometry.STRING_ROUND_DECIMALS_M));
                break;

            case ActionType.Translation:
            case ActionType.Rotation:
            case ActionType.Transformation:
                dec = string.Format("    {0} target{1}, {2}, {3}, {4}\\{5};",
                                    cursor.motionType == MotionType.Joint ? "MoveJ" : "MoveL",
                                    id,
                                    velNames[cursor.speed],
                                    zoneNames[cursor.precision],
                                    cursor.tool == null ? "Tool0" : toolNames[cursor.tool],
                                    "WObj:=WObj0");
                break;

            case ActionType.Axes:
                dec = string.Format("    MoveAbsJ target{0}, {1}, {2}, {3}\\{4};",
                                    id,
                                    velNames[cursor.speed],
                                    zoneNames[cursor.precision],
                                    cursor.tool == null ? "Tool0" : toolNames[cursor.tool],
                                    "WObj:=WObj0");
                break;

            case ActionType.Message:
                ActionMessage am = (ActionMessage)action;
                dec = string.Format("    TPWrite \"{0}\";",
                                    am.message.Length <= 80 ?
                                    am.message :
                                    am.message.Substring(0, 80)); // ABB TPWrite messages can only be 80 chars long
                break;

            case ActionType.Wait:
                ActionWait aw = (ActionWait)action;
                dec = string.Format("    WaitTime {0};",
                                    0.001 * aw.millis);
                break;

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

            case ActionType.Attach:
                ActionAttach aa = (ActionAttach)action;
                dec = string.Format("    {0} Tool \"{1}\" attached",      // this action has no actual RAPID instruction, just add a comment
                                    commChar,
                                    aa.tool.name);
                break;

            case ActionType.Detach:
                ActionDetach ad = (ActionDetach)action;
                dec = string.Format("    {0} Tool detached",      // this action has no actual RAPID instruction, just add a comment
                                    commChar);
                break;

            case ActionType.IODigital:
                ActionIODigital aiod = (ActionIODigital)action;
                if (aiod.pin < 0 || aiod.pin >= cursor.digitalOutputs.Length)
                {
                    dec = string.Format("    {0} ERROR on \"{1}\": IO number not available",
                                        commChar,
                                        aiod.ToString());
                }
                else
                {
                    dec = string.Format("    SetDO {0}, {1};",
                                        cursor.digitalOutputNames[aiod.pin],
                                        aiod.on ? "1" : "0");
                }
                break;

            case ActionType.IOAnalog:
                ActionIOAnalog aioa = (ActionIOAnalog)action;
                if (aioa.pin < 0 || aioa.pin >= cursor.analogOutputs.Length)
                {
                    dec = string.Format("    {0} ERROR on \"{1}\": IO number not available",
                                        commChar,
                                        aioa.ToString());
                }
                else
                {
                    dec = string.Format("    SetAO {0}, {1};",
                                        cursor.analogOutputNames[aioa.pin],
                                        aioa.value);
                }
                break;

                //default:
                //    dec = string.Format("    ! ACTION \"{0}\" NOT IMPLEMENTED", action);
                //    break;
            }

            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);
        }