Beispiel #1
0
        private async Task MakePicture()
        {
            Title.Text = "Detecting...";
            StorageFile filePath = await TakePhoto();

            FaceRectangle[] faceRects = await UploadAndDetectFaces(filePath);

            Title.Text = String.Format("Detection Finished. {0} face(s) detected", faceRects.Length);

            if (faceRects.Length > 0)
            {
                var maxRes = await USBCam.GetPictureRes();

                //move left if face too right and vice versa
                // need to have the rectangle centered, in a good proportion
                // proportion can be X% left and right of what is left
                // only use the first face detected
                int    fWidth             = faceRects[0].Width;
                int    fLeft              = faceRects[0].Left;
                int    iWidth             = (int)maxRes.Width;
                double percent            = 0.20;
                int    degreesperRotation = 4;

                if ((fLeft < (iWidth * percent)) && ((fLeft + fWidth) < iWidth * (1 - percent)))
                {
                    // 360° = 1 turn of motor = 90° real turn
                    // using a simple projection for the math
                    robot.TurnLeft(150, GetAngleToTurn(fLeft, iWidth, percent) * degreesperRotation);
                }
                else if (((fLeft + fWidth) > (iWidth * (1 - percent))) && (fLeft > (iWidth * percent)))
                {
                    robot.TurnRight(150, GetAngleToTurn(iWidth - (fLeft + fWidth), iWidth, percent) * degreesperRotation);
                }
            }
        }
Beispiel #2
0
        private async Task TestVehicule()
        {
            Vehicule veh = new Vehicule(BrickPortMotor.PORT_B, BrickPortMotor.PORT_C);

            veh.DirectionOpposite = true;
            veh.Backward(30, 5000);
            veh.Foreward(30, 5000);
            veh.TrunLeftTime(30, 5000);
            veh.TrunRightTime(30, 5000);
            veh.TurnLeft(30, 180);
            veh.TurnRight(30, 180);
        }