コード例 #1
0
 public ROS2LidarSubscription()
 {
     _r2l = ROS2Listener.instance;
     _sub = _r2l.node.CreateSubscription <LaserScan>(
         "scan", msg => {
         _curScan = msg;
     }, ROS2.Utils.QosProfile.Profile.SensorData);
 }
コード例 #2
0
    public void Config(LidarVisualizer viz)
    {
        _owner = viz;

        _r2l = ROS2Listener.instance;
        _sub = _r2l.node.CreateSubscription <LaserScan>(
            _owner.topic, msg => {
            _curScan = msg;
        }, ROS2.Utils.QosProfile.Profile.SensorData);
    }
コード例 #3
0
    /// <summary>
    /// Called only by the instance singleton getter when the instance has not yet been initialized.
    /// </summary>
    /// <returns>The instance of this singleton class</returns>
    private static ROS2Listener Init()
    {
        // attempt to find an instance already in the scene
        _instance = FindObjectOfType <ROS2Listener>();
        if (_instance != null)
        {
            Debug.LogWarning("ROS2Listener.Init() is being called even when the singleton instance already exists!");
            return(_instance);
        }

        Debug.Log("ROS is Awake");

        GameObject obj = new GameObject("ROS2Listener");

        _instance = obj.AddComponent <ROS2Listener>();

        /*
         * var t = typeof(RCLdotnet).Assembly.Location;
         * Debug.Log("RCLdotnet location = " + t);
         * var p = Path.GetDirectoryName(t);
         * var sb = new StringBuilder(256);
         * GetCurrentDirectoryA((uint)sb.Capacity, sb); */
        try
        {
            //SetCurrentDirectoryA(p);

            RCLRet ret = RCLdotnet.Init();
            if (ret == RCLRet.Ok)
            {
                Debug.Log("ROS is using " + RCLdotnet.GetRMWIdentifier());
            }
            else
            {
                Debug.Log("RCL InitE = " + RCLdotnet.GetErrorString());
            }

            _instance.node = RCLdotnet.CreateNode("listener");
        }
        catch (Exception e)
        {
            Destroy(_instance.gameObject);
            _instance = null;
            Debug.Log(e.ToString());
        }
        //SetCurrentDirectoryA(sb.ToString());
        DontDestroyOnLoad(_instance);
        return(_instance);
    }
コード例 #4
0
    /// <summary>
    /// Called only by the instance singleton getter when the instance has not yet been initialized.
    /// </summary>
    /// <returns>The instance of this singleton class</returns>
    private static ROS2Listener Init()
    {
        // attempt to find an instance already in the scene
        var instance = FindObjectOfType <ROS2Listener>();

        if (instance != null)
        {
            Debug.LogWarning("ROS2 Listender is already in the scene");
            return(instance);
        }

        Debug.Log("ROS is Awake");

        GameObject obj = new GameObject("ROS2Listener");

        instance = obj.AddComponent <ROS2Listener>();
        try
        {
            RCLRet ret = RCLdotnet.Init();
            if (ret == RCLRet.Ok)
            {
                Debug.Log("ROS is using " + RCLdotnet.GetRMWIdentifier());
            }
            else
            {
                Debug.Log("RCL Init Error = " + RCLdotnet.GetErrorString());
            }

            instance.node = RCLdotnet.CreateNode("listener");
        }
        catch (Exception e)
        {
            Destroy(instance.gameObject);
            instance = null;
            Debug.Log(e.ToString());
        }
        DontDestroyOnLoad(instance);
        return(instance);
    }