Beispiel #1
0
        /// <summary>
        ///  Replace a value list with one that has been pre-populated with possible speeds.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnParameterSourcesChanged(Object sender, GH_ParamServerEventArgs e)
        {
            int       index = e.ParameterIndex;
            IGH_Param param = e.Parameter;

            //Only add value list to the first input
            if (index != 0)
            {
                return;
            }

            //Only change value lists
            var extractedItems = param.Sources.Where(p => p.Name == "Value List");

            //Set up value list
            Dictionary <string, string> options = new Dictionary <string, string>();

            foreach (KeyValuePair <double, Speed> entity in Util.ABBSpeeds())
            {
                options.Add(entity.Value.Name, entity.Key.ToString());
            }
            Grasshopper.Kernel.Special.GH_ValueList gH_ValueList = Canvas.Component.CreateValueList("Speeds", options);

            //The magic
            Canvas.Component.ChangeObjects(extractedItems, gH_ValueList);
        }
        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);
        }
Beispiel #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <double> linVals  = new List <double>();
            List <double> rotVals  = new List <double>();
            List <double> timeVals = new List <double>();
            List <string> names    = new List <string>();

            if (!DA.GetDataList(0, linVals))
            {
                return;
            }

            // Get the optional inputs, if present.
            if (rotOption.Checked)
            {
                if (!DA.GetDataList("Rotation", rotVals))
                {
                    return;
                }
            }
            if (timeOption.Checked)
            {
                if (!DA.GetDataList("Time", timeVals))
                {
                    return;
                }
            }
            if (nameOption.Checked)
            {
                if (!DA.GetDataList("Name", names))
                {
                    return;
                }
            }

            // Always try to check for default dictionary zones.
            bool snapDefault = true;

            List <Speed>  speeds       = new List <Speed>();
            List <string> declarations = new List <string>();

            // Default and current speed dictionaries.
            Dictionary <double, Speed> defaultSpeeds = Util.ABBSpeeds();
            Dictionary <double, Speed> presentSpeeds = new Dictionary <double, Speed>();

            if (timeOption.Checked)
            {
                for (int i = 0; i < timeVals.Count; i++)
                {
                    if (i < names.Count)
                    {
                        Speed speed = new Speed(100, 30, names[i], timeVals[i]);
                        speeds.Add(speed);
                    }
                    else
                    {
                        Speed speed = new Speed(100, 30, "time_" + timeVals[i].ToString(), timeVals[i]);
                        speeds.Add(speed);
                    }
                }
            }
            else
            {
                // Default rotation value.
                double rotVal = 30;

                for (int i = 0; i < linVals.Count; i++)
                {
                    Speed speed = new Speed(100, 60, "Speed100");

                    if (snapDefault && defaultSpeeds.ContainsKey(linVals[i]))
                    {
                        speed = defaultSpeeds[linVals[i]];
                    }
                    else
                    {
                        if (rotOption.Checked)
                        {
                            if (i < rotVals.Count)
                            {
                                rotVal = rotVals[i];
                            }
                            else
                            {
                                rotVal = rotVals[rotVals.Count - 1];
                            }
                        }

                        if (i < names.Count)
                        {
                            speed = new Speed(linVals[i], rotVal, names[i], 0);
                        }
                        else
                        {
                            string name = linVals[i].ToString().Replace('.', '_');
                            speed = new Speed(linVals[i], rotVal, "v" + name, 0);
                        }
                    }

                    // Check to see if the dictionary contains the current speed, if not, add it.
                    if (presentSpeeds.ContainsKey(linVals[i]))
                    {
                        speeds.Add(speed);
                    }
                    else
                    {
                        speeds.Add(speed);
                        presentSpeeds.Add(speed.TranslationSpeed, speed);
                    }
                }
            }

            List <Speed> speedList = presentSpeeds.Values.ToList();

            for (int i = 0; i < speedList.Count; i++)
            {
                if (!defaultSpeeds.ContainsKey(speedList[i].TranslationSpeed))
                {
                    Speed  sp  = speedList[i];
                    string dec = "VAR speeddata " + sp.Name + " := [ " + Math.Round(sp.TranslationSpeed, 2).ToString() + ", " + Math.Round(sp.RotationSpeed, 2).ToString() + ", 200, 30 ];";
                    declarations.Add(dec);
                }
            }

            DA.SetDataList(0, speeds);

            if (declarationCheck.Checked)
            {
                DA.SetDataList("Declaration", declarations);
            }
        }
Beispiel #4
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);
             */
        }