Example #1
0
        public IPublisher <T> CreatePublisher <T> (string topic, QosProfile.Profile profile_id) where T : IMessage
        {
            MethodInfo m = typeof(T).GetTypeInfo().GetDeclaredMethod("_GET_TYPE_SUPPORT");

            IntPtr        typesupport     = (IntPtr)m.Invoke(null, new object[] { });
            IntPtr        publisherHandle = IntPtr.Zero;
            RCLRet        ret             = (RCLRet)NodeDelegates.native_rcl_create_publisher_handle(ref publisherHandle, Handle, topic, typesupport, profile_id);
            Publisher <T> publisher       = new Publisher <T> (publisherHandle);

            return(publisher);
        }
Example #2
0
        public ISubscription <T> CreateSubscription <T> (string topic, Action <T> callback, QosProfile.Profile profile_id) where T : IMessage, new ()
        {
            MethodInfo m = typeof(T).GetTypeInfo().GetDeclaredMethod("_GET_TYPE_SUPPORT");

            IntPtr           typesupport        = (IntPtr)m.Invoke(null, new object[] { });
            IntPtr           subscriptionHandle = IntPtr.Zero;
            RCLRet           ret          = (RCLRet)NodeDelegates.native_rcl_create_subscription_handle(ref subscriptionHandle, Handle, topic, typesupport, profile_id);
            Subscription <T> subscription = new Subscription <T> (subscriptionHandle, callback);

            this.subscriptions_.Add(subscription);
            return(subscription);
        }
Example #3
0
        public static RCLRet Init()
        {
            RCLRet ret = RCLRet.Ok;

            lock (syncLock) {
                if (!initialized)
                {
                    ret         = (RCLRet)RCLdotnetDelegates.native_rcl_init();
                    initialized = true;
                }
            }

            return(ret);
        }
Example #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
        _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);
    }
Example #5
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);
    }
Example #6
0
        private static bool Take(IntPtr subscriptionHandle, IMessage message)
        {
            bool   status        = false;
            IntPtr messageHandle = message._CREATE_NATIVE_MESSAGE();
            RCLRet ret           = (RCLRet)RCLdotnetDelegates.native_rcl_take(subscriptionHandle, messageHandle);

            switch (ret)
            {
            case RCLRet.Ok:
                message._READ_HANDLE(messageHandle);
                status = true;
                break;

            case RCLRet.SubscriptionTakeFailed:
                status = false;
                break;

            default:
                break;
            }
            message._DESTROY_NATIVE_MESSAGE(messageHandle);
            return(status);
        }
Example #7
0
 private static void Wait(IntPtr waitSetHandle, long timeout)
 {
     long   ns_timeout = timeout * 1000000;
     RCLRet ret        = (RCLRet)RCLdotnetDelegates.native_rcl_wait(waitSetHandle, ns_timeout);
     // TODO(esteve): do something with ret
 }