/// <summary> /// Creates text box for each subscriber and properly displays them above the drone. /// </summary> public void InitDroneMenu(ROSDroneConnectionInterface rosDroneConnection, List <string> droneSubscribers) { connection = rosDroneConnection; droneSubscriberTopics = droneSubscribers; infoTextsDict = new Dictionary <Text, string>(); // Creating Text label for each subscriber of the drone float offsetY = -190; // text position displacement from anchor location (top center) offsetY += droneSubscribers.Count * 60; // displacing top text position based on num subscribers droneNameText.rectTransform.anchoredPosition = new Vector3(0, offsetY, 0); // top text box is drone name droneNameText.text = this.name; foreach (string subscriber in droneSubscribers) { offsetY -= 60f; // create text box GameObject placeholder = new GameObject("text of " + subscriber); placeholder.transform.SetParent(menuCanvas.transform); placeholder.transform.localScale = new Vector3(1, 1, 1); //text location Text infoText = placeholder.AddComponent <Text>(); infoText.rectTransform.anchorMax = new Vector2(0.5f, 1); // top-center anchor location infoText.rectTransform.anchorMin = new Vector2(0.5f, 1); // top-center anchor location infoText.rectTransform.anchoredPosition = new Vector3(0, offsetY, 0); // text content & stylizing infoText.text = "Lorem Ipsum"; infoText.alignment = TextAnchor.MiddleCenter; infoText.verticalOverflow = VerticalWrapMode.Overflow; infoText.horizontalOverflow = HorizontalWrapMode.Overflow; infoText.font = menuFont; infoText.fontSize = 80; infoText.fontStyle = FontStyle.Bold; infoText.color = Color.green; infoTextsDict.Add(infoText, subscriber); } initialized = true; }
void OnClickEvent() { Drone selectedDrone = WorldProperties.GetSelectedDrone(); ROSDroneConnectionInterface droneROSConnection = selectedDrone.droneProperties.droneROSConnection; if (startMission) { Debug.Log("Start mission button clicked"); droneROSConnection.StartMission(); } if (pauseMission) { droneROSConnection.PauseMission(); } if (resumeMission) { droneROSConnection.ResumeMission(); } if (clearWaypoints) { selectedDrone.DeleteAllWaypoints(); } if (landDrone) { droneROSConnection.LandDrone(); } if (homeDrone) { droneROSConnection.FlyHome(); } }
/// <summary> /// Set the rosDroneConnection to given argument /// </summary> /// <param name="new_ROSDroneConnection"></param> public void UpdateDrone(ROSDroneConnectionInterface new_ROSDroneConnection) { rosDroneConnection = (Matrice_ROSDroneConnection)new_ROSDroneConnection; }
/// <summary> /// Create a Drone gameobject and attach DroneFlightSim, required ROSDroneConnnection and initialize the ROS connection. /// </summary> /// <param name="rosDroneConnectionInput"></param> private void InstantiateDrone(ROSDroneConnectionInput rosDroneConnectionInput) { // All the variables required to create the drone DroneType droneType = rosDroneConnectionInput.droneType; string droneIP = rosDroneConnectionInput.url; int dronePort = rosDroneConnectionInput.port; bool simFlight = rosDroneConnectionInput.simFlight; List <string> droneSubscribers = new List <string>(); foreach (DroneSubscribers subscriber in rosDroneConnectionInput.droneSubscribers) { droneSubscribers.Add(subscriber.ToString()); } // Create a new drone Drone droneInstance = new Drone(WorldProperties.worldObject.transform.position, uniqueID); Debug.Log("Drone that was just made " + droneInstance.gameObjectPointer.name); DroneProperties droneProperties = droneInstance.droneProperties; GameObject droneGameObject = droneInstance.gameObjectPointer; droneGameObject.name = rosDroneConnectionInput.droneName; ROSDroneConnectionInterface rosDroneConnection = null; // Add corresponding ros drone connection script switch (droneType) { case DroneType.M100: Debug.Log("M100 created"); M100_ROSDroneConnection M100_rosDroneConnection = droneGameObject.AddComponent <M100_ROSDroneConnection>(); M100_rosDroneConnection.InitilizeDrone(uniqueID, droneIP, dronePort, droneSubscribers, simFlight, droneProperties); rosDroneConnection = M100_rosDroneConnection; droneGameObject.GetComponent <DroneProperties>().droneROSConnection = M100_rosDroneConnection; ROSDroneConnections.Add(uniqueID, M100_rosDroneConnection); break; case DroneType.M210: Debug.Log("M210 created"); M210_ROSDroneConnection M210_rosDroneConnection = droneGameObject.AddComponent <M210_ROSDroneConnection>(); M210_rosDroneConnection.InitilizeDrone(uniqueID, droneIP, dronePort, droneSubscribers, simFlight, droneProperties); rosDroneConnection = M210_rosDroneConnection; droneGameObject.GetComponent <DroneProperties>().droneROSConnection = M210_rosDroneConnection; ROSDroneConnections.Add(uniqueID, M210_rosDroneConnection); break; case DroneType.M600: Debug.Log("M600 created"); M600_ROSDroneConnection M600_rosDroneConnection = droneGameObject.AddComponent <M600_ROSDroneConnection>(); M600_rosDroneConnection.InitilizeDrone(uniqueID, droneIP, dronePort, droneSubscribers, simFlight, droneProperties); rosDroneConnection = M600_rosDroneConnection; droneGameObject.GetComponent <DroneProperties>().droneROSConnection = M600_rosDroneConnection; ROSDroneConnections.Add(uniqueID, M600_rosDroneConnection); break; case DroneType.Sprite: Debug.Log("Sprite class not implemented created"); //Sprite_ROSDroneConnection drone_rosDroneConnection = drone.AddComponent<Sprite_ROSDroneConnection>(); break; default: Debug.Log("No drone type selected"); return; } // Create attached sensors foreach (ROSSensorConnectionInput rosSensorInput in rosDroneConnectionInput.attachedSensors) { ROSSensorConnectionInterface sensor = InstantiateSensor(rosSensorInput); droneInstance.AddSensor(sensor); } // Initilize drone sim manager script on the drone DroneSimulationManager droneSim = droneGameObject.GetComponent <DroneSimulationManager>(); droneSim.InitDroneSim(); droneProperties.droneSimulationManager = droneSim; // Get DroneMenu and instansiate. DroneMenu droneMenu = droneGameObject.GetComponent <DroneMenu>(); droneMenu.InitDroneMenu(rosDroneConnection, droneSubscribers); droneGameObject.GetComponent <DroneProperties>().droneMenu = droneMenu; uniqueID++; }