Ejemplo n.º 1
0
    private void SetupVirtualRobot()
    {
        string _configPath = Application.streamingAssetsPath + "/Config/Robots/";

        string[] paths = Directory.GetFiles(_configPath, "VirtualRobot_Arlobot.json");
        string   path  = paths[0];


        string robotName = Path.GetFileNameWithoutExtension(path);

        Debug.Log(robotName);
        string          robotFileJson = File.ReadAllText(path);
        RobotConfigFile robotFile     = JsonUtility.FromJson <RobotConfigFile>(robotFileJson);


        if (!robotFile.RosBridgeUri.StartsWith("ws://"))
        {
            robotFile.RosBridgeUri = "ws://" + robotFile.RosBridgeUri;
        }


        // rosbridge = new ROSBridgeWebSocketConnection(robotFile.RosBridgeUri, robotFile.RosBridgePort, robotName);

        //VirtualRobotController.InitialiseRobot(RobotInterface.Instance._rosBridge, robotFile, robotName);
        // VirtualRobotController.OverridePositionAndOrientation(VirtualRobotController.gameObject.transform.position, VirtualRobotController.gameObject.transform.rotation);
    }
Ejemplo n.º 2
0
 public Robot(int[] campuses, ROSBridgeWebSocketConnection rosBridge, string name, string uri, int port, bool isActive, RobotConfigFile robotConfig)
 {
     Campuses    = campuses;
     RosBridge   = rosBridge;
     Name        = name;
     Uri         = uri;
     Port        = port;
     IsActive    = isActive;
     RobotConfig = robotConfig;
 }
Ejemplo n.º 3
0
    private void LoadRobotsFromCampus(int campusId)
    {
        if (ActiveRobots != null)
        {
            foreach (KeyValuePair <string, ROSController> pair in ActiveRobots)
            {
                pair.Value.Destroy();
            }
        }

        ActiveRobots = new Dictionary <string, ROSController>();
        Robots       = new Dictionary <string, Robot>();
        string[] robotConfigPaths = Directory.GetFiles(_configPath, "*.json");
        foreach (string path in robotConfigPaths)
        {
            string          robotName     = Path.GetFileNameWithoutExtension(path);
            string          robotFileJson = File.ReadAllText(path);
            RobotConfigFile robotFile     = JsonUtility.FromJson <RobotConfigFile>(robotFileJson);

            if (!robotFile.Campuses.Contains(campusId))
            {
                continue;
            }

            if (!robotFile.RosBridgeUri.StartsWith("ws://"))
            {
                robotFile.RosBridgeUri = "ws://" + robotFile.RosBridgeUri;
            }
            ;

            ROSBridgeWebSocketConnection rosBridge = new ROSBridgeWebSocketConnection(robotFile.RosBridgeUri, robotFile.RosBridgePort, robotName);

            Robot robot = new Robot(robotFile.Campuses, rosBridge, robotName, robotFile.RosBridgeUri, robotFile.RosBridgePort, false, robotFile);
            Robots.Add(robotName, robot);
        }

        PlayerUIController.Instance.LoadRobots(Robots.Select(robot => robot.Value).ToList());
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Initialises robot and ROS Bridge connections and starts all attached modules.
    /// </summary>
    /// <param name="rosBridge">Ros bridge connection.</param>
    /// <param name="robotConfig">Config file that contains robot parameters.</param>
    public virtual void InitialiseRobot(ROSBridgeWebSocketConnection rosBridge, RobotConfigFile robotConfig, string robotName)
    {
        RobotName  = robotName;
        _rosBridge = rosBridge;
        _rosBridge.OnDisconnect += clean =>
        {
            if (!clean)
            {
                LostConnection();
            }
        };
        RobotConfig = robotConfig;
        StartROS();

        foreach (RobotModule module in _robotModules)
        {
            module.Initialise(rosBridge);
        }

        if (OnRosStarted != null)
        {
            OnRosStarted(rosBridge);
        }
    }