Beispiel #1
0
        public void Loop()
        {
            var msec_pause = (config.data_streamer_hz < 1) ? 0 : 1000 / config.data_streamer_hz;
            var start_time = DateTime.Now;

            bool   streaming_active;
            string msg;

            std_msgs.String msg_data = new std_msgs.String();
            while (true)
            {
                lock (config.ConfigLock)
                {
                    streaming_active = config.steaming_data;
                }

                if (streaming_active)
                {
                    if (ReinitHeadset())
                    {
                        start_time = DateTime.Now;
                    }

                    msg = DateTime.Now.Subtract(start_time).TotalMilliseconds.ToString();

                    msg_data.data = msg;
                }

                lock (config.SocketLock)
                {
                    config.socket.Publish(config.get_data_topic_id, msg_data);
                }
                Thread.Sleep(msec_pause);
            }
        }
        public void PublicationTest()
        {
            string id = RosSocket.Advertise <std_msgs.String>("/publication_test");

            std_msgs.String message = new std_msgs.String
            {
                data = "publication test message data"
            };
            RosSocket.Publish(id, message);
            RosSocket.Unadvertise(id);
            Thread.Sleep(100);
            Assert.IsTrue(true);
        }
        public static void Main(string[] args)
        {
            //RosSocket rosSocket = new RosSocket(new RosBridgeClient.Protocols.WebSocketSharpProtocol(uri));
            RosSocket rosSocket = new RosSocket(new RosBridgeClient.Protocols.WebSocketNetProtocol(uri));

            // Publication:
            std_msgs.String message = new std_msgs.String
            {
                data = "publication test message data"
            };

            string publication_id = rosSocket.Advertise <std_msgs.String>("publication_test");

            rosSocket.Publish(publication_id, message);


            // Subscription:
            string subscription_id = rosSocket.Subscribe <std_msgs.String>("/subscription_test", SubscriptionHandler);

            subscription_id = rosSocket.Subscribe <std_msgs.String>("/subscription_test", SubscriptionHandler);

            // Service Call:
            rosSocket.CallService <rosapi.GetParamRequest, rosapi.GetParamResponse>("/rosapi/get_param", ServiceCallHandler, new rosapi.GetParamRequest("/rosdistro", "default"));

            // Service Response:
            string service_id = rosSocket.AdvertiseService <std_srvs.TriggerRequest, std_srvs.TriggerResponse>("/service_response_test", ServiceResponseHandler);

            Console.WriteLine("Press any key to unsubscribe...");
            Console.ReadKey(true);
            rosSocket.Unadvertise(publication_id);
            rosSocket.Unsubscribe(subscription_id);
            rosSocket.UnadvertiseService(service_id);

            Console.WriteLine("Press any key to close...");
            Console.ReadKey(true);
            rosSocket.Close();
        }
 private static void SubscriptionHandler(std_msgs.String message)
 {
     Console.WriteLine((message).data);
 }
 private void SubscriptionHandler(std_msgs.String message)
 {
     OnMessageReceived.Set();
 }
Beispiel #6
0
 private void SubscriptionHandler(std_msgs.String message)
 {
     Debug.Log("Message received!");
     Debug.Log(message.data);
 }