Beispiel #1
0
        //  ╔═╗═╗ ╦╔╦╗╔═╗╦═╗╔╗╔╔═╗╦      ╔═╗═╗ ╦╦╔═╗
        //  ║╣ ╔╩╦╝ ║ ║╣ ╠╦╝║║║╠═╣║      ╠═╣╔╩╦╝║╚═╗
        //  ╚═╝╩ ╚═ ╩ ╚═╝╩╚═╝╚╝╩ ╩╩═╝────╩ ╩╩ ╚═╩╚═╝
        public bool ApplyAction(ActionExternalAxis action)
        {
            // Cartesian targets
            if (action.target == ExternalAxesTarget.All || action.target == ExternalAxesTarget.Cartesian)
            {
                if (this.externalAxesCartesian == null)
                {
                    this.externalAxesCartesian = new ExternalAxes();
                }


                if (action.relative)
                {
                    if (this.externalAxesCartesian[action.axisNumber - 1] == null)
                    {
                        //logger.Info($"Cannot apply \"{action}\", must initialize absolute axis value first for axis {action.axisNumber} before applying relative ones...");
                        logger.Error("Cannot increase cartesian external axis, value has not been initialized. Try `ExternalAxisTo()` instead.");
                        return(false);
                    }

                    this.externalAxesCartesian[action.axisNumber - 1] += action.value;
                }
                else
                {
                    this.externalAxesCartesian[action.axisNumber - 1] = action.value;
                }
            }

            // Joint targets
            if (action.target == ExternalAxesTarget.All || action.target == ExternalAxesTarget.Joint)
            {
                if (this.externalAxesJoints == null)
                {
                    this.externalAxesJoints = new ExternalAxes();
                }

                if (action.relative)
                {
                    if (this.externalAxesJoints[action.axisNumber - 1] == null)
                    {
                        //logger.Info($"Cannot apply \"{action}\", must initialize absolute axis value first for axis {action.axisNumber} before applying relative ones...");
                        logger.Error("Cannot increase joint external axis, value has not been initialized. Try `ExternalAxisTo()` instead.");
                        return(false);
                    }

                    this.externalAxesJoints[action.axisNumber - 1] += action.value;
                }
                else
                {
                    this.externalAxesJoints[action.axisNumber - 1] = action.value;
                }
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Apply Attach Tool Action.
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public bool ApplyAction(ActionAttachTool action)
        {
            // Sanity: this is a fix for pre-0.8.x compatibility where Attach came with the Tool object, not the name.
            // Older versions of Machina would yield error searching for `null` key on `availableTools`
            if (action.toolName == null)
            {
                logger.Error($"Obsolete version of AttachTool; please update Machina to latest update.");
                return(false);
            }

            // Sanity
            if (!availableTools.ContainsKey(action.toolName))
            {
                logger.Warning($"No tool named \"{action.toolName}\" defined in this robot; please use \"DefineTool\" first.");
                return(false);
            }
            // This would not work in case the user had defined a new tool with different values but same name (not great practice, but technically possible anyway...)
            //if (action.toolName == this.tool.name)
            //{
            //    logger.Verbose($"Attaching the same tool? No changes...");
            //    return true;
            //}


            // The cursor has now a tool attached to it
            Tool prevTool = this.tool;

            this.tool = availableTools[action.toolName];

            // Shim for lack of IK
            // If coming from axes motion, no need to transform the TCP
            if (this.position == null || this.rotation == null)
            {
                logger.Warning($"Attaching tool without TCP values, inconsistent results may follow...?");
            }
            // Otherwise transform the TCP
            else
            {
                if (prevTool != null)
                {
                    logger.Debug($"Detaching tool {prevTool.name} before attaching {this.tool.name}.");
                    UndoToolTransformOnCursor(this, prevTool, logger, _logRelativeActions);
                }

                ApplyToolTransformToCursor(this, this.tool, logger, _logRelativeActions);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Resets control parameters using the appropriate ControlManager.
        /// </summary>
        /// <returns></returns>
        private bool ResetControl()
        {
            _controlManager = ControlFactory.GetControlManager(this);

            bool success = _controlManager.Initialize();

            if (ControlMode == ControlType.Offline)
            {
                InitializeRobotCursors(null, Rotation.FlippedAroundY, null);    // @TODO: this should depend on the Robot brand, model, cursor and so many other things... Added this quick fix to allow programs to start with MoveTo() instructions.
            }

            if (!success)
            {
                logger.Error("Couldn't SetControlMode()");
                throw new Exception("Couldn't SetControlMode()");
            }

            return(success);
        }