public override bool CastFrom(object source) { switch (source) { case GH_Number number: Value = new[] { number.Value }; return(true); case GH_String text: { if (string.IsNullOrWhiteSpace(text.Value)) { Value = new double[0]; return(true); } string[] texts = text.Value.Split(','); double[] values = new double[texts.Length]; for (int i = 0; i < texts.Length; i++) { if (!GH_Convert.ToDouble_Secondary(texts[i], ref values[i])) { return(false); } } Value = values; return(true); } } return(false); }
public override bool CastFrom(object source) { if (source is Zone) { Value = source as Zone; return(true); } if (source is GH_Number) { Value = new Zone((source as GH_Number).Value); return(true); } double value = 0; if (GH_Convert.ToDouble_Secondary(source, ref value)) { Value = new Zone(value); return(true); } else { return(false); } }
public override bool CastFrom(object source) { switch (source) { case Zone zone: Value = zone; return(true); case GH_Number number: Value = new Zone(number.Value); return(true); case GH_String text: { string[] texts = text.Value.Split(','); double[] values = new double[texts.Length]; for (int i = 0; i < texts.Length; i++) { if (!GH_Convert.ToDouble_Secondary(texts[i], ref values[i])) { return(false); } } if (texts.Length == 1) { Value = new Zone(values[0]); return(true); } else if (texts.Length == 2) { Value = new Zone(values[0], values[1]); return(true); } break; } } double value = 0; if (GH_Convert.ToDouble_Secondary(source, ref value)) { Value = new Zone(value); return(true); } else { return(false); } }
public override bool CastFrom(object source) { if (source is Zone) { Value = source as Zone; return(true); } if (source is GH_Number) { Value = new Zone((source as GH_Number).Value); return(true); } if (source is GH_String) { string[] texts = (source as GH_String).Value.Split(','); double[] values = new double[texts.Length]; for (int i = 0; i < texts.Length; i++) { if (!GH_Convert.ToDouble_Secondary(texts[i], ref values[i])) { return(false); } } if (texts.Length == 1) { Value = new Zone(values[0]); return(true); } else if (texts.Length == 2) { Value = new Zone(values[0], values[1]); return(true); } } double value = 0; if (GH_Convert.ToDouble_Secondary(source, ref value)) { Value = new Zone(value); return(true); } else { return(false); } }
public override bool CastFrom(object source) { if (source is Target) { Value = source as Target; return(true); } if (source is GH_Point) { Value = new CartesianTarget(new Plane((source as GH_Point).Value, Vector3d.XAxis, Vector3d.YAxis)); return(true); } if (source is GH_Plane) { Value = new CartesianTarget((source as GH_Plane).Value); return(true); } if (source is GH_String) { string text = (source as GH_String).Value; string[] jointsText = text.Split(','); if (jointsText.Length != 6) { return(false); } var joints = new double[6]; for (int i = 0; i < 6; i++) { if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref joints[i])) { return(false); } } Value = new JointTarget(joints); return(true); } return(false); }
public override bool CastFrom(object source) { switch (source) { case Target target: Value = target; return(true); case GH_Point point: Value = new CartesianTarget(new Plane(point.Value, Vector3d.XAxis, Vector3d.YAxis)); return(true); case GH_Plane plane: Value = new CartesianTarget(plane.Value); return(true); case GH_String text: { string[] jointsText = text.Value.Split(','); if (jointsText.Length != 6) { return(false); } var joints = new double[6]; for (int i = 0; i < 6; i++) { if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref joints[i])) { return(false); } } Value = new JointTarget(joints); return(true); } } return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_RobotSystem robotSystem = null; var targets = new List <GH_Target>(); var prevJointsText = new List <GH_String>(); bool drawMeshes = false; if (!DA.GetData(0, ref robotSystem)) { return; } if (!DA.GetDataList(1, targets)) { return; } DA.GetDataList(2, prevJointsText); if (!DA.GetData(3, ref drawMeshes)) { return; } List <double[]> prevJoints = null; if (prevJointsText.Count > 0) { prevJoints = new List <double[]>(); foreach (var text in prevJointsText) { if (text != null) { string[] jointsText = text.Value.Split(','); var prevJoint = new double[jointsText.Length]; for (int i = 0; i < jointsText.Length; i++) { if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref prevJoint[i])) { throw new Exception(" Previous joints not formatted correctly."); } } prevJoints.Add(prevJoint); } } } var kinematics = robotSystem.Value.Kinematics(targets.Select(x => x.Value), prevJoints, drawMeshes); var errors = kinematics.SelectMany(x => x.Errors); if (errors.Count() > 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Errors in solution"); } var strings = kinematics.SelectMany(x => x.Joints).Select(x => new GH_Number(x).ToString()); var joints = string.Join(",", strings); var planes = kinematics.SelectMany(x => x.Planes); if (drawMeshes) { var meshes = kinematics.SelectMany(x => x.Meshes); DA.SetDataList(0, meshes.Select(x => new GH_Mesh(x))); } DA.SetData(1, joints); DA.SetDataList(2, planes.Select(x => new GH_Plane(x))); DA.SetDataList(3, errors); }
protected override void SolveInstance(IGH_DataAccess DA) { bool hasTarget = Params.Input.Any(x => x.Name == "Target"); bool hasJoints = Params.Input.Any(x => x.Name == "Joints"); bool hasPlane = Params.Input.Any(x => x.Name == "Plane"); bool hasConfig = Params.Input.Any(x => x.Name == "RobConf"); bool hasMotion = Params.Input.Any(x => x.Name == "Motion"); bool hasTool = Params.Input.Any(x => x.Name == "Tool"); bool hasSpeed = Params.Input.Any(x => x.Name == "Speed"); bool hasZone = Params.Input.Any(x => x.Name == "Zone"); bool hasCommand = Params.Input.Any(x => x.Name == "Command"); bool hasFrame = Params.Input.Any(x => x.Name == "Frame"); bool hasExternal = Params.Input.Any(x => x.Name == "External"); GH_Target sourceTarget = null; if (hasTarget) { if (!DA.GetData("Target", ref sourceTarget)) { return; } } double[] joints = null; var plane = new Plane(); Target.RobotConfigurations?configuration = null; Target.Motions motion = Target.Motions.Joint; Tool tool = null; Speed speed = null; Zone zone = null; Command command = null; Frame frame = null; double[] external = null; if (hasJoints) { GH_String jointsGH = null; if (!DA.GetData("Joints", ref jointsGH)) { return; } string[] jointsText = jointsGH.Value.Split(','); if (jointsText.Length != 6) { return; } joints = new double[6]; for (int i = 0; i < 6; i++) { if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref joints[i])) { return; } } } else if (sourceTarget != null) { if (sourceTarget.Value is JointTarget) { joints = (sourceTarget.Value as JointTarget).Joints; } } if (hasPlane) { GH_Plane planeGH = null; if (hasPlane) { if (!DA.GetData("Plane", ref planeGH)) { return; } } plane = planeGH.Value; } else if (sourceTarget != null) { if (sourceTarget.Value is CartesianTarget) { plane = (sourceTarget.Value as CartesianTarget).Plane; } } if (hasConfig) { GH_Integer configGH = null; if (hasConfig) { DA.GetData("RobConf", ref configGH); } configuration = (configGH == null) ? null : (Target.RobotConfigurations?)configGH.Value; } else if (sourceTarget != null) { if (sourceTarget.Value is CartesianTarget) { configuration = (sourceTarget.Value as CartesianTarget).Configuration; } } if (hasMotion) { GH_String motionGH = null; DA.GetData("Motion", ref motionGH); motion = (motionGH == null) ? Target.Motions.Joint : (Target.Motions)Enum.Parse(typeof(Target.Motions), motionGH.Value); } else if (sourceTarget != null) { if (sourceTarget.Value is CartesianTarget) { motion = (sourceTarget.Value as CartesianTarget).Motion; } } if (hasTool) { GH_Tool toolGH = null; DA.GetData("Tool", ref toolGH); tool = toolGH?.Value; } else if (sourceTarget != null) { tool = sourceTarget.Value.Tool; } if (hasSpeed) { GH_Speed speedGH = null; DA.GetData("Speed", ref speedGH); speed = speedGH?.Value; } else if (sourceTarget != null) { speed = sourceTarget.Value.Speed; } if (hasZone) { GH_Zone zoneGH = null; DA.GetData("Zone", ref zoneGH); zone = zoneGH?.Value; } else if (sourceTarget != null) { zone = sourceTarget.Value.Zone; } if (hasCommand) { GH_Command commandGH = null; DA.GetData("Command", ref commandGH); command = commandGH?.Value; } else if (sourceTarget != null) { command = sourceTarget.Value.Command; } if (hasFrame) { GH_Frame frameGH = null; DA.GetData("Frame", ref frameGH); frame = frameGH?.Value; } else if (sourceTarget != null) { frame = sourceTarget.Value.Frame; } if (hasExternal) { GH_String externalGH = null; if (!DA.GetData("External", ref externalGH)) { external = new double[0]; } else { string[] externalText = externalGH.Value.Split(','); int length = externalText.Length; external = new double[length]; for (int i = 0; i < length; i++) { if (!GH_Convert.ToDouble_Secondary(externalText[i], ref external[i])) { return; } } } } else if (sourceTarget != null) { external = sourceTarget.Value.External; } Target target; bool localCartesian = isCartesian; if (hasTarget && !hasPlane && !hasJoints) { localCartesian = sourceTarget.Value is CartesianTarget; } if (localCartesian) { target = new CartesianTarget(plane, configuration, motion, tool, speed, zone, command, frame, external); } else { target = new JointTarget(joints, tool, speed, zone, command, frame, external); } if (sourceTarget != null) { target.ExternalCustom = sourceTarget.Value.ExternalCustom; } DA.SetData(0, new GH_Target(target)); }
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); */ }