Beispiel #1
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)
        {
            // Fields
            E6AXIS           e6Axis         = new E6AXIS();
            GH_ObjectWrapper abstractSocket = new GH_ObjectWrapper();
            string           writeVariable  = "";
            List <double>    axisValues     = new List <double>();
            bool             run            = false;
            int refreshRate = 0;

            //Check input
            if (_clientSocket == null)
            {
                if (!DA.GetData(0, ref abstractSocket))
                {
                    return;
                }
                abstractSocket.CastTo(ref _clientSocket);
            }
            else if (_clientSocket != null && !DA.GetData(0, ref abstractSocket))
            {
                try
                {
                    _clientSocket = null;
                    return;
                }
                catch
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Waiting For Connection...");
                    return;
                }
            }
            if (!DA.GetData(1, ref writeVariable))
            {
                return;
            }
            if (!DA.GetDataList(2, axisValues))
            {
                return;
            }
            if (axisValues.Count != 6)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Make sure to only give 6 axis values.");
            }
            if (!DA.GetData(3, ref run))
            {
                return;
            }
            if (!DA.GetData(4, ref refreshRate))
            {
                return;
            }
            if (refreshRate < 15)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                  "WARNING: Refresh rate too low, this can cause performance issues for grasshopper. The maximum robot read speed is 5ms (for all messages)");
            }
            if (refreshRate < 5)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error,
                                  "Refresh Rate too low. Absolute maximum speed is 5ms. This is not recommended. Try more in the region of ~20-70 ms");
                return;
            }

            if (axisValues.Count == 6)
            {
                e6Axis.SerializeE6AXIS(axisValues[0], axisValues[1], axisValues[2], axisValues[3], axisValues[4],
                                       axisValues[5]);
            }

            if (run)
            {
                string response = Util.WriteVariable(ref _clientSocket, writeVariable, e6Axis.SerializedString, this);
                _writtenValues = response;

                if (this.Params.Input[3].Sources[0].GetType() == typeof(GH_BooleanToggle))
                {
                    GH_Document doc = OnPingDocument();
                    doc?.ScheduleSolution(refreshRate, ScheduleCallback);
                }
            }

            DA.SetData(0, _writtenValues);
        }
Beispiel #2
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)
        {
            // Fields
            GH_ObjectWrapper abstractSocket = new GH_ObjectWrapper();
            bool             triggerRead    = false;
            int refreshRate = 0;

            E6POS  currentPos    = new E6POS();
            E6AXIS currentAngles = new E6AXIS();

            bool getSocket = DA.GetData(0, ref abstractSocket);

            //Check input
            if (_clientSocket == null)
            {
                if (!getSocket)
                {
                    return;
                }
                abstractSocket.CastTo(ref _clientSocket);
            }
            else if (_clientSocket != null && !getSocket)
            {
                try
                {
                    _clientSocket = null;
                    return;
                }
                catch
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Waiting For Connection...");
                    return;
                }
            }
            if (!DA.GetData(1, ref triggerRead))
            {
                return;
            }
            if (!DA.GetData(2, ref refreshRate))
            {
                return;
            }
            if (refreshRate < 15)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                  "WARNING: Refresh rate too low, this can cause performance issues for grasshopper. The maximum robot read speed is 5ms (for all messages)");
            }
            if (refreshRate < 5)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error,
                                  "Refresh Rate too low. Absolute maximum speed is 5ms. This is not recommended. Try to stay in the region of ~20-70 ms");
                return;
            }

            //If trigger is pressed, read data and output.
            if (triggerRead)
            {
                string response = Util.ReadVariable(ref _clientSocket, "$POS_ACT", this);
                currentPos.DeserializeE6POS(response);
                CurrentPos = currentPos;

                string response2 = Util.ReadVariable(ref _clientSocket, "$AXIS_ACT", this);
                currentAngles.DeserializeE6AXIS(response2);
                CurrentAngles = currentAngles;
            }

            if (!CurrentAngles.IsNull() && !CurrentPos.IsNull())
            {
                DA.SetDataList(0, CurrentAngles.GetAxisValues());
                DA.SetData(1, new GH_Plane(CurrentPos.GetPlane()));
                DA.SetDataList(2, new List <double> {
                    CurrentPos.X, CurrentPos.Y, CurrentPos.Z
                });
                DA.SetDataList(3, new List <double> {
                    CurrentPos.A, CurrentPos.B, CurrentPos.C
                });
                DA.SetData(4, CurrentPos.SerializedString);
                DA.SetData(5, CurrentAngles.SerializedString);
            }

            if (this.Params.Input[1].Sources[0].GetType() == typeof(GH_BooleanToggle) && triggerRead)
            {
                GH_Document doc = OnPingDocument();
                doc?.ScheduleSolution(refreshRate, ScheduleCallback);
            }
        }