Beispiel #1
0
 public rcl_publisher_base(Node _node, rosidl_message_type_support_t _type_support, string _topic_name, rcl_publisher_options_t _options)
 {
     this.native_node  = _node.NativeNode;
     this.topic_name   = _topic_name;
     this.type_support = _type_support;
     this.options      = _options;
 }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="rclcs.Publisher`1"/> class.
        /// with a custom qos profile. <see cref="rclcs.rmw_qos_profile_t"/> for possible preconfigured profiles.
        /// </summary>
        /// <param name="_Node">Node.</param>
        /// <param name="_TopicName">Topic name.</param>
        /// <param name="_QOS">Custom qos profile.</param>
        ///
        public Publisher(Node _Node, string _TopicName, rmw_qos_profile_t _QOS)
        {
            QOSProfile = _QOS;
            RosNode    = _Node;
            TopicName  = _TopicName;

            //This is some reflection magic that is used in order to obtain the correct C typesupport.
            //Every generated message contains a method with a name similiar to rosidl_typesupport_introspection_c_get_message.
            //This is a interop method declaration that does a call in the corresponding C library and that returns a pointer to a rosidl_message_type_support_t struct.
            //This pointer is marshalled to a managed struct of the type rosidl_message_type_support_t.

            //This is the type of the wrapper class around the message struct
            Type wrapperType = typeof(T);
            //This variable will store the type of the message struct
            Type messageType = typeof(T);

            //Go through all methods of the wrapper class
            foreach (var item in wrapperType.GetMethods())
            {
                if (item.IsStatic)
                {
                    //If its a method called GetMessageType
                    if (item.Name.Contains("GetMessageType"))
                    {
                        //We call it and cast the returned object to a Type.
                        messageType = (Type)item.Invoke(null, null);
                    }
                }
            }

            //Now we do the same for the message struct
            foreach (var item in messageType.GetMethods())
            {
                if (item.IsStatic)
                {
                    //We search for the method that does the native call
                    if (item.Name.Contains("rosidl_typesupport_introspection_c_get_message"))
                    {
                        //We call it and marshal the returned IntPtr (a managed wrapper around a pointer) to the managed typesupport struct
                        TypeSupport = (rosidl_message_type_support_t)Marshal.PtrToStructure((IntPtr)item.Invoke(null, null), typeof(rosidl_message_type_support_t));
                    }
                }
            }
            //The case that the data pointer inside the type support struct is 0 is a strong indicator that the call failed somewhere
            //Or that we got a wrong typesupport object at least
            if (TypeSupport.data == IntPtr.Zero)
            {
                throw new Exception("Couldn't get typesupport");
            }
            //Get the default options for the rcl publisher
            PublisherOptions = rcl_publisher.get_default_options();
            //Set the custom qos profile
            PublisherOptions.qos = QOSProfile;
            //And create an new publisher
            InternalPublisher = new rcl_publisher(RosNode, TypeSupport, TopicName, PublisherOptions);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="rclcs.rcl_publisher"/> class.
        /// </summary>
        /// <param name="_node">Node.</param>
        /// <param name="_type_support">Type support.</param>
        /// <param name="_topic_name">Topic name.</param>
        /// <param name="_options">Options.</param>
        public rcl_publisher(Node _node, rosidl_message_type_support_t _type_support, string _topic_name, rcl_publisher_options_t _options)
        {
            this.native_node  = _node.NativeNode;
            this.topic_name   = _topic_name;
            this.type_support = _type_support;
            this.options      = _options;

            native_handle = rcl_get_zero_initialized_publisher();
            rcl_publisher_init(ref native_handle, ref native_node, ref type_support, topic_name, ref options);
        }
Beispiel #4
0
 public rcl_publisher(Node _node, rosidl_message_type_support_t _type_support, string _topic_name, rcl_publisher_options_t _options)
 {
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         Impl = new rcl_publisher_windows(_node, _type_support, _topic_name, _options);
     }
     else if (Environment.OSVersion.Platform == PlatformID.Unix)
     {
         Impl = new rcl_publisher_linux(_node, _type_support, _topic_name, _options);
     }
     else
     {
         throw new Exception("Operating system: " + Environment.OSVersion.Platform.ToString() + " not supported");
     }
 }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="rclcs.Subscription`1"/> class. With a custom qos profile
        /// </summary>
        /// <param name="_node">Node.</param>
        /// <param name="_topicName">Topic name.</param>
        /// <param name="_QOS">QO.</param>
        public Subscription(Node _node, string _topicName, rmw_qos_profile_t _QOS)
        {
            QOSProfile = _QOS;
            RosNode    = _node;
            TopicName  = _topicName;

            Type wrapperType = typeof(T);
            Type messageType = typeof(T);

            foreach (var item in wrapperType.GetMethods())
            {
                if (item.IsStatic)
                {
                    if (item.Name.Contains("GetMessageType"))
                    {
                        messageType = (Type)item.Invoke(null, null);
                    }
                }
            }
            bool foundMethod = false;

            foreach (var item in messageType.GetMethods())
            {
                if (item.IsStatic)
                {
                    if (item.Name.Contains("rosidl_typesupport_introspection_c__get_message_type_support_handle"))
                    {
                        foundMethod = true;
                        TypeSupport = (rosidl_message_type_support_t)Marshal.PtrToStructure((IntPtr)item.Invoke(null, null), typeof(rosidl_message_type_support_t));
                    }
                }
            }
            if (!foundMethod)
            {
                throw new MissingMethodException("Could not find typesupport method");
            }
            if (TypeSupport.data == IntPtr.Zero)
            {
                throw new Exception("Couldn't get typesupport");
            }
            SubscriptionOptions     = rcl_subscription.get_default_options();
            SubscriptionOptions.qos = QOSProfile;
            InternalSubscription    = new rcl_subscription(RosNode, TypeSupport, TopicName, SubscriptionOptions);
        }
        public rcl_subscription_linux(Node _node, rosidl_message_type_support_t _type_support, string _topic_name, rcl_subscription_options_t _options) : base(_node, _type_support, _topic_name, _options)
        {
            subscription = rcl_get_zero_initialized_subscription();

            rcl_subscription_init(ref subscription, ref native_node, ref _type_support, _topic_name, ref _options);
        }
 extern static int rcl_subscription_init(ref rcl_subscription_t subscription, ref rcl_node_t node, ref rosidl_message_type_support_t typesupport, string topic_name, ref rcl_subscription_options_t options);
Beispiel #8
0
 extern static int rcl_publisher_init(ref rcl_publisher_t publisher, ref rcl_node_t node, ref rosidl_message_type_support_t type_support, string topic_name, ref rcl_publisher_options_t options);
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="rclcs.rcl_publisher"/> class.
 /// </summary>
 /// <param name="_node">Node.</param>
 /// <param name="_type_support">Type support.</param>
 /// <param name="_topic_name">Topic name.</param>
 /// <param name="_options">Options.</param>
 public rcl_publisher_linux(Node _node, rosidl_message_type_support_t _type_support, string _topic_name, rcl_publisher_options_t _options) : base(_node, _type_support, _topic_name, _options)
 {
     native_handle = rcl_get_zero_initialized_publisher();
     rcl_publisher_init(ref native_handle, ref native_node, ref type_support, topic_name, ref options);
 }
Beispiel #10
0
 public rcl_subscription_base(Node _node, rosidl_message_type_support_t _type_support, string _topic_name, rcl_subscription_options_t _options)
 {
     native_node = _node.NativeNode;
 }