Example #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program = null;

            DA.GetData(0, ref program);

            var path        = DA.ParameterTargetPath(0);
            var cellTargets = program.Value.Targets;
            var groupCount  = cellTargets[0].ProgramTargets.Count;

            var planes        = new GH_Structure <GH_Plane>();
            var joints        = new GH_Structure <GH_Number>();
            var configuration = new GH_Structure <GH_String>();
            var deltaTime     = new GH_Structure <GH_Number>();

            for (int i = 0; i < groupCount; i++)
            {
                var tempPath = path.AppendElement(i);
                for (int j = 0; j < cellTargets.Count; j++)
                {
                    planes.AppendRange(cellTargets[j].ProgramTargets[i].Kinematics.Planes.Select(x => new GH_Plane(x)), tempPath.AppendElement(j));
                    joints.AppendRange(cellTargets[j].ProgramTargets[i].Kinematics.Joints.Select(x => new GH_Number(x)), tempPath.AppendElement(j));
                    configuration.Append(new GH_String(cellTargets[j].ProgramTargets[i].Kinematics.Configuration.ToString()), tempPath);
                    deltaTime.Append(new GH_Number(cellTargets[j].DeltaTime), tempPath);
                }
            }

            DA.SetDataTree(0, planes);
            DA.SetDataTree(1, joints);
            DA.SetDataTree(2, configuration);
            DA.SetDataTree(3, deltaTime);
        }
Example #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program ghProgram       = null;
            double     length          = 0;
            int        mechanicalGroup = 0;

            if (!DA.GetData(0, ref ghProgram))
            {
                return;
            }
            if (!DA.GetData(1, ref length))
            {
                return;
            }
            if (!DA.GetData(2, ref mechanicalGroup))
            {
                return;
            }

            if (ghProgram.Value != program)
            {
                program = ghProgram.Value;
                trail   = new SimpleTrail(program, length, mechanicalGroup);
            }

            if (trail != null)
            {
                trail.Length = length;
                trail.Update();
                if (trail.Polyline.Count >= 2)
                {
                    DA.SetData(0, new GH_Curve(trail.Polyline.ToNurbsCurve()));
                }
            }
        }
Example #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program = null;
            GH_String  ip      = null;

            if (!DA.GetData(0, ref program))
            {
                return;
            }

            var robotCellUR = program.Value.RobotSystem as RobotCellUR;

            if (DA.GetData(1, ref ip) && ip != null)
            {
                robotCellUR.Remote.IP = ip.Value;
            }

            bool connect = false, upload = false, play = false, pause = false;

            if (!DA.GetData("Connect", ref connect))
            {
                return;
            }
            if (!DA.GetData("Upload", ref upload))
            {
                return;
            }
            if (!DA.GetData("Play", ref play))
            {
                return;
            }
            if (!DA.GetData("Pause", ref pause))
            {
                return;
            }

            if (connect && !connected)
            {
                robotCellUR.Remote.Connect(); connected = true;
            }
            if (!connect && connected)
            {
                robotCellUR.Remote.Disconnect(); connected = false;
            }
            if (upload && connected)
            {
                robotCellUR.Remote.UploadProgram(program.Value);
            }
            if (play && connected)
            {
                robotCellUR.Remote.Play();
            }
            if (pause && connected)
            {
                robotCellUR.Remote.Pause();
            }

            DA.SetDataList(0, robotCellUR.Remote.Log);
        }
Example #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool connect = false;

            DA.GetData("Connect", ref connect);

            if (!connect && Connected)
            {
                Dispose();
            }

            if (Connected)
            {
                GH_Program program = null;
                if (!DA.GetData(0, ref program))
                {
                    return;
                }
                SendJoints(program.Value);
            }

            if (connect && !Connected)
            {
                GH_Number port = new GH_Number();
                GH_String ip   = new GH_String();
                if (!DA.GetData("PO", ref port))
                {
                    _log.Add("No Port found"); return;
                }
                if (!DA.GetData("IP", ref ip))
                {
                    _log.Add("No IP found"); return;
                }

                _port = (int)port.Value;
                _ip   = ip.ToString();

                _log.Clear();
                ConnectToUnreal();

                // if (_task == null || _task.Status != TaskStatus.Running)
                //  {


                //_task = Task.Run(async () => await ConnectToUnreal())
                // .ContinueWith(task =>
                //  {
                //       this.ExpireSolution(true);
                //   }, TaskScheduler.FromCurrentSynchronizationContext());
                // }
                //else
                // {
                //      _log.Add("Trying to connect to Unreal");
                // }
            }

            DA.SetDataList("Log", _log);
        }
Example #5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program      = null;
            GH_Number  sliderTimeGH = null;
            GH_Boolean isNormalized = null;

            if (!DA.GetData(0, ref program))
            {
                return;
            }
            if (!DA.GetData(1, ref sliderTimeGH))
            {
                return;
            }
            if (!DA.GetData(2, ref isNormalized))
            {
                return;
            }


            sliderTime = (isNormalized.Value) ? sliderTimeGH.Value * program.Value.Duration : sliderTimeGH.Value;
            if (!form.Visible)
            {
                time = sliderTime;
            }

            program.Value.Animate(time, false);
            var currentTarget = program.Value.CurrentSimulationTarget;

            var errors = currentTarget.ProgramTargets.SelectMany(x => x.Kinematics.Errors);
            var meshes = currentTarget.ProgramTargets.SelectMany(x => x.Kinematics.Meshes);
            var joints = currentTarget.ProgramTargets.SelectMany(x => x.Kinematics.Joints);
            var planes = currentTarget.ProgramTargets.SelectMany(x => x.Kinematics.Planes);

            if (errors.Count() > 0)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Errors in solution");
            }

            DA.SetDataList(0, meshes?.Select(x => new GH_Mesh(x)));
            DA.SetDataList(1, joints);
            DA.SetDataList(2, planes.Select(x => new GH_Plane(x)));
            DA.SetData(3, currentTarget.Index);
            DA.SetData(4, program.Value.CurrentSimulationTime);
            DA.SetData(5, new GH_Program(program.Value));
            DA.SetDataList(6, errors);

            if (form.Visible && form.play.Checked.Value)
            {
                var      currentTime = DateTime.Now;
                TimeSpan delta       = currentTime - lastTime;
                time    += delta.TotalSeconds * speed;
                lastTime = currentTime;
                this.ExpireSolution(true);
            }
        }
Example #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program = null;
            GH_String  ip      = null;

            if (!DA.GetData(0, ref program))
            {
                return;
            }

            var remote = program.Value.RobotSystem.Remote;

            if (remote == null)
            {
                throw new Exception("No remote functionality for this robot.");
            }
            if (DA.GetData(1, ref ip) && ip != null)
            {
                remote.IP = ip.Value;
            }

            bool upload = false, play = false, pause = false;

            if (!DA.GetData("Upload", ref upload))
            {
                return;
            }
            if (!DA.GetData("Play", ref play))
            {
                return;
            }
            if (!DA.GetData("Pause", ref pause))
            {
                return;
            }

            if (upload)
            {
                remote.Upload(program.Value);
            }
            if (play)
            {
                remote.Play();
            }
            if (pause)
            {
                remote.Pause();
            }

            DA.SetDataList(0, remote.Log);
        }
Example #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program          = null;
            var        first            = new List <GH_Integer>();
            var        second           = new List <GH_Integer>();
            GH_Mesh    environment      = null;
            int        environmentPlane = -1;
            double     linearStep       = 100;
            double     angularStep      = PI / 4;

            if (!DA.GetData(0, ref program))
            {
                return;
            }
            if (!DA.GetDataList(1, first))
            {
                return;
            }
            if (!DA.GetDataList(2, second))
            {
                return;
            }
            DA.GetData(3, ref environment);
            if (!DA.GetData(4, ref environmentPlane))
            {
                return;
            }
            if (!DA.GetData(5, ref linearStep))
            {
                return;
            }
            if (!DA.GetData(6, ref angularStep))
            {
                return;
            }

            var collision = program.Value.CheckCollisions(first.Select(x => x.Value), second.Select(x => x.Value), environment?.Value, environmentPlane, linearStep, angularStep);

            DA.SetData(0, collision.HasCollision);
            if (collision.HasCollision)
            {
                DA.SetData(1, collision.CollisionTarget.Index);
            }
            if (collision.HasCollision)
            {
                DA.SetDataList(2, collision.Meshes);
            }
        }
Example #8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program = null;
            //var code = new List<string>();
            string folder = null;

            if (!DA.GetData(0, ref program))
            {
                return;
            }
            if (!DA.GetData(1, ref folder))
            {
                return;
            }
            program.Value.Save(folder);
        }
Example #9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program = null;

            if (!DA.GetData(0, ref program))
            {
                return;
            }
            if (!DA.GetDataTree(1, out GH_Structure <GH_String> codeTree))
            {
                return;
            }

            var code = new List <List <List <string> > >
            {
                new List <List <string> >()
            };

            foreach (var branch in codeTree.Branches)
            {
                code[0].Add(branch.Select(s => s.Value).ToList());
            }

            var programCode = program.Value.Code;

            if (programCode?.Count > 0)
            {
                //var copyCode = programCode.ToList();

                //for (int i = 0; i < copyCode.Count; i++)
                //{
                //    copyCode[i] = copyCode[i].ToList();

                //    for (int j = 0; j < copyCode[i].Count; j++)
                //        copyCode[i][j] = copyCode[i][j].ToList();
                //}

                //copyCode[0][0] = code;

                var newProgram = program.Value.CustomCode(code);
                DA.SetData(0, new GH_Program(newProgram));
            }
        }
Example #10
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program = null;
            var        code    = new List <string>();

            if (!DA.GetData(0, ref program))
            {
                return;
            }
            if (!DA.GetDataList(1, code))
            {
                return;
            }
            var programCode = program.Value.Code;

            if (programCode != null && programCode.Count > 0)
            {
                programCode[0][0] = code;
            }
            var newProgram = program.Value.CustomCode(programCode);

            DA.SetData(0, new GH_Program(newProgram));
        }
Example #11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program = null;
            var        code    = new List <string>();

            if (!DA.GetData(0, ref program))
            {
                return;
            }
            if (!DA.GetDataList(1, code))
            {
                return;
            }

            var programCode = program.Value.Code;

            if (programCode != null && programCode.Count > 0)
            {
                var copyCode = programCode.ToList();

                for (int i = 0; i < copyCode.Count; i++)
                {
                    copyCode[i] = copyCode[i].ToList();

                    for (int j = 0; j < copyCode[i].Count; j++)
                    {
                        copyCode[i][j] = copyCode[i][j].ToList();
                    }
                }

                copyCode[0][0] = code;

                var newProgram = program.Value.CustomCode(copyCode);
                DA.SetData(0, new GH_Program(newProgram));
            }
        }
Example #12
0
 public GH_Program(GH_Program goo)
 {
     this.Value = goo.Value;
 }