/// <summary> /// GenerateRobot: Recreates a robot given the proper specifications by: /// 1. Recreating all of the joints and links as Unity objects, as well as setting their parents and children. /// 2. Setting the transforms of all of the individual objects. /// /// <param name="structure"> A protobuf object holding all of the necessary information to recreate a robot. </param> /// </summary> public static void GenerateRobot(RobotStructure structure) { Dictionary <int, GameObject> jointDict = new Dictionary <int, GameObject>(); Dictionary <int, GameObject> linkDict = new Dictionary <int, GameObject>(); // We should have all of the objects with their IDs in the dict now. foreach (KeyValuePair <int, JointStorage> joints in structure.JointDict) { GameObject GeneratedJoint = GenerateJoint(joints.Value); jointDict.Add(joints.Key, GeneratedJoint); } foreach (KeyValuePair <int, LinkStorage> links in structure.LinkDict) { GameObject GeneratedLink = GenerateLink(links.Value); linkDict.Add(links.Key, GeneratedLink); } if (jointDict.ContainsKey(structure.RootJointID)) { SetTransforms(jointDict[structure.RootJointID], jointDict, linkDict, true); } else { Debug.Log("RootJoint not found."); } }
// Helper function to determine if Robot has an active project open private bool IsRobotActive() { // Initialise connection to Robot if none exists if (!(iapp is RobotApplication)) { iapp = new RobotApplication(); } try { structure = iapp.Project.Structure; nodes = structure.Nodes; bars = structure.Bars; } catch (System.Runtime.InteropServices.COMException) { ErrorDialog("Robot does not appear to be running", "ERROR: Robot not running"); return(false); } if (iapp.Project.IsActive == 0) { ErrorDialog("No active Robot project was found", "ERROR: No active project"); return(false); } return(true); }
public static int AddNode(RobotStructure structureRSA, double x, double y, double z) { RobotNodeServer nodesRSA = structureRSA.Nodes; int freeNum = nodesRSA.FreeNumber; nodesRSA.Create(freeNum, x, y, z); return(freeNum); }
public static int AddBar(RobotStructure structureRSA, RobotNode node1, RobotNode node2) { int num1 = node1.Number; int num2 = node2.Number; RobotBarServer barsRSA = structureRSA.Bars; int freeNum = barsRSA.FreeNumber; barsRSA.Create(freeNum, num1, num2); return(freeNum); }
public static void Bot() { RobotApplication rob = new RobotApplication(); RobotStructure str = rob.Project.Structure; str.Nodes.Create(1, 0, 0, 0); Console.WriteLine("Node Added."); str = null; rob = null; Console.ReadKey(); }
public static void AddBar(RobotStructure structureRSA, RobotNode node1, RobotNode node2, IRobotLabel labelSect) { int num1 = node1.Number; int num2 = node2.Number; RobotBarServer barsRSA = structureRSA.Bars; int freeNum = barsRSA.FreeNumber; barsRSA.Create(freeNum, num1, num2); RobotSelection selection = structureRSA.Selections.Create(IRobotObjectType.I_OT_BAR); selection.FromText(freeNum.ToString()); barsRSA.SetLabel(selection, IRobotLabelType.I_LT_BAR_SECTION, labelSect.Name); }
/// <summary> /// Goes here after receiving a signal /// </summary> public static void ReadCallBack(IAsyncResult res) { UdpClient client = (UdpClient)res.AsyncState; IPEndPoint RemoteIPEndPoint = new IPEndPoint(IPAddress.Any, listenPort); Console.WriteLine("----------------------"); Console.WriteLine("UDP Connection made. Receiving data..."); byte[] received = client.EndReceive(res, ref RemoteIPEndPoint); listenPort = ((IPEndPoint)client.Client.LocalEndPoint).Port; Console.WriteLine("Data received from: {0} at Port: {1}", RemoteIPEndPoint.Address.ToString(), listenPort.ToString()); Console.WriteLine("Sending back changed position for debugging/testing purposes..."); using (MemoryStream ms = new MemoryStream()) { ms.Write(received, 0, received.Length); ms.Position = 0; if (listenPort == 8888) { replyPort = 9999; MessageParser<RobotStructure> parser = new MessageParser<RobotStructure>(() => new RobotStructure()); receivedStructure = parser.ParseFrom(ms); receivedStructure.RootJointID = 1; ms.Position = 0; SendBackStructure(receivedStructure); } else if (listenPort == 7777) { replyPort = 6666; MessageParser<PositionList> parser = new MessageParser<PositionList>(() => new PositionList()); receivedList = parser.ParseFrom(ms); receivedList.PList[0].Rotation = 30; ms.Position = 0; SendBackPositions(receivedList); } else if (listenPort == 1234) { replyPort = 4321; MessageParser<MeshList> parser = new MessageParser<MeshList>(() => new MeshList()); receivedMeshes = parser.ParseFrom(ms); Console.WriteLine("RECEIVED MESHES... LENGTH = {0}", receivedMeshes.Meshes.Count); StartBoth.ListeningMessage(); StartBoth._MeshListening = false; } } }
private void Init(IRobotApplication iapp) { if (iapp != null) { robot = iapp; } else { robot = new RobotApplication(); } str = robot.Project.Structure; Panel = new List <RSA_FE>(); PanelEdges = new List <Panel>(); ErrorList = new List <string>(); }
public static void SendBackStructure(RobotStructure received) { using (MemoryStream ms = new MemoryStream()) { received.WriteTo(ms); Socket tempSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint replyEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), replyPort); ms.Position = 0; tempSocket.SendTo(received.ToByteArray(), replyEndPoint); tempSocket.Close(); } Console.WriteLine("Data sent!"); StartBoth.ListeningMessage(); StartBoth._Structurelistening = false; }
public void test() { RobotApplication appRSA = new RobotApplication(); getMaterialNameListRSA(appRSA); getBarSectionNamesRSA(appRSA); RobotStructure structureRSA = appRSA.Project.Structure; RobotBarServer barsRSA = structureRSA.Bars; RobotNodeServer nodesRSA = structureRSA.Nodes; RobotObjObjectServer objRSA = structureRSA.Objects; RobotLabelServer labelsRSA = appRSA.Project.Structure.Labels; //Определение выборок выделенных в модели объектов RobotSelection barSel = structureRSA.Selections.Get(IRobotObjectType.I_OT_BAR); RobotSelection plateSel = structureRSA.Selections.Get(IRobotObjectType.I_OT_PANEL); RobotSelection holesSel = structureRSA.Selections.Get(IRobotObjectType.I_OT_GEOMETRY); RobotBarCollection barsMany = (RobotBarCollection)barsRSA.GetMany(barSel); RobotObjObjectCollection platesMany = (RobotObjObjectCollection)objRSA.GetMany(plateSel); IRobotBar barRSA = barsMany.Get(3); IRobotObjObject plate = platesMany.Get(1); IRobotLabel labelPlate = plate.GetLabel(IRobotLabelType.I_LT_PANEL_THICKNESS); RobotGeoPoint3DCollection defPoints = (RobotGeoPoint3DCollection)plate.Main.DefPoints; RobotGeoPoint3D pt1 = defPoints.Get(1); RobotGeoPoint3D pt2 = defPoints.Get(2); RobotGeoPoint3D pt3 = defPoints.Get(defPoints.Count); //IRobotGeoContour geoContour=(IRobotGeoContour)plate.Main.Geometry; //IRobotGeoObject geoObj=plate.Main.Geometry; IRobotLabel labelBar = barRSA.GetLabel(IRobotLabelType.I_LT_BAR_SECTION); RobotBarSectionData data = labelBar.Data; RobotBarSectionConcreteData cData = data.Concrete; double b = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_B); double h = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_H); double l1 = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_L1); double l2 = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_L2); double h1 = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_H1); double h2 = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_H2); double de = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_DE); double alfa = barRSA.Gamma; }
private void Update() { // This is for first movement in the sequence if (Input.GetKeyDown(KeyCode.A)) { testList.PList[4].Rotation = -45; testList.PList[5].Rotation = -45; testList.PList[8].Rotation = 90; testList.PList[9].Rotation = 90; ObjectJoint.SetJoints(testList, GameObject.Find("Sphere")); } // This is for the second movement in the sequence (repeate this and 3) if (Input.GetKeyDown(KeyCode.S)) { testList.PList[4].Rotation = 45; testList.PList[5].Rotation = 45; testList.PList[8].Rotation = -90; testList.PList[9].Rotation = -90; testList.PList[2].Rotation = -45; testList.PList[3].Rotation = -45; testList.PList[6].Rotation = 90; testList.PList[7].Rotation = 90; ObjectJoint.SetJoints(testList, GameObject.Find("Sphere")); } // Third movement in the sequence if (Input.GetKeyDown(KeyCode.D)) { testList.PList[4].Rotation = -45; testList.PList[5].Rotation = -45; testList.PList[8].Rotation = 90; testList.PList[9].Rotation = 90; testList.PList[2].Rotation = 45; testList.PList[3].Rotation = 45; testList.PList[6].Rotation = -90; testList.PList[7].Rotation = -90; GameObject root = GameObject.Find("Sphere"); root.transform.Translate(Vector3.left * Time.deltaTime * 100); ObjectJoint.SetJoints(testList, GameObject.Find("Sphere")); } #if ServerTesting // Configuring the robot with server test if (Input.GetKeyDown(KeyCode.A)) { RobotStructure test = ClientUDP <RobotStructure> .UDPSend(8888, testStructure); ConstructionManager.GenerateRobot(test); ObjectJoint.GetJoints(GameObject.Find("Sphere").GetComponent <ObjectJoint>().ChildObjectJoints, GameObject.Find("Sphere")); } // Moving the thing if (Input.GetKeyDown(KeyCode.Space)) { PositionListCreator.CreateList(GameObject.Find("Sphere"), testList.PList); PositionList newList = ClientUDP <PositionList> .UDPSend(7777, testList); ObjectJoint.SetJoints(newList, GameObject.Find("Sphere")); } #endif }
/// <summary> /// Gets the FE meshes from a Robot model using the fast query method /// </summary> /// <param name="panel_ids"></param> /// <param name="coords"></param> /// <param name="vertex_indices"></param> /// <param name="str_nodes"></param> /// <param name="filePath"></param> /// <returns></returns> public static bool GetFEMeshQuery(out int[] panel_ids, out double[][] coords, out Dictionary <int, int[]> vertex_indices, string filePath = "LiveLink") { RobotApplication robot = null; if (filePath == "LiveLink") { robot = new RobotApplication(); } //First call getnodesquery to get node points double[][] nodeCoords = null; //Dictionary<int, BHoM.Structural.Node> _str_nodes = new Dictionary<int, BHoM.Structural.Node>(); //RobotToolkit.Node.GetNodesQuery(project, filePath); //Dictionary<int, int> _nodeIds = new Dictionary<int, int>(); //for (int i = 0; i < _str_nodes.Count; i++) //{ // _nodeIds.Add(_str_nodes.ElementAt(i).Value.Number, i); //} RobotResultQueryParams result_params = (RobotResultQueryParams)robot.Kernel.CmpntFactory.Create(IRobotComponentType.I_CT_RESULT_QUERY_PARAMS); RobotStructure rstructure = robot.Project.Structure; RobotSelection FE_sel = rstructure.Selections.CreateFull(IRobotObjectType.I_OT_FINITE_ELEMENT); IRobotResultQueryReturnType query_return = IRobotResultQueryReturnType.I_RQRT_MORE_AVAILABLE; RobotSelection cas_sel = rstructure.Selections.Create(IRobotObjectType.I_OT_CASE); try { cas_sel.FromText(robot.Project.Structure.Cases.Get(1).Number.ToString()); } catch { } if (cas_sel.Count > 0) { result_params.Selection.Set(IRobotObjectType.I_OT_CASE, cas_sel); } //result_params.Selection.Set(IRobotObjectType.I_OT_NODE, FE_sel); result_params.SetParam(IRobotResultParamType.I_RPT_MULTI_THREADS, true); result_params.SetParam(IRobotResultParamType.I_RPT_THREAD_COUNT, 4); result_params.SetParam(IRobotResultParamType.I_RPT_SMOOTHING, IRobotFeResultSmoothing.I_FRS_NO_SMOOTHING); result_params.SetParam(IRobotResultParamType.I_RPT_DIR_X_DEFTYPE, IRobotObjLocalXDirDefinitionType.I_OLXDDT_CARTESIAN); result_params.SetParam(IRobotResultParamType.I_RPT_DIR_X, new double[] { 1, 0, 0 }); result_params.SetParam(IRobotResultParamType.I_RPT_NODE, 1); result_params.SetParam(IRobotResultParamType.I_RPT_PANEL, 1); result_params.SetParam(IRobotResultParamType.I_RPT_ELEMENT, 1); result_params.SetParam(IRobotResultParamType.I_RPT_RESULT_POINT_COORDINATES, 1); result_params.ResultIds.SetSize(2); result_params.ResultIds.Set(1, (int)IRobotFeResultType.I_FRT_DETAILED_MXX); result_params.ResultIds.Set(2, (int)IRobotFeResultType.I_FRT_DETAILED_MYY); RobotResultRowSet row_set = new RobotResultRowSet(); bool ok = false; RobotResultRow result_row = default(RobotResultRow); List <int> _panel_ids = new List <int>(); Dictionary <int, int[]> _vertex_indices = new Dictionary <int, int[]>(); int kounta = 0; while (!(query_return == IRobotResultQueryReturnType.I_RQRT_DONE)) { query_return = rstructure.Results.Query(result_params, row_set); ok = row_set.MoveFirst(); while (ok) { //int panel_num = (int)row_set.CurrentRow.GetValue(1252); //_panel_ids.Add(panel_num); int nodeId = (int)row_set.CurrentRow.GetParam(IRobotResultParamType.I_RPT_NODE); //int panelId = (int)row_set.CurrentRow.GetParam(IRobotResultParamType.I_RPT_PANEL); int elementId = (int)row_set.CurrentRow.GetParam(IRobotResultParamType.I_RPT_ELEMENT); //int number_of_indices = (row_set.CurrentRow.IsAvailable(567)) ? 4 : 3; //int[] temp_indices = new int[number_of_indices]; //for (int i = 0; i < number_of_indices; i++) //{ // temp_indices[i] = (int)row_set.CurrentRow.GetValue(564 + i); //} var resultIds = row_set.ResultIds; var xxxx = row_set.CurrentRow.GetParam(IRobotResultParamType.I_RPT_RESULT_POINT_COORDINATES); //_vertex_indices.Add(kounta, temp_indices); //kounta++; ok = row_set.MoveNext(); } row_set.Clear(); } result_params.Reset(); panel_ids = _panel_ids.ToArray(); vertex_indices = _vertex_indices; coords = nodeCoords; //str_nodes = _str_nodes; return(true); }