protected override void SolveInstance(IGH_DataAccess DA) { bool activate = false; bool scan = false; bool kill = false; bool clear = false; string ip = System.String.Empty; int index = 0; bool connect = false; bool resetPP = false; bool begin = false; bool stop = false; bool monitorTCP = false; bool monitorIO = false; bool stream = false; Target targ = null; if (!DA.GetData(0, ref activate)) { ; } if (!DA.GetData(1, ref scan)) { ; } if (!DA.GetData(2, ref kill)) { ; } if (!DA.GetData(3, ref clear)) { ; } if (!DA.GetData(4, ref ip)) { ; } if (!DA.GetData(5, ref index)) { ; } if (!DA.GetData(6, ref connect)) { ; } if (!DA.GetData(7, ref resetPP)) { ; } if (!DA.GetData(8, ref begin)) { ; } if (!DA.GetData(9, ref stop)) { ; } if (!DA.GetData(10, ref monitorTCP)) { ; } if (!DA.GetData(11, ref monitorIO)) { ; } if (!DA.GetData(12, ref stream)) { ; } if (!DA.GetData(13, ref targ)) { ; } this.controllerIndex = index; this.start = begin; double cRobX = 0; double cRobY = 0; double cRobZ = 0; double cRobQ1 = 0; double cRobQ2 = 0; double cRobQ3 = 0; double cRobQ4 = 0; Quaternion cRobQuat = new Quaternion(); //Check for valid licence /*if (bool (Core.AuthTest.loggedIn) != true) * { * new GH_RuntimeMessage("Please sign in to confirm your licence", GH_RuntimeMessageLevel.Error); * return; * }*/ if (activate) { if (scan) { // Scan the network for controllers and add them to our controller array scanner.Scan(); controllers = scanner.GetControllers(); if (controllers.Length > 0) { log.Add("Controllers found:"); // List the controller names that were found on the network. for (int i = 0; i < controllers.Length; i++) { log.Add(controllers[i].ControllerName); } } else { log.Add("Scan timed out. No controllers were found."); } } if (kill && controller != null) { controller.Logoff(); controller.Dispose(); controller = null; log.Add("Process killed! Abandon ship!"); } if (clear) { log.Clear(); log.Add("Log cleared."); } if (connect) { if (controller == null && controllers.Length > 0) { string controllerID = controllers[index].ControllerName; log.Add("Selected robot controller: " + controllers[index].ControllerName + "."); if (controllers[index].Availability == Availability.Available) { log.Add("Robot controller " + controllers[index].ControllerName + " is available."); if (controller != null) { controller.Logoff(); controller.Dispose(); controller = null; } controller = ControllerFactory.CreateFrom(controllers[index]); controller.Logon(UserInfo.DefaultUser); log.Add("Connection to robot controller " + controller.SystemName + " established."); // Get T_ROB1 queue to send messages to the RAPID task. if (!controller.Ipc.Exists("RMQ_T_ROB1")) { controller.Ipc.CreateQueue("RMQ_T_ROB1", 10, Ipc.MaxMessageSize); } tasks = controller.Rapid.GetTasks(); IpcQueue robotQueue = controller.Ipc.GetQueue("RMQ_T_ROB1"); int queueID = robotQueue.QueueId; string queueName = robotQueue.QueueName; log.Add("Established RMQ for T_ROB1 on network controller."); log.Add("Rapid Message Queue ID:" + queueID.ToString() + "."); log.Add("Rapid Message Queue Name:" + queueName + "."); RobotQueue = robotQueue; } else { log.Add("Selected controller not available."); } ControllerID = controllerID; } else { if (controller != null) { return; } else { string exceptionMessage = "No robot controllers found on network."; ControllerID = "No Controller"; log.Add(exceptionMessage); } } } if (resetPP && controller != null) { using (Mastership m = Mastership.Request(controller.Rapid)) { // Reset program pointer to main. tasks[0].ResetProgramPointer(); log.Add("Program pointer set to main on the active task."); } } if (begin) { // Execute robot tasks present on controller. try { if (controller.OperatingMode == ControllerOperatingMode.Auto) { using (Mastership m = Mastership.Request(controller.Rapid)) { // Perform operation. tasks[0].Start(); log.Add("Robot program started on robot " + controller.SystemName + "."); } } else { log.Add("Automatic mode is required to start execution from a remote client."); } } catch (System.InvalidOperationException ex) { log.Add("Mastership is held by another client." + ex.Message); } catch (System.Exception ex) { log.Add("Unexpected error occurred: " + ex.Message); } } if (stop) { try { if (controller.OperatingMode == ControllerOperatingMode.Auto) { using (Mastership m = Mastership.Request(controller.Rapid)) { // Stop operation. tasks[0].Stop(StopMode.Immediate); log.Add("Robot program stopped on robot " + controller.SystemName + "."); } } else { log.Add("Automatic mode is required to stop execution from a remote client."); } } catch (System.InvalidOperationException ex) { log.Add("Mastership is held by another client." + ex.Message); } catch (System.Exception ex) { log.Add("Unexpected error occurred: " + ex.Message); } } // If active, update the status of the TCP. if (monitorTCP) { if (tcpMonitoringOn == 0) { log.Add("TCP monitoring started."); } cRobTarg = tasks[0].GetRobTarget(); cRobX = Math.Round(cRobTarg.Trans.X, 3); cRobY = Math.Round(cRobTarg.Trans.Y, 3); cRobZ = Math.Round(cRobTarg.Trans.Z, 3); Point3d cRobPos = new Point3d(cRobX, cRobY, cRobZ); cRobQ1 = Math.Round(cRobTarg.Rot.Q1, 5); cRobQ2 = Math.Round(cRobTarg.Rot.Q2, 5); cRobQ3 = Math.Round(cRobTarg.Rot.Q3, 5); cRobQ4 = Math.Round(cRobTarg.Rot.Q4, 5); cRobQuat = new Quaternion(cRobQ1, cRobQ2, cRobQ3, cRobQ4); tcp = Util.QuaternionToPlane(cRobPos, cRobQuat); tcpMonitoringOn += 1; tcpMonitoringOff = 0; } else if (tcpMonitoringOn > 0) { if (tcpMonitoringOff == 0) { log.Add("TCP monitoring stopped."); } tcpMonitoringOff += 1; tcpMonitoringOn = 0; } // If active, update the status of the IO system. if (monitorIO) { if (ioMonitoringOn == 0) { log.Add("Signal monitoring started."); } // Filter only the digital IO system signals. IOFilterTypes dSignalFilter = IOFilterTypes.Common; SignalCollection dSignals = controller.IOSystem.GetSignals(dSignalFilter); IOstatus.Clear(); // Iterate through the found collection and print them to the IO monitoring list. foreach (Signal signal in dSignals) { string sigVal = signal.ToString() + ": " + signal.Value.ToString(); IOstatus.Add(sigVal); } ioMonitoringOn += 1; ioMonitoringOff = 0; } else if (ioMonitoringOn > 0) { if (ioMonitoringOff == 0) { log.Add("Signal monitoring stopped."); } ioMonitoringOff += 1; ioMonitoringOn = 0; } if (stream) { if (targ != null) { IpcMessage message = new IpcMessage(); pos.X = (float)targ.Position.X; pos.Y = (float)targ.Position.Y; pos.Z = (float)targ.Position.Z; ori.Q1 = targ.Quaternion.A; ori.Q2 = targ.Quaternion.B; ori.Q3 = targ.Quaternion.C; ori.Q4 = targ.Quaternion.D; pose.Trans = pos; pose.Rot = ori; string content = "SD;[" + "\"Linear\"," + pos.ToString() + "," + ori.ToString() + "," + pose.ToString() + "]"; byte[] data = new UTF8Encoding().GetBytes(content); message.SetData(data); RobotQueue.Send(message); } } // Output the status of the connection. Status = log; DA.SetDataList(0, log); DA.SetDataList(1, IOstatus); DA.SetData(2, new GH_Plane(tcp)); ExpireSolution(true); } }
public void listmethod() { ////data1 = objController.Rapid.GetTask("T_ROB1").GetModule("SWDEFUSR").GetRapidData("Version_SWDEFUSR"); //string //data1.ValueChanged += new EventHandler<DataValueChangedEventArgs>(data1_ValueChanged); data2 = objController.Rapid.GetTask("T_ROB1").GetModule("URUN_M1").GetRapidData("W_00049"); //robtarget //robot punta pozisyon bilgisi data2.ValueChanged += new EventHandler <DataValueChangedEventArgs>(data2_ValueChanged); //data3 = objController.Rapid.GetTask("T_ROB1").GetModule("SWDEFUSR").GetRapidData("MAX_DEFLECTION"); //num //data3.ValueChanged += new EventHandler<DataValueChangedEventArgs>(data3_ValueChanged); //data4 = objController.Rapid.GetTask("T_ROB1").GetModule("SPOTSRV").GetRapidData("nToplamAsinma"); //num //data4.ValueChanged += new EventHandler<DataValueChangedEventArgs>(data4_ValueChanged); //data5 = objController.Rapid.GetTask("T_ROB1").GetModule("BASE").GetRapidData("wobj0"); //wobjdata //data5.ValueChanged += new EventHandler<DataValueChangedEventArgs>(data4_ValueChanged); //data6 = objController.Rapid.GetTask("T_ROB1").GetModule("BASE").GetRapidData("load0"); //loaddata //data6.ValueChanged += new EventHandler<DataValueChangedEventArgs>(data4_ValueChanged); //data7 = objController.Rapid.GetTask("T_ROB1").GetModule("HOME_KONTROL").GetRapidData("delta_position1"); //jointtarget //data7.ValueChanged += new EventHandler<DataValueChangedEventArgs>(data4_ValueChanged); data8 = objController.Rapid.GetTask("T_ROB1").GetModule("SPOTSRV").GetRapidData("bRobot_FrezePrograminda"); //bool data8.ValueChanged += new EventHandler <DataValueChangedEventArgs>(data4_ValueChanged); data9 = objController.Rapid.GetTask("T_ROB1").GetModule("SWDEFUSR").GetRapidData("spot1"); //spotdata data9.ValueChanged += new EventHandler <DataValueChangedEventArgs>(data4_ValueChanged); data10 = objController.Rapid.GetTask("T_AutoBackup").GetModule("MainModule").GetRapidData("bCycleOn"); //bool data10.ValueChanged += new EventHandler <DataValueChangedEventArgs>(data4_ValueChanged); data11 = objController.Rapid.GetTask("T_AutoBackup").GetModule("MainModule").GetRapidData("nHataKodu"); //num data11.ValueChanged += new EventHandler <DataValueChangedEventArgs>(data4_ValueChanged); data12 = objController.Rapid.GetTask("T_ROB1").GetModule("SPOTSRV").GetRapidData("force_bileme"); //forcedata //firezeleme kuvveti data12.ValueChanged += new EventHandler <DataValueChangedEventArgs>(data4_ValueChanged); data13 = objController.Rapid.GetTask("T_AutoBackup").GetModule("MainModule").GetRapidData("bKaynakTamamlandi"); //bool data13.ValueChanged += new EventHandler <DataValueChangedEventArgs>(data4_ValueChanged); data14 = objController.Rapid.GetTask("T_ROB1").GetModule("URUN_M1").GetRapidData("nProgNo"); //num data14.ValueChanged += new EventHandler <DataValueChangedEventArgs>(data4_ValueChanged); _string1 = (ABB.Robotics.Controllers.RapidDomain.String)data1.Value; string1 = _string1.Value; _robTarget1 = (ABB.Robotics.Controllers.RapidDomain.RobTarget)data2.Value; robTarget1 = _robTarget1.Trans; _num3 = (ABB.Robotics.Controllers.RapidDomain.Num)data3.Value; num3 = _num3.Value; _num4 = (ABB.Robotics.Controllers.RapidDomain.Num)data4.Value; num4 = _num4.Value; _wobjData1 = (WobjData)data5.Value; wobjData1 = _wobjData1.Oframe; _loadData1 = (LoadData)data6.Value; loadData1 = _loadData1.Aom; _jointTarget1 = (JointTarget)data7.Value; jointTarget1 = _jointTarget1.RobAx; _bool1 = (Bool)data8.Value; bool1 = _bool1.Value; label4.Text = data9.Value.ToString(); _bool2 = (Bool)data10.Value; bool2 = _bool2.Value; _num5 = (ABB.Robotics.Controllers.RapidDomain.Num)data11.Value; num5 = _num5.Value; _bool3 = (Bool)data13.Value; bool3 = _bool3.Value; label9.Text = data12.Value.ToString(); _num6 = (ABB.Robotics.Controllers.RapidDomain.Num)data14.Value; num6 = _num6.Value; dataGridView1.Rows.Add(data1.Symbol.Scope[0], data1.Symbol.Scope[1], data1.Symbol.Scope[2], string1); dataGridView1.Rows.Add(data2.Symbol.Scope[0], data2.Symbol.Scope[1], data2.Symbol.Scope[2], robTarget1); dataGridView1.Rows.Add(data3.Symbol.Scope[0], data3.Symbol.Scope[1], data3.Symbol.Scope[2], num3); dataGridView1.Rows.Add(data4.Symbol.Scope[0], data4.Symbol.Scope[1], data4.Symbol.Scope[2], num4); dataGridView1.Rows.Add(data5.Symbol.Scope[0], data5.Symbol.Scope[1], data5.Symbol.Scope[2], wobjData1); dataGridView1.Rows.Add(data6.Symbol.Scope[0], data6.Symbol.Scope[1], data6.Symbol.Scope[2], loadData1); dataGridView1.Rows.Add(data7.Symbol.Scope[0], data7.Symbol.Scope[1], data7.Symbol.Scope[2], jointTarget1); dataGridView1.Rows.Add(data8.Symbol.Scope[0], data8.Symbol.Scope[1], data8.Symbol.Scope[2], bool1); dataGridView1.Rows.Add(data10.Symbol.Scope[0], data10.Symbol.Scope[1], data10.Symbol.Scope[2], bool2); dataGridView1.Rows.Add(data11.Symbol.Scope[0], data11.Symbol.Scope[1], data11.Symbol.Scope[2], num5); dataGridView1.Rows.Add(data12.Symbol.Scope[0], data12.Symbol.Scope[1], data12.Symbol.Scope[2], data12.Value); dataGridView1.Rows.Add(data13.Symbol.Scope[0], data13.Symbol.Scope[1], data13.Symbol.Scope[2], bool3); dataGridView1.Rows.Add(data14.Symbol.Scope[0], data14.Symbol.Scope[1], data14.Symbol.Scope[2], num6); dataGridView1.AutoGenerateColumns = false; }