Exemplo n.º 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
    }
Exemplo n.º 2
0
    void Start()
    {
        Connector = new RosBridgeConnector();
        Connector.BridgeStatus = BridgeStatus;

        if (GameObject.Find("RosRobots") == null)
        {
            Robot.Setup(UserInterface, Connector);
        }
        else
        {
            Destroy(this);
            Destroy(Robot.gameObject);
            Destroy(GameObject.Find("UserInterface"));
        }

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

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

        Ros.Bridge.canConnect = true;
    }
Exemplo n.º 3
0
    public RosBridgeConnector Add()
    {
        var connector = new RosBridgeConnector();

        activeAgents.Add(connector);
        return(connector);
    }
Exemplo n.º 4
0
    public RosBridgeConnector Add()
    {
        var robot = new RosBridgeConnector();

        Robots.Add(robot);
        return(robot);
    }
Exemplo n.º 5
0
    public void Add(RosBridgeConnector connector)
    {
        var robotConnectInfo = Instantiate(connectTemplateUI, ScrollArea.transform);

        var addressField     = robotConnectInfo.bridgeAddress;
        var robotOptionField = robotConnectInfo.robotOptions;

        robotOptionField.AddOptions(MenuScript.Instance.GetRobotOptions());

        if (connector.Port == RosBridgeConnector.DefaultPort)
        {
            addressField.text = connector.Address;
        }
        else
        {
            addressField.text = $"{connector.Address}:{connector.Port}";
        }

        robotOptionField.value = connector.robotType == null ? 0 : Robots.robotCandidates.IndexOf(connector.robotType);

        addressField.onValueChanged.AddListener((value) =>
        {
            var splits = value.Split(new char[] { ':' }, 2);
            if (splits.Length == 2)
            {
                int port;
                if (int.TryParse(splits[1], out port))
                {
                    connector.Address = splits[0];
                    connector.Port    = port;
                    connector.Disconnect();
                }
            }
            else if (splits.Length == 1)
            {
                connector.Address = splits[0];
                connector.Port    = RosBridgeConnector.DefaultPort;
                connector.Disconnect();
            }
        });

        robotOptionField.onValueChanged.AddListener((index) =>
        {
            connector.robotType = Robots.robotCandidates[index];
            connector.Disconnect();
        });

        if (connector.robotType == null)
        {
            connector.robotType = Robots.robotCandidates[0];
        }
        connector.BridgeStatus = robotConnectInfo.transform.Find("ConnectionStatus").GetComponent <Text>();
        connector.MenuObject   = robotConnectInfo.gameObject;

        transform.SetAsLastSibling();

        MenuScript.Instance.RunButtonInteractiveCheck();
    }
Exemplo n.º 6
0
    private void ActiveAgentChanged(RosBridgeConnector agent)
    {
        var missive = new ActiveAgentMissive
        {
            agent = agent
        };

        Missive.Send(missive);
    }
Exemplo n.º 7
0
 public void SetCurrentActiveAgent(int index)
 {
     if (activeAgents.Count == 0)
     {
         return;
     }
     currentActiveAgent = activeAgents[index];
     ActiveAgentChanged(currentActiveAgent);
     currentActiveAgent.Agent?.GetComponent <VehicleController>()?.SetDashUIState();
 }
Exemplo n.º 8
0
 public void SetCurrentActiveAgent(RosBridgeConnector agent)
 {
     if (agent == null)
     {
         return;
     }
     currentActiveAgent = agent;
     ActiveAgentChanged(currentActiveAgent);
     currentActiveAgent.Agent.GetComponent <VehicleController>()?.SetDashUIState();
 }
    public static void ChangeFocusUI(RosBridgeConnector connector)
    {
        for (int k = 0; k < ROSAgentManager.Instance.activeAgents.Count; k++)
        {
            var  agentConnector = ROSAgentManager.Instance.activeAgents[k];
            bool isFocus        = agentConnector == connector;
            agentConnector.UiObject.enabled = isFocus;
            var b = agentConnector.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 agentSetup = agentConnector.Agent.GetComponent <AgentSetup>();
            agentSetup.FollowCamera.gameObject.SetActive(isFocus);
            agentSetup.FollowCamera.enabled = isFocus;
            var inputControllers = agentConnector.Agent.GetComponentsInChildren <IInputController>().ToList();
            if (isFocus)
            {
                FocusUI = agentSetup.UI;
                inputControllers.ForEach(i => i.Enable());
                agentSetup.GetComponentInChildren <LidarSensor>()?.Reset();
                // TODO move to gameobject based
                ROSAgentManager.Instance?.SetCurrentActiveAgent(agentConnector);

                // set visual to true for radar, groundtruth2d, groundtruth3d, lidar TODO simplify and work for all sensors
                agentSetup.GetComponentInChildren <RadarSensor>()?.EnableVisualize(true);
                agentSetup.GetComponentInChildren <GroundTruthSensor2D>()?.EnableVisualize(true);
                agentSetup.GetComponentInChildren <GroundTruthSensor3D>()?.EnableVisualize(true);
                agentSetup.GetComponentInChildren <LidarSensor>()?.EnableVisualize(true);
                var planarSensors = agentSetup.GetComponentsInChildren <PlanarLidarSensor>();
                foreach (var item in planarSensors)
                {
                    item.EnableVisualize(true);
                }
            }
            else
            {
                inputControllers.ForEach(i => i.Disable());

                // turn off sensors when not in focus
                agentSetup.GetComponentInChildren <RadarSensor>()?.EnableVisualize(false);
                agentSetup.GetComponentInChildren <GroundTruthSensor2D>()?.EnableVisualize(false);
                agentSetup.GetComponentInChildren <GroundTruthSensor3D>()?.EnableVisualize(false);
                agentSetup.GetComponentInChildren <LidarSensor>()?.EnableVisualize(false);
                var planarSensors = agentSetup.GetComponentsInChildren <PlanarLidarSensor>();
                foreach (var item in planarSensors)
                {
                    item.EnableVisualize(false);
                }
            }
        }

        VehicleList.Instances?.ForEach(x => x.ToggleDisplay(FocusUI.MainPanel.gameObject.activeSelf)); //hack
    }
Exemplo n.º 10
0
    public void AddAgent()
    {
        var agentSetup = ROSAgentManager.Instance.agentPrefabs[0];
        var connector  = new RosBridgeConnector(agentSetup);

        ROSAgentManager.Instance.Add(connector);

        var agentConnectInfo = Instantiate(connectTemplateUI, ScrollArea.transform);

        var addressField     = agentConnectInfo.bridgeAddress;
        var agentOptionField = agentConnectInfo.agentOptions;

        agentOptionField.AddOptions(GetAgentOptions());

        addressField.text = connector.Address;

        agentOptionField.value = ROSAgentManager.Instance.agentPrefabs.IndexOf(connector.agentType);

        addressField.onValueChanged.AddListener((value) =>
        {
            var splits = value.Split(new char[] { ':' }, 2);
            if (splits.Length == 2)
            {
                int port;
                if (int.TryParse(splits[1], out port))
                {
                    connector.Address = splits[0];
                    connector.Port    = port;
                    connector.Disconnect();
                }
            }
            else if (splits.Length == 1)
            {
                connector.Address = splits[0];
                connector.Port    = RosBridgeConnector.DefaultPort;
                connector.Disconnect();
            }
        });

        agentOptionField.onValueChanged.AddListener((index) =>
        {
            connector.agentType = ROSAgentManager.Instance.agentPrefabs[index];
            connector.Disconnect();
        });

        connector.BridgeStatus = agentConnectInfo.transform.Find("ConnectionStatus").GetComponent <Text>();
        connector.MenuObject   = agentConnectInfo.gameObject;

        transform.SetAsLastSibling();

        RunButtonInteractiveCheck();
    }
Exemplo n.º 11
0
    public void SetRobotSettings(RobotSetup setup, RosBridgeConnector connector)
    {
        if (setup == null)
        {
            return;
        }

        robotAddress.text       = connector != null ? connector.PrettyAddress : "ROSBridgeConnector Missing!";
        robotConnectorData.text = GetRobotConnectorData(connector);
        //Button button = go.GetComponent<Button>();
        //ColorBlock tempCB = button.colors;
        //tempCB.normalColor = inactiveRobotUIColor;
    }
Exemplo n.º 12
0
 public static void ChangeCameraFocus(RosBridgeConnector connector, RosRobots robots)
 {
     for (int k = 0; k < robots.Robots.Count; k++)
     {
         var isFocus = robots.Robots[k] == connector;
         robots.Robots[k].UiObject.enabled = isFocus;
         var b = robots.Robots[k].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;
         robots.Robots[k].Robot.GetComponent <RobotSetup>().FollowCamera.gameObject.SetActive(isFocus);
     }
 }
Exemplo n.º 13
0
    public void InitRobotSettings(RobotSetup setup, RosBridgeConnector connector)
    {
        if (setup == null)
        {
            return;
        }

        GameObject go = Instantiate(robotUIPrefab, robotUIButtonHolder);

        go.transform.GetChild(0).GetComponent <Image>().sprite = setup.robotUISprite ?? defaultRobotUISprite;
        robotAddress.text       = connector != null ? connector.PrettyAddress : "ROSBridgeConnector Missing!";
        robotConnectorData.text = GetRobotConnectorData(connector);
        Button     button = go.GetComponent <Button>();
        ColorBlock tempCB = button.colors;

        tempCB.normalColor = inactiveRobotUIColor;
    }
Exemplo n.º 14
0
 static void FormatAgent(StringBuilder sb, RosBridgeConnector ros)
 {
     if (ros.Bridge.Status == Ros.Status.Connected)
     {
         sb.AppendLine($"{ros.PrettyAddress}");
         foreach (var topic in ros.Bridge.TopicPublishers)
         {
             sb.AppendLine($"PUB: {topic.Name} ({topic.Type})");
         }
         foreach (var topic in ros.Bridge.TopicSubscriptions)
         {
             sb.AppendLine($"SUB: {topic.Name} ({topic.Type})");
         }
     }
     else
     {
         sb.AppendLine($"{ros.PrettyAddress} ({ros.Bridge.Status})");
     }
 }
Exemplo n.º 15
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;
    }
Exemplo n.º 16
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);
    }
Exemplo n.º 17
0
    private void SetConfigAgents()
    {
        var candidate = ROSAgentManager.Instance.agentPrefabs[0];

        foreach (var staticVehicle in staticConfig.vehicles)
        {
            foreach (var agentPrefabs in ROSAgentManager.Instance.agentPrefabs)
            {
                if (agentPrefabs.name == staticVehicle.type)
                {
                    candidate = agentPrefabs;
                    break;
                }
            }
            var connector = new RosBridgeConnector(staticVehicle.address, staticVehicle.port, candidate);
            ROSAgentManager.Instance.Add(connector);
        }
        ROSAgentManager.Instance.SaveAgents();
        RosBridgeConnector.canConnect = true;
    }
Exemplo n.º 18
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
    }
Exemplo n.º 19
0
    private string GetRobotConnectorData(RosBridgeConnector connector)
    {
        if (SimulatorManager.Instance == null)
        {
            return("SimulatorManager Missing!");
        }
        if (connector == null)
        {
            return("ROSBridgeConnector Missing!");
        }

        StringBuilder sb = new StringBuilder();

        sb.Append("\nAvailable ROS Bridges:\n\n");
        if (SimulatorManager.Instance.IsRobots())
        {
            if (connector.Bridge.Status == Ros.Status.Connected)
            {
                sb.AppendLine($"{connector.PrettyAddress}");
                foreach (var topic in connector.Bridge.TopicPublishers)
                {
                    sb.AppendLine($"PUB: {topic.Name} ({topic.Type})");
                }
                foreach (var topic in connector.Bridge.TopicSubscriptions)
                {
                    sb.AppendLine($"SUB: {topic.Name} ({topic.Type})");
                }
            }
            else
            {
                sb.AppendLine($"{connector.PrettyAddress} ({connector.Bridge.Status})");
            }
        }


        return(sb.ToString());
    }
Exemplo n.º 20
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;
    }
Exemplo n.º 21
0
 public void Add(RosBridgeConnector connector)
 {
     activeAgents.Add(connector);
 }
Exemplo n.º 22
0
 public void DespawnVehicle(RosBridgeConnector connector)
 {
     Destroy(connector.UiObject.gameObject);
     Destroy(connector.UiName.gameObject);
     Destroy(connector.UiButton);
 }
Exemplo n.º 23
0
        public void Execute(JSONNode args)
        {
            var sim = Object.FindObjectOfType <SimulatorManager>();

            if (sim == null)
            {
                ApiManager.Instance.SendError("SimulatorManager not found! Is scene loaded?");
                return;
            }

            var name             = args["name"].Value;
            var type             = args["type"].AsInt;
            var position         = args["state"]["transform"]["position"].ReadVector3();
            var rotation         = args["state"]["transform"]["rotation"].ReadVector3();
            var velocity         = args["state"]["velocity"].ReadVector3();
            var angular_velocity = args["state"]["angular_velocity"].ReadVector3();

            if (type == (int)AgentType.Ego)
            {
                var agents = ROSAgentManager.Instance;
                foreach (var agent in agents.activeAgents)
                {
                    agent.Agent.GetComponent <AgentSetup>().FollowCamera.gameObject.SetActive(false);
                }

                var agentType = agents.agentPrefabs.Find(prefab => prefab.name == name);
                var connector = new RosBridgeConnector(agentType);
                agents.Add(connector);
                sim.SpawnVehicle(position, Quaternion.Euler(rotation), connector, null);

                agents.SetCurrentActiveAgent(connector);

                var setup = connector.Agent.GetComponent <AgentSetup>();
                setup.FollowCamera.gameObject.SetActive(true);

                var body = connector.Agent.GetComponent <Rigidbody>();
                body.velocity        = velocity;
                body.angularVelocity = angular_velocity;

                var uid = System.Guid.NewGuid().ToString();
                ApiManager.Instance.Agents.Add(uid, connector.Agent);
                ApiManager.Instance.AgentUID.Add(connector.Agent, uid);

                foreach (var sensor in setup.GetSensors())
                {
                    var sensor_uid = System.Guid.NewGuid().ToString();
                    ApiManager.Instance.SensorUID.Add(sensor, sensor_uid);
                    ApiManager.Instance.Sensors.Add(sensor_uid, sensor);
                }

                ApiManager.Instance.SendResult(new JSONString(uid));
            }
            else if (type == (int)AgentType.Npc)
            {
                var go = NPCManager.Instance.SpawnVehicle(name, position, Quaternion.Euler(rotation));

                var npc = go.GetComponent <NPCControllerComponent>();
                npc.Control = NPCControllerComponent.ControlType.Manual;

                var body = go.GetComponent <Rigidbody>();
                body.velocity        = velocity;
                body.angularVelocity = angular_velocity;

                var uid = go.name;
                ApiManager.Instance.Agents.Add(uid, go);
                ApiManager.Instance.AgentUID.Add(go, uid);
                ApiManager.Instance.SendResult(new JSONString(go.name));
            }
            else if (type == (int)AgentType.Pedestrian)
            {
                var ped = PedestrianManager.Instance.SpawnPedestrianApi(name, position, Quaternion.Euler(rotation));
                if (ped == null)
                {
                    ApiManager.Instance.SendError($"Unknown '{name}' pedestrian name");
                    return;
                }

                var uid = System.Guid.NewGuid().ToString();
                ApiManager.Instance.Agents.Add(uid, ped);
                ApiManager.Instance.AgentUID.Add(ped, uid);

                ApiManager.Instance.SendResult(new JSONString(uid));
            }
            else
            {
                ApiManager.Instance.SendError($"Unsupported '{args["type"]}' type");
            }
        }
Exemplo n.º 24
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;
        }
    }
Exemplo n.º 25
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);
        //});
    }
Exemplo n.º 26
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
    }
Exemplo n.º 27
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;
        }
    }
Exemplo n.º 28
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);
        }
    }