public static void Main(string[] args)
        {
            //Create instance of RCL class which handles functions from rcl.h
            RCL rcl = new RCL();

            //Initialise RCL with default allocator
            rcl.Init(args);

            //Create an executor that will task our node
            Executor demoExecutor = new SingleThreadedExecutor();

            //Let the executor task all nodes with the given timespan
            demoExecutor.Spin(new TimeSpan(0, 0, 0, 0, 10));
            //Create a Node
            Node testNode = new Node("BasicNodeExample");

            //Add node to executor
            demoExecutor.AddNode(testNode);

            //Do some fancy stuff

            //Dispose the node so there won't be any unmanaged resources
            testNode.Dispose();
            //Remember to stop the executor - you could start it again afterwards
            demoExecutor.Cancel();
            //Dispose the rcl object - this will call rcl_shutdown
            rcl.Dispose();
        }
        public static void Main(string[] args)
        {
            //Create instance of RCL class which handles functions from rcl.h
            //RCL implements IDisposable so the using statement makes sure rcl_shutdown will be called after usages
            using (RCL rcl = new RCL()) {
                //Initialise RCL with default allocator
                rcl.Init(args);
                Console.WriteLine("RCL Init was successfull");
                //Create an executor that will task our node
                using (Executor demoExecutor = new SingleThreadedExecutor()) {
                    //Let the executor task all nodes with the given timespan
                    demoExecutor.Spin(new TimeSpan(0, 0, 0, 0, 10));
                    //Create a Node
                    using (Node testNode = new Node("BasicNodeExample")) {
                        Console.WriteLine("Creation of node was successfull");
                        //Add node to executor
                        demoExecutor.AddNode(testNode);

                        //Now do some fancy stuff

                        //Keeps app from closing instantly
                        Console.ReadKey();
                    }
                    Console.WriteLine("Disposed node");
                }
            }
            //rcl_shutdown gets called automatically
        }
示例#3
0
        public static void Main(string[] args)
        {
            //Create instance of RCL class which handles functions from rcl.h
            //RCL implements IDisposable so the using statement makes sure rcl_shutdown will be called after usages
            using (RCL rcl = new RCL()) {
                //Initialise RCL with default allocator
                rcl.Init(args);

                //Create an executor that will task our node
                Executor demoExecutor = new SingleThreadedExecutor();
                //Let the executor task all nodes with the given timespan
                demoExecutor.Spin(new TimeSpan(0, 0, 0, 0, 10));
                //Create a Node
                using (Node testNode = new Node("BasicNodeExample")) {
                    //Add node to executor
                    demoExecutor.AddNode(testNode);

                    //Now we're creating a publisher with the Dummy message
                    //TODO show alternative to Node.CreatePublisher<T>
                    using (Publisher <cs_msgs.msg.Dummy> testPublisher = testNode.CreatePublisher <cs_msgs.msg.Dummy> ("TestTopic")) {
                        //Create a message
                        using (cs_msgs.msg.Dummy testMsg = new cs_msgs.msg.Dummy()) {
                            //Fill the message fields
                            testMsg.thisafloat32 = 0.4f;
                            //Fill a string
                            testMsg.thisisastring = "TestString";
                            //Fill an array
                            testMsg.thisafloat32array = (new float[] { 1.3f, 100000.4f });
                            //Use a nested type
                            testMsg.thisisatime.sec = 100;
                            //And now publish the message
                            testPublisher.Publish(testMsg);
                            //Free unmanaged memory
                        }
                    }
                }
                //Remember to stop the executor - you could start it again afterwards
                demoExecutor.Cancel();
            }
            //rcl_shutdown gets called automatically
        }
示例#4
0
        public static void Main(string[] args)
        {
            //Create instance of RCL class which handles functions from rcl.h
            //RCL implements IDisposable so the using statement makes sure rcl_shutdown will be called after usages
            using (RCL rcl = new RCL()) {
                //Initialise RCL with default allocator
                rcl.Init(args);

                //Create an executor that will task our node
                Executor demoExecutor = new SingleThreadedExecutor();
                //Let the executor task all nodes with the given timespan
                demoExecutor.Spin(new TimeSpan(0, 0, 0, 0, 10));
                //Create a Node
                using (Node testNode = new Node("BasicNodeExample")) {
                    //Add node to executor
                    demoExecutor.AddNode(testNode);

                    //Create subscription on TestTopic
                    using (Subscription <cs_msgs.msg.Dummy> testSub = testNode.CreateSubscription <cs_msgs.msg.Dummy> ("TestTopic")) {
                        //Register on MessageRecieved event
                        testSub.MessageRecieved += (object sender, MessageRecievedEventArgs <cs_msgs.msg.Dummy> e) =>
                        {
                            //Simply print all message items
                            foreach (var item in e.Message.GetType().GetFields())
                            {
                                Console.Write(item.Name + "      :" + item.GetValue(e.Message));
                                Console.WriteLine();
                            }
                        };
                        //Call readkey so the program won't close instantly
                        Console.ReadKey();
                    }
                }
                //Remember to stop the executor - you could start it again afterwards
                demoExecutor.Cancel();
            }
            //rcl_shutdown gets called automatically
        }
示例#5
0
        public static void Main(string[] args)
        {
            //Create instance of RCL class which handles functions from rcl.h
            //RCL implements IDisposable so the using statement makes sure rcl_shutdown will be called after usages
            using (RCL rcl = new RCL()) {
                //Initialise RCL with default allocator
                rcl.Init(args);
                Console.WriteLine("RCL Init was successfull");
                //Create an executor that will task our node
                using (Executor demoExecutor = new SingleThreadedExecutor()) {
                    //Let the executor task all nodes with the given timespan
                    demoExecutor.Spin(new TimeSpan(0, 0, 0, 0, 10));
                    //Create a Node
                    using (Node testNode = new Node("BasicNodeExample")) {
                        Console.WriteLine("Creation of node was successfull");
                        //Add node to executor
                        demoExecutor.AddNode(testNode);

                        using (Client <cs_msgs.srv.DummySrv_Request, cs_msgs.srv.DummySrv_Response> DummyClient = new Client <cs_msgs.srv.DummySrv_Request, cs_msgs.srv.DummySrv_Response> (testNode, "TestService")) {
                            DummyClient.RecievedResponse += (object sender, ClientRecievedResponseEventArgs <cs_msgs.srv.DummySrv_Response> e) =>
                            {
                                Console.WriteLine("Dummy client recieved response");
                            };
                            using (cs_msgs.srv.DummySrv_Request testRequest = new cs_msgs.srv.DummySrv_Request()) {
                                testRequest.a = 10;
                                testRequest.b = 100;
                                DummyClient.SendRequest(testRequest);
                            }
                        }

                        //Keeps app from closing instantly
                        Console.ReadKey();
                    }
                    Console.WriteLine("Disposed node");
                }
            }
            //rcl_shutdown gets called automatically
        }
示例#6
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Init RCL");

            using (RCL rcl = new RCL()) {
                rcl.Init(args);


                Console.WriteLine("Creating node");
                using (Node test_node = new Node("test_node")) {
                    Console.WriteLine("Creating test publisher");
                    using (Publisher <cs_msgs.msg.Dummy> test_pub = new Publisher <cs_msgs.msg.Dummy> (test_node, "TestTopic", rmw_qos_profile_t.rmw_qos_profile_sensor_data)) {
                        Console.WriteLine("Creating test subscription");
                        Subscription <cs_msgs.msg.Dummy> test_subscription = test_node.CreateSubscription <cs_msgs.msg.Dummy> ("TestTopic", rmw_qos_profile_t.rmw_qos_profile_sensor_data);
                        test_subscription.MessageRecieved += (object sender, MessageRecievedEventArgs <cs_msgs.msg.Dummy> e) => {
                            Console.WriteLine("Recieved message on test topic: ");
                            foreach (var item in e.Message.GetType().GetProperties())
                            {
                                Console.Write(item.Name + "      :" + item.GetValue(e.Message));
                                Console.WriteLine();
                            }
                            Console.Write("Float32 Array: ");
                            foreach (var arritem in e.Message.thisafloat32array)
                            {
                                Console.Write(arritem + " ,");
                            }
                            Console.WriteLine();

                            Console.Write("Double Array: ");
                            foreach (var arritem in e.Message.thisisfloat64array)
                            {
                                Console.Write(arritem + " ,");
                            }
                            Console.WriteLine();

                            Console.Write("int8 Array: ");
                            foreach (var arritem in e.Message.thisisaint8array)
                            {
                                Console.Write(arritem + " ,");
                            }
                            Console.WriteLine();

                            Console.Write("string Array: ");
                            foreach (var arritem in e.Message.thisisastringarray)
                            {
                                Console.WriteLine(arritem + " ,");
                            }
                            Console.WriteLine();
                            Console.Write("fixed Array: ");
                            foreach (var arritem in e.Message.thisisafixedint16array)
                            {
                                Console.WriteLine(arritem + " ,");
                            }
                            Console.WriteLine();
                            Console.WriteLine("Seconds: " + e.Message.thisisatime.sec);
                        };
                        Console.WriteLine("Creating executor");
                        Executor executor = new SingleThreadedExecutor();
                        executor.AddNode(test_node);
                        Console.WriteLine("Spinning");
                        executor.Spin(new TimeSpan(0, 0, 0, 0, 10));
                        Console.WriteLine("Creating new test_msgs.Dummy");
                        using (cs_msgs.msg.Dummy test_msg = new cs_msgs.msg.Dummy()) {
                            test_msg.thisiauint8            = 10;
                            test_msg.thisisabool            = 1;
                            test_msg.thisisaint16           = 15;
                            test_msg.thisisfloat64          = 10.0f;
                            test_msg.thisisastring          = "test_test_test";
                            test_msg.thisisanotherstring    = "test2";
                            test_msg.thisafloat32array      = new float[] { 10.0f, 1.1f };
                            test_msg.thisisafixedint16array = new short[] { 10, 100, 5 };
                            test_msg.thisisastringarray     = (new string[] {
                                "test1",
                                "test2",
                                "test3"
                            });
                            test_msg.thisisaint8array   = (new byte[] { 100, 102, 200 });
                            test_msg.thisisfloat64array = new double[] { 10.4, 100.1, 100.10 };
                            test_msg.thisisatime.sec    = 10;

                            Console.WriteLine("Test seconds: " + test_msg.thisisatime.sec);
                            Console.WriteLine("Test_2 seconds: " + test_msg.Data.thisisatime.sec);
                            Console.WriteLine("Publishing message");
                            if (test_pub.Publish(test_msg))
                            {
                                Console.WriteLine("Publish was successfull");
                            }
                        }

                        /*Console.WriteLine ("####################################################");
                         * Console.WriteLine ("Creating service");
                         * Service<test_msgs.srv.DummySrv_Request,test_msgs.srv.DummySrv_Response> test_service = test_node.CreateService<test_msgs.srv.DummySrv_Request,test_msgs.srv.DummySrv_Response> ("TestService");
                         * test_service.RequestRecieved += (object sender, ServiceRecievedRequestEventArgs<test_msgs.srv.DummySrv_Request,test_msgs.srv.DummySrv_Response> e) => {
                         *      Console.WriteLine ("Recieved new request");
                         *      using(test_msgs.srv.DummySrv_Response response = new test_msgs.srv.DummySrv_Response())
                         *      {
                         *              response.sum = e.Request.a + e.Request.b;
                         *              e.SendResponseFunc(response);
                         *      }
                         *
                         * };
                         * Client<test_msgs.srv.DummySrv_Request,test_msgs.srv.DummySrv_Response> test_client = test_node.CreateClient<test_msgs.srv.DummySrv_Request,test_msgs.srv.DummySrv_Response> ("TestService");
                         * test_client.RecievedResponse += (object sender, ClientRecievedResponseEventArgs<test_msgs.srv.DummySrv_Response> e) => {
                         *      Console.WriteLine ("Client recived response : sum:  " + e.Response.sum);
                         * };
                         * using (test_msgs.srv.DummySrv_Request testRequest = new test_msgs.srv.DummySrv_Request ()) {
                         *      testRequest.a = 10;
                         *      testRequest.b = 100;
                         *      test_client.SendRequest (testRequest);
                         * }*/
                        Console.WriteLine("Press any key to exit");
                        Console.ReadKey();
                        executor.Cancel();
                    }
                }
            }
        }