/* * public bool sendTwoPartCommand(byte module, byte action, int number) * { * byte[] header_bytes = new byte[3] { (byte)'A', module, action }; * NetMQMessage req_msg = new NetMQMessage(); * req_msg.Append(header_bytes); * req_msg.Append((byte)number); * NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg(); // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo? * * reqSrv = new ReliableExternalClient( * GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3); * if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg)) * { * UnityEngine.Debug.Log("Client: server not respoding"); * return false; * } * * return true; * } */ /// <summary> /// Command to send the matrix to the server /// </summary> /// <param name="matrix"></param> /// <returns></returns> public bool sendCommand(RegistrationMatrix matrix) { byte[] header_bytes = new byte[68]; NetMQMessage req_msg = new NetMQMessage(); header_bytes[0] = (byte)'A'; header_bytes[1] = matrix.MatrixHeader.module; header_bytes[2] = matrix.MatrixHeader.action; header_bytes[3] = matrix.rowMajor; for (int i = 0; i < 16; i++) { byte[] aux = BitConverter.GetBytes(matrix.elems[i]); header_bytes[i * 4 + 4] = aux[0]; header_bytes[i * 4 + 5] = aux[1]; header_bytes[i * 4 + 6] = aux[2]; header_bytes[i * 4 + 7] = aux[3]; } req_msg.Append(header_bytes); NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg(); // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo? reqSrv = new ReliableExternalClient( GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3); if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg)) { UnityEngine.Debug.Log("Client: server not respoding"); return(false); } return(true); }
//Once the drone finishes the path, a button appears which, once it is clicked, will call this function public void finish() { clientUnity.client.SendCommand((byte)Modules.PLAN_EXECUTOR_MODULE, (byte)PlanExecutorCommandType.PLAN_EXEC_EXIT); isRecState = false; registrationMatrix = null; FlyButtonStateMachine.state = FlyButtonStateMachine.buttonState.DEACTIVATED; SceneManager.LoadScene("General"); }
void Awake() { GeneralSceneManager.sceneState = GeneralSceneManager.SceneState.Recording; topInfoPanel.transform.GetChild(0).GetChild(0).GetComponent <Image>().color = new Color(1, 1, 1, 0.4f); topInfoPanel.transform.GetChild(1).GetChild(0).GetComponent <Image>().color = new Color(1, 1, 1, 0.4f); topInfoPanel.transform.GetChild(2).GetChild(0).GetComponent <Image>().color = new Color(1, 1, 1, 0.4f); topInfoPanel.transform.GetChild(3).GetChild(0).GetComponent <Image>().color = new Color(1, 1, 1, 0.4f); modelLoadingPanel = GameObject.Find("ModelLoadingPanel"); modelLoadingPanel.transform.GetChild(0).GetComponent <RectTransform>().anchoredPosition = new Vector2(0, Screen.height / 7); modelLoadingPanel.transform.GetChild(0).GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width / 1.5f, Screen.height / 3); modelLoadingPanel.transform.GetChild(1).GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -Screen.height / 7); modelLoadingPanel.transform.GetChild(1).GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.height / 8, Screen.height / 8); modelLoadingPanel.transform.GetChild(0).GetComponent <Text>().fontSize = (int)(Screen.width * 0.05f); StartCoroutine(WaitForModel()); fpvRender.sizeDelta = new Vector2(Screen.width / 4, Screen.height / 3); warningAccept.sizeDelta = new Vector2(Screen.width / 6, Screen.height / 10); warningCancel.sizeDelta = new Vector2(Screen.width / 6, Screen.height / 10); warningTakeOff.sizeDelta = new Vector2(Screen.width / 6, Screen.height / 10); warningAccept.anchoredPosition = new Vector2(Screen.width / 8, 0); warningCancel.anchoredPosition = new Vector2(-Screen.width / 8, 0); WarningPanel.anchoredPosition = new Vector2(0, Screen.height / 4); WarningPanel.sizeDelta = new Vector2(WarningPanel.sizeDelta.x, 3 * Screen.height / 4); warningTitle.fontSize = Screen.height / 16; warningTitle.GetComponent <RectTransform>().anchoredPosition = new Vector2(warningTitle.GetComponent <RectTransform>().anchoredPosition.x, Screen.height / 12); warningText.fontSize = Screen.height / 28; warningText.rectTransform.sizeDelta = new Vector2(warningText.rectTransform.sizeDelta.x, Screen.height / 4); warningText.rectTransform.anchoredPosition = new Vector2(warningText.rectTransform.anchoredPosition.x, -2 * Screen.height / 12); warningRecStartPanel.anchoredPosition = new Vector2(0, Screen.height / 4); warningRecStartPanel.sizeDelta = new Vector2(WarningPanel.sizeDelta.x, 3 * Screen.height / 6); warningRecStartTitle.fontSize = Screen.height / 16; warningRecStartTitle.GetComponent <RectTransform>().anchoredPosition = new Vector2(warningTitle.GetComponent <RectTransform>().anchoredPosition.x, Screen.height / 12); warningRecStartText.fontSize = Screen.height / 28; warningRecStartText.rectTransform.sizeDelta = new Vector2(warningText.rectTransform.sizeDelta.x, Screen.height / 4); warningRecStartText.rectTransform.anchoredPosition = new Vector2(warningText.rectTransform.anchoredPosition.x, -2 * Screen.height / 12); playPauseImage = playButton.GetComponent <Image>(); playPauseRect = playButton.GetComponent <RectTransform>(); playPauseRect.sizeDelta = new Vector2(Screen.height / 16, Screen.height / 16); backRect.sizeDelta = new Vector2(Screen.height / 16, Screen.height / 16); playPauseRect.anchoredPosition = new Vector2(Screen.width / 20, 0); backRect.anchoredPosition = new Vector2(-Screen.width / 20, 0); recordingPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Screen.width / 20, 2 * Screen.height / 8); clientUnity = GameObject.Find("ClientUnity").GetComponent <ClientUnity>(); droneHasFinishedPanel.gameObject.SetActive(false); droneHasFinishedPanel.sizeDelta = new Vector2(droneHasFinishedPanel.sizeDelta.x, Screen.height / 16); droneHasFinishedPanel.anchoredPosition = new Vector2(0, 2 * Screen.height / 8); droneHasFinishedText.GetComponent <Text>().fontSize = Screen.width / 60; droneHasFinishedButton.sizeDelta = new Vector2(Screen.width / 8, Screen.height / 16); //Create Path path = Path.Instance; string jsonString = File.ReadAllText(Application.persistentDataPath + "/PersistentData/Missions/" + MissionManager.guid + ".json.mission"); Map map = JsonUtility.FromJson <Map>(jsonString); //UnityEngine.Debug.Log("Guid: " + MissionManager.guid); //UnityEngine.Debug.Log("PlanIndex: " + MissionManager.planIndex); //UnityEngine.Debug.Log("PathsCount: " + map.Paths.Count); Path anotherPath = map.Paths[MissionManager.planIndex]; //We get the matrix that will transform from unity to pozyx to send it registrationMatrix = new RegistrationMatrix(); for (int i = 0; i < 16; i++) { registrationMatrix.elems[i] = map.unityToAnchors[i]; UnityEngine.Debug.Log(registrationMatrix.elems[i]); } registrationMatrix.rowMajor = 0; //path.setPath(anotherPath); //If the drone isn't in recording state if (!isRecState) { //We enter recording state, which will send the matrix and the plan clientUnity.client.SendCommand((byte)Modules.ATREYU_MODULE, (byte)AtreyuCommandType.ATREYU_ENTER_RECORDING_STATE); //clientUnity.client.sendCommand((byte)Modules.POSITIONING_MODULE, (byte)PositioningCommandType.IPS_SYSTEM); } else { //else we start to look at the drone travel FlyButtonStateMachine.state = FlyButtonStateMachine.buttonState.ACTIVATED; isRecState = false; } //for (int i = 0; i < path.Count(); i++) //{ // GameObject auxPoint = Instantiate(point, path.GetPoint(i).PointPosition, Quaternion.Euler(0, 0, 0), parent.transform); // path.GetPoint(i).PointTransf = auxPoint.transform; // auxPoint.SetActive(true); // auxPoint.AddComponent<PathPoint>().createPathPointWithPoint(path.GetPoint(i), 0,0); // waypoints.Add(auxPoint); //} //topCam.gameObject.GetComponent<PostRenderFront>().enabled = true; //lineMat.SetPass(0); ////WarningPanel.gameObject.SetActive(false); //for (int i = 0; i < path.Count() - 1; i++) //{ // CatmullRomSpline.DisplayCatmullRomSpline2(path, i, ref path.middlePointsTop, topCam.orthographicSize / 2.0f, true, topCam); //} ////modelMaterial.SetFloat("_Discard", 0); // waypoints.Sort((IComparer<GameObject>)new SortPointsByID()); // indexWaypoints = 0; // indexMiddlePoints = 0; // TotalindexMiddlePoints = 0; // drone.transform.position = waypoints[0].transform.position; // actualWaypoint = waypoints[0].transform.position; // nextWaypoint = path.middlePointsTop[0]; // if (waypoints[0].GetComponent<PathPoint>().Poi != null) // { // drone.transform.LookAt(waypoints[0].GetComponent<PathPoint>().Poi); // } // else // { // drone.transform.rotation = Quaternion.Euler(0, 0, 0); // // } //recordingPanel.SetActive(true); }