/// <summary> /// Creates declarations in the RAPID program module inside the RAPID Generator. /// This method is called inside the RAPID generator. /// </summary> /// <param name="RAPIDGenerator"> The RAPID Generator. </param> public override void ToRAPIDDeclaration(RAPIDGenerator RAPIDGenerator) { // Generate the code for the zone and speeddata _speedData.ToRAPIDDeclaration(RAPIDGenerator); _zoneData.ToRAPIDDeclaration(RAPIDGenerator); // Generate code from robot targets if (_target is RobotTarget robotTarget) { // Update the movement of the inverse kinematics RAPIDGenerator.Robot.InverseKinematics.Movement = this; // Generates the robot target variable for a MoveL or MoveJ instruction if (_movementType == MovementType.MoveL || _movementType == MovementType.MoveJ) { RAPIDGenerator.Robot.InverseKinematics.CalculateExternalJointPosition(); robotTarget.ToRAPIDDeclaration(RAPIDGenerator); } // Generates the joint target variable from a robot target for a MoveAbsJ instruction else { if (!RAPIDGenerator.Targets.ContainsKey(robotTarget.Name + "_jt")) { // Calculate the axis values from the robot target RAPIDGenerator.Robot.InverseKinematics.Calculate(); RAPIDGenerator.ErrorText.AddRange(new List <string>(RAPIDGenerator.Robot.InverseKinematics.ErrorText)); // Create a joint target from the axis values RobotJointPosition robJointPosition = RAPIDGenerator.Robot.InverseKinematics.RobotJointPosition.Duplicate(); ExternalJointPosition extJointPosition = RAPIDGenerator.Robot.InverseKinematics.ExternalJointPosition.Duplicate(); JointTarget jointTarget = new JointTarget(robotTarget.Name + "_jt", robJointPosition, extJointPosition); jointTarget.ReferenceType = _target.ReferenceType; // Create the RAPID code jointTarget.ToRAPIDDeclaration(RAPIDGenerator); } } } // Generate code from joint targets else if (_target is JointTarget jointTarget) { // JointTarget with MoveAbsJ if (_movementType == MovementType.MoveAbsJ) { jointTarget.ToRAPIDDeclaration(RAPIDGenerator); RAPIDGenerator.ErrorText.AddRange(jointTarget.CheckAxisLimits(RAPIDGenerator.Robot)); } // Joint Target combined with MoveL or MoveJ else { throw new InvalidOperationException("Invalid Move instruction: A Joint Target cannot be combined with a MoveL or MoveJ instruction."); } } }
/// <summary> /// Used to create variable definitions in the RAPID Code. It is typically called inside the CreateRAPIDCode() method of the RAPIDGenerator class. /// </summary> /// <param name="RAPIDGenerator"> Defines the RAPIDGenerator. </param> public override void ToRAPIDDeclaration(RAPIDGenerator RAPIDGenerator) { // Creates SpeedData Variable Code _speedData.ToRAPIDDeclaration(RAPIDGenerator); // Creates ZoneData Variable Code _zoneData.ToRAPIDDeclaration(RAPIDGenerator); // Only adds target code if target is not already defined if (!RAPIDGenerator.Targets.ContainsKey(_name)) { RAPIDGenerator.Targets.Add(_name, this.ConvertToJointTarget()); RAPIDGenerator.StringBuilder.Append(Environment.NewLine + "\t" + this.ToRAPIDDeclaration(RAPIDGenerator.Robot)); RAPIDGenerator.ErrorText.AddRange(this.CheckForAxisLimits(RAPIDGenerator.Robot)); } }