Exemplo n.º 1
0
        public void KeyInputIsSentAfterHandsInput_KeyInputIsNotIgnored()
        {
            var skinColorHandsDetectorMock = new Mock <ISkinColorHandsDetector>();

            skinColorHandsDetectorMock.Setup(schd => schd.Tuned).Returns(true);

            var left  = new NormalizedHand(0.15, 0.2, 0.18);
            var right = new NormalizedHand(0.85, 0.2, 0.18);
            var hands = new NormalizedHands(left, right);
            var handsDetectorResult = new HandsDetectorResult(hands, null);

            skinColorHandsDetectorMock.Setup(schd => schd.DetectHands(It.IsAny <BgrImage>()))
            .Returns(handsDetectorResult);

            var keyInputEvaluator   = new GeneralDroneKeyInputEvaluator();
            var handsInputEvaluator = new DroneControllerHandsInputEvaluator();
            var neutralLeft         = new NormalizedHand(0.15, 0.5, 0.18);
            var neutralRight        = new NormalizedHand(0.85, 0.5, 0.18);
            var neutralHands        = new NormalizedHands(neutralLeft, neutralRight);

            handsInputEvaluator.Tune(neutralHands);

            this.caduhdApp = new CaduhdApp(null, skinColorHandsDetectorMock.Object, this.tello, keyInputEvaluator, handsInputEvaluator);

            this.caduhdApp.Input(BgrImage.GetBlank(1, 1, Color.Black));
            this.udpClient.Client.ReceiveTimeout = 1000;

            string response          = string.Empty;
            bool   handsInputIgnored = false;

            try
            {
                response = this.udpClient.Receive(ref this.anyEndPoint).AsString();
                Assert.Equal($"rc 0 0 {this.tello.Speed} 0", response);
            }
            catch (SocketException)
            {
            }

            this.caduhdApp.Input(new KeyInfo(Key.D, KeyState.Down));

            try
            {
                response = this.udpClient.Receive(ref this.anyEndPoint).AsString();
            }
            catch (SocketException e)
            {
                if (e.SocketErrorCode == SocketError.TimedOut)
                {
                    handsInputIgnored = true;
                }
            }

            this.tello.Dispose();
            Assert.False(handsInputIgnored);
            Assert.Equal($"rc 0 0 0 {this.tello.Speed}", response);
        }
Exemplo n.º 2
0
        public void DifferentHandsInputsAfterEachOther_BothSent()
        {
            var skinColorHandsDetectorMock = new Mock <ISkinColorHandsDetector>();

            skinColorHandsDetectorMock.Setup(schd => schd.Tuned).Returns(true);

            var firstLeft  = new NormalizedHand(0.15, 0.2, 0.18);
            var firstRight = new NormalizedHand(0.85, 0.2, 0.18);
            var firstHands = new NormalizedHands(firstLeft, firstRight);
            var firstHandsDetectorResult = new HandsDetectorResult(firstHands, null);

            var secondLeft  = new NormalizedHand(0.15, 0.8, 0.18);
            var secondRight = new NormalizedHand(0.85, 0.7, 0.18);
            var secondHands = new NormalizedHands(secondLeft, secondRight);
            var secondandsDetectorResult = new HandsDetectorResult(secondHands, null);

            skinColorHandsDetectorMock.SetupSequence(schd => schd.DetectHands(It.IsAny <BgrImage>()))
            .Returns(firstHandsDetectorResult)
            .Returns(secondandsDetectorResult);

            var keyInputEvaluator   = new GeneralDroneKeyInputEvaluator();
            var handsInputEvaluator = new DroneControllerHandsInputEvaluator();
            var neutralLeft         = new NormalizedHand(0.15, 0.5, 0.18);
            var neutralRight        = new NormalizedHand(0.85, 0.5, 0.18);
            var neutralHands        = new NormalizedHands(neutralLeft, neutralRight);

            handsInputEvaluator.Tune(neutralHands);

            this.caduhdApp = new CaduhdApp(null, skinColorHandsDetectorMock.Object, this.tello, keyInputEvaluator, handsInputEvaluator);

            this.caduhdApp.Input(BgrImage.GetBlank(1, 1, Color.Black));
            this.caduhdApp.Input(BgrImage.GetBlank(1, 1, Color.Black));

            this.udpClient.Client.ReceiveTimeout = 1000;
            int counter = 0;

            try
            {
                string response = this.udpClient.Receive(ref this.anyEndPoint).AsString();
                Assert.Equal($"rc 0 0 {this.tello.Speed} 0", response);
                counter++;
                response = this.udpClient.Receive(ref this.anyEndPoint).AsString();
                Assert.Equal($"rc 0 0 -{this.tello.Speed} 0", response);
                counter++;
            }
            catch (SocketException)
            {
            }

            this.tello.Dispose();
            Assert.Equal(2, counter);
        }
Exemplo n.º 3
0
        public void HandsInputAnalyzerTuned_HandsInput_MoveDownwards_HandsInputEvaluated_CorrectMoveCommandSent()
        {
            var skinColorHandsDetectorMock = new Mock <ISkinColorHandsDetector>();

            skinColorHandsDetectorMock.Setup(schd => schd.Tuned).Returns(true);

            var neutralLeft  = new NormalizedHand(0.15, 0.5, 0.18);
            var neutralRight = new NormalizedHand(0.85, 0.5, 0.18);
            var neutralHands = new NormalizedHands(neutralLeft, neutralRight);

            var left  = new NormalizedHand(0.15, 0.8, 0.18);
            var right = new NormalizedHand(0.85, 0.8, 0.18);
            var hands = new NormalizedHands(left, right);
            var handsDetectorResult = new HandsDetectorResult(hands, null);

            skinColorHandsDetectorMock.Setup(schd => schd.DetectHands(It.IsAny <BgrImage>()))
            .Returns(handsDetectorResult);

            var keyInputEvaluator   = new GeneralDroneKeyInputEvaluator();
            var handsInputEvaluator = new DroneControllerHandsInputEvaluator();

            handsInputEvaluator.Tune(neutralHands);

            this.caduhdApp = new CaduhdApp(null, skinColorHandsDetectorMock.Object, this.tello, keyInputEvaluator, handsInputEvaluator);

            string response = string.Empty;

            this.caduhdApp.Input(BgrImage.GetBlank(1, 1, Color.Black));

            try
            {
                response = this.udpClient.Receive(ref this.anyEndPoint).AsString();
            }
            catch (SocketException)
            {
            }

            // it needs to be disposed of here
            this.tello.Dispose();

            Assert.Equal($"rc 0 0 -{this.tello.Speed} 0", response);
        }