public void AdvertiseAsync_MessageDispatcherSendAsyncShouldCalledWithAppropriateObject()
        {
            //arrange
            string testTopic  = "testTopic";
            string testType   = "testType";
            string uniqueId   = Guid.NewGuid().ToString();
            Task   resultTask = Task.Run(() => { });

            _messageDispatcherMock.Setup(dispatcher => dispatcher.GetNewUniqueID()).Returns(uniqueId);
            _rosMessageAttributeHelper.Setup(helper => helper.GetRosMessageTypeFromTypeAttribute(typeof(object)))
            .Returns(testType);
            _messageDispatcherMock.Setup(dispatcher => dispatcher.SendAsync(It.IsAny <RosAdvertiseMessage>())).Returns(resultTask);

            Publisher <object> testClass = new Publisher <object>(testTopic, _messageDispatcherMock.Object, _rosMessageAttributeHelper.Object);

            //act
            Task result = testClass.AdvertiseAsync();

            //assert
            result.Should().NotBeNull();
            result.Should().Be(resultTask);
            _messageDispatcherMock.Verify(dispatcher => dispatcher.SendAsync(It.Is <RosAdvertiseMessage>(message =>
                                                                                                         message.Id == uniqueId &&
                                                                                                         message.Topic == testTopic &&
                                                                                                         message.Type == testType)), Times.Once);
        }
        public async Task AdvertiseAsync_MessageDispatcherStarted_WebSocketShouldSendCorrectByteArray()
        {
            //arrange
            RosAdvertiseMessage rosAdvertiseMessage = new RosAdvertiseMessage()
            {
                Id    = _publisher._uniqueId,
                Topic = TOPIC,
                Type  = TYPE
            };

            byte[] serialized = _messageSerializer.Serialize(rosAdvertiseMessage);

            _clientWebSocketMock.SetupGet(clientWebSocket => clientWebSocket.State).Returns(WebSocketState.Open);

            await _messageDispatcher.StartAsync();

            //act
            await _publisher.AdvertiseAsync();

            //assert
            _clientWebSocketMock.Verify(clientWebSocket => clientWebSocket.SendAsync(
                                            It.Is <ArraySegment <byte> >(arraySegment => arraySegment.Array.SequenceEqual(serialized)),
                                            WebSocketMessageType.Text,
                                            true,
                                            _cancellationTokenSource.Token));
        }
Esempio n. 3
0
        public async Task landing()
        {
            if (md != null)
            {
                Publisher publisher = new Publisher("/bebop/land", "std_msgs/Empty", md);
                await publisher.AdvertiseAsync();

                var msg = JObject.Parse("{}");
                await publisher.PublishAsync(msg);

                //await publisher.UnadvertiseAsync();
                publisher = null;
            }
        }
Esempio n. 4
0
        public async Task ConnectAsync(Uri uri)
        {
            dispatcher = new MessageDispatcher(new Socket(uri), new MessageSerializerV2_0());
            await dispatcher.StartAsync();

            publisher_transition_goal =
                new Publisher("transition_controller/goal", "robot_controllers/TransitionActionGoal", dispatcher);
            await publisher_transition_goal.AdvertiseAsync();

            publisher_transition_cancel =
                new Publisher("transition_controller/cancel", "actionlib_msgs/GoalID", dispatcher);
            await publisher_transition_cancel.AdvertiseAsync();

            subscriber_transition_feedback =
                new Subscriber("transition_controller/feedback/", "robot_controllers/TransitionActionFeedback", dispatcher);
            subscriber_transition_feedback.MessageReceived += subscriber_transition_feedback_MessageReceived;
            await subscriber_transition_feedback.SubscribeAsync();
        }
Esempio n. 5
0
        public async Task navigate(Twist twist)
        {
            if (md != null)
            {
                if (navigatePub == null)
                {
                    navigatePub = new Publisher("/bebop/cmd_vel", "geometry_msgs/Twist", md);
                    await navigatePub.AdvertiseAsync();
                }

                //Publisher publisher = new Publisher("/bebop/cmd_vel", "geometry_msgs/Twist", md);
                //await publisher.AdvertiseAsync();
                await navigatePub.PublishAsync(twist);

                //await navigatePub.UnadvertiseAsync();
                //publisher = null;
            }
        }
Esempio n. 6
0
        private async void sendROSCommand(string action)
        {
            // compute angle relative to target.
            double width      = (double)cWidth;
            double height     = (double)cHeight;
            double faceWidth  = (double)faceW;
            double faceHeight = (double)faceH;

            double azimuth   = (hfov / 2) * (faceX + faceWidth / 2 - width / 2) / (width / 2);
            double elevation = -(vfov / 2) * (faceY + faceHeight / 2 - height / 2) / (height / 2);

            Console.WriteLine("Azimuth: " + azimuth);
            Console.WriteLine("Elevation: " + elevation);

            await publisher.AdvertiseAsync();

            await publisher.PublishAsync(new { x = azimuth, y = elevation, z = 3.2 });

            Console.Write(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> sent message");
        }
Esempio n. 7
0
        private async void ConfigureROSBridge()
        {
            // for Rosbridge

            // Start the message dispatcher
            md = new MessageDispatcher(new Rosbridge.Client.Socket(new Uri("ws://10.183.126.141:9090")), new MessageSerializerV2_0());
            await md.StartAsync();


            // Publish to a topic
            publisher = new Publisher("/balloonPosition", "geometry_msgs/Point32", md);
            await publisher.AdvertiseAsync();

            await publisher.PublishAsync(new { x = 2.2, y = 5.5, z = 3.2 });

            Console.Write(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> sent message");

            // Clean-up
            //await subscriber.UnsubscribeAsync();
            //await publisher.UnadvertiseAsync();
            //await md.StopAsync();
        }
Esempio n. 8
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            TopicLabel.Content = "Publish to \"" + _publisher.Topic.Replace("_", "__") + "\" (" + _publisher.Type.Replace("_", "__") + ")";

            await _publisher.AdvertiseAsync();
        }