/// <summary> /// Replace a value list with one that has been pre-populated with possible zones. /// </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, Zone> entity in Util.ABBZones()) { options.Add(entity.Value.Name, entity.Key.ToString()); } Grasshopper.Kernel.Special.GH_ValueList gH_ValueList = Canvas.Component.CreateValueList("Zones", 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); }
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); */ }
protected override void SolveInstance(IGH_DataAccess DA) { List <double> pathTCP = new List <double>(); List <double> orientTCP = new List <double>(); List <double> extTCP = new List <double>(); List <double> orientation = new List <double>(); List <double> linExt = new List <double>(); List <double> rotExt = new List <double>(); if (!DA.GetDataList(0, pathTCP)) { return; } // Always try to check for default dictionary zones. bool snapDefault = true; // Get the optional inputs, if present. if (orientOpt.Checked) { snapDefault = false; if (!DA.GetDataList("Reorientation", orientTCP)) { return; } } if (extAxOpt.Checked) { snapDefault = false; if (!DA.GetDataList("External", extTCP)) { return; } } if (toolOriOpt.Checked) { snapDefault = false; if (!DA.GetDataList("Degrees", orientation)) { return; } } if (linExtOpt.Checked) { snapDefault = false; if (!DA.GetDataList("Linear", linExt)) { return; } } if (rotExtOpt.Checked) { snapDefault = false; if (!DA.GetDataList("Rotary", rotExt)) { return; } } List <Zone> zones = new List <Zone>(); List <string> declarations = new List <string>(); // Default and current zone dictionaries. Dictionary <double, Zone> defaultZones = Util.ABBZones(); Dictionary <double, Zone> presentZones = new Dictionary <double, Zone>(); for (int i = 0; i < pathTCP.Count; i++) { Zone zone = new Zone(false, 5, 7.5, 7.5, 0.5, 7.5, 0.5, "EmptyZone"); // If we want to program stop points, do so and skip the rest. if (stopPoint.Checked) { zone = defaultZones[-1]; zones.Add(zone); } else { if (snapDefault && defaultZones.ContainsKey(pathTCP[i])) { zone = defaultZones[pathTCP[i]]; zones.Add(zone); } else { // Set the finepoint if our radius is -1, and ignore the rest. if (pathTCP[i] == -1) { zone.StopPoint = true; zones.Add(zone); } else { zone.StopPoint = false; zone.PathRadius = pathTCP[i]; // Path zone reorientation if (orientOpt.Checked) { if (i < orientTCP.Count) { zone.PathOrient = orientTCP[i]; } else { zone.PathOrient = orientTCP[orientTCP.Count - 1]; } } else { // Use the default convention of a value of 1.5 times the TCP path val. zone.PathOrient = pathTCP[i] * 1.5; } // External zone if (extAxOpt.Checked) { if (i < extTCP.Count) { zone.PathExternal = extTCP[i]; } else { zone.PathExternal = extTCP[extTCP.Count - 1]; } } else { // Use the default convention of a value of 1.5 times the TCP path val. zone.PathExternal = pathTCP[i] * 1.5; } // Tool reorientation degrees if (toolOriOpt.Checked) { if (i < orientation.Count) { zone.Orientation = orientation[i]; } else { zone.Orientation = orientation[orientation.Count - 1]; } } else { // Use the default convention of a value of 1.5 times the TCP path val divided by 10. zone.Orientation = (pathTCP[i] * 1.5) / 10; } // Linear external axis zone if (linExtOpt.Checked) { if (i < linExt.Count) { zone.LinearExternal = linExt[i]; } else { zone.LinearExternal = linExt[linExt.Count - 1]; } } else { // Use the default convention of a value of 1.5 times the TCP path val. zone.LinearExternal = (pathTCP[i] * 1.5); } // Linear external axis zone if (rotExtOpt.Checked) { if (i < rotExt.Count) { zone.RotaryExternal = rotExt[i]; } else { zone.RotaryExternal = rotExt[rotExt.Count - 1]; } } else { // Use the default convention of a value of 1.5 times the TCP path val divided by 10 zone.RotaryExternal = (pathTCP[i] * 1.5) / 10; } zone.Name = "Zone" + zone.PathRadius.ToString(); // Check to see if the dictionary contains the current zone, if not, add it. if (presentZones.ContainsKey(pathTCP[i])) { zones.Add(zone); } else { zones.Add(zone); presentZones.Add(zone.PathRadius, zone); } } } } } DA.SetDataList(0, zones); List <Zone> zoneList = presentZones.Values.ToList(); for (int i = 0; i < zoneList.Count; i++) { Zone z = zoneList[i]; string dec = "VAR zonedata " + z.Name + " := [" + z.StopPoint.ToString() + ", " + Math.Round(z.PathRadius, 1).ToString() + ", " + Math.Round(z.PathOrient, 1).ToString() + ", " + Math.Round(z.PathExternal, 1).ToString() + ", " + Math.Round(z.Orientation, 1).ToString() + ", " + Math.Round(z.LinearExternal, 1).ToString() + ", " + Math.Round(z.RotaryExternal, 1).ToString() + " ];"; declarations.Add(dec); } if (declarationCheck.Checked) { DA.SetDataList("Declaration", declarations); } }