protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <double>    angles  = new List <double>();
            double           lin     = 0;
            double           rot     = 0;
            Tool             tool    = ABBTool.Default;
            GH_ObjectWrapper speedIn = new GH_ObjectWrapper();
            GH_ObjectWrapper zoneIn  = new GH_ObjectWrapper();

            bool hasTool  = true;
            bool hasSpeed = true;
            bool hasZone  = true;

            if (!DA.GetDataList(0, angles))
            {
                angles = new List <double> {
                    0, 0, 0, 0, 0, 0
                }
            }
            ;
            if (!DA.GetData(1, ref tool))
            {
                hasTool = false;
            }
            if (!DA.GetData(2, ref speedIn))
            {
                hasSpeed = false;
            }
            if (!DA.GetData(3, ref zoneIn))
            {
                hasZone = false;
            }

            Speed speed = Speed.Default;
            Zone  zone  = Zone.Default;

            // Check to see if we have speeds, and if they are custom speed objects, otherwise use values.
            if (hasSpeed)
            {
                // Default speed dictionary.
                Dictionary <double, Speed> defaultSpeeds = Util.ABBSpeeds();
                double speedVal = 0;

                GH_ObjectWrapper speedObj = speedIn;
                Type             cType    = speedObj.Value.GetType();
                GH_Convert.ToDouble_Secondary(speedObj.Value, ref speedVal);

                if (cType.Name == "Speed")
                {
                    speed = speedObj.Value as Speed;
                }
                else
                {
                    if (!defaultSpeeds.ContainsKey(speedVal))
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Supplied speed value is non-standard. Please supply a default value (check the Axis Wiki - Controlling Speed for more info) or create a custom speed using the Speed component.");
                    }
                    else
                    {
                        speed = defaultSpeeds[speedVal];
                    }
                }
            }
            // If we don't have any speed values, use the default speed.
            else
            {
                speed = Speed.Default;
            }

            // Check to see if we have zones, and if they are custom zones objects, otherwise use values.
            if (hasZone)
            {
                // Default zone dictionary.
                Dictionary <double, Zone> defaultZones = Util.ABBZones();
                double zoneVal = 0;

                GH_ObjectWrapper zoneObj = zoneIn;
                Type             cType   = zoneObj.Value.GetType();
                GH_Convert.ToDouble_Secondary(zoneObj.Value, ref zoneVal);

                if (cType.Name == "Zone")
                {
                    zone = zoneObj.Value as Zone;
                }
                else
                {
                    if (!defaultZones.ContainsKey(zoneVal))
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Supplied zone value is non-standard. Please supply a default value (check the Axis Wiki - Controlling Zone for more info) or create a custom zone using the Zoe component.");
                    }
                    else
                    {
                        zone = defaultZones[zoneVal];
                    }
                }
            }
            // If we don't have any zone values, use the default zone.
            else
            {
                zone = Zone.Default;
            }

            if (useRotary)
            {
                if (!DA.GetData("Rotary", ref rot))
                {
                    return;
                }
            }
            if (useLinear)
            {
                if (!DA.GetData("Linear", ref lin))
                {
                    return;
                }
            }

            //Poor mans temporary fix
            var rType = Manufacturer.ABB;

            if (manufacturer)
            {
                rType = Manufacturer.Kuka;
            }

            Target jointTarget = new ABBTarget(angles, speed, zone, tool, rot, lin);

            DA.SetData(0, jointTarget);
        }
Exemple #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.Message = m_Manufacturer.ToString();

            List <Plane>            planes   = new List <Plane>();
            List <GH_ObjectWrapper> speedsIn = new List <GH_ObjectWrapper>();
            List <GH_ObjectWrapper> zonesIn  = new List <GH_ObjectWrapper>();
            List <Tool>             tools    = new List <Tool>();
            List <CSystem>          wobjs    = new List <CSystem>();
            List <int> methods = new List <int>();

            // Store the input lists of external axis values to synchronise with the targets.
            List <double> eRotVals = new List <double>();
            List <double> eLinVals = new List <double>();

            bool hasSpeed = true;
            bool hasZone  = true;

            if (!DA.GetDataList(0, planes))
            {
                return;
            }
            if (!DA.GetDataList(1, speedsIn))
            {
                hasSpeed = false;
            }
            if (!DA.GetDataList(2, zonesIn))
            {
                hasZone = false;
            }
            if (!DA.GetDataList(3, tools))
            {
                tools.Add(ABBTool.Default);
            }
            if (!DA.GetDataList(4, wobjs))
            {
                wobjs.Add(CSystem.Default);
            }

            // If interpolation types are specified, get them.
            if (m_interpolationTypes)
            {
                if (!DA.GetDataList("*Method", methods))
                {
                    return;
                }
            }

            // If the inputs are present, get the external axis values.
            if (extRotary)
            {
                if (!DA.GetDataList("Rotary", eRotVals))
                {
                    return;
                }
            }
            if (extLinear)
            {
                if (!DA.GetDataList("Linear", eLinVals))
                {
                    return;
                }
            }

            List <Speed> speeds = new List <Speed>();
            List <Zone>  zones  = new List <Zone>();

            // Check to see if we have speeds, and if they are custom speed objects, otherwise use values.
            if (hasSpeed)
            {
                // Default speed dictionary.
                Dictionary <double, Speed> defaultSpeeds = Util.ABBSpeeds();
                double speedVal = 0;

                foreach (GH_ObjectWrapper speedIn in speedsIn)
                {
                    GH_ObjectWrapper speedObj = speedIn;
                    Type             cType    = speedObj.Value.GetType();
                    GH_Convert.ToDouble_Secondary(speedObj.Value, ref speedVal);

                    if (cType.Name == "Speed")
                    {
                        speeds.Add(speedObj.Value as Speed);
                    }
                    else
                    {
                        if (!defaultSpeeds.ContainsKey(speedVal))
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Supplied speed value is non-standard. Please supply a default value (check the Axis Wiki - Controlling Speed for more info) or create a custom speed using the Speed component.");
                        }
                        else
                        {
                            speeds.Add(defaultSpeeds[speedVal]);
                        }
                    }
                }
            }
            // If we don't have any speed values, use the default speed.
            else
            {
                speeds.Add(Speed.Default);
            }

            // Check to see if we have zones, and if they are custom zones objects, otherwise use values.
            if (hasZone)
            {
                // Default zone dictionary.
                Dictionary <double, Zone> defaultZones = Util.ABBZones();
                double zoneVal = 0;

                foreach (GH_ObjectWrapper zoneIn in zonesIn)
                {
                    GH_ObjectWrapper zoneObj = zoneIn;
                    Type             cType   = zoneObj.Value.GetType();
                    GH_Convert.ToDouble_Secondary(zoneObj.Value, ref zoneVal);

                    if (cType.Name == "Zone")
                    {
                        zones.Add(zoneObj.Value as Zone);
                    }
                    else
                    {
                        if (!defaultZones.ContainsKey(zoneVal))
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Supplied zone value is non-standard. Please supply a default value (check the Axis Wiki - Controlling Zone for more info) or create a custom zone using the Zoe component.");
                        }
                        else
                        {
                            zones.Add(defaultZones[zoneVal]);
                        }
                    }
                }
            }
            // If we don't have any zone values, use the default zone.
            else
            {
                zones.Add(Zone.Default);
            }

            List <Target> targets = new List <Target>();
            List <string> code    = new List <string>();
            Speed         speed   = Speed.Default;
            Zone          zone    = Zone.Default;
            Tool          tool    = ABBTool.Default;
            CSystem       wobj    = CSystem.Default;
            int           method  = 0;

            // External axis placeholders
            double extRot = Util.ExAxisTol;
            double extLin = Util.ExAxisTol;

            for (int i = 0; i < planes.Count; i++)
            {
                if (m_interpolationTypes)
                {
                    // Method
                    if (i < methods.Count)
                    {
                        method = methods[i];
                    }
                    else if (methods != null && i >= methods.Count)
                    {
                        method = methods[methods.Count - 1];
                    }
                    else
                    {
                        method = 0;
                    }
                }

                if (speeds.Count > 0)
                {
                    if (i < speeds.Count)
                    {
                        speed = speeds[i];
                    }
                    else
                    {
                        speed = speeds[speeds.Count - 1];
                    }
                }
                else
                {
                    speed = Speed.Default;
                }

                // Zone
                if (i < zones.Count)
                {
                    zone = zones[i];
                }
                else
                {
                    zone = zones[zones.Count - 1];
                }

                // External rotary axis
                if (extRotary)
                {
                    if (i < eRotVals.Count)
                    {
                        extRot = Math.Round(eRotVals[i], 3);
                    }
                    else
                    {
                        extRot = Math.Round(eRotVals[eRotVals.Count - 1], 3);
                    }
                }

                // External linear axis
                if (extLinear)
                {
                    if (i < eLinVals.Count)
                    {
                        extLin = Math.Round(eLinVals[i], 3);
                    }
                    else
                    {
                        extLin = Math.Round(eLinVals[eLinVals.Count - 1], 3);
                    }
                }

                // Tools
                if (tools.Count > 0)
                {
                    if (i < tools.Count)
                    {
                        tool = tools[i];
                    }
                    else
                    {
                        tool = tools[tools.Count - 1];
                    }
                }
                else
                {
                    tool = ABBTool.Default;
                }

                // Wobjs
                if (wobjs.Count > 0)
                {
                    if (i < wobjs.Count)
                    {
                        wobj = wobjs[i];
                    }
                    else
                    {
                        wobj = wobjs[wobjs.Count - 1];
                    }
                }
                else
                {
                    wobj = CSystem.Default;
                }

                // Methods
                MotionType mType = MotionType.Linear;

                if (method == 1)
                {
                    mType = MotionType.Joint;
                }
                else if (method == 2)
                {
                    mType = MotionType.AbsoluteJoint;
                }

                // Create the robot target.
                Target robTarg = new ABBTarget(planes[i], mType, speed, zone, tool, wobj, extRot, extLin);
                targets.Add(robTarg);

                code.Add(robTarg.RobStr(m_Manufacturer));
            }
            DA.SetDataList(0, targets);

            m_targets = targets;

            List <Point3d> points = new List <Point3d>();

            foreach (Target t in targets)
            {
                points.Add(t.Position);
            }
            m_bBox = new BoundingBox(points);

            /*
             * if (m_outputTarget)
             *  DA.SetDataList("Code", code);
             */
        }