Esempio n. 1
0
        /// <summary>
        /// Waits for the ActionServer to connect to this client. Spins the callbacks.
        /// <seealso cref="WaitForActionServerToStart"/>
        /// </summary>
        public bool WaitForActionServerToStartSpinning(TimeSpan?timeout, SingleThreadSpinner spinner)
        {
            var tic = DateTime.UtcNow;

            while (ROS.OK)
            {
                if (IsServerConnected())
                {
                    return(true);
                }

                if (timeout != null)
                {
                    var toc = DateTime.UtcNow;
                    if (toc - tic > timeout)
                    {
                        return(false);
                    }
                }

                spinner.SpinOnce();
                Thread.Sleep(1);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Waits for the ActionServer to connect to this client. Spins the callbacks.
        /// <seealso cref="WaitForActionServerToStart"/>
        /// </summary>
        public bool WaitForActionServerToStartSpinning(TimeSpan?timeout, SingleThreadSpinner spinner)
        {
            var tic = DateTime.UtcNow;

            while (ROS.OK)
            {
                if (IsServerConnected())
                {
                    return(true);
                }

                if (timeout != null)
                {
                    var      toc     = DateTime.UtcNow;
                    TimeSpan elapsed = toc - tic;
                    if (elapsed > timeout)
                    {
                        break;
                    }
                }

                spinner.SpinOnce();
                Thread.Sleep(1);
            }

            return(CheckActionServerStatusAndLog());
        }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            ROS.Init(args, "Talker");
            var        spinner = new SingleThreadSpinner();
            NodeHandle node    = new NodeHandle();
            Publisher <std_msgs.String> Talker = node.Advertise <std_msgs.String>("/chatter", 1);
            int count = 0;

            while (ROS.OK && !Console.KeyAvailable)
            {
                Console.WriteLine("publishing message");
                ROS.Info()("Publishing a chatter message:    \"Blah blah blah " + count + "\"");
                String pow = new String("Blah blah blah " + (count++));

                Talker.Publish(pow);
                spinner.SpinOnce();
                Thread.Sleep(1000);
            }

            ROS.Shutdown();
        }
Esempio n. 4
0
        private void Start(int numberOfRuns)
        {
            NodeHandle clientNodeHandle = new NodeHandle();

            spinner = new SingleThreadSpinner(ROS.GlobalCallbackQueue);

            /*TestParams.Add(new TestParameters("Reject Goal", GoalStatus.REJECTED, 0, false, null));
            *  TestParams.Add(new TestParameters("Cancel not yet accepted goal", GoalStatus.RECALLED, 0, true, null));
            *  TestParams.Add(new TestParameters("Cancel accepted goal", GoalStatus.PREEMPTED, 0, true, null));
            *  TestParams.Add(new TestParameters("Abort Goal", GoalStatus.ABORTED, 100, false, null));*/
            TestParams.Add(new TestParameters("Get Result 123", GoalStatus.SUCCEEDED, 100, false, 123));
            var successfulTestCount = 0;
            var failedTestCount     = 0;

            Console.WriteLine("Create client");
            actionClient = new ActionClient <Messages.actionlib.TestGoal, Messages.actionlib.TestResult,
                                             Messages.actionlib.TestFeedback>("test_action", clientNodeHandle, 120);

            Console.WriteLine("Wait for client and server to negotiate connection");
            bool started = actionClient.WaitForActionServerToStartSpinning(new TimeSpan(0, 0, 3), spinner);

            var      sw        = Stopwatch.StartNew();
            DateTime?firstFail = null;
            var      startTime = DateTime.Now;

            for (int i = 0; i < numberOfRuns; i++)
            {
                bool testError = false;
                if (started)
                {
                    Console.WriteLine("Server connected, start tests");
                    foreach (var parameter in TestParams)
                    {
                        if (!TestCase(parameter.Name, parameter.ExpectedState, parameter.ExpectedFeedback,
                                      parameter.CancelGoal, parameter.ExpectedGoal))
                        {
                            testError = true;
                            if (firstFail == null)
                            {
                                firstFail = DateTime.Now;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    ROS.Error()("Could not connect to server");
                    testError = true;
                }

                if (testError)
                {
                    ROS.Error()("Errors ocured during testing!");
                    failedTestCount++;
                }
                else
                {
                    successfulTestCount++;
                    ROS.Info()("Testbed completed successfully");
                }
            }

            Console.WriteLine("-----------");
            Console.WriteLine($"Test took {sw.Elapsed} StartTime: {startTime} Goals/s {numberOfRuns / sw.Elapsed.TotalSeconds}");
            Console.WriteLine($"Successful: {successfulTestCount} Failed: {failedTestCount} FirstFail: {firstFail}");
            Console.WriteLine("All done, press any key to exit");
            Console.WriteLine("-----------");

            while (!Console.KeyAvailable)
            {
                Thread.Sleep(1);
            }

            Console.WriteLine("Shutdown client");
            actionClient.Shutdown();
            clientNodeHandle.shutdown();
        }