/// <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); }
//██████╗ ██████╗ ██╗██╗ ██╗ █████╗ ████████╗███████╗ //██╔══██╗██╔══██╗██║██║ ██║██╔══██╗╚══██╔══╝██╔════╝ //██████╔╝██████╔╝██║██║ ██║███████║ ██║ █████╗ //██╔═══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══██║ ██║ ██╔══╝ //██║ ██║ ██║██║ ╚████╔╝ ██║ ██║ ██║ ███████╗ //╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ // THIS IS NOW A TASK FOR THE ControlManager.SetCommunicationObject() /// <summary> /// Initializes the Communication object. /// </summary> /// <returns></returns> //private bool InitializeCommunication() //{ // Console.WriteLine("InitializeCommunication"); // // If there is already some communication going on // if (_driver != null) // { // Console.WriteLine("Communication protocol might be active. Please CloseControllerCommunication() first."); // return false; // } // // @TODO: shim assignment of correct robot model/brand // //_driver = new DriverABB(this); // if (this.parentRobot.Brand == RobotType.ABB) // { // _driver = new DriverABB(this); // } // else if (this.parentRobot.Brand == RobotType.UR) // { // _driver = new DriverUR(this); // } // else // { // throw new NotImplementedException(); // } // // Pass the streamQueue object as a shared reference // //comm.LinkStreamQueue(streamQueue); // if (_controlMode == ControlType.Stream) // { // _driver.LinkWriteCursor(ref writeCursor); // } // return true; //} /// <summary> /// Disconnects and resets the Communication object. /// </summary> /// <returns></returns> private bool DropCommunication() { if (_driver == null) { logger.Debug("Communication protocol not established, no DropCommunication() performed."); return(false); } bool success = _driver.DisconnectFromDevice(); _driver = null; return(success); }