Example #1
0
    public static void ChangeFocusUI(RosBridgeConnector connector, RosRobots robots)
    {
        for (int k = 0; k < robots.Robots.Count; k++)
        {
            var  robotConnector = robots.Robots[k];
            bool isFocus        = robotConnector == connector;
            robotConnector.UiObject.enabled = isFocus;
            var b = robotConnector.UiButton.GetComponent <Button>();
            var c = b.colors;
            c.normalColor = isFocus ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f);
            b.colors      = c;
            var robotSetup = robotConnector.Robot.GetComponent <RobotSetup>();
            robotSetup.FollowCamera.gameObject.SetActive(isFocus);
            robotSetup.FollowCamera.enabled = isFocus;
            var inputControllers = robotConnector.Robot.GetComponentsInChildren <IInputController>().ToList();
            if (isFocus)
            {
                FocusUI = robotSetup.UI;
                inputControllers.ForEach(i => i.Enable());

                // TODO move to gameobject based
                SimulatorManager.Instance?.SetCurrentActiveRobot(robotSetup.gameObject);
            }
            else
            {
                inputControllers.ForEach(i => i.Disable());
            }
        }

        VehicleList.Instances?.ForEach(x => x.ToggleDisplay(FocusUI.MainPanel.gameObject.activeSelf)); //hack
    }
 private void Awake()
 {
     if (Instances == null)
     {
         Instances = new List <UserInterfaceSetup>();
         FocusUI   = this;
     }
     Instances.Add(this);
 }
Example #3
0
 protected virtual void Awake()
 {
     if (Instances == null)
     {
         Instances = new List <UserInterfaceSetup>();
         FocusUI   = this;
     }
     Instances.Add(this);
 }
    void Start()
    {
        state = 1;
        MainPanel.gameObject.SetActive(true);
        cameraViewPanel.gameObject.SetActive(true);
        LGWatermark.gameObject.SetActive(false);
        fpsUI.gameObject.SetActive(true);
        DashUIManager.Instance?.ToggleUI(true);

        UI = GetComponent <UserInterfaceSetup>();
    }
Example #5
0
    void Start()
    {
        userInterface = Instantiate(uiPrefab);
        bridgeStatus  = userInterface.BridgeStatus;

        Connector = new RosBridgeConnector();
        Connector.BridgeStatus = bridgeStatus;

        robotSetup.Setup(userInterface, Connector, null);

        string overrideAddress = System.Environment.GetEnvironmentVariable("ROS_BRIDGE_HOST");

        if (overrideAddress != null)
        {
            Address = overrideAddress;
        }

        Ros.Bridge.canConnect = true;
    }
Example #6
0
    private void AddDevModeAgents()
    {
        activeAgents.Clear();
        string            overrideAddress = System.Environment.GetEnvironmentVariable("ROS_BRIDGE_HOST");
        List <AgentSetup> tempAgents      = FindObjectsOfType <AgentSetup>().ToList();

        foreach (var agent in tempAgents)
        {
            RosBridgeConnector connector = new RosBridgeConnector(overrideAddress == null ? agent.address : overrideAddress, agent.port, agent);
            UserInterfaceSetup uiSetup   = Instantiate(uiPrefab);
            uiSetup.agent          = agent.gameObject;
            connector.Agent        = agent.gameObject;
            connector.BridgeStatus = uiSetup.BridgeStatus;
            activeAgents.Add(connector);
            agent.Setup(uiSetup, connector, null);
        }
        RosBridgeConnector.canConnect = true;
        SetCurrentActiveAgent(0);
    }
Example #7
0
    public static void ChangeFocusUI(RosBridgeConnector connector, RosRobots robots)
    {
        for (int k = 0; k < robots.Robots.Count; k++)
        {
            var  robotConnector = robots.Robots[k];
            bool isFocus        = robotConnector == connector;
            robotConnector.UiObject.enabled = isFocus;
            var b = robotConnector.UiButton.GetComponent <Button>();
            var c = b.colors;
            c.normalColor = isFocus ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f);
            b.colors      = c;
            var robotSetup = robotConnector.Robot.GetComponent <RobotSetup>();
            robotSetup.FollowCamera.gameObject.SetActive(isFocus);
            robotSetup.FollowCamera.enabled = isFocus;

            if (isFocus)
            {
                FocusUI = robotSetup.UI;
            }
        }

        VehicleList.Instances.ForEach(x => x.ToggleDisplay(FocusUI.MainPanel.gameObject.activeSelf)); //hack
    }
Example #8
0
    void SceneLoadFinished(AsyncOperation op)
    {
        if (!Application.isEditor)
        {
            allLoadedBundles.ForEach(b => b.Unload(false));
            allLoadedBundles.Clear();
        }

        var robotListCanvas = Instantiate(UserInterfaceRobotList);
        var robotList       = robotListCanvas.transform.FindDeepChild("Content");

        float height = 0;

        if (Robots.Robots.Count > 1)
        {
            height = robotListCanvas.transform.FindDeepChild("RobotList").GetComponent <RectTransform>().rect.height;
        }
        else
        {
            robotListCanvas.enabled = false;
        }

        Vector3    defaultSpawnPosition = new Vector3(1.0f, 0.018f, 0.7f);
        Quaternion defaultSpawnRotation = Quaternion.identity;

        var spawnInfos    = FindObjectsOfType <SpawnInfo>();
        var spawnInfoList = spawnInfos.ToList();

        spawnInfoList.Reverse();

        //avoid first frame collision
        var sceneRobots = FindObjectsOfType <RobotSetup>();

        foreach (var robot in sceneRobots)
        {
            var cols = robot.GetComponentsInChildren <Collider>();
            foreach (var col in cols)
            {
                col.enabled = false;
            }
        }

        for (int i = 0; i < Robots.Robots.Count; i++)
        {
            var robotImage = Instantiate(DuckiebotRobot, robotList);
            robotImage.transform.FindDeepChild("Address").GetComponent <Text>().text = Robots.Robots[i].PrettyAddress;
            var ilocal = i;
            var button = robotImage.GetComponent <Button>();
            button.onClick.AddListener(() =>
            {
                UserInterfaceSetup.ChangeCameraFocus(Robots.Robots[ilocal], Robots);
            });

            var robotSetup = Robots.Robots[i].robotType;
            var spawnPos   = defaultSpawnPosition;
            var spawnRot   = defaultSpawnRotation;
            if (spawnInfoList.Count > 0)
            {
                spawnPos = spawnInfoList[spawnInfoList.Count - 1].transform.position;
                spawnRot = spawnInfoList[spawnInfoList.Count - 1].transform.rotation;
                spawnInfoList.RemoveAt(spawnInfoList.Count - 1);
            }
            var bot = Instantiate(robotSetup == null ? Robots.robotCandidates[0].gameObject : robotSetup.gameObject, spawnPos - new Vector3(0.25f * i, 0, 0), spawnRot);

            var bridgeConnector = Robots.Robots[i];

            var uiObject = Instantiate(UserInterface);
            uiObject.GetComponent <RfbClient>().Address = Robots.Robots[i].Address;
            var ui = uiObject.transform;
            uiObject.GetComponent <UserInterfaceSetup>().MainPanel.transform.Translate(new Vector3(0, -height, 0));
            bridgeConnector.UiObject     = uiObject;
            bridgeConnector.UiButton     = robotImage;
            bridgeConnector.BridgeStatus = uiObject.GetComponent <UserInterfaceSetup>().BridgeStatus;
            ui.GetComponent <HelpScreenUpdate>().Robots = Robots;

            bot.GetComponent <RobotSetup>().Setup(ui.GetComponent <UserInterfaceSetup>(), bridgeConnector);

            bot.GetComponent <RobotSetup>().FollowCamera.gameObject.SetActive(i == 0);
            uiObject.enabled = i == 0;
            var colors = button.colors;
            colors.normalColor = i == 0 ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f);
            button.colors      = colors;

            var name = new GameObject($"robot_{i}_name");
            name.transform.parent                     = robotListCanvas.transform.FindDeepChild("Panel").transform;
            bridgeConnector.UiName                    = name.AddComponent <Text>();
            bridgeConnector.UiName.font               = Resources.GetBuiltinResource <Font>("Arial.ttf");
            bridgeConnector.UiName.text               = Robots.Robots[i].PrettyAddress;
            bridgeConnector.UiName.fontSize           = 16;
            bridgeConnector.UiName.fontStyle          = FontStyle.Bold;
            bridgeConnector.UiName.horizontalOverflow = HorizontalWrapMode.Overflow;
            bridgeConnector.UiName.verticalOverflow   = VerticalWrapMode.Overflow;

            bridgeConnector.Robot = bot;
        }

        //destroy spawn information after use
        foreach (var spawnInfo in spawnInfos)
        {
            Destroy(spawnInfo.gameObject);
        }

        //Configure shadow settings due to huge difference between different cars
        bool useRealSizeSetting = false;

        for (int i = 0; i < Robots.Robots.Count; i++)
        {
            var robotSetup = Robots.Robots[i].robotType;

            if (robotSetup.GetComponentInChildren <SimpleCarController>() == null)
            {
                useRealSizeSetting = true;
                break;
            }
        }
        if (useRealSizeSetting)
        {
            RealSizeGlobalShadowSettings();
        }
    }
Example #9
0
    public virtual void Setup(UserInterfaceSetup ui, RosBridgeConnector connector, VehicleConfig config)
    {
        Connector = connector;
        UI        = ui;
        var bridge = connector.Bridge;

        ui.PositionReset.RobotController = CarController;

        ui.SensorEffectsToggle.onValueChanged.AddListener(enabled => ToggleSensorEffect(enabled));

        // ui.WheelScale.onValueChanged.AddListener(value =>
        // {
        //     try
        //     {
        //         CarController.SetWheelScale(float.Parse(value));
        //     }
        //     catch (System.Exception)
        //     {
        //         Debug.Log("ROS Wheel Force Scaler: Please input valid number!");
        //     }
        // });

        // Cameras.ForEach(c =>
        // {
        //     var pp = c.GetComponent<PostProcessingListener>();
        //     if (pp != null)
        //     {
        //         ui.CameraSaturation.onValueChanged.AddListener(x =>
        //         {
        //             pp.SetSaturationValue(x);
        //         });
        //     }
        // });

        ui.HighQualityRendering.onValueChanged.AddListener(enabled =>
        {
            FollowCamera.GetComponent <PostProcessingBehaviour>().enabled = enabled;
            CameraMan?.SetHighQualityRendering(enabled);
        });

        ui.TrafficToggle.onValueChanged.AddListener(enabled =>
        {
            if (enabled)
            {
                FindObjectOfType <TrafSpawner>()?.ReSpawnTrafficCars();
            }
            else
            {
                FindObjectOfType <TrafSpawner>()?.KillTrafficCars();
            }

            //hack to sync toggle value among cars UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.TrafficToggle.onValueChanged;
                    otherUI.TrafficToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.TrafficToggle.isOn           = enabled;
                    otherUI.TrafficToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.PedestriansToggle.onValueChanged.AddListener(enabled =>
        {
            if (enabled)
            {
                FindObjectOfType <PedestrianManager>()?.SpawnNPCPedestrians();
            }
            else
            {
                FindObjectOfType <PedestrianManager>()?.KillNPCPedestrians();
            }

            //hack to sync toggle value among car UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.PedestriansToggle.onValueChanged;
                    otherUI.PedestriansToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.PedestriansToggle.isOn           = enabled;
                    otherUI.PedestriansToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.SteerwheelFeedback.onValueChanged.AddListener(enabled =>
        {
            var steerwheels = FindObjectsOfType <SteeringWheelInputController>();
            foreach (var steerwheel in steerwheels)
            {
                steerwheel.useFeedback = enabled;
            }
        });

        foreach (var item in NeedsBridge)
        {
            if (item == null)
            {
                continue;
            }
            var a = item as Ros.IRosClient;
            a.OnRosBridgeAvailable(bridge);
        }

        ui.AddTweakables(Tweakables);

        if (config != null)
        {
            ui.ToggleTweakable(Tweakables, "Lidar", config.enable_lidar);
            ui.ToggleTweakable(Tweakables, "GPS", config.enable_gps);
            ui.ToggleTweakable(Tweakables, "IMU", config.enable_imu);
            ui.ToggleTweakable(Tweakables, "Main Camera", config.enable_main_camera);
            ui.ToggleTweakable(Tweakables, "Telephoto Camera", config.enable_telephoto_camera);

            ui.HighQualityRendering.isOn = config.enable_high_quality_rendering;
            ui.SensorEffectsToggle.isOn  = config.enable_sensor_effects;
        }
    }
Example #10
0
    public void SpawnVehicle(Vector3 position, Quaternion rotation, RosBridgeConnector connector, VehicleConfig staticConfig, float height = 0.0f)
    {
        var agentImage = Instantiate(AgentUI, AgentList);

        agentImage.transform.FindDeepChild("Address").GetComponent <Text>().text = connector.PrettyAddress;
        var button = agentImage.GetComponent <Button>();

        button.onClick.AddListener(() =>
        {
            UserInterfaceSetup.ChangeFocusUI(connector);
            SteeringWheelInputController.ChangeFocusSteerWheel(connector.Agent.GetComponentInChildren <SteeringWheelInputController>());
        });

        var agentSetup = connector.agentType;

        GameObject bot = Instantiate(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject : agentSetup.gameObject, position, rotation); // TODO better system

        AnalyticsManager.Instance?.EgoStartEvent(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject.name : agentSetup.gameObject.name);

        var uiObject = Instantiate(UserInterfaceAgent);

        uiObject.GetComponent <RfbClient>().Address = connector.Address;
        var ui = uiObject.transform;

        ui.GetComponent <UserInterfaceSetup>().agent = bot;

        if (bot.name.Contains("duckiebot"))
        {
            HelpScreenUpdate helpScreen = uiObject.GetComponent <HelpScreenUpdate>();
            helpScreen.Help       = helpScreen.DuckieHelp;
            helpScreen.agentsText = helpScreen.duckieText;
        }

        // offset for multiple vehicle UI
        RectTransform rect = uiObject.GetComponent <UserInterfaceSetup>().MainPanel;

        if (rect != null)
        {
            rect.offsetMax = new Vector2(0, rect.offsetMax.y - height);
        }
        connector.UiObject     = uiObject;
        connector.UiButton     = agentImage;
        connector.BridgeStatus = uiObject.GetComponent <UserInterfaceSetup>().BridgeStatus;

        bot.GetComponent <AgentSetup>().Setup(ui.GetComponent <UserInterfaceSetup>(), connector, staticConfig);

        bot.GetComponent <AgentSetup>().FollowCamera.gameObject.SetActive(false);
        button.image.sprite = bot.GetComponent <AgentSetup>().agentUISprite;

        //uiObject.enabled = i == 0;
        var colors = button.colors;

        //colors.normalColor = i == 0 ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f);
        button.colors = colors;

        var name = new GameObject();

        name.transform.parent               = AgentListCanvas.transform.FindDeepChild("Panel").transform;
        connector.UiName                    = name.AddComponent <Text>();
        connector.UiName.font               = Resources.GetBuiltinResource <Font>("Arial.ttf");
        connector.UiName.text               = connector.PrettyAddress;
        connector.UiName.fontSize           = 16;
        connector.UiName.fontStyle          = FontStyle.Bold;
        connector.UiName.horizontalOverflow = HorizontalWrapMode.Overflow;
        connector.UiName.verticalOverflow   = VerticalWrapMode.Overflow;

        connector.Agent = bot;
    }
Example #11
0
    private void InitScene()
    {
        if (ROSAgentManager.Instance.currentMode == StartModeTypes.Dev)
        {
            return;
        }

        AgentListCanvas = Instantiate(UserInterfaceAgentList);
        AgentList       = AgentListCanvas.transform.FindDeepChild("Content"); // TODO needs to change !!! asap

        float height = 0;

        if (ROSAgentManager.Instance.activeAgents.Count > 1)
        {
            height = AgentListCanvas.transform.FindDeepChild("AgentList").GetComponent <RectTransform>().rect.height; // TODO needs to change !!! asap
        }
        else
        {
            AgentListCanvas.enabled = false;
        }

        // TODO: update spawn position from static config
        Vector3    defaultSpawnPosition = new Vector3(1.0f, 0.018f, 0.7f);
        Quaternion defaultSpawnRotation = Quaternion.identity;

        var spawnInfos    = FindObjectsOfType <SpawnInfo>();
        var spawnInfoList = spawnInfos.ToList();

        spawnInfoList.Reverse();

        RosBridgeConnector first = null;

        for (int i = 0; i < ROSAgentManager.Instance.activeAgents.Count; i++)
        {
            var connector = ROSAgentManager.Instance.activeAgents[i];

            var agentSetup = connector.agentType;
            var spawnPos   = defaultSpawnPosition;
            var spawnRot   = defaultSpawnRotation;
            if (spawnInfoList.Count > 0)
            {
                spawnPos = spawnInfoList[spawnInfoList.Count - 1].transform.position;
                spawnRot = spawnInfoList[spawnInfoList.Count - 1].transform.rotation;
                spawnInfoList.RemoveAt(spawnInfoList.Count - 1);
            }
            spawnPos -= new Vector3(0.25f * i, 0, 0);

            if (FindObjectOfType <StaticConfigManager>() != null &&
                StaticConfigManager.Instance.staticConfig.initialized &&
                ROSAgentManager.Instance.currentMode == StartModeTypes.StaticConfig)
            {
                var staticConfig = StaticConfigManager.Instance.staticConfig.vehicles[i];

                var gps = agentSetup.gameObject.transform.GetComponentInChildren <GpsDevice>();

                var pos = staticConfig.position;
                if (pos.e != 0.0f || pos.n != 0.0f)
                {
                    spawnPos   = gps.GetPosition(pos.e, pos.n);
                    spawnPos.y = pos.h;
                    var rot = staticConfig.orientation;
                    spawnRot = Quaternion.Euler(rot.r, rot.y, rot.p);
                }
                SpawnVehicle(spawnPos, spawnRot, connector, staticConfig, height);
            }
            else
            {
                SpawnVehicle(spawnPos, spawnRot, connector, null, height);
            }

            if (first == null)
            {
                first = connector;
            }
        }

        if (first != null)
        {
            first.Agent.GetComponent <AgentSetup>().FollowCamera.gameObject.SetActive(true);
            UserInterfaceSetup.ChangeFocusUI(first);
            SteeringWheelInputController.ChangeFocusSteerWheel(first.Agent.GetComponentInChildren <SteeringWheelInputController>());
            ROSAgentManager.Instance?.SetCurrentActiveAgent(first);
        }

        InitGlobalShadowSettings(); // TODO better way for small maps
    }
Example #12
0
 void Start()
 {
     UI = GetComponent <UserInterfaceSetup>();
 }
Example #13
0
    public virtual void Setup(UserInterfaceSetup ui, RosBridgeConnector connector, VehicleConfig config)
    {
        // needed for npc
        foreach (Transform child in transform)
        {
            if (child.CompareTag("MainCamera"))
            {
                mainCamera = child.GetComponent <Camera>();
            }
        }

        Connector = connector;
        UI        = ui;
        var bridge = connector.Bridge;

        ui.agentController = agentController;

        ui.SensorEffectsToggle.onValueChanged.AddListener(enabled => ToggleSensorEffect(enabled));

        // ui.WheelScale.onValueChanged.AddListener(value =>
        // {
        //     try
        //     {
        //         CarController.SetWheelScale(float.Parse(value));
        //     }
        //     catch (System.Exception)
        //     {
        //         Debug.Log("ROS Wheel Force Scaler: Please input valid number!");
        //     }
        // });

        // Cameras.ForEach(c =>
        // {
        //     var pp = c.GetComponent<PostProcessingListener>();
        //     if (pp != null)
        //     {
        //         ui.CameraSaturation.onValueChanged.AddListener(x =>
        //         {
        //             pp.SetSaturationValue(x);
        //         });
        //     }
        // });

        ui.LowQualityRendering.onValueChanged.AddListener(useLowQuality =>
        {
            FollowCamera.GetComponent <PostProcessingBehaviour>().enabled = !useLowQuality;
            CameraMan?.SetHighQualityRendering(!useLowQuality);
        });
        ui.LowQualityRendering.onValueChanged.Invoke(ui.LowQualityRendering.isOn);

        ui.TrafficToggle.onValueChanged.AddListener(enabled =>
        {
            FindObjectOfType <NPCManager>()?.ToggleNPCS(enabled);

            //hack to sync toggle value among cars UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.TrafficToggle.onValueChanged;
                    otherUI.TrafficToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.TrafficToggle.isOn           = enabled;
                    otherUI.TrafficToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.TrafficPhysicsModeToggle.onValueChanged.AddListener(enabled =>
        {
            FindObjectOfType <NPCManager>()?.ToggleNPCPhysicsMode(enabled);
            //hack to sync toggle value among cars UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.TrafficPhysicsModeToggle.onValueChanged;
                    otherUI.TrafficPhysicsModeToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.TrafficPhysicsModeToggle.isOn           = enabled;
                    otherUI.TrafficPhysicsModeToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.PedestriansToggle.onValueChanged.AddListener(enabled =>
        {
            if (enabled)
            {
                FindObjectOfType <PedestrianManager>()?.SpawnPedestrians();
            }
            else
            {
                FindObjectOfType <PedestrianManager>()?.KillPedestrians();
            }

            //hack to sync toggle value among car UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.PedestriansToggle.onValueChanged;
                    otherUI.PedestriansToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.PedestriansToggle.isOn           = enabled;
                    otherUI.PedestriansToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.SteerwheelFeedback.onValueChanged.AddListener(enabled =>
        {
            var steerwheels = FindObjectsOfType <SteeringWheelInputController>();
            foreach (var steerwheel in steerwheels)
            {
                steerwheel.useFeedback = enabled;
            }
        });

        foreach (var item in NeedsBridge)
        {
            if (item == null)
            {
                continue;
            }
            var a = item as Comm.BridgeClient;
            a.OnBridgeAvailable(bridge);
        }

        ui.AddTweakables(Tweakables);

        if (config != null)
        {
            ui.ToggleTweakable(Tweakables, "Lidar", config.enable_lidar);
            ui.ToggleTweakable(Tweakables, "GPS", config.enable_gps);
            ui.ToggleTweakable(Tweakables, "IMU", config.enable_imu);
            ui.ToggleTweakable(Tweakables, "Main Camera", config.enable_main_camera);
            ui.ToggleTweakable(Tweakables, "Telephoto Camera", config.enable_telephoto_camera);

            ui.LowQualityRendering.isOn = !config.enable_high_quality_rendering;
            ui.SensorEffectsToggle.isOn = config.enable_sensor_effects;
        }

        if (config != null)
        {
            if (StaticConfigManager.Instance.staticConfig.initialized && ROSAgentManager.Instance.currentMode == StartModeTypes.StaticConfig)
            {
                ui.CheckStaticConfigTraffic();
            }
        }

        // CES
        CarInputController cc = GetComponent <CarInputController>();

        if (cc != null)
        {
            cc[InputEvent.TOGGLE_SENSOR_EFFECTS].Press += ToggleSensorEffect;
            cc[InputEvent.TOGGLE_TRAFFIC].Press        += ToggleTraffic;
            cc[InputEvent.TOGGLE_UI].Press             += ToggleUI;
        }
    }
Example #14
0
    public void Setup(UserInterfaceSetup ui, RosBridgeConnector connector)
    {
        var bridge = connector.Bridge;

        ui.WheelScale.onValueChanged.AddListener(value =>
        {
            try
            {
                CarController.SetWheelScale(float.Parse(value));
            }
            catch (System.Exception)
            {
                Debug.Log("ROS Wheel Force Scaler: Please input valid number!");
            }
        });

        if (SideCameras)
        {
            ui.SideCameras.onValueChanged.AddListener(SideCameras.SideCamToggleValueChanged);
        }

        if (LidarSensor != null)
        {
            ui.Lidar.onValueChanged.AddListener(LidarSensor.Enable);
        }

        ui.Gps.onValueChanged.AddListener(enabled => GpsDevice.PublishMessage = enabled);
        ui.CameraPreview.renderCamera    = Cameras[0].GetComponent <Camera>();
        ui.PositionReset.RobotController = CarController;
        ui.MainCameraToggle.Camera       = Cameras[0].GetComponent <Camera>();

        Cameras.ForEach(c =>
        {
            var pp = c.GetComponent <PostProcessingListener>();
            if (pp != null)
            {
                ui.CameraSaturation.onValueChanged.AddListener(x =>
                {
                    pp.SetSaturationValue(x);
                });
            }

            ui.CameraFramerate.onValueChanged.AddListener(value =>
            {
                try
                {
                    c.GetComponent <VideoToROS>().ValueChangeCallback(int.Parse(value));
                }
                catch (System.Exception)
                {
                    Debug.Log("Duckiebot Cam FPS: Please input valid number!");
                }
            });

            var ppb = c.GetComponent <PostProcessingBehaviour>();
            if (ppb != null)
            {
                ui.HighQualityRendering.onValueChanged.AddListener(enabled => ppb.enabled = enabled);
            }
        });
        ui.HighQualityRendering.onValueChanged.AddListener(enabled => FollowCamera.GetComponent <PostProcessingBehaviour>().enabled = enabled);

        foreach (var item in NeedsBridge)
        {
            var a = item as Ros.IRosClient;
            if (a == null)
            {
                Debug.Log(1111);
            }
            a.OnRosBridgeAvailable(bridge);
        }
        //NeedsBridge.ForEach(b =>
        //{
        //    (b as Ros.IRosClient).OnRosBridgeAvailable(bridge);
        //});
    }
Example #15
0
    void SceneLoadFinished(AsyncOperation op)
    {
        if (!Application.isEditor)
        {
            allLoadedBundles.ForEach(b => b.Unload(false));
            allLoadedBundles.Clear();
        }

        var robotListCanvas = Instantiate(UserInterfaceRobotList);
        var robotList       = robotListCanvas.transform.FindDeepChild("Content");

        float height = 0;

        if (Robots.Robots.Count > 1)
        {
            height = robotListCanvas.transform.FindDeepChild("RobotList").GetComponent <RectTransform>().rect.height;
        }
        else
        {
            robotListCanvas.enabled = false;
        }

        // TODO: update spawn position from static config
        Vector3    defaultSpawnPosition = new Vector3(1.0f, 0.018f, 0.7f);
        Quaternion defaultSpawnRotation = Quaternion.identity;

        var spawnInfos    = FindObjectsOfType <SpawnInfo>();
        var spawnInfoList = spawnInfos.ToList();

        spawnInfoList.Reverse();

        //avoid first frame collision
        //var sceneRobots = FindObjectsOfType<RobotSetup>();
        //foreach (var robot in sceneRobots)
        //{
        //    var cols = robot.GetComponentsInChildren<Collider>();
        //    foreach (var col in cols)
        //    {
        //        col.enabled = false;
        //    }
        //}

        for (int i = 0; i < Robots.Robots.Count; i++)
        {
            var robotImage = Instantiate(DuckiebotRobot, robotList);
            robotImage.transform.FindDeepChild("Address").GetComponent <Text>().text = Robots.Robots[i].PrettyAddress;
            var ilocal = i;
            var button = robotImage.GetComponent <Button>();
            button.onClick.AddListener(() =>
            {
                UserInterfaceSetup.ChangeFocusUI(Robots.Robots[ilocal], Robots);
                SteeringWheelInputController.ChangeFocusSteerWheel(Robots.Robots[ilocal].Robot.GetComponentInChildren <SteeringWheelInputController>());
            });

            var robotSetup = Robots.Robots[i].robotType;
            var spawnPos   = defaultSpawnPosition;
            var spawnRot   = defaultSpawnRotation;
            if (spawnInfoList.Count > 0)
            {
                spawnPos = spawnInfoList[spawnInfoList.Count - 1].transform.position;
                spawnRot = spawnInfoList[spawnInfoList.Count - 1].transform.rotation;
                spawnInfoList.RemoveAt(spawnInfoList.Count - 1);
            }

            GameObject bot = new GameObject();

            if (staticConfig.initialized)
            {
                var gps = robotSetup.gameObject.transform.GetComponentInChildren <GpsDevice>();

                var pos = staticConfig.vehicles[i].position;
                if (pos.e != 0.0 || pos.n != 0.0)
                {
                    spawnPos   = gps.GetPosition(pos.e, pos.n);
                    spawnPos.y = pos.h;
                    var rot = staticConfig.vehicles[i].orientation;
                    spawnRot = Quaternion.Euler(rot.r, rot.y, rot.p);
                }
                bot = Instantiate(robotSetup == null ? Robots.robotCandidates[0].gameObject : robotSetup.gameObject, spawnPos, spawnRot);
            }
            else
            {
                bot = Instantiate(robotSetup == null ? Robots.robotCandidates[0].gameObject : robotSetup.gameObject, spawnPos - new Vector3(0.25f * i, 0, 0), spawnRot); // TODO better system
            }

            AnalyticsManager.Instance?.EgoStartEvent(robotSetup == null ? Robots.robotCandidates[0].gameObject.name : robotSetup.gameObject.name);

            var bridgeConnector = Robots.Robots[i];

            var uiObject = Instantiate(UserInterface);
            uiObject.GetComponent <RfbClient>().Address = Robots.Robots[i].Address;
            var ui = uiObject.transform;

            if (bot.name.Contains("duckiebot"))
            {
                HelpScreenUpdate helpScreen = uiObject.GetComponent <HelpScreenUpdate>();
                helpScreen.Help       = helpScreen.DuckieHelp;
                helpScreen.RobotsText = helpScreen.DuckieRobotsText;
            }

            // offset for multiple vehicle UI
            RectTransform rect = uiObject.GetComponent <UserInterfaceSetup>().MainPanel;
            if (rect != null)
            {
                rect.offsetMax = new Vector2(0, rect.offsetMax.y - height);
            }
            bridgeConnector.UiObject     = uiObject;
            bridgeConnector.UiButton     = robotImage;
            bridgeConnector.BridgeStatus = uiObject.GetComponent <UserInterfaceSetup>().BridgeStatus;
            ui.GetComponent <HelpScreenUpdate>().Robots = Robots;

            bot.GetComponent <RobotSetup>().Setup(ui.GetComponent <UserInterfaceSetup>(), bridgeConnector, staticConfig.initialized ? staticConfig.vehicles[i] : null);

            bot.GetComponent <RobotSetup>().FollowCamera.gameObject.SetActive(i == 0);
            button.image.sprite = bot.GetComponent <RobotSetup>().robotUISprite;

            uiObject.enabled = i == 0;
            var colors = button.colors;
            colors.normalColor = i == 0 ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f);
            button.colors      = colors;

            var name = new GameObject($"robot_{i}_name");
            name.transform.parent                     = robotListCanvas.transform.FindDeepChild("Panel").transform;
            bridgeConnector.UiName                    = name.AddComponent <Text>();
            bridgeConnector.UiName.font               = Resources.GetBuiltinResource <Font>("Arial.ttf");
            bridgeConnector.UiName.text               = Robots.Robots[i].PrettyAddress;
            bridgeConnector.UiName.fontSize           = 16;
            bridgeConnector.UiName.fontStyle          = FontStyle.Bold;
            bridgeConnector.UiName.horizontalOverflow = HorizontalWrapMode.Overflow;
            bridgeConnector.UiName.verticalOverflow   = VerticalWrapMode.Overflow;

            bridgeConnector.Robot = bot;

            SimulatorManager.Instance?.AddActiveRobot(bot);
        }

        // hack for dev
        SimulatorManager.Instance.SpawnDashUI();

        UserInterfaceSetup.ChangeFocusUI(Robots.Robots[0], Robots);
        SteeringWheelInputController.ChangeFocusSteerWheel(Robots.Robots[0].Robot.GetComponentInChildren <SteeringWheelInputController>());
        SimulatorManager.Instance.SetCurrentActiveRobot(Robots.Robots[0].Robot);

        //destroy spawn information after use
        foreach (var spawnInfo in spawnInfos)
        {
            Destroy(spawnInfo.gameObject);
        }

        //Configure shadow settings due to huge difference between different cars
        bool useRealSizeSetting = false;

        for (int i = 0; i < Robots.Robots.Count; i++)
        {
            var robotSetup = Robots.Robots[i].robotType;

            if (robotSetup.GetComponentInChildren <SimpleCarController>() == null)
            {
                useRealSizeSetting = true;
                break;
            }
        }
        if (useRealSizeSetting)
        {
            RealSizeGlobalShadowSettings();
        }

        UserInterfaceSetup.FocusUI.Invoke("CheckStaticConfigTraffic", 0.5f);
    }
Example #16
0
    public virtual void Setup(UserInterfaceSetup ui, RosBridgeConnector connector)
    {
        Connector = connector;
        UI        = ui;
        var bridge = connector.Bridge;

        ui.WheelScale.onValueChanged.AddListener(value =>
        {
            try
            {
                CarController.SetWheelScale(float.Parse(value));
            }
            catch (System.Exception)
            {
                Debug.Log("ROS Wheel Force Scaler: Please input valid number!");
            }
        });

        if (FollowCamera != null)
        {
            ui.SensorEffectsToggle.onValueChanged.AddListener(on =>
            {
                if (on)
                {
                    FollowCamera.cullingMask = MainCam.cullingMask | 1 << LayerMask.NameToLayer("Sensor Effects");
                }
                else
                {
                    FollowCamera.cullingMask = MainCam.cullingMask & ~(1 << LayerMask.NameToLayer("Sensor Effects"));
                }
            });
        }

        if (MainCam != null)
        {
            ui.CameraPreview.renderCamera = ui.CameraPreview.renderCamera == null ? MainCam : ui.CameraPreview.renderCamera;
            MainCam.GetComponent <VideoToROS>().Init();
            ui.MainCameraToggle.onValueChanged.AddListener(enabled =>
            {
                MainCam.enabled = enabled;
                MainCam.GetComponent <VideoToROS>().enabled = enabled;
                ui.CameraPreview.gameObject.SetActive(enabled);
            });
        }

        SideCams.ForEach(cam =>
        {
            cam.GetComponent <VideoToROS>().Init();
            ui.SideCameraToggle.onValueChanged.AddListener(enabled =>
            {
                cam.enabled = enabled;
                cam.GetComponent <VideoToROS>().enabled = enabled;
            });
        });

        if (TelephotoCam != null)
        {
            TelephotoCam.GetComponent <VideoToROS>().Init();
            ui.TelephotoCamera.onValueChanged.AddListener(enabled =>
            {
                TelephotoCam.enabled = enabled;
                TelephotoCam.GetComponent <VideoToROS>().enabled = enabled;
            });
        }

        if (ColorSegmentCam != null)
        {
            var segmentColorer = FindObjectOfType <SegmentColorer>();
            if (segmentColorer != null)
            {
                segmentColorer.ApplyToCamera(ColorSegmentCam);

                ColorSegmentCam.GetComponent <VideoToROS>().Init();
                ui.ColorSegmentPreview.renderCamera = ColorSegmentCam;
                ui.ColorSegmentCamera.onValueChanged.AddListener(enabled =>
                {
                    ColorSegmentCam.enabled = enabled;
                    ColorSegmentCam.GetComponent <VideoToROS>().enabled = enabled;
                    ui.ColorSegmentPreview.gameObject.SetActive(enabled);
                });
            }
        }

        if (DepthCameraEnabler != null)
        {
            DepthCameraEnabler.TextureDisplay = ui.ColorSegmentPreview;
        }

        if (imuSensor != null)
        {
            ui.Imu.onValueChanged.AddListener(imuSensor.Enable);
        }

        if (LidarSensor != null)
        {
            ui.Lidar.onValueChanged.AddListener(LidarSensor.Enable);
        }

        if (RidarSensor != null)
        {
            ui.Radar.onValueChanged.AddListener(RidarSensor.Enable);
        }

        ui.Gps.onValueChanged.AddListener(enabled => GpsDevice.PublishMessage = enabled);
        ui.PositionReset.RobotController = CarController;

        var Cameras = new List <Camera>();

        if (MainCam != null)
        {
            Cameras.Add(MainCam);
        }
        if (TelephotoCam != null)
        {
            Cameras.Add(TelephotoCam);
        }
        if (SideCams != null)
        {
            Cameras.AddRange(SideCams);
        }

        ui.HDToggle.onValueChanged.AddListener(enabled =>
        {
            ui.CameraPreview.renderTexture = null;
            if (enabled)
            {
                Cameras.ForEach(cam =>
                {
                    if (cam != null)
                    {
                        var vs = cam.GetComponent <VideoToROS>();
                        vs.SwitchResolution(1920, 1080); //HD
                        ui.CameraPreview.SwitchResolution(vs.videoResolution.Item1, vs.videoResolution.Item2);
                    }
                });
            }
            else
            {
                Cameras.ForEach(cam =>
                {
                    if (cam != null)
                    {
                        var vs = cam.GetComponent <VideoToROS>();
                        vs.SwitchResolution();
                        ui.CameraPreview.SwitchResolution(vs.videoResolution.Item1, vs.videoResolution.Item2);
                    }
                });
            }
        });

        Cameras.ForEach(c =>
        {
            var pp = c.GetComponent <PostProcessingListener>();
            if (pp != null)
            {
                ui.CameraSaturation.onValueChanged.AddListener(x =>
                {
                    pp.SetSaturationValue(x);
                });
            }

            ui.CameraFramerate.onValueChanged.AddListener(value =>
            {
                try
                {
                    c.GetComponent <VideoToROS>().FPSChangeCallback(int.Parse(value));
                }
                catch (System.Exception)
                {
                    Debug.Log("Duckiebot Cam FPS: Please input valid number!");
                }
            });

            var ppb = c.GetComponent <PostProcessingBehaviour>();
            if (ppb != null)
            {
                ui.HighQualityRendering.onValueChanged.AddListener(enabled => ppb.enabled = enabled);
            }
        });

        ui.HighQualityRendering.onValueChanged.AddListener(enabled => FollowCamera.GetComponent <PostProcessingBehaviour>().enabled = enabled);

        ui.TrafficToggle.onValueChanged.AddListener(enabled =>
        {
            if (enabled)
            {
                FindObjectOfType <TrafSpawner>()?.ReSpawnTrafficCars();
            }
            else
            {
                FindObjectOfType <TrafSpawner>()?.KillTrafficCars();
            }
        });

        ui.SteerwheelFeedback.onValueChanged.AddListener(enabled =>
        {
            var steerwheels = FindObjectsOfType <SteeringWheelInputController>();
            foreach (var steerwheel in steerwheels)
            {
                steerwheel.useFeedback = enabled;
            }
        });

        foreach (var item in NeedsBridge)
        {
            if (item == null)
            {
                continue;
            }
            var a = item as Ros.IRosClient;
            a.OnRosBridgeAvailable(bridge);
        }
    }
Example #17
0
    private void InitScene()
    {
        if (ROSAgentManager.Instance.currentMode == StartModeTypes.Dev)
        {
            return;
        }

        var agentListCanvas = Instantiate(UserInterfaceAgentList);
        var agentList       = agentListCanvas.transform.FindDeepChild("Content"); // TODO needs to change !!! asap

        float height = 0;

        if (ROSAgentManager.Instance.activeAgents.Count > 1)
        {
            height = agentListCanvas.transform.FindDeepChild("AgentList").GetComponent <RectTransform>().rect.height; // TODO needs to change !!! asap
        }
        else
        {
            agentListCanvas.enabled = false;
        }

        // TODO: update spawn position from static config
        Vector3    defaultSpawnPosition = new Vector3(1.0f, 0.018f, 0.7f);
        Quaternion defaultSpawnRotation = Quaternion.identity;

        var spawnInfos    = FindObjectsOfType <SpawnInfo>();
        var spawnInfoList = spawnInfos.ToList();

        spawnInfoList.Reverse();

        for (int i = 0; i < ROSAgentManager.Instance.activeAgents.Count; i++)
        {
            var agentImage = Instantiate(AgentUI, agentList);
            agentImage.transform.FindDeepChild("Address").GetComponent <Text>().text = ROSAgentManager.Instance.activeAgents[i].PrettyAddress;
            var ilocal = i;
            var button = agentImage.GetComponent <Button>();
            button.onClick.AddListener(() =>
            {
                UserInterfaceSetup.ChangeFocusUI(ROSAgentManager.Instance.activeAgents[ilocal]);
                SteeringWheelInputController.ChangeFocusSteerWheel(ROSAgentManager.Instance.activeAgents[ilocal].Agent.GetComponentInChildren <SteeringWheelInputController>());
            });

            var agentSetup = ROSAgentManager.Instance.activeAgents[i].agentType;
            var spawnPos   = defaultSpawnPosition;
            var spawnRot   = defaultSpawnRotation;
            if (spawnInfoList.Count > 0)
            {
                spawnPos = spawnInfoList[spawnInfoList.Count - 1].transform.position;
                spawnRot = spawnInfoList[spawnInfoList.Count - 1].transform.rotation;
                spawnInfoList.RemoveAt(spawnInfoList.Count - 1);
            }

            GameObject bot = new GameObject();

            if (FindObjectOfType <StaticConfigManager>() != null)
            {
                if (StaticConfigManager.Instance.staticConfig.initialized && ROSAgentManager.Instance.currentMode == StartModeTypes.StaticConfig)
                {
                    var gps = agentSetup.gameObject.transform.GetComponentInChildren <GpsDevice>();

                    var pos = StaticConfigManager.Instance.staticConfig.vehicles[i].position;
                    if (pos.e != 0.0 || pos.n != 0.0)
                    {
                        spawnPos   = gps.GetPosition(pos.e, pos.n);
                        spawnPos.y = pos.h;
                        var rot = StaticConfigManager.Instance.staticConfig.vehicles[i].orientation;
                        spawnRot = Quaternion.Euler(rot.r, rot.y, rot.p);
                    }
                    bot = Instantiate(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject : agentSetup.gameObject, spawnPos, spawnRot);
                }
            }
            else
            {
                bot = Instantiate(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject : agentSetup.gameObject, spawnPos - new Vector3(0.25f * i, 0, 0), spawnRot); // TODO better system
            }

            AnalyticsManager.Instance?.EgoStartEvent(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject.name : agentSetup.gameObject.name);

            var bridgeConnector = ROSAgentManager.Instance.activeAgents[i];

            var uiObject = Instantiate(UserInterfaceAgent);
            uiObject.GetComponent <RfbClient>().Address = ROSAgentManager.Instance.activeAgents[i].Address;
            var ui = uiObject.transform;
            ui.GetComponent <UserInterfaceSetup>().agent = bot;

            if (bot.name.Contains("duckiebot"))
            {
                HelpScreenUpdate helpScreen = uiObject.GetComponent <HelpScreenUpdate>();
                helpScreen.Help       = helpScreen.DuckieHelp;
                helpScreen.agentsText = helpScreen.duckieText;
            }

            // offset for multiple vehicle UI
            RectTransform rect = uiObject.GetComponent <UserInterfaceSetup>().MainPanel;
            if (rect != null)
            {
                rect.offsetMax = new Vector2(0, rect.offsetMax.y - height);
            }
            bridgeConnector.UiObject     = uiObject;
            bridgeConnector.UiButton     = agentImage;
            bridgeConnector.BridgeStatus = uiObject.GetComponent <UserInterfaceSetup>().BridgeStatus;

            var isVehicleConfig = false;
            if (FindObjectOfType <StaticConfigManager>() != null)
            {
                isVehicleConfig = StaticConfigManager.Instance.staticConfig.initialized && ROSAgentManager.Instance.currentMode == StartModeTypes.StaticConfig;
            }

            bot.GetComponent <AgentSetup>().Setup(ui.GetComponent <UserInterfaceSetup>(), bridgeConnector, isVehicleConfig ? StaticConfigManager.Instance.staticConfig.vehicles[i] : null);

            bot.GetComponent <AgentSetup>().FollowCamera.gameObject.SetActive(i == 0);
            button.image.sprite = bot.GetComponent <AgentSetup>().agentUISprite;

            uiObject.enabled = i == 0;
            var colors = button.colors;
            colors.normalColor = i == 0 ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f);
            button.colors      = colors;

            var name = new GameObject($"agent_{i}_name");
            name.transform.parent                     = agentListCanvas.transform.FindDeepChild("Panel").transform;
            bridgeConnector.UiName                    = name.AddComponent <Text>();
            bridgeConnector.UiName.font               = Resources.GetBuiltinResource <Font>("Arial.ttf");
            bridgeConnector.UiName.text               = ROSAgentManager.Instance.activeAgents[i].PrettyAddress;
            bridgeConnector.UiName.fontSize           = 16;
            bridgeConnector.UiName.fontStyle          = FontStyle.Bold;
            bridgeConnector.UiName.horizontalOverflow = HorizontalWrapMode.Overflow;
            bridgeConnector.UiName.verticalOverflow   = VerticalWrapMode.Overflow;

            bridgeConnector.Agent = bot;
        }

        UserInterfaceSetup.ChangeFocusUI(ROSAgentManager.Instance.activeAgents[0]);
        SteeringWheelInputController.ChangeFocusSteerWheel(ROSAgentManager.Instance.activeAgents[0].Agent.GetComponentInChildren <SteeringWheelInputController>());
        ROSAgentManager.Instance?.SetCurrentActiveAgent(ROSAgentManager.Instance.activeAgents[0]);

        //destroy spawn information after use
        foreach (var spawnInfo in spawnInfos)
        {
            Destroy(spawnInfo.gameObject);
        }

        InitGlobalShadowSettings(); // TODO better way for small maps
    }