コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: rvlietstra/ROS.NET
         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();
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: rvlietstra/ROS.NET
         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();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: wiwing/ROS.NET
 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);
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: wijanarko-sukma/ROS.NET
 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);
 }