protected virtual void Start()
        {
            if (this.rosBridgeIP.Equals(string.Empty))
            {
                this.rosBridgeIP = ConfigManager.Instance.configInfo.rosbridgeIP;
            }
            if (this.rosBridgePort == 0)
            {
                this.rosBridgePort = ConfigManager.Instance.configInfo.rosbridgePort;
            }

            if (!RosConnectionManager.Instance.rosConnections.rosBridgeWebSocketConnectionMap.ContainsKey(topicName))
            {
                this.webSocketConnection = new SIGVerse.RosBridge.RosBridgeWebSocketConnection(rosBridgeIP, rosBridgePort);

                RosConnectionManager.Instance.rosConnections.rosBridgeWebSocketConnectionMap.Add(topicName, this.webSocketConnection);

                this.publisher = this.webSocketConnection.Advertise <Tmsg>(topicName);

                // Connect to ROSbridge server
                this.webSocketConnection.Connect();
            }
            else
            {
                this.webSocketConnection = RosConnectionManager.Instance.rosConnections.rosBridgeWebSocketConnectionMap[topicName];

                this.publisher = this.webSocketConnection.Advertise <Tmsg>(topicName);
            }
        }
        /// <summary>
        /// Remove a publisher from this connection
        /// </summary>
        /// <param name="publisher"></param>
        public void Unadvertise(RosBridgePublisher publisher)
        {
            if (this.IsConnected)
            {
                this.webSocket.Send(RosBridgeMsg.UnAdvertiseTopic(publisher.Topic));
            }

            publisher.Unadvertise();
            this.publishers.Remove(publisher);
        }
        /// <summary>
        /// Add a publisher to this connection. There can be many publishers.
        /// </summary>
        /// <typeparam name="Tpub">Publisher type to advertise</typeparam>
        /// <param name="topic">Topic to advertise on</param>
        /// <returns>A publisher which can be used to broadcast data on the given topic</returns>
        public RosBridgePublisher <Tmsg> Advertise <Tmsg>(string topic, uint queueSize = 0) where Tmsg : RosMessage
        {
            RosBridgePublisher <Tmsg> publisher = (RosBridgePublisher <Tmsg>)Activator.CreateInstance(typeof(RosBridgePublisher <Tmsg>), new object[] { topic, queueSize });

            publisher.SetConnection(this);
            publisher.CreatePublishingThread();

            this.publishers.Add(publisher);

            if (this.IsConnected)
            {
                this.webSocket.Send(RosBridgeMsg.AdvertiseTopic(publisher.Topic, publisher.Type));
            }

            return(publisher);
        }
Beispiel #4
0
        void Start()
        {
            if (!ConfigManager.Instance.configInfo.rosbridgeIP.Equals(string.Empty))
            {
                this.rosBridgeIP   = ConfigManager.Instance.configInfo.rosbridgeIP;
                this.rosBridgePort = ConfigManager.Instance.configInfo.rosbridgePort;
            }

            this.webSocketConnection = new RosBridgeWebSocketConnection(rosBridgeIP, rosBridgePort);

            this.stringPublisher = this.webSocketConnection.Advertise <std_msgs.String>(topicName);

            // Connect to ROSbridge server
            this.webSocketConnection.Connect();

            this.stringMessage = new std_msgs.String();
        }