Пример #1
0
 public void RemovePublisher(ROSBridgePublisher publisher)
 {
     _publishers.Remove(publisher);
     if (IsConnected)
     {
         WebSocket.Send(ROSBridgeMsg.UnAdvertise(publisher.GetMessageTopic()));
     }
 }
Пример #2
0
 public void AddPublisher(ROSBridgePublisher publisher)
 {
     _publishers.Add(publisher);
     if (IsConnected && !IsDisconnecting)
     {
         WebSocket.Send(ROSBridgeMsg.Advertise(publisher.GetMessageTopic(), publisher.GetMessageType()));
     }
 }
        /// <summary>
        /// Remove a publisher from this connection
        /// </summary>
        /// <param name="pub"></param>
        public void Unadvertise(ROSBridgePublisher pub)
        {
            if (connected)
            {
                _ws.Send(ROSBridgeMsg.UnAdvertiseTopic(pub.topic));
            }

            _publishers.Remove(pub);
        }
 /// <summary>
 /// Publish a message to be sent to the ROS environment. Note: You must Advertise() before you can Publish().
 /// </summary>
 /// <param name="publisher">Publisher associated with the topic to publish to</param>
 /// <param name="msg">Message to publish</param>
 public void Publish(ROSBridgePublisher publisher, ROSMessage msg)
 {
     if (_ws != null && connected)
     {
         _ws.Send(publisher.ToMessage(msg));
     }
     else
     {
         Debug.LogWarning("Could not publish message! No current connection to ROSBridge...");
     }
 }
Пример #5
0
    void Start()
    {
        ROSHost = "ws://" + ROSHost;

        ros      = new ROSBridgeLib.ROSBridgeWebSocketConnection(ROSHost, ROSPort);
        pose_sub = ros.Subscribe <SimplePoseArray>("/unity/simple_bot/pose", OnNewPoseMsg);
        hand_sub = ros.Subscribe <ROSBridgeLib.simple_unity_bot.HandState>("/unity/simple_bot/hands", OnNewHandMsg);
        pose_pub = ros.Advertise <SimplePoseArray>("/unity/simple_bot/target_pose");
        hand_pub = ros.Advertise <ROSBridgeLib.simple_unity_bot.HandState>("/unity/simple_bot/hand_targets");

        ros.Connect();
    }
        /// <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) where Tmsg : ROSMessage
        {
            ROSBridgePublisher <Tmsg> pub = (ROSBridgePublisher <Tmsg>)Activator.CreateInstance(typeof(ROSBridgePublisher <Tmsg>), new object[] { topic });

            pub.SetBridgeConnection(this);

            _publishers.Add(pub);

            if (connected)
            {
                _ws.Send(ROSBridgeMsg.AdvertiseTopic(pub.topic, pub.type));
            }

            return(pub);
        }
 public PublishTask(ROSBridgePublisher publisher, ROSMessage msg)
 {
     _publisher = publisher;
     _msg       = msg;
 }