コード例 #1
0
 // Update is called once per frame
 private void OnDestroy()
 {
     // Close any existing connection
     if (status == Status.SUCCESS)
     {
         rosSocket.Close();
     }
 }
コード例 #2
0
        public static void Main(string[] args)
        {
            string uri = "ws://192.168.56.102:9090";

            for (int i = 1; i < 3; i++)
            {
                RosBridgeClient.Protocols.WebSocketNetProtocol webSocketNetProtocol = new RosBridgeClient.Protocols.WebSocketNetProtocol(uri);
                RosSocket rosSocket     = new RosSocket(webSocketNetProtocol);
                string    urdfParameter = "/robot_description";

                // Publication:
                UrdfTransferFromRos urdfTransferFromRos = new UrdfTransferFromRos(rosSocket, System.IO.Directory.GetCurrentDirectory(), urdfParameter);
                urdfTransferFromRos.Transfer();

                urdfTransferFromRos.Status["robotNameReceived"].WaitOne();
                Console.WriteLine("Robot Name Received: " + urdfTransferFromRos.RobotName);

                urdfTransferFromRos.Status["robotDescriptionReceived"].WaitOne();
                Console.WriteLine("Robot Description received... ");

                urdfTransferFromRos.Status["resourceFilesReceived"].WaitOne();
                Console.WriteLine("Resource Files received " + urdfTransferFromRos.FilesBeingProcessed.Count);

                rosSocket.Close();
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadKey(true);
        }
コード例 #3
0
        private void ImportAssets()
        {
            if (!statusEvents["connected"].WaitOne(timeout * 1000))
            {
                Debug.LogWarning("Failed to connect to ROS before timeout");
                return;
            }

            // setup urdfImporter
            RosBridgeClient.UrdfImporter urdfImporter = new RosBridgeClient.UrdfImporter(rosSocket, assetPath);
            statusEvents["robotNameReceived"]        = urdfImporter.Status["robotNameReceived"];
            statusEvents["robotDescriptionReceived"] = urdfImporter.Status["robotDescriptionReceived"];
            statusEvents["resourceFilesReceived"]    = urdfImporter.Status["resourceFilesReceived"];

            urdfImporter.Import();

            if (statusEvents["robotNameReceived"].WaitOne(timeout * 1000))
            {
                robotName      = urdfImporter.RobotName;
                localDirectory = urdfImporter.LocalDirectory;
            }

            // import URDF assets:
            if (statusEvents["resourceFilesReceived"].WaitOne(timeout * 1000))
            {
                Debug.Log("Imported urdf resources to " + urdfImporter.LocalDirectory);
            }
            else
            {
                Debug.LogWarning("Not all resource files have been received before timeout.");
            }

            rosSocket.Close();
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            //RosSocket rosSocket = new RosSocket(new RosBridgeClient.Protocols.WebSocketSharpProtocol(uri));
            rosSocket = new RosSocket(new RosBridgeClient.Protocols.WebSocketNetProtocol(uri));

            // Initialize server
            fibonacciActionServer = new FibonacciActionServer(actionName, rosSocket, new Log(x => Console.WriteLine(x)));
            fibonacciActionServer.Initialize();

            // Run server and wait for goal
            isWaitingForGoal.Set();
            Console.WriteLine("Waiting for goal");
            Thread waitForGoal = new Thread(WaitForGoal);

            waitForGoal.Start();

            Console.WriteLine("\nPress any key to stop server...");
            Console.ReadKey(true);
            isWaitingForGoal.Reset();
            waitForGoal.Join();
            fibonacciActionServer.Terminate();

            // End of console example
            Console.WriteLine("\nPress any key to close...");
            Console.ReadKey(true);
            rosSocket.Close();
        }
コード例 #5
0
    private void rosSocketConnect()
    {
        // intialize
        foreach (ManualResetEvent manualResetEvent in status.Values)
        {
            manualResetEvent.Reset();
        }

        // connectto ROSbridge
        RosSocket rosSocket = new RosSocket(address);

        status["connected"].Set();

        // setup urdfImporter
        urdfImporter = new UrdfImporter(rosSocket, urdfAssetPath);
        status["robotNameReceived"]        = urdfImporter.Status["robotNameReceived"];
        status["robotDescriptionReceived"] = urdfImporter.Status["robotDescriptionReceived"];
        status["resourceFilesReceived"]    = urdfImporter.Status["resourceFilesReceived"];
        urdfImportThread = new Thread(() => urdfImporter.Import());
        urdfImportThread.Start();

        // import URDF assets:
        if (status["resourceFilesReceived"].WaitOne(int.Parse(timeout) * 1000))
        {
            Debug.Log("Imported urdf resources to " + urdfImporter.LocalDirectory);
        }
        else
        {
            Debug.LogWarning("Not all resource files have been received before timeout.");
        }

        // close the ROSBridge socket
        rosSocket.Close();
        status["disconnected"].Set();
    }
コード例 #6
0
        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("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"));
            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();
        }
コード例 #7
0
 public virtual void OnDisable()
 {
     if (RosSocket != null)
     {
         RosSocket.Close();
     }
 }
コード例 #8
0
        public static void Main(string[] args)
        {
            string uri = "ws://192.168.56.102:9090";

            RosBridgeClient.Protocols.WebSocketNetProtocol webSocketNetProtocol;
            RosSocket rosSocket;

            for (int i = 1; i < 3; i++)
            {
                webSocketNetProtocol = new RosBridgeClient.Protocols.WebSocketNetProtocol(uri);
                rosSocket            = new RosSocket(webSocketNetProtocol);

                // Publication:
                UrdfImporter urdfImporter = new UrdfImporter(rosSocket, System.IO.Directory.GetCurrentDirectory());
                urdfImporter.Import();

                urdfImporter.Status["robotNameReceived"].WaitOne();
                Console.WriteLine("Robot Name Received: " + urdfImporter.RobotName);

                urdfImporter.Status["robotDescriptionReceived"].WaitOne();
                Console.WriteLine("Robot Description received... ");

                urdfImporter.Status["resourceFilesReceived"].WaitOne();
                Console.WriteLine("Resource Files received " + urdfImporter.RequestedResourceFiles.Count);

                rosSocket.Close();
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadKey(true);
        }
コード例 #9
0
        // on ROS system:
        // launch before starting:
        // roslaunch file_server ros_sharp_communication.launch

        // launch after starting:
        // roslaunch file_server visualize_robot.launch

        public static void Main(string[] args)
        {
            string uri = "ws://192.168.56.102:9090";
            string robotDescription = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "TestUrdf", "R2D2WithTexture.urdf");

            WebSocketNetProtocol webSocketNetProtocol = new WebSocketNetProtocol(uri);
            RosSocket            rosSocket            = new RosSocket(webSocketNetProtocol);

            // Publication:
            UrdfTransferToRos transferor = new UrdfTransferToRos(rosSocket, "Robot", robotDescription, "test_package");

            transferor.Transfer();

            transferor.Status["robotNamePublished"].WaitOne();
            Console.WriteLine("Robot Name Published: " + transferor.RobotName);

            transferor.Status["robotDescriptionPublished"].WaitOne();
            Console.WriteLine("Robot Description received... ");

            transferor.Status["resourceFilesSent"].WaitOne();
            Console.WriteLine("Resource Files sent: " + transferor.FilesBeingProcessed.Count);

            Console.WriteLine("Press any key to close...");
            Console.ReadKey(true);

            rosSocket.Close();
        }
コード例 #10
0
        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:
            int ImageDataSize = 100;

            sensor_msgs.CompressedImage image = new sensor_msgs.CompressedImage();
            image.header.frame_id = "Test";
            string publication_id = rosSocket.Advertise <sensor_msgs.CompressedImage>("/test_image");

            Console.WriteLine("Press any key to start publication...");
            Console.ReadKey(true);
            for (int i = 0; i < 100000; i++)
            {
                image.header.seq += 1;
                image.data        = Enumerable.Repeat((byte)0x20, ImageDataSize).ToArray();
                rosSocket.Publish(publication_id, image);
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadKey(true);
            rosSocket.Unadvertise(publication_id);
            rosSocket.Close();
        }
コード例 #11
0
        private void rosSocketConnect()
        {
            // initialize
            foreach (ManualResetEvent manualResetEvent in status.Values)
            {
                manualResetEvent.Reset();
            }

            // connect to rosbrige_suite:
            RosBridgeClient.Protocols.IProtocol protocol = GetProtocol();
            RosSocket rosSocket = new RosSocket(protocol);

            CheckConnection(protocol);

            if (!status["connected"].WaitOne(0))
            {
                rosSocket.Close();
                return;
            }

            // setup urdfImporter
            RosBridgeClient.UrdfImporter urdfImporter = new RosBridgeClient.UrdfImporter(rosSocket, assetPath);
            status["robotNameReceived"]        = urdfImporter.Status["robotNameReceived"];
            status["robotDescriptionReceived"] = urdfImporter.Status["robotDescriptionReceived"];
            status["resourceFilesReceived"]    = urdfImporter.Status["resourceFilesReceived"];

            urdfImporter.Import();

            if (status["robotNameReceived"].WaitOne(timeout * 1000))
            {
                robotName      = urdfImporter.RobotName;
                localDirectory = urdfImporter.LocalDirectory;
            }

            // import URDF assets:
            if (status["resourceFilesReceived"].WaitOne(timeout * 1000))
            {
                Debug.Log("Imported urdf resources to " + urdfImporter.LocalDirectory);
            }
            else
            {
                Debug.LogWarning("Not all resource files have been received before timeout.");
            }

            status["disconnected"].Set();
            rosSocket.Close();
        }
コード例 #12
0
 public void Terminate()
 {
     /*
      * TERMINATE CLIENT
      */
     moveGroupActionClient.Terminate();
     rosSocket.Close();
 }
コード例 #13
0
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            if (_reader != null)
            {
                _reader.Dispose();
            }

            if (_sensor != null)
            {
                _sensor.Close();
            }
            rosSocket.Close();
        }
コード例 #14
0
        private void button13_Click(object sender, EventArgs e)
        {
            rosSocket.Unsubscribe(zm_robot_pose);
            rosSocket.Unsubscribe(zm_robot_vel);
            rosSocket.Unadvertise(zm_robot_vel_pub);

            thr_subscriber.Abort();

            rosSocket.Close();
            label20.Text     = "Disconection success.";
            button1.Enabled  = true;
            button13.Enabled = false;
            button14.Enabled = false;
        }
コード例 #15
0
        public static void Main(string[] args)
        {
            //RosSocket rosSocket = new RosSocket(new RosBridgeClient.Protocols.WebSocketSharpProtocol(uri));

            for (int i = 0; i < 2; i++)
            {
                RosSocket    rosSocket    = new RosSocket(new RosBridgeClient.Protocols.WebSocketNetProtocol(uri));
                UrdfImporter urdfImporter = new UrdfImporter(rosSocket, System.IO.Directory.GetCurrentDirectory().ToString());
                urdfImporter.Import();
                Console.WriteLine("Press any key to close...");
                Console.ReadKey(true);
                rosSocket.Close();
            }
        }
コード例 #16
0
        public static void Main(string[] args)
        {
            //RosSocket rosSocket = new RosSocket(new RosBridgeClient.Protocols.WebSocketSharpProtocol(uri));
            rosSocket = new RosSocket(new RosBridgeClient.Protocols.WebSocketNetProtocol(uri));

            // Initialize Client
            fibonacciActionClient = new FibonacciActionClient(actionName, rosSocket);
            fibonacciActionClient.Initialize();

            // Send goal
            Console.WriteLine("\nPress any key to send goal with fibonacci order 5...");
            Console.ReadKey(true);
            fibonacciActionClient.fibonacciOrder = 5;
            fibonacciActionClient.SendGoal();

            // Get feedback, status and result
            do
            {
                Console.WriteLine(fibonacciActionClient.GetFeedbackString());
                Console.WriteLine(fibonacciActionClient.GetStatusString());
                Thread.Sleep(100);
            } while (fibonacciActionClient.goalStatus.status != GoalStatus.SUCCEEDED);

            Thread.Sleep(500);
            Console.WriteLine(fibonacciActionClient.GetResultString());
            Console.WriteLine(fibonacciActionClient.GetStatusString());

            // Cancel goal
            Console.WriteLine("\nPress any key to send goal with fibonacci order 50...");
            Console.ReadKey(true);
            fibonacciActionClient.fibonacciOrder = 50;
            fibonacciActionClient.SendGoal();

            Console.WriteLine("\nPress any key to cancel the goal...");
            Console.ReadKey(true);
            fibonacciActionClient.CancelGoal();
            Thread.Sleep(1000);
            Console.WriteLine(fibonacciActionClient.GetResultString());
            Console.WriteLine(fibonacciActionClient.GetFeedbackString());
            Console.WriteLine(fibonacciActionClient.GetStatusString());

            // Terminate client
            fibonacciActionClient.Terminate();

            // End of console example
            Console.WriteLine("\nPress any key to close...");
            Console.ReadKey(true);
            rosSocket.Close();
        }
コード例 #17
0
        public void ShouldImportFilesDirectly()
        {
            string uri = "ws://localhost:9090";

            RosSharp.RosBridgeClient.Protocols.WebSocketNetProtocol webSocketNetProtocol = new RosSharp.RosBridgeClient.Protocols.WebSocketNetProtocol(uri);
            RosSocket rosSocket     = new RosSocket(webSocketNetProtocol);
            string    urdfParameter = "/robot_description";
            string    t             = JsonConvert.SerializeObject(rosSocket);

            // Publication:
            UrdfTransferFromRos urdfTransferFromRos = new UrdfTransferFromRos(rosSocket, System.IO.Directory.GetCurrentDirectory(), urdfParameter);

            //urdfTransferFromRos.Transfer();
            urdfTransferFromRos.RobotName = "UR3";
            urdfTransferFromRos.ImportResourceFiles(UrdfTests.Properties.Resources.xmlUr5);
            urdfTransferFromRos.Status["resourceFilesReceived"].WaitOne();
            Console.WriteLine("Resource Files received " + urdfTransferFromRos.FilesBeingProcessed.Count);

            rosSocket.Close();
        }
コード例 #18
0
        public static void Main(string[] args)
        {
            //string uri = "ws://localhost:9090";
            string uri = "ws://localhost:9090";

            Console.WriteLine($"Trying to connect to RosBridge via {uri}");

            try
            {
                for (int i = 1; i < 3; i++)
                {
                    RosBridgeClient.Protocols.WebSocketNetProtocol webSocketNetProtocol = new RosBridgeClient.Protocols.WebSocketNetProtocol(uri);
                    RosSocket rosSocket     = new RosSocket(webSocketNetProtocol);
                    string    urdfParameter = "/robot_description";

                    // Publication:
                    UrdfTransferFromRos urdfTransferFromRos = new UrdfTransferFromRos(rosSocket, System.IO.Directory.GetCurrentDirectory(), urdfParameter);
                    urdfTransferFromRos.Transfer();

                    urdfTransferFromRos.Status["robotNameReceived"].WaitOne();
                    Console.WriteLine("Robot Name Received: " + urdfTransferFromRos.RobotName);

                    urdfTransferFromRos.Status["robotDescriptionReceived"].WaitOne();
                    Console.WriteLine("Robot Description received... ");

                    urdfTransferFromRos.Status["resourceFilesReceived"].WaitOne();
                    Console.WriteLine("Resource Files received " + urdfTransferFromRos.FilesBeingProcessed.Count);

                    rosSocket.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to connect: {ex.Message}");
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadKey(true);
        }
コード例 #19
0
        internal void connect()
        {
            if (rosSocket != null)
            {
                rosSocket.Close();
                rosSocket = null;
            }

            rosWebSocketProtocol = new RosSharp.RosBridgeClient.Protocols.WebSocketUWPProtocol(uri);

            // Todo refactor the async connector.
            rosSocket    = new RosSocket(rosWebSocketProtocol);
            imageSubId   = rosSocket.Subscribe <sensor_msgs.Image>("/tracked_objects/image", SubscriptionHandler);
            logSubId     = rosSocket.Subscribe <rosgraph.Log>("/rosout", LogSubscriptionHandler);
            trackedSubId = rosSocket.Subscribe <DetectedObjectPose>("/detected_object", DetectedSubscriptionHandler);
            commandPubId = rosSocket.Advertise <std_msgs.RosInt32>("/goto");

            dispatcherTimer.Tick    += DispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(0, 0, 3);
            dispatcherTimer.Start();

            UpdateCurrentTask("Connected", "");
        }
コード例 #20
0
 public void TearDown()
 {
     RosSocket.Close();
 }
コード例 #21
0
 public void Stop()
 {
     socket.Close(millisecondsTimestep);
 }
コード例 #22
0
 void OnDestroy()
 {
     // Close ROS socket connection
     rosSocket.Close();
 }