/// <summary>
        /// Disconnect from the remote ros environment.
        /// </summary>
        public void Disconnect()
        {
            if (!connected)
            {
                return;
            }

            _recvThread.Abort();
            foreach (var sub in _subscribers)
            {
                _ws.Send(ROSBridgeMsg.UnSubscribe(sub.Key.topic));
            }
            foreach (var p in _publishers)
            {
                _ws.Send(ROSBridgeMsg.UnAdvertiseTopic(p.topic));
            }
            foreach (var srv in _serviceServers)
            {
                _ws.Send(ROSBridgeMsg.UnadvertiseService(srv.Key.topic));
            }

            _ws.Close();
            _msgQueue.Clear();

            _connected = false;
        }
 /**
  * Disconnect from the remote ros environment.
  */
 public void Disconnect()
 {
     _applicationIsPlaying = false;
     _myThread.Join();
     //_myThread.Abort (); // Abort() does not guarantee that the thread is stopped
     if (_ws != null)
     {
         foreach (Type p in _subscribers)
         {
             try
             {
                 _ws.Send(ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
                 UnityEngine.Debug.Log("Send " + ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
             } catch
             {
                 UnityEngine.Debug.LogWarning("Sending " + ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)) + " failed.");
             }
         }
         foreach (Type p in _publishers)
         {
             try
             {
                 _ws.Send(ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
                 UnityEngine.Debug.Log("Send " + ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
             } catch
             {
                 UnityEngine.Debug.LogWarning("Sending " + ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)) + " failed.");
             }
         }
     }
     _ws.Close();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Disconnects from the ROS Bridge and unsubscribes from all subscribed topics.
        /// </summary>
        public void Disconnect()
        {
            IsDisconnecting = true;
            Debug.Log("Disconnecting from " + _host);
            _myThread.Abort();
            if (WebSocket == null)
            {
                return;
            }
            foreach (ROSBridgeSubscriber subscriber in _subscribers)
            {
                WebSocket.Send(ROSBridgeMsg.UnSubscribe(subscriber.GetMessageTopic()));
                Debug.Log("Sending " + ROSBridgeMsg.UnSubscribe(subscriber.GetMessageTopic()));
            }
            foreach (ROSBridgePublisher publisher in _publishers)
            {
                WebSocket.Send(ROSBridgeMsg.UnAdvertise(publisher.GetMessageTopic()));

                Debug.Log("Sending " + ROSBridgeMsg.UnAdvertise(publisher.GetMessageTopic()));
            }
            _subscribers.Clear();
            _publishers.Clear();
            //fix this in a better way
            RobotInterface.Instance.StartCoroutine(Example());
            WebSocket.Close();
            IsConnected = false;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Disconnect from the remote ros environment.
 /// </summary>
 public void Disconnect()
 {
     _connected = false;
     _myThread.Abort();
     foreach (string topicName in static_subscribers.Keys)
     {
         _ws.Send(ROSBridgeMsg.UnSubscribe(topicName));
         Debug.Log("Sending " + ROSBridgeMsg.UnSubscribe(topicName));
     }
     foreach (string topicName in subscribers.Keys)
     {
         if (!static_subscribers.ContainsKey(topicName))
         {
             _ws.Send(ROSBridgeMsg.UnSubscribe(topicName));
             Debug.Log("Sending " + ROSBridgeMsg.UnSubscribe(topicName));
         }
     }
     foreach (string topicName in static_publishers.Keys)
     {
         _ws.Send(ROSBridgeMsg.UnAdvertise(topicName));
         Debug.Log("Sending " + ROSBridgeMsg.UnAdvertise(topicName));
     }
     _ws.Close();
     static_subscribers.Clear();
     static_publishers.Clear();
     subscribers.Clear();
 }
Exemplo n.º 5
0
 public void RemoveSubcriber(ROSBridgeSubscriber subscriber)
 {
     _subscribers.Remove(subscriber);
     if (IsConnected)
     {
         WebSocket.Send(ROSBridgeMsg.UnSubscribe(subscriber.GetMessageTopic()));
     }
 }
Exemplo n.º 6
0
        /**
         * Removes a subscriber and disconnects him if the connection is already running.
         */
        public void RemoveSubscriber(Type subscriber)
        {
            if (!_subscribers.Contains(subscriber))
            {
                return;
            }

            _subscribers.Remove(subscriber);
            if (_running)
            {
                _ws.Send(ROSBridgeMsg.UnSubscribe(GetMessageTopic(subscriber)));
            }
        }
Exemplo n.º 7
0
 /**
  * Disconnect from the remote ros environment.
  */
 public void Disconnect()
 {
     _myThread.Abort();
     foreach (Type p in _subscribers)
     {
         _ws.Send(ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
         //Debug.Log ("Sending " + ROSBridgePacket.unSubscribe(getMessageTopic(p)));
     }
     foreach (Type p in _publishers)
     {
         _ws.Send(ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
         //Debug.Log ("Sending " + ROSBridgePacket.unAdvertise (getMessageTopic(p)));
     }
     _ws.Close();
 }
        /// <summary>
        /// Remove a subscriber callback from this connection.
        /// </summary>
        /// <param name="sub"></param>
        public void Unsubscribe(ROSBridgeSubscriber sub)
        {
            if (sub == null)
            {
                return;
            }

            _subscribers.Remove(sub);
            _msgQueue.Remove(sub.topic);

            if (connected)
            {
                _ws.Send(ROSBridgeMsg.UnSubscribe(sub.topic));
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Unsubscribe from a specific topic
 /// TODO: Test this function.
 /// </summary>
 /// <param name="topicName"></param>
 public void RemoveSubscriber(string topicName)
 {
     if (_connected)
     {
         if (subscribers.ContainsKey(topicName))
         {
             _ws.Send(ROSBridgeMsg.UnSubscribe(topicName));
             Debug.Log("Sending " + ROSBridgeMsg.UnSubscribe(topicName));
             subscribers.Remove(topicName);
         }
         else
         {
             Debug.Log("Invalid subscriber topic name key: " + topicName);
         }
     }
     else
     {
         Debug.Log("ROS Connection is inactive");
     }
 }
Exemplo n.º 10
0
        /**
         * Disconnect from the remote ros environment.
         */
        public void Disconnect()
        {
#if UNITY_EDITOR
            _myThread.Abort();
            foreach (Type p in _subscribers)
            {
                _ws.Send(ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
                Debug.Log("Sending " + ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
            }
            foreach (Type p in _publishers)
            {
                _ws.Send(ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
                Debug.Log("Sending " + ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
            }
            _ws.Close();
            _connected = false;
#endif
#if !UNITY_EDITOR
            Debug.Log("Disconnectig...");
            foreach (Type p in _subscribers)
            {
                dataWriter.WriteString(ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
                dataWriter.StoreAsync();
                Debug.Log("Sending " + ROSBridgeMsg.UnSubscribe(GetMessageTopic(p)));
            }
            foreach (Type p in _publishers)
            {
                dataWriter.WriteString(ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
                dataWriter.StoreAsync();
                Debug.Log("Sending " + ROSBridgeMsg.UnAdvertise(GetMessageTopic(p)));
            }
            messageWebSocket.Dispose();
            messageWebSocket = null;
            _connected       = false;
#endif
        }
Exemplo n.º 11
0
 /**
  * Unsubcribe this connection.
  */
 public void UnSubcribe(Type unsubcriber)
 {
     _ws.Send(ROSBridgeMsg.UnSubscribe(GetMessageTopic(unsubcriber)));
 }