void OnClickEvent()
    {
        if (surface_pointcloud)
        {
            Debug.Log("Switching to surface point cloud");
            GameObject sensor = WorldProperties.GetSelectedSensor();
            LampSensor_ROSSensorConnection lampSensor_ROS = sensor.GetComponent <LampSensor_ROSSensorConnection>();
            //lampSensor_ROS.Unsubscribe();
        }

        if (Level_0)
        {
            Debug.Log("Switching to Level 0");
            GameObject sensor = WorldProperties.GetSelectedSensor();
            LampSensor_ROSSensorConnection lampSensor_ROS = sensor.GetComponent <LampSensor_ROSSensorConnection>();
            //lampSensor_ROS.Unsubscribe();
        }

        if (Level_1)
        {
            Debug.Log("Switching to Level 1");
            GameObject sensor = WorldProperties.GetSelectedSensor();
            LampSensor_ROSSensorConnection lampSensor_ROS = sensor.GetComponent <LampSensor_ROSSensorConnection>();
            //lampSensor_ROS.Unsubscribe();
        }

        if (Level_2)
        {
            Debug.Log("Switching to Level 2");
            GameObject sensor = WorldProperties.GetSelectedSensor();
            LampSensor_ROSSensorConnection lampSensor_ROS = sensor.GetComponent <LampSensor_ROSSensorConnection>();
            //lampSensor_ROS.Unsubscribe();
        }


        if (Level_3)
        {
            Debug.Log("Switching to Level 3");
            GameObject sensor = WorldProperties.GetSelectedSensor();
            LampSensor_ROSSensorConnection lampSensor_ROS = sensor.GetComponent <LampSensor_ROSSensorConnection>();
            //lampSensor_ROS.Unsubscribe();
        }

        if (Level_4)
        {
            Debug.Log("Switching to Level 4");
            GameObject sensor = WorldProperties.GetSelectedSensor();
            LampSensor_ROSSensorConnection lampSensor_ROS = sensor.GetComponent <LampSensor_ROSSensorConnection>();
            //lampSensor_ROS.Unsubscribe();
        }

        if (Level_5)
        {
            Debug.Log("Switching to Level 5");
            GameObject sensor = WorldProperties.GetSelectedSensor();
            LampSensor_ROSSensorConnection lampSensor_ROS = sensor.GetComponent <LampSensor_ROSSensorConnection>();
        }
    }
Exemple #2
0
    /// <summary>
    /// Create a Sensor gameobject and attach & init required ROSSensorConnnection.
    /// </summary>
    /// <param name="rosSensorConnectionInput"></param>
    private ROSSensorConnectionInterface InstantiateSensor(ROSSensorConnectionInput rosSensorConnectionInput)
    {
        SensorType    sensorType        = rosSensorConnectionInput.sensorType;
        string        sensorIP          = rosSensorConnectionInput.url;
        int           sensorPort        = rosSensorConnectionInput.port;
        List <string> sensorSubscribers = new List <string>();
        ROSSensorConnectionInterface rosSensorConnection = null;

        foreach (SensorSubscribers subscriber in rosSensorConnectionInput.sensorSubscribers)
        {
            sensorSubscribers.Add(subscriber.ToString());
        }

        GameObject sensor = new GameObject(rosSensorConnectionInput.sensorName);

        sensor.transform.parent = this.transform;

        switch (sensorType)
        {
        case SensorType.PointCloud:
            Debug.Log("PointCloud Sensor created");
            PointCloudSensor_ROSSensorConnection pcSensor_rosSensorConnection = sensor.AddComponent <PointCloudSensor_ROSSensorConnection>();
            pcSensor_rosSensorConnection.InitilizeSensor(uniqueID, sensorIP, sensorPort, sensorSubscribers);
            ROSSensorConnections.Add(uniqueID, pcSensor_rosSensorConnection);
            rosSensorConnection = pcSensor_rosSensorConnection;
            break;

        case SensorType.Mesh:
            Debug.Log("Mesh Sensor created");
            MeshSensor_ROSSensorConnection meshSensor_rosSensorConnection = sensor.AddComponent <MeshSensor_ROSSensorConnection>();
            meshSensor_rosSensorConnection.InitilizeSensor(uniqueID, sensorIP, sensorPort, sensorSubscribers);
            ROSSensorConnections.Add(uniqueID, meshSensor_rosSensorConnection);
            rosSensorConnection = meshSensor_rosSensorConnection;
            break;

        case SensorType.LAMP:
            Debug.Log("LAMP Sensor created");
            LampSensor_ROSSensorConnection lamp_rosSensorConnection = sensor.AddComponent <LampSensor_ROSSensorConnection>();
            lamp_rosSensorConnection.InitilizeSensor(uniqueID, sensorIP, sensorPort, sensorSubscribers);
            ROSSensorConnections.Add(uniqueID, lamp_rosSensorConnection);
            rosSensorConnection = lamp_rosSensorConnection;
            break;

        case SensorType.PCFace:
            Debug.Log("PCFace Sensor created");
            PCFaceSensor_ROSSensorConnection pcFace_rosSensorConnection = sensor.AddComponent <PCFaceSensor_ROSSensorConnection>();
            pcFace_rosSensorConnection.InitilizeSensor(uniqueID, sensorIP, sensorPort, sensorSubscribers);
            ROSSensorConnections.Add(uniqueID, pcFace_rosSensorConnection);
            rosSensorConnection = pcFace_rosSensorConnection;
            break;

        case SensorType.Image:
            Debug.Log("Camera Stream created");
            CameraSensor_ROSSensorConnection camera_rosSensorConnection = sensor.AddComponent <CameraSensor_ROSSensorConnection>();
            VideoPlayers videoType = rosSensorConnectionInput.videoPlayers;
            switch (videoType)
            {
            case VideoPlayers.BackVideo:
                camera_rosSensorConnection.SetVideoType("BackVideo");
                break;

            case VideoPlayers.FrontVideo:
                camera_rosSensorConnection.SetVideoType("FrontVideo");
                break;

            case VideoPlayers.LeftVideo:
                camera_rosSensorConnection.SetVideoType("LeftVideo");
                break;

            case VideoPlayers.RightVideo:
                camera_rosSensorConnection.SetVideoType("RightVideo");
                break;

            default:
                Debug.Log("No Video Type Selected.");
                return(null);
            }
            camera_rosSensorConnection.InitilizeSensor(uniqueID, sensorIP, sensorPort, sensorSubscribers);
            ROSSensorConnections.Add(uniqueID, camera_rosSensorConnection);
            rosSensorConnection = camera_rosSensorConnection;
            break;

        default:
            Debug.Log("No sensor type selected");
            return(null);
        }


        // Add sensor to list of sensors in World Properties
        WorldProperties.AddSensor(uniqueID, sensor);

        uniqueID++;

        return(rosSensorConnection);
    }