Example #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ROS.ROS_MASTER_URI = "http://10.0.2.88:11311";
            ROS.ROS_HOSTNAME   = "10.0.2.152";
            ROS.Init(new string[0], NODE_NAME);

            nodeHandle = new NodeHandle();

            //server = nodeHandle.advertiseService<Messages.roscpp_tutorials.TwoInts, Messages.roscpp_tutorials.TwoInts.Request, Messages.roscpp_tutorials.TwoInts.Response>("/add_two_ints", addition);
            client = nodeHandle.serviceClient <Messages.roscpp_tutorials.TwoInts.Request, Messages.roscpp_tutorials.TwoInts.Response>("/add_two_ints");

            new Thread(new ThreadStart(() =>
            {
                Random r = new Random();
                while (!ROS.shutting_down)
                {
                    TwoInts.Request req = new TwoInts.Request()
                    {
                        a = r.Next(100), b = r.Next(100)
                    };
                    TwoInts.Response resp = new TwoInts.Response();
                    if (client.call(req, ref resp))
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            math.Content = "" + req.a + " + " + req.b + " = " + resp.sum;
                        }));
                    }
                    Thread.Sleep(500);
                }
            })).Start();
        }
Example #2
0
         private void Window_Loaded(object sender, RoutedEventArgs e) 
         {
            ROS.Init(new string[0], NODE_NAME+DateTime.Now.Ticks);

            nodeHandle = new NodeHandle();

            new Thread(new ThreadStart(() =>
                {
                    Random r = new Random();
                    while (ROS.ok)
                    {
                        TwoInts.Request req = new TwoInts.Request() { a = r.Next(100), b = r.Next(100) };
                        TwoInts.Response resp = new TwoInts.Response();
                        DateTime before = DateTime.Now;
                        bool res = nodeHandle.serviceClient<TwoInts.Request, TwoInts.Response>("/add_two_ints").call(req, ref resp);
                        TimeSpan dif = DateTime.Now.Subtract(before);
                            Dispatcher.Invoke(new Action(() =>
                                {
                                    string str = "";
                                    if (res)
                                        str = "" + req.a + " + " + req.b + " = " + resp.sum + "\n";
                                    else
                                        str = "call failed after\n";
                                    str += Math.Round(dif.TotalMilliseconds,2) + " ms";
                                    math.Content = str;
                                }));
                        Thread.Sleep(500);
                    }
                })).Start();
        }
Example #3
0
         private void Window_Loaded(object sender, RoutedEventArgs e) 
         {
            ROS.ROS_MASTER_URI = "http://10.0.2.88:11311";
            ROS.ROS_HOSTNAME = "10.0.2.152";
            ROS.Init(new string[0], NODE_NAME);

            nodeHandle = new NodeHandle();

            //server = nodeHandle.advertiseService<Messages.roscpp_tutorials.TwoInts, Messages.roscpp_tutorials.TwoInts.Request, Messages.roscpp_tutorials.TwoInts.Response>("/add_two_ints", addition);
            client = nodeHandle.serviceClient<Messages.roscpp_tutorials.TwoInts.Request, Messages.roscpp_tutorials.TwoInts.Response>("/add_two_ints");

            new Thread(new ThreadStart(() =>
                {
                    Random r = new Random();
                    while (!ROS.shutting_down)
                    {
                        TwoInts.Request req = new TwoInts.Request() { a = r.Next(100), b = r.Next(100) };
                        TwoInts.Response resp = new TwoInts.Response();
                        if (client.call(req, ref resp))
                            Dispatcher.Invoke(new Action(() =>
                                {
                                    math.Content = "" + req.a + " + " + req.b + " = " + resp.sum;
                                }));
                        Thread.Sleep(500);
                    }
                })).Start();
        }
Example #4
0
 private static bool addition(TwoInts.Request req, ref TwoInts.Response resp)
 {
     Logger.LogInformation("[ServiceServerSample] addition callback");
     resp.sum = req.a + req.b;
     Logger.LogInformation(req.ToString());
     Logger.LogInformation(resp.sum.ToString());
     return(true);
 }
Example #5
0
 private static bool addition(TwoInts.Request req, ref TwoInts.Response resp)
 {
     ROS.Info()("[ServiceServerSample] addition callback");
     resp.sum = req.a + req.b;
     ROS.Info()(req.ToString());
     ROS.Info()(resp.sum.ToString());
     return(true);
 }
Example #6
0
        static void Main(string[] args)
        {
            string NODE_NAME = "ServiceClientTest";

            try
            {
                ROS.Init(ref args, NODE_NAME + DateTime.Now.Ticks);
                var spinner = new AsyncSpinner();
                spinner.Start();
            }
            catch (RosException e)
            {
                ROS.Critical()("ROS.Init failed, shutting down: {0}", e.Message);
                ROS.shutdown();
                ROS.waitForShutdown();
                return;
            }

            try
            {
                var nodeHandle = new NodeHandle();
                while (ROS.ok)
                {
                    Random          r   = new Random();
                    TwoInts.Request req = new TwoInts.Request()
                    {
                        a = r.Next(100), b = r.Next(100)
                    };
                    TwoInts.Response resp   = new TwoInts.Response();
                    DateTime         before = DateTime.Now;
                    bool             res    = nodeHandle.serviceClient <TwoInts.Request, TwoInts.Response>("/add_two_ints").call(req, ref resp);
                    TimeSpan         dif    = DateTime.Now.Subtract(before);

                    string str = "";
                    if (res)
                    {
                        str = "" + req.a + " + " + req.b + " = " + resp.sum + "\n";
                    }
                    else
                    {
                        str = "call failed after ";
                    }

                    str += Math.Round(dif.TotalMilliseconds, 2) + " ms";
                    ROS.Info()(str);
                    Thread.Sleep(1000);
                }
            }
            catch (RosException e)
            {
                ROS.Critical()("Shutting down: {0}", e.Message);
            }

            ROS.shutdown();
            ROS.waitForShutdown();
        }
Example #7
0
        private bool addition(TwoInts.Request req, ref TwoInts.Response resp)
        {
            resp.sum = req.a + req.b;
            long sum = resp.sum;

            //Dispatcher.BeginInvoke(new Action(() =>
            //{
            //    math.Content = "" + req.a + " + " + req.b + " = ??\n" + sum;
            //}));
            return(true);
        }
Example #8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ROS.Init(new string[0], NODE_NAME + DateTime.Now.Ticks);

            nodeHandle = new NodeHandle();

            new Thread(new ThreadStart(() =>
            {
                Random r = new Random();
                while (ROS.ok)
                {
                    TwoInts.Request req = new TwoInts.Request()
                    {
                        a = r.Next(100), b = r.Next(100)
                    };
                    TwoInts.Response resp = new TwoInts.Response();
                    DateTime before       = DateTime.Now;
                    bool res     = nodeHandle.serviceClient <TwoInts.Request, TwoInts.Response>("/add_two_ints").call(req, ref resp);
                    TimeSpan dif = DateTime.Now.Subtract(before);
                    Dispatcher.Invoke(new Action(() =>
                    {
                        string str = "";
                        if (res)
                        {
                            str = "" + req.a + " + " + req.b + " = " + resp.sum + "\n";
                        }
                        else
                        {
                            str = "call failed after\n";
                        }
                        str         += Math.Round(dif.TotalMilliseconds, 2) + " ms";
                        math.Content = str;
                    }));
                    Thread.Sleep(500);
                }
            })).Start();
        }
Example #9
0
        static void Main(string[] args)
        {
            string NODE_NAME = "ServiceClientTest";

            var loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(
                new ConsoleLoggerProvider(
                    (string text, LogLevel logLevel) => { return(logLevel >= LogLevel.Debug); }, true)
                );
            Logger = ApplicationLogging.CreateLogger(nameof(Main));
            ROS.SetLoggerFactory(loggerFactory);


            try
            {
                ROS.Init(new string[0], NODE_NAME + DateTime.Now.Ticks);
            }
            catch (RosException e)
            {
                Logger.LogCritical("ROS.Init failed, shutting down: {0}", e.Message);
                ROS.shutdown();
                ROS.waitForShutdown();
                return;
            }

            try
            {
                var nodeHandle = new NodeHandle();
                while (ROS.ok)
                {
                    Random          r   = new Random();
                    TwoInts.Request req = new TwoInts.Request()
                    {
                        a = r.Next(100), b = r.Next(100)
                    };
                    TwoInts.Response resp   = new TwoInts.Response();
                    DateTime         before = DateTime.Now;
                    bool             res    = nodeHandle.serviceClient <TwoInts.Request, TwoInts.Response>("/add_two_ints").call(req, ref resp);
                    TimeSpan         dif    = DateTime.Now.Subtract(before);

                    string str = "";
                    if (res)
                    {
                        str = "" + req.a + " + " + req.b + " = " + resp.sum + "\n";
                    }
                    else
                    {
                        str = "call failed after ";
                    }

                    str += Math.Round(dif.TotalMilliseconds, 2) + " ms";
                    Logger.LogInformation(str);
                    Thread.Sleep(1000);
                }
            }
            catch (RosException e)
            {
                Logger.LogCritical("Shutting down: {0}", e.Message);
            }

            ROS.shutdown();
            ROS.waitForShutdown();
        }