/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Input variables RobotTool robotTool = null; // Catch the input data if (!DA.GetData(0, ref robotTool)) { return; } // Check if the object is valid if (!robotTool.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The Robot Tool is not valid"); } // Output DA.SetData(0, robotTool.Name); DA.SetData(1, robotTool.Mesh); DA.SetData(2, robotTool.AttachmentPlane); DA.SetData(3, robotTool.ToolPlane); DA.SetData(4, robotTool.Mass); DA.SetData(5, robotTool.CenterOfGravity); DA.SetData(6, robotTool.Inertia); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Plane positionPlane = Plane.WorldXY; RobotTool tool = null; List <ExternalAxis> externalAxis = new List <ExternalAxis>(); if (!DA.GetData(0, ref positionPlane)) { return; } if (!DA.GetData(1, ref tool)) { tool = new RobotTool(); } if (!DA.GetDataList(2, externalAxis)) { externalAxis = new List <ExternalAxis>() { }; } Robot robot = new Robot(); try { robot = IRB6700_175_305.GetRobot(positionPlane, tool, externalAxis); } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message); } DA.SetData(0, robot); }
/// <summary> /// Returns a new IRB2600-12/1.85 Robot instance. /// </summary> /// <param name="positionPlane"> The position and orientation of the Robot in world coordinate space. </param> /// <param name="tool"> The Robot Tool. </param> /// <param name="externalAxes"> The external axes attached to the Robot. </param> /// <returns> The Robot preset. </returns> public static Robot GetRobot(Plane positionPlane, RobotTool tool, List <ExternalAxis> externalAxes = null) { string name = "IRB2600-12/1.85"; List <Mesh> meshes = GetMeshes(); List <Plane> axisPlanes = GetAxisPlanes(); List <Interval> axisLimits = GetAxisLimits(); Plane mountingFrame = GetToolMountingFrame(); // Override the position plane when an external axis is coupled that moves the robot for (int i = 0; i < externalAxes.Count; i++) { if (externalAxes[i].MovesRobot == true) { positionPlane = externalAxes[i].AttachmentPlane; break; } } Robot robotInfo = new Robot(name, meshes, axisPlanes, axisLimits, Plane.WorldXY, mountingFrame, tool, externalAxes); Transform trans = Transform.PlaneToPlane(Plane.WorldXY, positionPlane); robotInfo.Transfom(trans); return(robotInfo); }
/// <summary> /// Initializes a new instance of the Path Generator class. /// </summary> /// <param name="robot"> The Robot to generate the path for. </param> public PathGenerator(Robot robot) { _planes = new List <Plane>(); _paths = new List <Curve>(); _robotJointPositions = new List <RobotJointPosition>(); _externalJointPositions = new List <ExternalJointPosition>(); _robot = robot.Duplicate(); // Since we might swap tools and therefore change the robot tool we make a deep copy _initialTool = robot.Tool.DuplicateWithoutMesh(); }
/// <summary> /// Initialize the fields to construct a valid Inverse Kinematics instance. /// </summary> private void Initialize() { // Check robot tool: override if the movement contains a robot tool if (_movement.RobotTool == null) { _robotTool = _robot.Tool; } // Check if the set tool is not empty else if (_movement.RobotTool.Name != "" && _movement.RobotTool.Name != null) //TODO: RobotTool.IsValid is maybe better? { _robotTool = _movement.RobotTool; } // Otherwise use the tool that is attached to the robot else { _robotTool = _robot.Tool; } // Movement related fields _target = _movement.Target; if (_target is RobotTarget) { // Calculate the position and the orientation of the target plane in the word coordinate system // If there is an external axes connected to work object of the movement the // target plane will be re-oriented according to the pose of the this external axes. _targetPlane = _movement.GetPosedGlobalTargetPlane(); // Update the base plane / position plane _positionPlane = GetPositionPlane(); Transform trans = Transform.PlaneToPlane(_positionPlane, Plane.WorldXY); // Needed for transformation from the robot world coordinate system to the local robot coordinate system Transform orient = Transform.PlaneToPlane(_robot.BasePlane, Plane.WorldXY); // Orient the target plane to the robot coordinate system _targetPlane = TransformToolPlane(_targetPlane, _robotTool.AttachmentPlane, _robotTool.ToolPlane); _endPlane = new Plane(_targetPlane.Origin, _targetPlane.YAxis, _targetPlane.XAxis); //rotates, flips plane for TCP Offset moving in the right direction _endPlane.Transform(trans); // Deep copy and orient to internal axis planes of the robot. _axisPlanes = new List <Plane>(); for (int i = 0; i < _robot.InternalAxisPlanes.Count; i++) { Plane plane = new Plane(_robot.InternalAxisPlanes[i]); plane.Transform(orient); _axisPlanes.Add(plane); } // Other robot info related fields _wristOffset = _axisPlanes[5].Origin.X - _axisPlanes[4].Origin.X; _lowerArmLength = _axisPlanes[1].Origin.DistanceTo(_axisPlanes[2].Origin); _upperArmLength = _axisPlanes[2].Origin.DistanceTo(_axisPlanes[4].Origin); _axis4offsetAngle = Math.Atan2(_axisPlanes[4].Origin.Z - _axisPlanes[2].Origin.Z, _axisPlanes[4].Origin.X - _axisPlanes[2].Origin.X); _wrist = new Point3d(_endPlane.PointAt(0, 0, _wristOffset)); } }
/// <summary> /// Method to create an absolute joint movement. /// </summary> /// <param name="name">Name of joint target, must be unique.</param> /// <param name="internalAxisValues">List of internal axis values. The length of the list should be equal to 6.</param> /// <param name="externalAxisValues">List of external axis values. The length of the list should be (for now) equal to 1.</param> /// <param name="speedData"> The SpeedData as a SpeedData </param> /// <param name="zoneData"> The ZoneData as a ZoneData </param> /// <param name="robotTool"> The Robot Tool. This will override the set default tool. </param> public AbsoluteJointMovement(string name, List <double> internalAxisValues, List <double> externalAxisValues, SpeedData speedData, ZoneData zoneData, RobotTool robotTool) { _name = name; _internalAxisValues = CheckInternalAxisValues(internalAxisValues); _externalAxisValues = CheckExternalAxisValues(externalAxisValues); _speedData = speedData; _movementType = MovementType.MoveAbsJ; // The movement type is always an Absolute Joint Movement _zoneData = zoneData; _robotTool = robotTool; }
/// <summary> /// Method to create a absolute joint movement with an empty robot tool (no override). /// </summary> /// <param name="name">Name of joint target, must be unique.</param> /// <param name="internalAxisValues">List of internal axis values. The length of the list should be equal to 6.</param> /// <param name="externalAxisValues">List of external axis values. </param> /// <param name="speedData"> The SpeedData as a SpeedData </param> /// <param name="precision"> Robot movement precision. This value will be casted to the nearest predefined zonedata value. Use -1 for fine. </param> public AbsoluteJointMovement(string name, List <double> internalAxisValues, List <double> externalAxisValues, SpeedData speedData, int precision) { _name = name; _internalAxisValues = CheckInternalAxisValues(internalAxisValues); _externalAxisValues = CheckExternalAxisValues(externalAxisValues); _speedData = speedData; _movementType = MovementType.MoveAbsJ; // The movement type is always an Absolute Joint Movement _zoneData = new ZoneData(precision); _robotTool = new RobotTool(); // Default Robot Tool tool0 _robotTool.Clear(); // Empty Robot Tool }
/// <summary> /// Method to create an absolute joint movement with internal and external axis values. /// </summary> /// <param name="name">Name of joint target, must be unique.</param> /// <param name="internalAxisValues">List of internal axis values. The length of the list should be equal to 6.</param> /// <param name="externalAxisValues">List of external axis values. </param> public AbsoluteJointMovement(string name, List <double> internalAxisValues, List <double> externalAxisValues) { _name = name; _internalAxisValues = CheckInternalAxisValues(internalAxisValues); _externalAxisValues = CheckExternalAxisValues(externalAxisValues); _speedData = new SpeedData(5); // Slowest predefined tcp speed _movementType = MovementType.MoveAbsJ; // The movementType is always an Absolute Joint Movement _zoneData = new ZoneData(0); _robotTool = new RobotTool(); // Default Robot Tool tool0 _robotTool.Clear(); // Empty Robot Tool }
/// <summary> /// Initializes a new instance of the Movement class. /// This constructor is typically used to cast a Robot Target to a movement. /// </summary> /// <param name="target"> The Target. </param> public Movement(ITarget target) { _movementType = 0; _target = target; _id = -1; _speedData = new SpeedData(5); // Slowest predefined tcp speed _zoneData = new ZoneData(0); _robotTool = new RobotTool(); // Default Robot Tool tool0 _robotTool.Clear(); // Empty Robot Tool _workObject = new WorkObject(); // Default work object wobj0 _digitalOutput = new DigitalOutput(); // InValid / empty DO }
/// <summary> /// Protected constructor needed for deserialization of the object. /// </summary> /// <param name="info"> The SerializationInfo to extract the data from. </param> /// <param name="context"> The context of this deserialization. </param> protected Movement(SerializationInfo info, StreamingContext context) { // int version = (int)info.GetValue("Version", typeof(int)); // <-- use this if the (de)serialization changes _movementType = (MovementType)info.GetValue("Movement Type", typeof(MovementType)); _target = (ITarget)info.GetValue("Target", typeof(ITarget)); _id = (int)info.GetValue("ID", typeof(int)); _speedData = (SpeedData)info.GetValue("Speed Data", typeof(SpeedData)); _zoneData = (ZoneData)info.GetValue("Zone Data", typeof(ZoneData)); _robotTool = (RobotTool)info.GetValue("Robot Tool", typeof(RobotTool)); _workObject = (WorkObject)info.GetValue("Work Object", typeof(WorkObject)); _digitalOutput = (DigitalOutput)info.GetValue("Digital Output", typeof(DigitalOutput)); }
/// <summary> /// Initializes a new instance of the Movement class. /// </summary> /// <param name="movementType"> The Movement Type. </param> /// <param name="target"> The Target. </param> /// <param name="speedData"> The Speed Data. </param> /// <param name="zoneData"> The Zone Data. </param> /// <param name="robotTool"> The Robot Tool. This will override the set default tool. </param> /// <param name="workObject"> The Work Object. </param> /// <param name="digitalOutput"> The Digital Output. When set this will define a MoveLDO or a MoveJDO instruction. </param> public Movement(MovementType movementType, ITarget target, SpeedData speedData, ZoneData zoneData, RobotTool robotTool, WorkObject workObject, DigitalOutput digitalOutput) { _movementType = movementType; _target = target; _id = -1; _speedData = speedData; _zoneData = zoneData; _robotTool = robotTool; _workObject = workObject; _digitalOutput = digitalOutput; CheckCombination(); }
/// <summary> /// Initializes a new instance of the Movement class with a default Work object (wobj0) and an empty Digital Output. /// </summary> /// <param name="movementType"> The Movement Type. </param> /// <param name="target"> The Target. </param> /// <param name="speedData"> The Speed Data. </param> /// <param name="zoneData"> The Zone Data. </param> /// <param name="robotTool"> The Robot Tool. This will override the set default tool. </param> public Movement(MovementType movementType, ITarget target, SpeedData speedData, ZoneData zoneData, RobotTool robotTool) { _movementType = movementType; _target = target; _id = -1; _speedData = speedData; _zoneData = zoneData; _robotTool = robotTool; _workObject = new WorkObject(); // Default work object wobj0 _digitalOutput = new DigitalOutput(); // InValid / empty DO CheckCombination(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Plane positionPlane = Plane.WorldXY; RobotTool tool = null; List <ExternalAxis> externalAxis = new List <ExternalAxis>(); if (!DA.GetData(0, ref positionPlane)) { return; } if (!DA.GetData(1, ref tool)) { tool = new RobotTool(); } if (!DA.GetDataList(2, externalAxis)) { externalAxis = new List <ExternalAxis>() { }; } Robot robot = new Robot(); if (_robotPreset == RobotPreset.EMPTY | _fromMenu) { _robotPreset = GetRobotPreset(); } try { robot = Robot.GetRobotPreset(_robotPreset, positionPlane, tool, externalAxis); int position = robot.Name.IndexOf("-"); if (position < 0) { this.Message = robot.Name; } else { this.Message = robot.Name.Substring(0, position); } this.ExpirePreview(true); } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message); } DA.SetData(0, robot); }
/// <summary> /// Initializes a new instance of the Movement class with an empty Robot Tool (no override) and a default Work Object (wobj0) /// </summary> /// <param name="movementType"> The Movement Type. </param> /// <param name="target"> The Target. </param> /// <param name="speedData"> The Speed Data.</param> /// <param name="zoneData"> The Zone Data. </param> /// <param name="digitalOutput"> The Digital Output. When set this will define a MoveLDO or a MoveJDO instruction. </param> public Movement(MovementType movementType, ITarget target, SpeedData speedData, ZoneData zoneData, DigitalOutput digitalOutput) { _movementType = movementType; _target = target; _id = -1; _speedData = speedData; _zoneData = zoneData; _robotTool = new RobotTool(); // Default Robot Tool tool0 _robotTool.Clear(); // Empty Robot Tool _workObject = new WorkObject(); // Default work object wobj0 _digitalOutput = digitalOutput; CheckCombination(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Input variables RobotTool tool = new RobotTool(); // Catch input data if (!DA.GetData(0, ref tool)) { tool.Name = "tool0";; } // Create action OverrideRobotTool OverrideRobotTool = new OverrideRobotTool(tool); // Output DA.SetData(0, OverrideRobotTool); }
/// <summary> /// Creates a new absolute joint movement by duplicating an existing absolute joint movement. /// This creates a deep copy of the existing absolute joint movement. /// </summary> /// <param name="jointMovement"> The absolute joint movement that should be duplicated. </param> /// <param name="duplicateMesh"> A boolean that indicates if the meshes should be duplicated. </param> public AbsoluteJointMovement(AbsoluteJointMovement jointMovement, bool duplicateMesh = true) { _name = jointMovement.Name; _internalAxisValues = new List <double>(jointMovement.InternalAxisValues); _externalAxisValues = new List <double>(jointMovement.ExternalAxisValues); _speedData = jointMovement.SpeedData.Duplicate(); _movementType = jointMovement.MovementType; _zoneData = jointMovement.ZoneData.Duplicate(); if (duplicateMesh == true) { _robotTool = jointMovement.RobotTool.Duplicate(); } else { _robotTool = jointMovement.RobotTool.DuplicateWithoutMesh(); } }
/// <summary> /// Initializes a new instance of the Movement class by duplicating an existing Movement instance. /// </summary> /// <param name="movement"> The Movement instance to duplicate. </param> /// <param name="duplicateMesh"> Specifies whether the meshes should be duplicated. </param> public Movement(Movement movement, bool duplicateMesh = true) { _movementType = movement.MovementType; _target = movement.Target.DuplicateTarget(); _id = movement.SyncID; _speedData = movement.SpeedData.Duplicate(); _zoneData = movement.ZoneData.Duplicate(); _digitalOutput = movement.DigitalOutput.Duplicate(); if (duplicateMesh == true) { _robotTool = movement.RobotTool.Duplicate(); _workObject = movement.WorkObject.Duplicate(); } else { _robotTool = movement.RobotTool.DuplicateWithoutMesh(); _workObject = movement.WorkObject.DuplicateWithoutMesh(); } }
/// <summary> /// Resets / clears the current solution. /// </summary> private void Reset() { // Clear current solution _robotJointPositions.Clear(); _externalJointPositions.Clear(); _planes.Clear(); _paths.Clear(); _errorText.Clear(); // Reinitiate starting values _currentTool = _initialTool; _linearConfigurationControl = true; _jointConfigurationControl = true; _firstMovementIsMoveAbsJ = false; _lastRobotJointPosition = new RobotJointPosition(); _lastExternalJointPosition = new ExternalJointPosition(); for (int i = 0; i < _robot.ExternalAxes.Count; i++) { _lastExternalJointPosition[_robot.ExternalAxes[i].AxisNumber] = _robot.ExternalAxes[i].AxisLimits.Min; } }
/// <summary> /// Calculates the path from a list with Actions. /// </summary> /// <param name="actions"> The list with Actions. </param> /// <param name="interpolations"> The amount of interpolations between two targets. </param> public void Calculate(List <Actions.Action> actions, int interpolations) { _robot.ForwardKinematics.HideMesh = true; _interpolations = interpolations; int counter = 0; Reset(); // Ungroup actions List <Action> ungrouped = new List <Action>() { }; for (int i = 0; i < actions.Count; i++) { if (actions[i] is ActionGroup group) { ungrouped.AddRange(group.Actions); } else { ungrouped.Add(actions[i]); } } // Check fist movement _firstMovementIsMoveAbsJ = CheckFirstMovement(ungrouped); // Get path from the list with actions for (int i = 0; i < ungrouped.Count; i++) { if (ungrouped[i] is OverrideRobotTool overrideRobotTool) { _currentTool = overrideRobotTool.RobotTool.DuplicateWithoutMesh(); } else if (ungrouped[i] is JointConfigurationControl jointConfigurationControl) { _jointConfigurationControl = jointConfigurationControl.IsActive; } else if (ungrouped[i] is LinearConfigurationControl linearConfigurationControl) { _linearConfigurationControl = linearConfigurationControl.IsActive; } else if (ungrouped[i] is Movement movement) { if (movement.Target is RobotTarget && movement.MovementType == MovementType.MoveAbsJ) { JointMovementFromRobotTarget(movement); counter++; } else if (movement.Target is RobotTarget && movement.MovementType == MovementType.MoveL) { LinearMovementFromRobotTarget(movement); counter++; } else if (movement.Target is RobotTarget && movement.MovementType == MovementType.MoveJ) { JointMovementFromRobotTarget(movement); counter++; } else if (movement.Target is JointTarget && movement.MovementType == MovementType.MoveAbsJ) { JointMovementFromJointTarget(movement); counter++; } } // OBSOLETE else if (ungrouped[i] is AutoAxisConfig autoAxisConfig) { _linearConfigurationControl = !autoAxisConfig.IsActive; _jointConfigurationControl = !autoAxisConfig.IsActive; } // OBSOLETE else if (ungrouped[i] is AbsoluteJointMovement absoluteJointMovement) { JointMovementFromJointTarget(absoluteJointMovement.ConvertToMovement()); counter++; } } // Add joint positions and plane from last movement if (counter > 0) { _robotJointPositions.Add(_lastRobotJointPosition); _externalJointPositions.Add(_lastExternalJointPosition); _robot.ForwardKinematics.Calculate(_lastRobotJointPosition, _lastExternalJointPosition); _planes.Add(_robot.ForwardKinematics.TCPPlane); } // Remove first dummy values if (counter > 0) { _robotJointPositions.RemoveRange(0, interpolations); _externalJointPositions.RemoveRange(0, interpolations); _planes.RemoveRange(0, interpolations); _paths.RemoveAt(0); } // Remove null _paths.RemoveAll(val => val == null); // Remove duplicates from error text _errorText = _errorText.Distinct().ToList(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Warning that this component is OBSOLETE AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component is OBSOLETE and will be removed in the future. Instead, " + "combine Joint Targets with Movements."); // Input variables List <string> names = new List <string>(); GH_Structure <GH_Number> internalAxisValuesTree = new GH_Structure <GH_Number>(); GH_Structure <GH_Number> externalAxisValuesTree = new GH_Structure <GH_Number>(); List <SpeedData> speedDatas = new List <SpeedData>(); List <ZoneData> zoneDatas = new List <ZoneData>(); List <RobotTool> robotTools = new List <RobotTool>(); // Create an empty Robot Tool RobotTool emptyRobotTool = new RobotTool(); emptyRobotTool.Clear(); // Catch the input data from the fixed parameters if (!DA.GetDataList(0, names)) { return; } if (!DA.GetDataTree(1, out internalAxisValuesTree)) { return; } if (!DA.GetDataTree(2, out externalAxisValuesTree)) { return; } if (!DA.GetDataList(3, speedDatas)) { return; } if (!DA.GetDataList(4, zoneDatas)) { zoneDatas = new List <ZoneData>() { new ZoneData(0) }; } // Catch the input data from the variable parameteres if (Params.Input.Any(x => x.Name == variableInputParameters[0].Name)) { if (!DA.GetDataList(variableInputParameters[0].Name, robotTools)) { robotTools = new List <RobotTool>() { new RobotTool(emptyRobotTool) }; } } // Make sure variable input parameters have a default value if (robotTools.Count == 0) { robotTools.Add(new RobotTool(emptyRobotTool)); // Empty Robot Tool } // Get longest Input List int[] sizeValues = new int[6]; sizeValues[0] = names.Count; sizeValues[1] = internalAxisValuesTree.PathCount; sizeValues[2] = externalAxisValuesTree.PathCount; sizeValues[3] = speedDatas.Count; sizeValues[4] = zoneDatas.Count; sizeValues[5] = robotTools.Count; int biggestSize = HelperMethods.GetBiggestValue(sizeValues); // Keeps track of used indicies int namesCounter = -1; int internalValueCounter = -1; int externalValueCounter = -1; int speedDataCounter = -1; int precisionCounter = -1; int robotToolCounter = -1; // Clear list _jointMovements.Clear(); // Creates movements for (int i = 0; i < biggestSize; i++) { string name; List <double> internalAxisValues = new List <double>(); List <double> externalAxisValues = new List <double>(); SpeedData speedData; ZoneData zoneData; RobotTool robotTool; // Target counter if (i < sizeValues[0]) { name = names[i]; namesCounter++; } else { name = names[namesCounter] + "_" + (i - namesCounter); } // internal axis values counter if (i < sizeValues[1]) { internalAxisValues = internalAxisValuesTree[i].ConvertAll(x => (double)x.Value); internalValueCounter++; } else { internalAxisValues = internalAxisValuesTree[internalValueCounter].ConvertAll(x => (double)x.Value); } // External axis values counter if (sizeValues[2] == 0) // In case no external axis values are defined. { externalAxisValues = new List <double>() { }; } else { if (i < sizeValues[2]) { externalAxisValues = externalAxisValuesTree[i].ConvertAll(x => (double)x.Value); externalValueCounter++; } else { externalAxisValues = externalAxisValuesTree[externalValueCounter].ConvertAll(x => (double)x.Value); } } // SpeedData counter if (i < sizeValues[3]) { speedData = speedDatas[i]; speedDataCounter++; } else { speedData = speedDatas[speedDataCounter]; } // Precision counter if (i < sizeValues[4]) { zoneData = zoneDatas[i]; precisionCounter++; } else { zoneData = zoneDatas[precisionCounter]; } // Robot tool counter if (i < sizeValues[5]) { robotTool = robotTools[i]; robotToolCounter++; } else { robotTool = robotTools[robotToolCounter]; } // JointMovement constructor AbsoluteJointMovement jointMovement = new AbsoluteJointMovement(name, internalAxisValues, externalAxisValues, speedData, zoneData, robotTool); _jointMovements.Add(jointMovement); } // Check if an exact predefined zonedata value is used for (int i = 0; i < zoneDatas.Count; i++) { if (zoneDatas[i].ExactPredefinedValue == false & zoneDatas[i].PreDefinied == true) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Predefined zonedata value <" + i + "> is invalid. " + "The nearest valid predefined speeddata value is used. Valid predefined zonedata values are -1, " + "0, 1, 5, 10, 15, 20, 30, 40, 50, 60, 80, 100, 150 or 200. " + "A value of -1 will be interpreted as fine movement in RAPID Code."); break; } } // Check if an exact predefined speeddata value is used for (int i = 0; i < speedDatas.Count; i++) { if (speedDatas[i].ExactPredefinedValue == false & speedDatas[i].PreDefinied == true) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Predefined speeddata value <" + i + "> is invalid. " + "The nearest valid predefined speeddata value is used. Valid predefined speeddata values are 5, 10, " + "20, 30, 40, 50, 60, 80, 100, 150, 200, 300, 400, 500, 600, 800, 1000, 1500, 2000, 2500, 3000, 4000, " + "5000, 6000 and 7000."); break; } } // Output DA.SetDataList(0, _jointMovements); #region Object manager // Gets ObjectManager of this document _objectManager = DocumentManager.GetDocumentObjectManager(this.OnPingDocument()); // Clears targetNames for (int i = 0; i < _targetNames.Count; i++) { _objectManager.TargetNames.Remove(_targetNames[i]); } _targetNames.Clear(); // Removes lastName from targetNameList if (_objectManager.TargetNames.Contains(_lastName)) { _objectManager.TargetNames.Remove(_lastName); } // Adds Component to JointTargetsByGuid Dictionary if (!_objectManager.OldJointTargetsByGuid2.ContainsKey(this.InstanceGuid)) { _objectManager.OldJointTargetsByGuid2.Add(this.InstanceGuid, this); } // Checks if target name is already in use and counts duplicates #region Check name in object manager _namesUnique = true; for (int i = 0; i < names.Count; i++) { if (_objectManager.TargetNames.Contains(names[i])) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name already in use."); _namesUnique = false; _lastName = ""; break; } else { // Adds Target Name to list _targetNames.Add(names[i]); _objectManager.TargetNames.Add(names[i]); // Run SolveInstance on other Targets with no unique Name to check if their name is now available _objectManager.UpdateTargets(); _lastName = names[i]; } // Checks if variable name exceeds max character limit for RAPID Code if (HelperMethods.VariableExeedsCharacterLimit32(names[i])) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name exceeds character limit of 32 characters."); break; } // Checks if variable name starts with a number if (HelperMethods.VariableStartsWithNumber(names[i])) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name starts with a number which is not allowed in RAPID Code."); break; } } #endregion // Recognizes if Component is Deleted and removes it from Object Managers target and name list GH_Document doc = this.OnPingDocument(); if (doc != null) { doc.ObjectsDeleted += DocumentObjectsDeleted; } #endregion }
/// <summary> /// Initializes a new instance of the Override Robot Tool class. /// </summary> /// <param name="robotTool"> The Robot Tool that should be set. </param> public OverrideRobotTool(RobotTool robotTool) { _robotTool = robotTool; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Input variables string name = "default_tool"; List <Mesh> meshes = new List <Mesh>(); Plane attachmentPlane = Plane.Unset; Plane toolPlane = Plane.Unset; // Catch the input data if (!DA.GetData(0, ref name)) { return; } if (!DA.GetDataList(1, meshes)) { meshes = new List <Mesh>() { new Mesh() }; } if (!DA.GetData(2, ref attachmentPlane)) { return; } if (!DA.GetData(3, ref toolPlane)) { return; } ; // Replace spaces name = HelperMethods.ReplaceSpacesAndRemoveNewLines(name); // Create the Robot Tool _robotTool = new RobotTool(name, meshes, attachmentPlane, toolPlane); // Outputs DA.SetData(0, _robotTool); #region Object manager // Gets ObjectManager of this document _objectManager = DocumentManager.GetDocumentObjectManager(this.OnPingDocument()); // Clears tool name _objectManager.ToolNames.Remove(_toolName); _toolName = String.Empty; // Removes lastName from toolNameList if (_objectManager.ToolNames.Contains(_lastName)) { _objectManager.ToolNames.Remove(_lastName); } // Adds Component to ToolsByGuid Dictionary if (!_objectManager.OldRobotToolFromPlanesGuid2.ContainsKey(this.InstanceGuid)) { _objectManager.OldRobotToolFromPlanesGuid2.Add(this.InstanceGuid, this); } // Checks if the tool name is already in use and counts duplicates #region Check name in object manager if (_objectManager.ToolNames.Contains(_robotTool.Name)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Tool Name already in use."); _nameUnique = false; _lastName = ""; } else { // Adds Robot Tool Name to list _toolName = _robotTool.Name; _objectManager.ToolNames.Add(_robotTool.Name); // Run SolveInstance on other Tools with no unique Name to check if their name is now available _objectManager.UpdateRobotTools(); _lastName = _robotTool.Name; _nameUnique = true; } // Checks if variable name exceeds max character limit for RAPID Code if (HelperMethods.VariableExeedsCharacterLimit32(name)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Robot Tool Name exceeds character limit of 32 characters."); } // Checks if variable name starts with a number if (HelperMethods.VariableStartsWithNumber(name)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Robot Tool Name starts with a number which is not allowed in RAPID Code."); } #endregion // Recognizes if Component is Deleted and removes it from Object Managers tool and name list GH_Document doc = this.OnPingDocument(); if (doc != null) { doc.ObjectsDeleted += DocumentObjectsDeleted; } #endregion }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Warning that this component is OBSOLETE AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component is OBSOLETE and will be removed " + "in the future. Remove this component from your canvas and replace it by picking the new component " + "from the ribbon."); // Input variables string name = "default_tool"; List <Mesh> meshes = new List <Mesh>(); double x = 0.0; double y = 0.0; double z = 0.0; double quat1 = 0.0; double quat2 = 0.0; double quat3 = 0.0; double quat4 = 0.0; // Catch the input data if (!DA.GetData(0, ref name)) { return; } if (!DA.GetDataList(1, meshes)) { meshes = new List <Mesh>() { new Mesh() }; } if (!DA.GetData(2, ref x)) { return; } if (!DA.GetData(3, ref y)) { return; } if (!DA.GetData(4, ref z)) { return; } if (!DA.GetData(5, ref quat1)) { return; } if (!DA.GetData(6, ref quat2)) { return; } if (!DA.GetData(7, ref quat3)) { return; } if (!DA.GetData(8, ref quat4)) { return; } // Create the robot tool _robotTool = new RobotTool(name, meshes, x, y, z, quat1, quat2, quat3, quat4); // Outputs DA.SetData(0, _robotTool); DA.SetData(1, _robotTool.ToRAPIDDeclaration()); #region Object manager // Gets ObjectManager of this document _objectManager = DocumentManager.GetDocumentObjectManager(this.OnPingDocument()); // Clears toolNames _objectManager.ToolNames.Remove(_toolName); _toolName = String.Empty; // Removes lastName from toolNameList if (_objectManager.ToolNames.Contains(_lastName)) { _objectManager.ToolNames.Remove(_lastName); } // Adds Component to ToolsByGuid Dictionary if (!_objectManager.OldToolsQuaternionByGuid.ContainsKey(this.InstanceGuid)) { _objectManager.OldToolsQuaternionByGuid.Add(this.InstanceGuid, this); } // Checks if tool name is already in use and counts duplicates #region Check name in object manager if (_objectManager.ToolNames.Contains(_robotTool.Name)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Tool Name already in use."); _nameUnique = false; _lastName = ""; } else { // Adds Robot Tool Name to list _toolName = _robotTool.Name; _objectManager.ToolNames.Add(_robotTool.Name); // Run SolveInstance on other Tools with no unique Name to check if their name is now available _objectManager.UpdateRobotTools(); _lastName = _robotTool.Name; _nameUnique = true; } // Checks if variable name exceeds max character limit for RAPID Code if (HelperMethods.VariableExeedsCharacterLimit32(name)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Robot Tool Name exceeds character limit of 32 characters."); } // Checks if variable name starts with a number if (HelperMethods.VariableStartsWithNumber(name)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Robot Tool Name starts with a number which is not allowed in RAPID Code."); } #endregion // Recognizes if Component is Deleted and removes it from Object Managers tool and name list GH_Document doc = this.OnPingDocument(); if (doc != null) { doc.ObjectsDeleted += DocumentObjectsDeleted; } #endregion }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Warning that this component is OBSOLETE AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component is OBSOLETE and will be removed " + "in the future. Remove this component from your canvas and replace it by picking the new component " + "from the ribbon."); // Creates the input value list and attachs it to the input parameter CreateValueList(); // Expire solution of this component if (_expire == true) { _expire = false; this.ExpireSolution(true); } // Input variables List <ITarget> targets = new List <ITarget>(); List <SpeedData> speedDatas = new List <SpeedData>(); List <int> movementTypes = new List <int>(); List <ZoneData> zoneDatas = new List <ZoneData>(); List <RobotTool> robotTools = new List <RobotTool>(); List <WorkObject> workObjects = new List <WorkObject>(); List <DigitalOutput> digitalOutputs = new List <DigitalOutput>(); // Create an empty Robot Tool RobotTool emptyRobotTool = new RobotTool(); emptyRobotTool.Clear(); // Catch the input data from the fixed parameters if (!DA.GetDataList(0, targets)) { return; } if (!DA.GetDataList(1, speedDatas)) { return; } if (!DA.GetDataList(2, movementTypes)) { return; } if (!DA.GetDataList(3, zoneDatas)) { zoneDatas = new List <ZoneData>() { new ZoneData(0) }; } // Catch the input data from the variable parameteres if (Params.Input.Any(x => x.Name == variableInputParameters[0].Name)) { if (!DA.GetDataList(variableInputParameters[0].Name, robotTools)) { robotTools = new List <RobotTool>() { new RobotTool(emptyRobotTool) }; } } if (Params.Input.Any(x => x.Name == variableInputParameters[1].Name)) { if (!DA.GetDataList(variableInputParameters[1].Name, workObjects)) { workObjects = new List <WorkObject>() { new WorkObject() }; } } if (Params.Input.Any(x => x.Name == variableInputParameters[2].Name)) { if (!DA.GetDataList(variableInputParameters[2].Name, digitalOutputs)) { digitalOutputs = new List <DigitalOutput>() { new DigitalOutput() }; } } // Make sure variable input parameters have a default value if (robotTools.Count == 0) { robotTools.Add(new RobotTool(emptyRobotTool)); // Empty Robot Tool } if (workObjects.Count == 0) { workObjects.Add(new WorkObject()); // Makes a default WorkObject (wobj0) } if (digitalOutputs.Count == 0) { digitalOutputs.Add(new DigitalOutput()); // InValid / empty DO } // Get longest Input List int[] sizeValues = new int[7]; sizeValues[0] = targets.Count; sizeValues[1] = speedDatas.Count; sizeValues[2] = movementTypes.Count; sizeValues[3] = zoneDatas.Count; sizeValues[4] = robotTools.Count; sizeValues[5] = workObjects.Count; sizeValues[6] = digitalOutputs.Count; int biggestSize = HelperMethods.GetBiggestValue(sizeValues); // Keeps track of used indicies int targetGooCounter = -1; int speedDataCounter = -1; int movementTypeCounter = -1; int zoneDataCounter = -1; int robotToolGooCounter = -1; int workObjectGooCounter = -1; int digitalOutputGooCounter = -1; // Creates movements List <Movement> movements = new List <Movement>(); for (int i = 0; i < biggestSize; i++) { ITarget target; SpeedData speedData; int movementType; ZoneData zoneData; RobotTool robotTool; WorkObject workObject; DigitalOutput digitalOutput; // Target counter if (i < sizeValues[0]) { target = targets[i]; targetGooCounter++; } else { target = targets[targetGooCounter]; } // Workobject counter if (i < sizeValues[1]) { speedData = speedDatas[i]; speedDataCounter++; } else { speedData = speedDatas[speedDataCounter]; } // Movement type counter if (i < sizeValues[2]) { movementType = movementTypes[i]; movementTypeCounter++; } else { movementType = movementTypes[movementTypeCounter]; } // Precision counter if (i < sizeValues[3]) { zoneData = zoneDatas[i]; zoneDataCounter++; } else { zoneData = zoneDatas[zoneDataCounter]; } // Robot tool counter if (i < sizeValues[4]) { robotTool = robotTools[i]; robotToolGooCounter++; } else { robotTool = robotTools[robotToolGooCounter]; } // Work Object counter if (i < sizeValues[5]) { workObject = workObjects[i]; workObjectGooCounter++; } else { workObject = workObjects[workObjectGooCounter]; } // Digital Output counter if (i < sizeValues[6]) { digitalOutput = digitalOutputs[i]; digitalOutputGooCounter++; } else { digitalOutput = digitalOutputs[digitalOutputGooCounter]; } // Movement constructor Movement movement = new Movement((MovementType)movementType, target, speedData, zoneData, robotTool, workObject, digitalOutput); movements.Add(movement); } // Check if a right value is used for the movement type for (int i = 0; i < movementTypes.Count; i++) { if (movementTypes[i] != 0 && movementTypes[i] != 1 && movementTypes[i] != 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Movement type value <" + i + "> is invalid. " + "In can only be set to 0, 1 and 2. Use 0 for MoveAbsJ, 1 for MoveL and 2 for MoveJ."); break; } } // Check if an exact predefined zonedata value is used for (int i = 0; i < zoneDatas.Count; i++) { if (zoneDatas[i].ExactPredefinedValue == false & zoneDatas[i].PreDefinied == true) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Predefined zonedata value <" + i + "> is invalid. " + "The nearest valid predefined speeddata value is used. Valid predefined zonedata values are -1, " + "0, 1, 5, 10, 15, 20, 30, 40, 50, 60, 80, 100, 150 or 200. " + "A value of -1 will be interpreted as fine movement in RAPID Code."); break; } } // Check if an exact predefined speeddata value is used for (int i = 0; i < speedDatas.Count; i++) { if (speedDatas[i].ExactPredefinedValue == false & speedDatas[i].PreDefinied == true) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Predefined speeddata value <" + i + "> is invalid. " + "The nearest valid predefined speed data value is used. Valid predefined speeddata values are 5, 10, " + "20, 30, 40, 50, 60, 80, 100, 150, 200, 300, 400, 500, 600, 800, 1000, 1500, 2000, 2500, 3000, 4000, " + "5000, 6000 and 7000."); break; } } // Output DA.SetDataList(0, movements); }
/// <summary> /// Initializes a new instance of the Override Robot Tool class by duplicating an existing Override Robot Tool instance. /// </summary> /// <param name="overrideRobotTool"> The Override Robot Tool instance to duplicate. </param> public OverrideRobotTool(OverrideRobotTool overrideRobotTool) { _robotTool = overrideRobotTool.RobotTool.Duplicate(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Input variables string name = "default robot"; List <Mesh> meshes = new List <Mesh>(); List <Plane> axisPlanes = new List <Plane>(); List <Interval> axisLimits = new List <Interval>(); Plane positionPlane = Plane.WorldXY; Plane mountingFrame = Plane.Unset; RobotTool tool = null; List <ExternalAxis> externalAxis = new List <ExternalAxis>(); // Catch the input data if (!DA.GetData(0, ref name)) { return; } if (!DA.GetDataList(1, meshes)) { return; } if (!DA.GetDataList(2, axisPlanes)) { return; } if (!DA.GetDataList(3, axisLimits)) { return; } if (!DA.GetData(4, ref positionPlane)) { return; } if (!DA.GetData(5, ref mountingFrame)) { return; } if (!DA.GetData(6, ref tool)) { tool = new RobotTool(); } if (!DA.GetDataList(7, externalAxis)) { externalAxis = new List <ExternalAxis>() { }; } // Construct empty robot Robot robot = new Robot(); // Override position plane when an external axis is coupled for (int i = 0; i < externalAxis.Count; i++) { if (externalAxis[i] is ExternalLinearAxis) { positionPlane = (externalAxis[i] as ExternalLinearAxis).AttachmentPlane; } } // Construct the robot try { robot = new Robot(name, meshes, axisPlanes, axisLimits, Plane.WorldXY, mountingFrame, tool, externalAxis); Transform trans = Transform.PlaneToPlane(Plane.WorldXY, positionPlane); robot.Transfom(trans); } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message); } // Output DA.SetData(0, robot); }
/// <summary> /// Returns the RAPID program code. /// This method also overwrites or creates a file if the property 'SaveToFile is set equal to true. /// </summary> /// <returns> The RAPID program code as a string. </returns> public string CreateProgramCode() { // Reset fields _speedDatas.Clear(); _targets.Clear(); _zoneDatas.Clear(); _robotTools.Clear(); _workObjects.Clear(); _errorText.Clear(); // Save initial tool and add to used tools RobotTool initTool = _robot.Tool.Duplicate(); _robotTools.Add(_robot.Tool.Name, _robot.Tool); // Check if the first movement is an Absolute Joint Movement _firstMovementIsMoveAbsJ = CheckFirstMovement(); // Creates String Builder _stringBuilder = new StringBuilder(); // Creates Main Module _stringBuilder.Append("MODULE " + _programModuleName); _stringBuilder.Append(Environment.NewLine); _stringBuilder.Append(Environment.NewLine); // Add comment lines for tracking which version of RC was used _stringBuilder.Append("\t" + "! This RAPID code was generated with RobotComponents v" + VersionNumbering.CurrentVersion); _stringBuilder.Append(Environment.NewLine); _stringBuilder.Append("\t" + "! Visit www.github.com/RobotComponents for more information"); _stringBuilder.Append(Environment.NewLine); // Creates declarations for (int i = 0; i != _actions.Count; i++) { _actions[i].ToRAPIDDeclaration(this); } // Create Program _stringBuilder.Append(Environment.NewLine); _stringBuilder.Append(Environment.NewLine); _stringBuilder.Append("\t" + "PROC main()"); // Set back initial tool _robot.Tool = initTool; // Creates instructions for (int i = 0; i != _actions.Count; i++) { _actions[i].ToRAPIDInstruction(this); } // Closes Program _stringBuilder.Append(Environment.NewLine); _stringBuilder.Append("\t" + "ENDPROC"); // Closes Module _stringBuilder.Append(Environment.NewLine); _stringBuilder.Append(Environment.NewLine); _stringBuilder.Append("ENDMODULE"); // Update field _programCode = _stringBuilder.ToString(); // Write to file if (_saveToFile == true) { WriteProgramCodeToFile(); } // Return return(_programCode); }
private RobotTool _robotTool; // The robot that should be used #endregion #region (de)serialization /// <summary> /// Protected constructor needed for deserialization of the object. /// </summary> /// <param name="info"> The SerializationInfo to extract the data from. </param> /// <param name="context"> The context of this deserialization. </param> protected OverrideRobotTool(SerializationInfo info, StreamingContext context) { // int version = (int)info.GetValue("Version", typeof(int)); // <-- use this if the (de)serialization changes _robotTool = (RobotTool)info.GetValue("Robot Tool", typeof(RobotTool)); }