/// <summary> /// 从服务器xml中定义到robot /// </summary> public void LoadRobot(string strXml) { XmlDocument doc = new XmlDocument(); doc.LoadXml(strXml); XmlNode rootNode = doc.DocumentElement; robotName = ((XmlElement)rootNode).GetAttribute("Name"); brand = ((XmlElement)rootNode).GetAttribute("Brand"); model = ((XmlElement)rootNode).GetAttribute("Model"); XmlNode modelPathNode = rootNode.SelectSingleNode("ModelPath"); mainModelPath = modelPathNode.SelectSingleNode("MainModel").InnerText; XmlNodeList othersList = modelPathNode.SelectNodes("OtherModel"); foreach (XmlNode other in othersList) { otherModelPaths.Add(other.InnerText); } XmlNode listNode = rootNode.SelectSingleNode("PartList"); XmlNodeList partNode = listNode.SelectNodes("PartObj"); foreach (XmlNode node in partNode) { Part_U onePart = new Part_U(); XmlElement robotEle = (XmlElement)node; onePart.partObjName = robotEle.GetAttribute("Name"); string partIDStr = robotEle.GetAttribute("ID"); if (!String.IsNullOrEmpty(partIDStr)) { try { onePart.partID = int.Parse(partIDStr); } catch (Exception e) { } } if (false) { onePart.modelPath = node.SelectSingleNode("ModelPath").InnerText; } string partPQstr = node.SelectSingleNode("PQ").InnerText; if (!String.IsNullOrEmpty(partPQstr)) { try { partPQstr = partPQstr.Replace(" ", ""); string[] strList = partPQstr.Split(new char[] { ',' }); for (int i = 0; i < strList.Length; i++) { onePart.partPQ_initial.Add(float.Parse(strList[i])); } } catch (Exception e) { } } partList.Add(onePart); } XmlNode jointNode = rootNode.SelectSingleNode("JointList"); XmlNodeList jointNodeList = jointNode.SelectNodes("Axis"); foreach (XmlNode joint in jointNodeList) { Joint_U oneJoint = new Joint_U(); try { oneJoint.jointID = int.Parse(((XmlElement)joint).GetAttribute("ID")); oneJoint.partID_1 = int.Parse(((XmlElement)joint).GetAttribute("PartID1")); oneJoint.partID_2 = int.Parse(((XmlElement)joint).GetAttribute("PartID2")); oneJoint.jointType = int.Parse(((XmlElement)joint).GetAttribute("Type")); string posStr = joint.SelectSingleNode("Pos").InnerText; posStr = posStr.Replace(" ", ""); string[] posStrList = posStr.Split(new char[] { ',' }); string dirStr = joint.SelectSingleNode("Dir").InnerText; dirStr = dirStr.Replace(" ", ""); string[] dirStrList = dirStr.Split(new char[] { ',' }); for (int i = 0; i < 3; i++) { oneJoint.jointAxisPos.Add(float.Parse(posStrList[i])); oneJoint.jointAxisDir.Add(float.Parse(dirStrList[i])); } } catch (Exception e) { } jointList.Add(oneJoint); } XmlNode eeNode = rootNode.SelectSingleNode("EndEffectorList"); XmlNodeList eeList = eeNode.SelectNodes("EE"); foreach (XmlNode ee in eeList) { EE_U oneEE = new EE_U(); try { oneEE.eeID = int.Parse(((XmlElement)ee).GetAttribute("ID")); oneEE.eePartID = int.Parse(((XmlElement)ee).GetAttribute("PartID")); oneEE.eeObj_Name = ((XmlElement)ee).GetAttribute("ObjName"); string pqStr = ee.SelectSingleNode("PQ").InnerText; pqStr = pqStr.Replace(" ", ""); string[] strList = pqStr.Split(new char[] { ',' }); for (int i = 0; i < strList.Length; i++) { oneEE.eePQ_initial.Add(float.Parse(strList[i])); } } catch (Exception e) { } endEList.Add(oneEE); } }
/// <summary> /// 从服务器xml中定义到robot, aris格式 /// </summary> public void LoadRobot_Aris(string strXml, bool isPath) { XmlDocument doc = new XmlDocument(); if (isPath) { doc.Load(strXml); } else { doc.LoadXml(strXml); } XmlNode rootNode = doc.DocumentElement; robotName = "AnyRobot"; brand = "AnyBrand"; model = "AnyModel"; //brand = ((XmlElement)rootNode).GetAttribute("Brand"); //model = ((XmlElement)rootNode).GetAttribute("Model"); XmlNode modelNode = rootNode.SelectSingleNode("model"); XmlNode part_pool_node = modelNode.SelectSingleNode("part_pool"); XmlNodeList part_list_node = part_pool_node.ChildNodes; foreach (XmlNode oneNode in part_list_node) { Part_U onePart = new Part_U(); onePart.partObjName = oneNode.Name; XmlElement oneElement = (XmlElement)oneNode; string peStr = oneElement.GetAttribute("pq"); //Debug.Log(peStr); peStr = peStr.Replace("{", ""); peStr = peStr.Replace("}", ""); peStr = peStr.Replace(" ", ""); //Debug.Log(peStr); string[] peStr_List = peStr.Split(new char[] { ',' }); for (int str_i = 0; str_i < peStr_List.Length; str_i++) { if (!String.IsNullOrEmpty(peStr_List[str_i])) { try { onePart.partPQ_initial.Add(float.Parse(peStr_List[str_i])); } catch (Exception e) { //Debug.Log(e.ToString()); Console.WriteLine(e.ToString()); } } } XmlNode geometry_pool_node = oneNode.SelectSingleNode("geometry_pool"); XmlNodeList geo_list_node = geometry_pool_node.ChildNodes; foreach (XmlNode oneGeoNode in geo_list_node) { XmlElement oneGeoElement = (XmlElement)oneGeoNode; Console.WriteLine(oneGeoElement.GetAttribute("graphic_file_path")); onePart.geometryPathList.Add(oneGeoElement.GetAttribute("graphic_file_path")); string geoPeStr = oneGeoElement.GetAttribute("pq"); geoPeStr = geoPeStr.Replace("{", ""); geoPeStr = geoPeStr.Replace("}", ""); geoPeStr = geoPeStr.Replace(" ", ""); foreach (string str in geoPeStr.Split(new char[] { ',' })) { try { onePart.geometryPQ_List.Add(float.Parse(str)); } catch (Exception e) { Console.WriteLine(e.ToString()); //throw; } } //string[] geoPeStr_list = geoPeStr.Split(new char[] { ',' }); } partList.Add(onePart); } }