Пример #1
0
        /// <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)
        {
            // Variables
            string                name = "";
            RobotJointPosition    robotJointPosition    = new RobotJointPosition();
            ExternalJointPosition externalJointPosition = new ExternalJointPosition();

            // Catch input data
            if (!DA.GetData(0, ref name))
            {
                return;
            }
            if (!DA.GetData(1, ref robotJointPosition))
            {
                robotJointPosition = new RobotJointPosition();
            }
            if (!DA.GetData(2, ref externalJointPosition))
            {
                externalJointPosition = new ExternalJointPosition();
            }

            // Replace spaces
            name = HelperMethods.ReplaceSpacesAndRemoveNewLines(name);

            JointTarget jointTarget = new JointTarget(name, robotJointPosition, externalJointPosition);

            // Sets Output
            DA.SetData(0, jointTarget);
        }
Пример #2
0
        private void btnHome_Click(object sender, EventArgs e)
        {
            // JointTarget jCurPos = this.controller.MotionSystem.ActiveMechanicalUnit.GetPosition();
            JointTarget jCurPos = new JointTarget();

            jCurPos.FillFromString2("[[0,0,0,0,90,0],[9E9,9E9,9E9,9E9,9E9,9E9]]");

            try
            {
                using (this.master = Mastership.Request(controller.Rapid))
                {
                    RapidData rd = controller.Rapid.GetRapidData("T_ROB1", "Module1", "jTarget");
                    controller.Rapid.GetTask("T_ROB1").SetProgramPointer("Module1", "moveJoint");
                    rd.Value = jCurPos;
                    controller.Rapid.Start();
                }
                if (this.controller.Rapid.ExecutionStatus != ExecutionStatus.Running)
                {
                    master.Release();
                }
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show("Mastership is held by another client." + ex.Message);
                master.Release();
                master = Mastership.Request(controller);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Unexpected error occurred: " + ex.Message);
            }
        }
 /// <summary>
 /// Defines a Forward Kinematic object from a Joint Target with defined Joint Positions obtained from a Joint Target.
 /// </summary>
 /// <param name="robot"> The Robot. </param>
 /// <param name="jointTarget"> The Joint Target. </param>
 /// <param name="hideMesh"> Specifies whether the mesh will be supressed. </param>
 public ForwardKinematics(Robot robot, JointTarget jointTarget, bool hideMesh = false)
 {
     _robot                 = robot;
     _hideMesh              = hideMesh;
     _robotJointPosition    = jointTarget.RobotJointPosition;
     _externalJointPosition = jointTarget.ExternalJointPosition;
 }
Пример #4
0
        // Additional methods
        #region additional methods
        /// <summary>
        /// Get the internal axis values from a defined joint target
        /// </summary>
        /// <param name="jointTarget"> The joint target to get the internal axis values from. </param>
        /// <returns></returns>
        private List <double> GetInternalAxisValuesAsList(JointTarget jointTarget)
        {
            // Initiate the list with internal axis values
            List <double> result = new List <double>()
            {
            };

            // Get the axis values from the joint target
            result.Add(jointTarget.RobAx.Rax_1);
            result.Add(jointTarget.RobAx.Rax_2);
            result.Add(jointTarget.RobAx.Rax_3);
            result.Add(jointTarget.RobAx.Rax_4);
            result.Add(jointTarget.RobAx.Rax_5);
            result.Add(jointTarget.RobAx.Rax_6);

            // Replace large numbers (the not connected axes) with an axis value equal to zero
            for (int i = 0; i < result.Count; i++)
            {
                if (result[i] > 9.0e+8)
                {
                    result[i] = 0;
                }
            }

            // Return the list with axis values
            return(result);
        }
Пример #5
0
        /// <summary>
        /// Get the external axis values from a defined joint target
        /// </summary>
        /// <param name="jointTarget"> The joint target to get the external axis values from. </param>
        /// <returns></returns>
        private List <double> GetExternalAxisValuesAsList(JointTarget jointTarget)
        {
            // Initiate the list with external axis values
            List <double> result = new List <double>()
            {
            };

            // Get the axis values from the joint target
            result.Add(jointTarget.ExtAx.Eax_a);
            result.Add(jointTarget.ExtAx.Eax_b);
            result.Add(jointTarget.ExtAx.Eax_c);
            result.Add(jointTarget.ExtAx.Eax_d);
            result.Add(jointTarget.ExtAx.Eax_e);
            result.Add(jointTarget.ExtAx.Eax_f);

            // Replace large numbers (the not connected axes) with an axis value equal to zero
            for (int i = 0; i < result.Count; i++)
            {
                if (result[i] > 9.0e+8)
                {
                    result[i] = 0;
                }
            }

            // Return the list with axis values
            return(result);
        }
Пример #6
0
        /// <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)
        {
            // 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
            GH_Controller controllerGoo = null;

            // Catch input data
            if (!DA.GetData(0, ref controllerGoo))
            {
                return;
            }

            // Clear output variables
            _internalAxisValues.Clear();
            _externalAxisValues.Clear();

            // Data needed for making the datatree with axis values
            MechanicalUnitCollection mechanicalUnits = controllerGoo.Value.MotionSystem.MechanicalUnits;
            int           internalAxisValuesPath     = 0;
            int           externalAxisValuesPath     = 0;
            List <double> values;
            GH_Path       path;

            // Make the output datatree with names with a branch for each mechanical unit
            for (int i = 0; i < mechanicalUnits.Count; i++)
            {
                // Get the ABB joint target of the mechanical unit
                MechanicalUnit mechanicalUnit = mechanicalUnits[i];
                JointTarget    jointTarget    = mechanicalUnit.GetPosition();

                // For internal axis values
                if (mechanicalUnit.Type == MechanicalUnitType.TcpRobot)
                {
                    values = GetInternalAxisValuesAsList(jointTarget);
                    path   = new GH_Path(internalAxisValuesPath);
                    _internalAxisValues.AppendRange(values.ConvertAll(val => new GH_Number(val)), path);
                    internalAxisValuesPath += 1;
                }

                // For external axis values
                else
                {
                    values = GetExternalAxisValuesAsList(jointTarget);
                    path   = new GH_Path(externalAxisValuesPath);
                    _externalAxisValues.AppendRange(values.GetRange(0, mechanicalUnit.NumberOfAxes).ConvertAll(val => new GH_Number(val)), path);
                    externalAxisValuesPath += 1;
                }
            }

            // Output
            DA.SetDataTree(0, _internalAxisValues);
            DA.SetDataTree(1, _externalAxisValues);
        }
Пример #7
0
        private void Jogging(string joint, float OffsJointValue)
        {
            JointTarget jCurPos = this.controller.MotionSystem.ActiveMechanicalUnit.GetPosition();

            switch (joint)
            {
            case "J1":
                jCurPos.RobAx.Rax_1 += OffsJointValue;
                break;

            case "J2":
                jCurPos.RobAx.Rax_2 += OffsJointValue;
                break;

            case "J3":
                jCurPos.RobAx.Rax_3 += OffsJointValue;
                break;

            case "J4":
                jCurPos.RobAx.Rax_4 += OffsJointValue;
                break;

            case "J5":
                jCurPos.RobAx.Rax_5 += OffsJointValue;
                break;

            case "J6":
                jCurPos.RobAx.Rax_6 += OffsJointValue;
                break;
            }
            try
            {
                using (this.master = Mastership.Request(controller.Rapid))
                {
                    RapidData rd = controller.Rapid.GetRapidData("T_ROB1", "Module1", "jTarget");
                    controller.Rapid.GetTask("T_ROB1").SetProgramPointer("Module1", "moveJoint");
                    rd.Value = jCurPos;
                    controller.Rapid.Start();
                }
                if (this.controller.Rapid.ExecutionStatus != ExecutionStatus.Running)
                {
                    master.Release();
                }
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show("Mastership is held by another client." + ex.Message);
                master.Release();
                master = Mastership.Request(controller);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Unexpected error occurred: " + ex.Message);
            }
        }
Пример #8
0
    Target HomeEnd()
    {
        var command = new Group()
        {
            new Message("Se acabó."),
        };

        var home = new JointTarget(_att.Home, _tool, _att.SafeSpeed, _att.SafeZone, command, _att.Frame);

        return(home);
    }
Пример #9
0
 /// <summary>
 /// Create joint target from list of rotational values.
 /// </summary>
 /// <param name="joints">List of degrees</param>
 /// <returns></returns>
 public static JointTarget JointTargetAtList(List<double> joints)
 {
     var target = new JointTarget();
     if (joints != null)
     {
         target.FillFromString2(
             string.Format("[[{0},{1},{2},{3},{4},{5}],[9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09]];",
             joints[0], joints[1], joints[2], joints[3], joints[4], joints[5]));
     }
     return target;
 }
Пример #10
0
    Target HomeStart()
    {
        var command = new Group()
        {
            new Message("Press play to start milling..."),
            new Stop()
        };

        var home = new JointTarget(_att.Home, _tool, _att.SafeSpeed, _att.SafeZone, command, _att.Frame);

        return(home);
    }
        /// <summary>
        /// Checks if the given Joint Positions are within the axis limits of the robot.
        /// </summary>
        /// <returns> A list with erros messages. When the list is empty, all the joint positions are within the limits. </returns>
        public List <string> CheckJointPositionsAxisLimits()
        {
            List <string> errors = new List <string>();

            for (int i = 0; i < _robotJointPositions.Count; i++)
            {
                JointTarget jointTarget = new JointTarget((i + 1).ToString(), _robotJointPositions[i], _externalJointPositions[i]);
                errors.AddRange(jointTarget.CheckAxisLimits(_robot));
            }

            return(errors);
        }
        /// <summary>
        /// Calculates the interpolated path of a joint movement from a Joint Target.
        /// </summary>
        /// <param name="movement"> The movement with as Target a Joint Target. </param>
        private void JointMovementFromJointTarget(Movement movement)
        {
            // Set the correct tool for this movement
            SetRobotTool(movement);

            // Get the joint target
            JointTarget jointTarget = movement.Target as JointTarget;

            // Get the final joint positions of this movement
            RobotJointPosition    towardsRobotJointPosition    = jointTarget.RobotJointPosition;
            ExternalJointPosition towardsExternalJointPosition = jointTarget.ExternalJointPosition;

            // Add error text
            _errorText.AddRange(jointTarget.CheckAxisLimits(_robot).ConvertAll(item => string.Copy(item)));

            // Interpolate
            InterpolateJointMovement(towardsRobotJointPosition, towardsExternalJointPosition);
        }
Пример #13
0
        public override bool CastFrom(object source)
        {
            if (source is Target)
            {
                Value = source as Target;
                return(true);
            }

            if (source is GH_Point)
            {
                Value = new CartesianTarget(new Plane((source as GH_Point).Value, Vector3d.XAxis, Vector3d.YAxis));
                return(true);
            }

            if (source is GH_Plane)
            {
                Value = new CartesianTarget((source as GH_Plane).Value);
                return(true);
            }

            if (source is GH_String)
            {
                string   text       = (source as GH_String).Value;
                string[] jointsText = text.Split(',');
                if (jointsText.Length != 6)
                {
                    return(false);
                }

                var joints = new double[6];
                for (int i = 0; i < 6; i++)
                {
                    if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref joints[i]))
                    {
                        return(false);
                    }
                }

                Value = new JointTarget(joints);
                return(true);
            }
            return(false);
        }
Пример #14
0
        private void UiRefresh()      //这种多线程界面更新为直接传递参数给代理函数
        {
            string returnRapid;
            int    i;

            while (true)  //Important
            {
                if (RBTCtroller != null)
                {
                    MotionSystem modata = RBTCtroller.MotionSystem;
                    i = modata.SpeedRatio;
                    JointTarget jt = new JointTarget();
                    jt          = RBTCtroller.MotionSystem.ActiveMechanicalUnit.GetPosition();
                    returnRapid = jt.ToString();
                    this.BeginInvoke(mydel, new object[] { returnRapid });//这种多线程界面更新为直接传递参数给代理函数
                }
                Thread.Sleep(1000);
            }
        }
Пример #15
0
        /// <summary>
        /// Get JointTarget Axis Value.
        /// </summary>
        /// <param name="jtValue">JointTarget with Values</param>
        /// <param name="axis">Axis number</param>
        /// <param name="mut">MechanicalUnitType to know if robot or other.</param>
        /// <returns></returns>
        private double GetJointTargetAxis(JointTarget jtValue, int axis, ABB.Robotics.Controllers.MotionDomain.MechanicalUnitType mut = ABB.Robotics.Controllers.MotionDomain.MechanicalUnitType.TcpRobot)
        {
            switch (axis)
            {
            case 1:
                switch (mut)
                {
                case ABB.Robotics.Controllers.MotionDomain.MechanicalUnitType.TcpRobot:
                    return(((double)jtValue.RobAx.Rax_1 / 360) * 2 * Math.PI);

                case ABB.Robotics.Controllers.MotionDomain.MechanicalUnitType.SingleAxis:
                    return((double)jtValue.ExtAx.Eax_a / 1000);

                default:
                    Logger.AddMessage("RSMoveMecha: GetJointTargetAxis for unmanaged MechanicalUnitType. Returns 0.", LogMessageSeverity.Error);
                    return(0);
                }

            case 2: return(((double)jtValue.RobAx.Rax_2 / 360) * 2 * Math.PI);

            case 3: return(((double)jtValue.RobAx.Rax_3 / 360) * 2 * Math.PI);

            case 4: return(((double)jtValue.RobAx.Rax_4 / 360) * 2 * Math.PI);

            case 5: return(((double)jtValue.RobAx.Rax_5 / 360) * 2 * Math.PI);

            case 6: return(((double)jtValue.RobAx.Rax_6 / 360) * 2 * Math.PI);

            case 7: return(((double)jtValue.ExtAx.Eax_a / 360) * 2 * Math.PI);

            case 8: return(((double)jtValue.ExtAx.Eax_b / 360) * 2 * Math.PI);

            case 9: return(((double)jtValue.ExtAx.Eax_c / 360) * 2 * Math.PI);

            case 10: return(((double)jtValue.ExtAx.Eax_d / 360) * 2 * Math.PI);

            case 11: return(((double)jtValue.ExtAx.Eax_e / 360) * 2 * Math.PI);

            case 12: return(((double)jtValue.ExtAx.Eax_f / 360) * 2 * Math.PI);

            default: return(0);
            }
        }
Пример #16
0
        /// <summary>
        /// Returns a Joints object representing the rotations of the 6 axes of this robot.
        /// </summary>
        /// <returns></returns>
        public Joints GetCurrentJoints()
        {
            if (!_isConnected)
            {
                logger.Debug("Cannot GetCurrentJoints, not connected to controller");
                return(null);
            }

            try
            {
                JointTarget jt = controller.MotionSystem.ActiveMechanicalUnit.GetPosition();
                return(new Joints(jt.RobAx.Rax_1, jt.RobAx.Rax_2, jt.RobAx.Rax_3, jt.RobAx.Rax_4, jt.RobAx.Rax_5, jt.RobAx.Rax_6));
            }
            catch (ABB.Robotics.Controllers.ServiceNotSupportedException e)
            {
                logger.Debug("CANNOT RETRIEVE JOINTS FROM CONTROLLER");
                logger.Debug(e);
                return(null);
            }
        }
Пример #17
0
    protected override void SetJoints(Target target, double[]?prevJoints)
    {
        for (int i = 0; i < _mechanism.Joints.Length; i++)
        {
            int externalNum = _mechanism.Joints[i].Number - 6;
            if (target.External.Length - 1 < externalNum)
            {
                Errors.Add($"Positioner external axis not configured on this target.");
            }
            else
            {
                Joints[i] = target.External[externalNum];
            }
        }

        if (prevJoints is not null)
        {
            Joints = JointTarget.GetAbsoluteJoints(Joints, prevJoints);
        }
    }
Пример #18
0
    protected override void SetJoints(Target target, double[]?prevJoints)
    {
        if (target is JointTarget jointTarget)
        {
            Joints = jointTarget.Joints;
        }
        else if (target is CartesianTarget cartesianTarget)
        {
            Plane tcp = target.Tool.Tcp;
            tcp.Rotate(PI, Vector3d.ZAxis, Point3d.Origin);

            Plane targetPlane = cartesianTarget.Plane;
            targetPlane.Orient(ref target.Frame.Plane);

            var transform = Planes[0].ToInverseTransform() * Transform.PlaneToPlane(tcp, targetPlane);

            List <string> errors;
            double[]      joints;

            if (cartesianTarget.Configuration is not null || prevJoints is null)
            {
                Configuration = cartesianTarget.Configuration ?? RobotConfigurations.None;
                joints        = InverseKinematics(transform, Configuration, out errors);
            }
            else
            {
                joints        = GetClosestSolution(transform, prevJoints, out var configuration, out errors, out _);
                Configuration = configuration;
            }

            if (prevJoints is not null)
            {
                Joints = JointTarget.GetAbsoluteJoints(joints, prevJoints);
            }
            else
            {
                Joints = joints;
            }

            Errors.AddRange(errors);
        }
Пример #19
0
        private void showRobotPosition()
        {
            while (true)
            {
                try
                {
                    JointTarget currentJointPoint = this.controller.MotionSystem.ActiveMechanicalUnit.GetPosition();
                    tbJ1.Text = Math.Round(currentJointPoint.RobAx.Rax_1, 2).ToString();
                    tbJ2.Text = Math.Round(currentJointPoint.RobAx.Rax_2, 2).ToString();
                    tbJ3.Text = Math.Round(currentJointPoint.RobAx.Rax_3, 2).ToString();
                    tbJ4.Text = Math.Round(currentJointPoint.RobAx.Rax_4, 2).ToString();
                    tbJ5.Text = Math.Round(currentJointPoint.RobAx.Rax_5, 2).ToString();
                    tbJ6.Text = Math.Round(currentJointPoint.RobAx.Rax_6, 2).ToString();


                    RobTarget currentCartesianPoint = this.controller.MotionSystem.ActiveMechanicalUnit.GetPosition(ABB.Robotics.Controllers.MotionDomain.CoordinateSystemType.World);
                    tbX.Text = Math.Round(currentCartesianPoint.Trans.X, 2).ToString();
                    tbY.Text = Math.Round(currentCartesianPoint.Trans.Y, 2).ToString();
                    tbZ.Text = Math.Round(currentCartesianPoint.Trans.Z, 2).ToString();

                    double q0, q1, q2, q3;
                    //double Rz,Ry,Rx;
                    q0 = currentCartesianPoint.Rot.Q1;
                    q1 = currentCartesianPoint.Rot.Q2;
                    q2 = currentCartesianPoint.Rot.Q3;
                    q3 = currentCartesianPoint.Rot.Q4;
                    //Rz = Math.Atan(2 * (q1 * q2 - q0 * q3) / (q0 * q0 + q1 * q1 - q2 * q2 - q3 * q3));
                    //Ry = Math.Asin(-2*(q0*q2+q1*q3));
                    //Rx = Math.Atan(2 * (q2 * q3 - q0 * q1) / (q0 * q0 - q1 * q1 - q2 * q2 + q3 * q3));
                    //tbQ1.Text = Rx.ToString();
                    //tbQ2.Text = Ry.ToString();
                    //tbQ3.Text = Rz.ToString();
                    tbQ1.Text = Math.Round(q0, 2).ToString();
                    tbQ2.Text = Math.Round(q1, 2).ToString();
                    tbQ3.Text = Math.Round(q2, 2).ToString();
                    tbQ4.Text = Math.Round(q3, 2).ToString();
                }
                catch
                { }
            }
        }
Пример #20
0
    public override bool CastFrom(object source)
    {
        switch (source)
        {
        case Target target:
            Value = target;
            return(true);

        case GH_Point point:
            Value = new CartesianTarget(new Plane(point.Value, Vector3d.XAxis, Vector3d.YAxis));
            return(true);

        case GH_Plane plane:
            Value = new CartesianTarget(plane.Value);
            return(true);

        case GH_String text:
        {
            string[] jointsText = text.Value.Split(',');
            if (jointsText.Length != 6)
            {
                return(false);
            }

            var joints = new double[6];
            for (int i = 0; i < 6; i++)
            {
                if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref joints[i]))
                {
                    return(false);
                }
            }

            Value = new JointTarget(joints);
            return(true);
        }
        }

        return(false);
    }
        /// <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
            JointTarget jointTarget = null;

            // Catch the input data
            if (!DA.GetData(0, ref jointTarget))
            {
                return;
            }

            // Check if the object is valid
            if (!jointTarget.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The Joint Target is not valid");
            }

            // Output
            DA.SetData(0, jointTarget.Name);
            DA.SetData(1, jointTarget.RobotJointPosition);
            DA.SetData(2, jointTarget.ExternalJointPosition);
        }
Пример #22
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool hasTarget   = Params.Input.Any(x => x.Name == "Target");
            bool hasJoints   = Params.Input.Any(x => x.Name == "Joints");
            bool hasPlane    = Params.Input.Any(x => x.Name == "Plane");
            bool hasConfig   = Params.Input.Any(x => x.Name == "RobConf");
            bool hasMotion   = Params.Input.Any(x => x.Name == "Motion");
            bool hasTool     = Params.Input.Any(x => x.Name == "Tool");
            bool hasSpeed    = Params.Input.Any(x => x.Name == "Speed");
            bool hasZone     = Params.Input.Any(x => x.Name == "Zone");
            bool hasCommand  = Params.Input.Any(x => x.Name == "Command");
            bool hasFrame    = Params.Input.Any(x => x.Name == "Frame");
            bool hasExternal = Params.Input.Any(x => x.Name == "External");

            GH_Target sourceTarget = null;

            if (hasTarget)
            {
                if (!DA.GetData("Target", ref sourceTarget))
                {
                    return;
                }
            }

            double[] joints = null;
            var      plane  = new Plane();

            Target.RobotConfigurations?configuration = null;
            Target.Motions             motion        = Target.Motions.Joint;
            Tool    tool    = null;
            Speed   speed   = null;
            Zone    zone    = null;
            Command command = null;
            Frame   frame   = null;

            double[] external = null;

            if (hasJoints)
            {
                GH_String jointsGH = null;
                if (!DA.GetData("Joints", ref jointsGH))
                {
                    return;
                }

                string[] jointsText = jointsGH.Value.Split(',');
                if (jointsText.Length != 6)
                {
                    return;
                }

                joints = new double[6];

                for (int i = 0; i < 6; i++)
                {
                    if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref joints[i]))
                    {
                        return;
                    }
                }
            }
            else if (sourceTarget != null)
            {
                if (sourceTarget.Value is JointTarget)
                {
                    joints = (sourceTarget.Value as JointTarget).Joints;
                }
            }

            if (hasPlane)
            {
                GH_Plane planeGH = null;
                if (hasPlane)
                {
                    if (!DA.GetData("Plane", ref planeGH))
                    {
                        return;
                    }
                }
                plane = planeGH.Value;
            }
            else if (sourceTarget != null)
            {
                if (sourceTarget.Value is CartesianTarget)
                {
                    plane = (sourceTarget.Value as CartesianTarget).Plane;
                }
            }

            if (hasConfig)
            {
                GH_Integer configGH = null;
                if (hasConfig)
                {
                    DA.GetData("RobConf", ref configGH);
                }
                configuration = (configGH == null) ? null : (Target.RobotConfigurations?)configGH.Value;
            }
            else if (sourceTarget != null)
            {
                if (sourceTarget.Value is CartesianTarget)
                {
                    configuration = (sourceTarget.Value as CartesianTarget).Configuration;
                }
            }

            if (hasMotion)
            {
                GH_String motionGH = null;
                DA.GetData("Motion", ref motionGH);
                motion = (motionGH == null) ? Target.Motions.Joint : (Target.Motions)Enum.Parse(typeof(Target.Motions), motionGH.Value);
            }
            else if (sourceTarget != null)
            {
                if (sourceTarget.Value is CartesianTarget)
                {
                    motion = (sourceTarget.Value as CartesianTarget).Motion;
                }
            }

            if (hasTool)
            {
                GH_Tool toolGH = null;
                DA.GetData("Tool", ref toolGH);
                tool = toolGH?.Value;
            }
            else if (sourceTarget != null)
            {
                tool = sourceTarget.Value.Tool;
            }

            if (hasSpeed)
            {
                GH_Speed speedGH = null;
                DA.GetData("Speed", ref speedGH);
                speed = speedGH?.Value;
            }
            else if (sourceTarget != null)
            {
                speed = sourceTarget.Value.Speed;
            }

            if (hasZone)
            {
                GH_Zone zoneGH = null;
                DA.GetData("Zone", ref zoneGH);
                zone = zoneGH?.Value;
            }
            else if (sourceTarget != null)
            {
                zone = sourceTarget.Value.Zone;
            }

            if (hasCommand)
            {
                GH_Command commandGH = null;
                DA.GetData("Command", ref commandGH);
                command = commandGH?.Value;
            }
            else if (sourceTarget != null)
            {
                command = sourceTarget.Value.Command;
            }

            if (hasFrame)
            {
                GH_Frame frameGH = null;
                DA.GetData("Frame", ref frameGH);
                frame = frameGH?.Value;
            }
            else if (sourceTarget != null)
            {
                frame = sourceTarget.Value.Frame;
            }

            if (hasExternal)
            {
                GH_String externalGH = null;
                if (!DA.GetData("External", ref externalGH))
                {
                    external = new double[0];
                }
                else
                {
                    string[] externalText = externalGH.Value.Split(',');
                    int      length       = externalText.Length;
                    external = new double[length];
                    for (int i = 0; i < length; i++)
                    {
                        if (!GH_Convert.ToDouble_Secondary(externalText[i], ref external[i]))
                        {
                            return;
                        }
                    }
                }
            }
            else if (sourceTarget != null)
            {
                external = sourceTarget.Value.External;
            }

            Target target;

            bool localCartesian = isCartesian;

            if (hasTarget && !hasPlane && !hasJoints)
            {
                localCartesian = sourceTarget.Value is CartesianTarget;
            }

            if (localCartesian)
            {
                target = new CartesianTarget(plane, configuration, motion, tool, speed, zone, command, frame, external);
            }
            else
            {
                target = new JointTarget(joints, tool, speed, zone, command, frame, external);
            }

            if (sourceTarget != null)
            {
                target.ExternalCustom = sourceTarget.Value.ExternalCustom;
            }

            DA.SetData(0, new GH_Target(target));
        }
Пример #23
0
        /// <summary>
        /// Attempt a cast from generic object.
        /// </summary>
        /// <param name="source"> Reference to source of cast. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }

            //Cast from Movement
            if (typeof(Movement).IsAssignableFrom(source.GetType()))
            {
                Value = source as Movement;
                return(true);
            }

            //Cast from Target
            if (typeof(ITarget).IsAssignableFrom(source.GetType()))
            {
                Value = new Movement(source as ITarget);
                return(true);
            }

            //Cast from Target Goo
            if (typeof(GH_Target).IsAssignableFrom(source.GetType()))
            {
                GH_Target targetGoo = source as GH_Target;
                Value = new Movement(targetGoo.Value);
                return(true);
            }

            //Cast from Robot Target
            if (typeof(RobotTarget).IsAssignableFrom(source.GetType()))
            {
                RobotTarget target = (RobotTarget)source;
                Value = new Movement(target);
                return(true);
            }

            //Cast from Robot Target Goo
            if (typeof(GH_RobotTarget).IsAssignableFrom(source.GetType()))
            {
                GH_RobotTarget targetGoo = (GH_RobotTarget)source;
                Value = new Movement(targetGoo.Value);
                return(true);
            }

            //Cast from Joint Target
            if (typeof(JointTarget).IsAssignableFrom(source.GetType()))
            {
                JointTarget target = (JointTarget)source;
                Value = new Movement(target);
                return(true);
            }

            //Cast from Joint Target Goo
            if (typeof(GH_JointTarget).IsAssignableFrom(source.GetType()))
            {
                GH_JointTarget targetGoo = (GH_JointTarget)source;
                Value = new Movement(targetGoo.Value);
                return(true);
            }

            //Cast from Action
            if (typeof(Action).IsAssignableFrom(source.GetType()))
            {
                if (source is Movement action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Action Goo
            if (typeof(GH_Action).IsAssignableFrom(source.GetType()))
            {
                GH_Action actionGoo = source as GH_Action;
                if (actionGoo.Value is Movement action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Instruction
            if (typeof(IInstruction).IsAssignableFrom(source.GetType()))
            {
                if (source is Movement instruction)
                {
                    Value = instruction;
                    return(true);
                }
            }

            //Cast from Instruction Goo
            if (typeof(GH_Instruction).IsAssignableFrom(source.GetType()))
            {
                GH_Instruction instructionGoo = source as GH_Instruction;
                if (instructionGoo.Value is Movement instruction)
                {
                    Value = instruction;
                    return(true);
                }
            }

            return(false);
        }
Пример #24
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool hasTarget = Params.Input.Any(x => x.Name == "Target");
            bool hasJoints = Params.Input.Any(x => x.Name == "Joints");
            bool hasPlane = Params.Input.Any(x => x.Name == "Plane");
            bool hasConfig = Params.Input.Any(x => x.Name == "RobConf");
            bool hasMotion = Params.Input.Any(x => x.Name == "Motion");
            bool hasTool = Params.Input.Any(x => x.Name == "Tool");
            bool hasSpeed = Params.Input.Any(x => x.Name == "Speed");
            bool hasZone = Params.Input.Any(x => x.Name == "Zone");
            bool hasCommand = Params.Input.Any(x => x.Name == "Command");
            bool hasFrame = Params.Input.Any(x => x.Name == "Frame");
            bool hasExternal = Params.Input.Any(x => x.Name == "External");

            GH_Target sourceTarget = null;
            if (hasTarget) if (!DA.GetData("Target", ref sourceTarget)) return;

            double[] joints = null;
            var plane = new Plane();
            Target.RobotConfigurations? configuration = null;
            Target.Motions motion = Target.Motions.Joint;
            Tool tool = null;
            Speed speed = null;
            Zone zone = null;
            Command command = null;
            Frame frame = null;
            double[] external = null;

            if (hasJoints)
            {
                GH_String jointsGH = null;
                if (!DA.GetData("Joints", ref jointsGH)) return;

                string[] jointsText = jointsGH.Value.Split(',');
                if (jointsText.Length != 6) return;

                joints = new double[6];

                for (int i = 0; i < 6; i++)
                    if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref joints[i])) return;
            }
            else if (sourceTarget != null)
            {
                if (sourceTarget.Value is JointTarget) joints = (sourceTarget.Value as JointTarget).Joints;
            }

            if (hasPlane)
            {
                GH_Plane planeGH = null;
                if (hasPlane) if (!DA.GetData("Plane", ref planeGH)) return;
                plane = planeGH.Value;
            }
            else if (sourceTarget != null)
            {
                if (sourceTarget.Value is CartesianTarget) plane = (sourceTarget.Value as CartesianTarget).Plane;
            }

            if (hasConfig)
            {
                GH_Integer configGH = null;
                if (hasConfig) DA.GetData("RobConf", ref configGH);
                configuration = (configGH == null) ? null : (Target.RobotConfigurations?)configGH.Value;
            }
            else if (sourceTarget != null)
            {
                if (sourceTarget.Value is CartesianTarget) configuration = (sourceTarget.Value as CartesianTarget).Configuration;
            }

            if (hasMotion)
            {
                GH_String motionGH = null;
                DA.GetData("Motion", ref motionGH);
                motion = (motionGH == null) ? Target.Motions.Joint : (Target.Motions)Enum.Parse(typeof(Target.Motions), motionGH.Value);
            }
            else if (sourceTarget != null)
            {
                if (sourceTarget.Value is CartesianTarget) motion = (sourceTarget.Value as CartesianTarget).Motion;
            }

            if (hasTool)
            {
                GH_Tool toolGH = null;
                DA.GetData("Tool", ref toolGH);
                tool = toolGH?.Value;
            }
            else if (sourceTarget != null)
            {
                tool = sourceTarget.Value.Tool;
            }

            if (hasSpeed)
            {
                GH_Speed speedGH = null;
                DA.GetData("Speed", ref speedGH);
                speed = speedGH?.Value;
            }
            else if (sourceTarget != null)
            {
                speed = sourceTarget.Value.Speed;
            }

            if (hasZone)
            {
                GH_Zone zoneGH = null;
                DA.GetData("Zone", ref zoneGH);
                zone = zoneGH?.Value;
            }
            else if (sourceTarget != null)
            {
                zone = sourceTarget.Value.Zone;
            }

            if (hasCommand)
            {
                GH_Command commandGH = null;
                DA.GetData("Command", ref commandGH);
                command = commandGH?.Value;
            }
            else if (sourceTarget != null)
            {
                command = sourceTarget.Value.Command;
            }

            if (hasFrame)
            {
                GH_Frame frameGH = null;
                DA.GetData("Frame", ref frameGH);
                frame = frameGH?.Value;
            }
            else if (sourceTarget != null)
            {
                frame = sourceTarget.Value.Frame;
            }

            if (hasExternal)
            {
                GH_String externalGH = null;
                if (!DA.GetData("External", ref externalGH))
                {
                    external = new double[0];
                }
                else
                {
                    string[] externalText = externalGH.Value.Split(',');
                    int length = externalText.Length;
                    external = new double[length];
                    for (int i = 0; i < length; i++)
                        if (!GH_Convert.ToDouble_Secondary(externalText[i], ref external[i])) return;
                }
            }
            else if (sourceTarget != null)
            {
                external = sourceTarget.Value.External;
            }

            Target target;

            bool localCartesian = isCartesian;

            if (hasTarget && !hasPlane && !hasJoints)
                localCartesian = sourceTarget.Value is CartesianTarget;

            if (localCartesian)
                target = new CartesianTarget(plane, configuration, motion, tool, speed, zone, command, frame, external);
            else
                target = new JointTarget(joints, tool, speed, zone, command, frame, external);

            DA.SetData(0, new GH_Target(target));
        }
Пример #25
0
 /// <summary>
 /// Create joint target from rotational values per axis.
 /// </summary>
 /// <param name="j1">Degrees</param>
 /// <param name="j2">Degrees</param>
 /// <param name="j3">Degrees</param>
 /// <param name="j4">Degrees</param>
 /// <param name="j5">Degrees</param>
 /// <param name="j6">Degrees</param>
 /// <returns></returns>
 public static JointTarget JointTargetAtVals(double j1, double j2, double j3, double j4, double j5, double j6)
 {
     var target = new JointTarget();
     target.FillFromString2(
         string.Format("[[{0},{1},{2},{3},{4},{5}],[9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09]];",
         j1, j2, j3, j4, j5, j6));
     return target;
 }
Пример #26
0
        private void UIshow()
        {
            ControllerOperatingMode ctrlMode;
            ControllerState         ctrlState;

            ctrlMode = RBTCtroller.OperatingMode;
            switch (ctrlMode.ToString())
            {
            case "0":
                btnModel.Text = "Auto"; break;

            case "1":
                btnModel.Text = "Init"; break;

            case "2":
                btnModel.Text = "MannualReducedSpeed"; break;

            case "3":
                btnModel.Text = "ManualFullSpeed"; break;

            case "4":
                btnModel.Text = "AutoChange"; break;

            case "5":
                btnModel.Text = "MannualFullSpeedChange"; break;

            case "6":
                btnModel.Text = "NotApplicable"; break;

            default:
                btnModel.Text = ctrlMode.ToString();
                break;
            }
            ctrlState = RBTCtroller.State;
            switch (ctrlState.ToString())
            {
            case "0":
                lblState.Text = "Init"; break;

            case "1":
                lblState.Text = "MotorsOff"; break;

            case "2":
                lblState.Text = "MotorsOn"; break;

            case "3":
                lblState.Text = "GuardStop"; break;

            case "4":
                lblState.Text = "EmgStopp"; break;

            case "5":
                lblState.Text = "EmgStopRest"; break;

            case "6":
                lblState.Text = "SystemFailure"; break;

            case "99":
                lblState.Text = "Unknown"; break;

            default:
                lblState.Text = ctrlState.ToString();
                break;
            }


            //throw new NotImplementedException();
            switch (comboBox1.SelectedItem.ToString())
            {
            case "Base":       //注意获取直角坐标的类继承关系,及参数
                p = RBTCtroller.MotionSystem.ActiveMechanicalUnit.GetPosition(CoordinateSystemType.Base);
                break;

            case "Tool":
                p = RBTCtroller.MotionSystem.ActiveMechanicalUnit.GetPosition(CoordinateSystemType.Tool);
                break;

            case "WorkObject":
                p = RBTCtroller.MotionSystem.ActiveMechanicalUnit.GetPosition(CoordinateSystemType.WorkObject);
                break;

            case "World":
                p = RBTCtroller.MotionSystem.ActiveMechanicalUnit.GetPosition(CoordinateSystemType.World);
                break;

            case "Undefined":
                J = RBTCtroller.MotionSystem.ActiveMechanicalUnit.GetPosition();
                break;

            default: break;
            }
            textBox1Num.Text = p.Trans.X.ToString();   //此次的p要定义到函数外边,否则会提示:有可能未赋值的错误!!!
            textBox2Num.Text = p.Trans.Y.ToString();
            textBox3Num.Text = p.Trans.Z.ToString();
            textBox4Num.Text = p.Rot.Q1.ToString();
            textBox5Num.Text = p.Rot.Q2.ToString();
            textBox6Num.Text = p.Rot.Q3.ToString();    //此次还有个Q4不知道用来做什么
        }
Пример #27
0
        public static Dictionary<string, string> WZLimJointDef(string varName, string Inside_Outside, JointTarget loJointVal, JointTarget hiJointVal)
        {
            string cnst = string.Format("\n\tVAR wzstationary wl{0};" +
                                        "\n\tVAR shapedata js{0};" +
                                        "\n\tCONST jointtarget lo{0}:={1};" +
                                        "\n\tCONST jointtarget hi{0}:={2};",
                                        varName, loJointVal, hiJointVal);
            string inst = string.Format("WZLimJointDef \\{0},js{1},lo{1},hi{1};" +
                                        "WzLimSup \\Stat, wl{1},js{1};",
                                        Inside_Outside, varName);

            return new Dictionary<string, string>
            {
                {"cnst", cnst},
                {"inst", inst},
             };
        }
Пример #28
0
        /// <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)
        {
            // Variables
            List <string>                names = new List <string>();
            List <RobotJointPosition>    robotJointPositions    = new List <RobotJointPosition>();
            List <ExternalJointPosition> externalJointPositions = new List <ExternalJointPosition>();

            // Catch input data
            if (!DA.GetDataList(0, names))
            {
                return;
            }
            if (!DA.GetDataList(1, robotJointPositions))
            {
                robotJointPositions = new List <RobotJointPosition>()
                {
                    new RobotJointPosition()
                };
            }
            if (!DA.GetDataList(2, externalJointPositions))
            {
                externalJointPositions = new List <ExternalJointPosition>()
                {
                    new ExternalJointPosition()
                };
            }

            // Replace spaces
            names = HelperMethods.ReplaceSpacesAndRemoveNewLines(names);

            // Get longest input List
            int[] sizeValues = new int[3];
            sizeValues[0] = names.Count;
            sizeValues[1] = robotJointPositions.Count;
            sizeValues[2] = externalJointPositions.Count;

            int biggestSize = HelperMethods.GetBiggestValue(sizeValues);

            // Keeps track of used indicies
            int nameCounter   = -1;
            int robPosCounter = -1;
            int extPosCounter = -1;

            // Clear list
            _jointTargets.Clear();

            // Creates the joint targets
            for (int i = 0; i < biggestSize; i++)
            {
                string                name;
                RobotJointPosition    robotJointPosition;
                ExternalJointPosition externalJointPosition;

                // Names counter
                if (i < sizeValues[0])
                {
                    name = names[i];
                    nameCounter++;
                }
                else
                {
                    name = names[nameCounter] + "_" + (i - nameCounter);
                }

                // Robot Joint Position counter
                if (i < sizeValues[1])
                {
                    robotJointPosition = robotJointPositions[i];
                    robPosCounter++;
                }
                else
                {
                    robotJointPosition = robotJointPositions[robPosCounter];
                }

                // External Joint Position counter
                if (i < sizeValues[2])
                {
                    externalJointPosition = externalJointPositions[i];
                    extPosCounter++;
                }
                else
                {
                    externalJointPosition = externalJointPositions[extPosCounter];
                }

                JointTarget jointTarget = new JointTarget(name, robotJointPosition, externalJointPosition);
                _jointTargets.Add(jointTarget);
            }

            // Sets Output
            DA.SetDataList(0, _jointTargets);

            #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 TargetByGuid Dictionary
            if (!_objectManager.OldJointTargetsByGuid3.ContainsKey(this.InstanceGuid))
            {
                _objectManager.OldJointTargetsByGuid3.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
        }
Пример #29
0
        void CreateTargets(List <List <SimpleTarget> > paths)
        {
            double totalDistance  = 0;
            var    externalCustom = new[] { "motorValue" };

            _targets.Add(HomeStart());

            foreach (var path in paths)
            {
                var first = path[0].Location;
                var last  = path[path.Count - 1].Location;

                var firstSafe = first; firstSafe.Origin += firstSafe.Normal * _att.SafeZOffset;

                _targets.Add(CreateTarget(firstSafe, _att.SafeSpeed, _att.SafeZone, 0));

                _targets.Add(CreateTarget(first, _att.ApproachSpeed, _att.ApproachZone, 0));
                _targets.Add(CreateTarget(first, _att.ApproachSpeed, _att.ApproachZone, _startDistance));

                for (int i = 1; i < path.Count; i++)
                {
                    //double segmentLength = path[i - 1].DistanceTo(path[i]);
                    Plane  position      = path[i].Location;
                    double segmentLength = path[i].Length;

                    var zone = i != path.Count - 1 ? _att.ExtrusionZone : _att.ApproachZone;
                    _targets.Add(CreateTarget(position, _att.ExtrusionSpeed, zone, segmentLength));
                }

                _targets.Add(CreateTarget(last, _att.ExtrusionSpeed, _att.ApproachZone, _suckBack));

                var lastOffset = last; lastOffset.Origin += lastOffset.Normal * (_att.SafeZOffset + _att.LayerHeight);
                _targets.Add(CreateTarget(lastOffset, _att.ApproachSpeed, _att.SafeZone, 0));

                SubPrograms.Add(_targets.Count);
            }

            _targets.Add(HomeEnd());
            SubPrograms.RemoveAt(SubPrograms.Count - 1);


            Target CreateTarget(Plane location, Speed speed, Zone zone, double externalDistance)
            {
                var frame = _att.Frame;
                var tool  = _att.Tool;

                totalDistance += externalDistance * _extrusionFactor;

                Command command = null;

                if (externalDistance != 0)
                {
                    string sign            = externalDistance < 0 ? "+" : "-";
                    string code            = $"motorValue:=motorValue{sign}{Abs(externalDistance):0.000}*extrusionFactor;";
                    var    externalCommand = new Robots.Commands.Custom($"SetExternal{_targets.Count}", command: code);
                    externalCommand.RunBefore = true;
                    command = externalCommand;
                }

                var target = new CartesianTarget(location, null, Motions.Linear, tool, speed, zone, command, frame, new[] { totalDistance });

                target.ExternalCustom = externalCustom;
                return(target);
            }

            Target HomeStart()
            {
                var externalValue = ExternalValue(_loopDistance);

                string declaration = $@"VAR num motorValue:= 0;
PERS num extrusionFactor:={_extrusionFactor: 0.000};
VAR robtarget current;
VAR num choice:=0;
";
                string initCode    = $@"current:= CRobT(\Tool:= {_att.Tool.Name} \WObj:= {_att.Frame.Name});
EOffsSet current.extax;";

                string testCode = $@"TPReadFK choice,""Choose mode"",stEmpty,stEmpty,stEmpty,""Program"",""Test"";
current:= CRobT(\Tool:= {_att.Tool.Name} \WObj:= {_att.Frame.Name});
WHILE choice = 5 DO
    motorValue:= motorValue - {externalValue:0.00}*extrusionFactor;
    current.extax.eax_a:= motorValue;
    MoveL Offs(current,0,{_loopDistance},0),{_att.ExtrusionSpeed.Name},{_att.ExtrusionZone.Name},{_att.Tool.Name} \WObj:= {_att.Frame.Name};
    motorValue:= motorValue - {externalValue:0.00}*extrusionFactor;
    current.extax.eax_a:= motorValue;
    MoveL Offs(current,0,0,0),{_att.ExtrusionSpeed.Name},{_att.ExtrusionZone.Name},{_att.Tool.Name} \WObj:= {_att.Frame.Name};
ENDWHILE";

                var initCommand = new Robots.Commands.Custom("Init", declaration: declaration, command: initCode);

                initCommand.RunBefore = true;
                var testCommand = new Robots.Commands.Custom("Test", command: testCode);

                var command = new Group(new[] { initCommand, testCommand });
                var home    = new JointTarget(_att.Home, _att.Tool, _att.SafeSpeed, _att.SafeZone, command, _att.Frame, new[] { totalDistance });

                home.ExternalCustom = externalCustom;
                return(home);
            }

            Target HomeEnd()
            {
                var command = new Group()
                {
                    new Message("Se acabó."),
                    new Stop()
                };
                var home = new JointTarget(_att.Home, _att.Tool, _att.SafeSpeed, _att.SafeZone, command, _att.Frame, new[] { totalDistance });

                home.ExternalCustom = externalCustom;
                return(home);
            }
        }
Пример #30
0
        /// <summary>
        /// Update Mechanism axes values
        /// </summary>
        /// <param name="component">Component that owns signals. </param>
        /// <param name="jtValue">JointTarget Value</param>
        private void UpdateAxis(SmartComponent component, Controller controller)
        {
            int iCtrlMechanismIndex = (int)component.Properties["CtrlMechanism"].Value;

            if ((iCtrlMechanismIndex < 1) || (iCtrlMechanismIndex > controller.MotionSystem.MechanicalUnits.Count))
            {
                component.Properties["CtrlMechanism"].Value = iCtrlMechanismIndex = 1;
            }

            //Get Controller Values
            ABB.Robotics.Controllers.MotionDomain.MechanicalUnit mu = controller.MotionSystem.MechanicalUnits[iCtrlMechanismIndex - 1];
            int         iCtrlNumberOfAxes = mu.NumberOfAxes;
            JointTarget jtValue           = mu.GetPosition();

            component.Properties["CtrlSpecAxis"].Attributes["MaxValue"] = iCtrlNumberOfAxes.ToString();
            int iCtrlSpecAxis = (int)component.Properties["CtrlSpecAxis"].Value;

            if (iCtrlSpecAxis > iCtrlNumberOfAxes)
            {
                component.Properties["CtrlSpecAxis"].Value = iCtrlSpecAxis = iCtrlNumberOfAxes;
            }
            if (iCtrlSpecAxis < 0)
            {
                component.Properties["CtrlSpecAxis"].Value = iCtrlSpecAxis = 0;
            }

            //Get Mechanism Values
            Mechanism mecha = (Mechanism)component.Properties["Mechanism"].Value;

            if (mecha == null)
            {
                return;
            }
            int[] mechaAxes         = mecha.GetActiveJoints();
            int   iMechNumberOfAxes = mechaAxes.Length;

            double[] mechaValues = mecha.GetJointValues();
            component.Properties["MechSpecAxis"].Attributes["MaxValue"] = iMechNumberOfAxes.ToString();
            int iMechSpecAxis = (int)component.Properties["MechSpecAxis"].Value;

            if (iMechSpecAxis > iCtrlNumberOfAxes)
            {
                component.Properties["MechSpecAxis"].Value = iMechSpecAxis = iMechNumberOfAxes;
            }
            if (iMechSpecAxis < 0)
            {
                component.Properties["MechSpecAxis"].Value = iMechSpecAxis = 0;
            }

            //Start Updating
            int iAxesUpdated = 0;

            if (iCtrlSpecAxis == 0)
            {
                if (iMechSpecAxis == 0)
                {                 //Take all Controller axes to update all Mechanism
                    for (int iAxis = 1; (iAxis <= iCtrlNumberOfAxes) && (iAxis <= iMechNumberOfAxes); ++iAxis)
                    {
                        mechaValues[iAxis - 1] = GetJointTargetAxis(jtValue, iAxis, mu.Type);
                    }
                }
                else
                {                 //Only Take Mechanism Specific axis from controller to update it
                    if ((iMechSpecAxis <= iCtrlNumberOfAxes) && (iMechSpecAxis <= iMechNumberOfAxes))
                    {
                        mechaValues[iMechSpecAxis - 1] = GetJointTargetAxis(jtValue, iMechSpecAxis, mu.Type);
                    }
                }
            }
            else
            {
                if (iMechSpecAxis == 0)
                {                 //Only Take Controller Specific axis to update same in Mechanism
                    if ((iCtrlSpecAxis <= iCtrlNumberOfAxes) && (iCtrlSpecAxis <= iMechNumberOfAxes))
                    {
                        mechaValues[iCtrlSpecAxis - 1] = GetJointTargetAxis(jtValue, iCtrlSpecAxis, mu.Type);
                    }
                }
                else
                {                 //Only Take Controller Specific axis to update Mechanism Specific axis
                    if ((iCtrlSpecAxis <= iCtrlNumberOfAxes) && (iMechSpecAxis <= iMechNumberOfAxes))
                    {
                        mechaValues[iMechSpecAxis - 1] = GetJointTargetAxis(jtValue, iCtrlSpecAxis, mu.Type);
                    }
                }
            }


            iAxesUpdated = ((iCtrlSpecAxis == 0) && (iMechSpecAxis == 0)) ? Math.Min(iCtrlNumberOfAxes, iMechNumberOfAxes) : 1;

            //Updating
            if (!mecha.SetJointValues(mechaValues, true))
            {
                component.Properties["Status"].Value = "Error";
                Logger.AddMessage("RSMoveMecha: Component " + component.Name + " can't update " + mecha.Name + ".", LogMessageSeverity.Error);
            }
            else
            {
                string sNumberOfAxesStatus = iAxesUpdated.ToString() + "/" + iMechNumberOfAxes.ToString() + " Mechanism axes updated from " + iCtrlNumberOfAxes.ToString() + " Controller axes.";
                component.Properties["NumberOfAxesStatus"].Value = sNumberOfAxesStatus;
            }
        }