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 Publisher(string topic, Node node)
        {
            nodeHandle = node.handle;
            handle     = NativeMethods.rcl_get_zero_initialized_publisher();
            rcl_publisher_options_t publisherOptions = NativeMethods.rcl_publisher_get_default_options();

            //TODO(samiam): Figure out why System.Reflection is not available
            //when building with colcon/xtool on ubuntu 18.04 and mono 4.5

            //MethodInfo m = typeof(T).GetTypeInfo().GetDeclaredMethod("_GET_TYPE_SUPPORT");
            //IntPtr typeSupportHandle = (IntPtr)m.Invoke(null, new object[] { });

            IRclcsMessage msg = new T();
            IntPtr        typeSupportHandle = msg.TypeSupportHandle;

            Utils.CheckReturnEnum(NativeMethods.rcl_publisher_init(
                                      ref handle,
                                      ref nodeHandle,
                                      typeSupportHandle,
                                      topic,
                                      ref publisherOptions));
        }
Beispiel #5
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 #6
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 #7
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");
     }
 }