/// <summary>
        /// This method displays the robot pose for the given axis values.
        /// </summary>
        /// <param name="args"> Preview display arguments for IGH_PreviewObjects. </param>
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            // Check if there is a mesh available to display and the onlyTCP function not active
            if (!_hideMesh)
            {
                // Initiate the display color and transparancy of the robot mesh
                Color  color;
                double trans;

                // Calculate forward kinematics
                _forwardKinematics.HideMesh = _hideMesh;
                _forwardKinematics.Calculate(_inverseKinematics.RobotJointPosition, _inverseKinematics.ExternalJointPosition);

                // Set the display color and transparancy of the robot mesh
                if (_forwardKinematics.InLimits == true)
                {
                    color = Color.FromArgb(225, 225, 225);
                    trans = 0.0;
                }
                else
                {
                    color = Color.FromArgb(150, 0, 0);
                    trans = 0.5;
                }

                // Display the internal axes of the robot
                for (int i = 0; i != _forwardKinematics.PosedInternalAxisMeshes.Count; i++)
                {
                    args.Display.DrawMeshShaded(_forwardKinematics.PosedInternalAxisMeshes[i], new Rhino.Display.DisplayMaterial(color, trans));
                }

                // Display the external axes
                for (int i = 0; i != _forwardKinematics.PosedExternalAxisMeshes.Count; i++)
                {
                    for (int j = 0; j != _forwardKinematics.PosedExternalAxisMeshes[i].Count; j++)
                    {
                        args.Display.DrawMeshShaded(_forwardKinematics.PosedExternalAxisMeshes[i][j], new Rhino.Display.DisplayMaterial(color, trans));
                    }
                }
            }
        }
        /// <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
            List <RobotComponents.Actions.Action> actions = new List <RobotComponents.Actions.Action>();
            int    interpolations      = 0;
            double interpolationSlider = 0;
            bool   update = false;

            // Catch the input data
            if (!DA.GetData(0, ref _robot))
            {
                return;
            }
            if (!DA.GetDataList(1, actions))
            {
                return;
            }
            if (!DA.GetData(2, ref interpolations))
            {
                return;
            }
            if (!DA.GetData(3, ref interpolationSlider))
            {
                return;
            }
            if (!DA.GetData(4, ref update))
            {
                return;
            }

            // Update the path
            if (update == true || _lastInterpolations != interpolations)
            {
                // Create forward kinematics for mesh display
                _forwardKinematics = new ForwardKinematics(_robot);

                // Create the path generator
                _pathGenerator = new PathGenerator(_robot);

                // Re-calculate the path
                _pathGenerator.Calculate(actions, interpolations);

                // Get all the targets
                _planes.Clear();
                _planes = _pathGenerator.Planes;

                // Get the new path curve
                _paths.Clear();
                _paths = _pathGenerator.Paths;

                // Clear the lists with the internal and external axis values
                _robotJointPositions.Clear();
                _externalJointPositions.Clear();
                _robotJointPositions    = _pathGenerator.RobotJointPositions;
                _externalJointPositions = _pathGenerator.ExternalJointPositions;

                // Store the number of interpolations that are used, to check if this value is changed.
                _lastInterpolations = interpolations;

                // Raise warnings
                if (_pathGenerator.ErrorText.Count != 0)
                {
                    _raiseWarnings = true;
                }
                else
                {
                    _raiseWarnings = false;
                }
            }

            // Get the index number of the current target
            int index = (int)(((_planes.Count - 1) * interpolationSlider));

            // Create list with external axis values
            List <double> externalAxisValues = _externalJointPositions[index].ToList();

            externalAxisValues.RemoveAll(val => val == 9e9);

            // Calcualte foward kinematics
            _forwardKinematics.RobotJointPosition    = _robotJointPositions[index];
            _forwardKinematics.ExternalJointPosition = _externalJointPositions[index];
            _forwardKinematics.HideMesh = !_previewMesh;
            _forwardKinematics.Calculate();

            // Show error messages
            if (_raiseWarnings == true)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Only axis values of absolute joint movements are checked.");

                for (int i = 0; i < _pathGenerator.ErrorText.Count; i++)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, _pathGenerator.ErrorText[i]);
                    if (i == 30)
                    {
                        break;
                    }
                }
            }

            // Output
            DA.SetData(0, _forwardKinematics.TCPPlane);
            DA.SetDataList(1, _forwardKinematics.PosedExternalAxisPlanes);
            DA.SetDataList(2, _forwardKinematics.RobotJointPosition.ToList());
            DA.SetDataList(3, externalAxisValues);
            if (_previewCurve == true)
            {
                DA.SetDataList(4, _paths);
            }
            else
            {
                DA.SetDataList(4, null);
            }
        }
Example #3
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)
        {
            // Input variables
            List <RobotComponents.Actions.Action> actions = new List <RobotComponents.Actions.Action>();
            int    interpolations      = 0;
            double interpolationSlider = 0;
            bool   update = false;

            // Catch the input data
            if (!DA.GetData(0, ref _robot))
            {
                return;
            }
            if (!DA.GetDataList(1, actions))
            {
                return;
            }
            if (!DA.GetData(2, ref interpolations))
            {
                return;
            }
            if (!DA.GetData(3, ref interpolationSlider))
            {
                return;
            }
            if (!DA.GetData(4, ref update))
            {
                return;
            }

            // Update the path
            if (update == true | _calculated == false)
            {
                // Create forward kinematics for mesh display
                _forwardKinematics = new ForwardKinematics(_robot);

                // Create the path generator
                _pathGenerator = new PathGenerator(_robot);

                // Re-calculate the path
                _pathGenerator.Calculate(actions, interpolations);

                // Makes sure that there is always a calculated solution
                _calculated = true;
            }

            // Get the index number of the current target
            int index = (int)(((_pathGenerator.Planes.Count - 1) * interpolationSlider));

            // Calculate foward kinematics
            _forwardKinematics.HideMesh = !_previewMesh;
            _forwardKinematics.Calculate(_pathGenerator.RobotJointPositions[index], _pathGenerator.ExternalJointPositions[index]);

            // Show error messages
            if (_pathGenerator.ErrorText.Count != 0)
            {
                for (int i = 0; i < _pathGenerator.ErrorText.Count; i++)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, _pathGenerator.ErrorText[i]);
                    if (i == 30)
                    {
                        break;
                    }
                }
            }

            // Output Parameters
            int ind;

            if (Params.Output.Any(x => x.NickName.Equality(outputParameters[0].NickName)))
            {
                ind = Params.Output.FindIndex(x => x.NickName.Equality(outputParameters[0].NickName));
                DA.SetData(ind, _pathGenerator.Planes[index]);
            }
            if (Params.Output.Any(x => x.NickName.Equality(outputParameters[1].NickName)))
            {
                ind = Params.Output.FindIndex(x => x.NickName.Equality(outputParameters[1].NickName));
                DA.SetDataList(ind, _pathGenerator.Planes);
            }
            if (Params.Output.Any(x => x.NickName.Equality(outputParameters[2].NickName)))
            {
                ind = Params.Output.FindIndex(x => x.NickName.Equality(outputParameters[2].NickName));
                DA.SetData(ind, _pathGenerator.RobotJointPositions[index]);
            }
            if (Params.Output.Any(x => x.NickName.Equality(outputParameters[3].NickName)))
            {
                ind = Params.Output.FindIndex(x => x.NickName.Equality(outputParameters[3].NickName));
                DA.SetDataList(ind, _pathGenerator.RobotJointPositions);
            }
            if (Params.Output.Any(x => x.NickName.Equality(outputParameters[4].NickName)))
            {
                ind = Params.Output.FindIndex(x => x.NickName.Equality(outputParameters[4].NickName));
                DA.SetDataList(ind, _forwardKinematics.PosedExternalAxisPlanes);
            }
            if (Params.Output.Any(x => x.NickName.Equality(outputParameters[5].NickName)))
            {
                ind = Params.Output.FindIndex(x => x.NickName.Equality(outputParameters[5].NickName));
                DA.SetData(ind, _pathGenerator.ExternalJointPositions[index]);
            }
            if (Params.Output.Any(x => x.NickName.Equality(outputParameters[6].NickName)))
            {
                ind = Params.Output.FindIndex(x => x.NickName.Equality(outputParameters[6].NickName));
                DA.SetDataList(ind, _pathGenerator.ExternalJointPositions);
            }
            if (Params.Output.Any(x => x.NickName.Equality(outputParameters[7].NickName)))
            {
                ind = Params.Output.FindIndex(x => x.NickName.Equality(outputParameters[7].NickName));
                DA.SetDataList(ind, _pathGenerator.ErrorText);
            }
            DA.SetDataList(outputParameters[8].Name, _pathGenerator.Paths);
        }
Example #4
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)
        {
            // Input variables
            List <RobotComponents.Actions.Action> actions = new List <RobotComponents.Actions.Action>();
            int    interpolations      = 0;
            double interpolationSlider = 0;
            bool   update = false;

            // Catch the input data
            if (!DA.GetData(0, ref _robot))
            {
                return;
            }
            if (!DA.GetDataList(1, actions))
            {
                return;
            }
            if (!DA.GetData(2, ref interpolations))
            {
                return;
            }
            if (!DA.GetData(3, ref interpolationSlider))
            {
                return;
            }
            if (!DA.GetData(4, ref update))
            {
                return;
            }

            // Update the path
            if (update == true || _lastInterpolations != interpolations)
            {
                // Create forward kinematics for mesh display
                _forwardKinematics = new ForwardKinematics(_robot);

                // Create the path generator
                _pathGenerator = new PathGenerator(_robot);

                // Re-calculate the path
                _pathGenerator.Calculate(actions, interpolations);

                // Get all the targets
                _planes.Clear();
                _planes = _pathGenerator.Planes;

                // Get the new path curve
                _paths.Clear();
                _paths = _pathGenerator.Paths;

                // Clear the lists
                _robotJointPositions.Clear();
                _externalJointPositions.Clear();

                // Get new lists
                _robotJointPositions    = _pathGenerator.RobotJointPositions;
                _externalJointPositions = _pathGenerator.ExternalJointPositions;

                // Store the number of interpolations that are used, to check if this value is changed.
                _lastInterpolations = interpolations;
            }

            // Get the index number of the current target
            int index = (int)(((_planes.Count - 1) * interpolationSlider));

            // Calculate foward kinematics
            _forwardKinematics.HideMesh = !_previewMesh;
            _forwardKinematics.Calculate(_robotJointPositions[index], _externalJointPositions[index]);

            // Show error messages
            if (_pathGenerator.ErrorText.Count != 0)
            {
                for (int i = 0; i < _pathGenerator.ErrorText.Count; i++)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, _pathGenerator.ErrorText[i]);
                    if (i == 30)
                    {
                        break;
                    }
                }
            }

            // Output
            DA.SetData(0, _forwardKinematics.TCPPlane);
            DA.SetDataList(1, _forwardKinematics.PosedExternalAxisPlanes);
            DA.SetData(2, _forwardKinematics.RobotJointPosition);
            DA.SetData(3, _forwardKinematics.ExternalJointPosition);
            if (_previewCurve == true)
            {
                DA.SetDataList(4, _paths);
            }
            else
            {
                DA.SetDataList(4, null);
            }
        }