Esempio n. 1
0
        /// <summary>
        /// Goes forward over the line until an endpoint. It will try to correct the position if it loses position.
        /// </summary>
        /// <param name="isForward"></param>
        private void followLine(bool isForward)
        {
            PositioningState prevState = PositioningState.Init;
            bool             isFlying  = true;
            Bitmap           bmp       = _controller.GetBitmapFromBottomCam();

            while (!CircleProcessor.Instance.IsCircleInCenter(bmp) && isFlying)//Go forward and correct until endpoint is found
            {
                PositioningState state = LineProcessor.Instance.ProcessLine(bmp);
                if (state != prevState)
                {
                    prevState = state;
                    isFlying  = _positioningHandler.HandlePositioningChange(state, prevState, isForward);
                }
                System.Threading.Thread.Sleep(10);
                bmp = _controller.GetBitmapFromBottomCam();
            }
            _controller.Hover();
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if the drone can detect the line when flying in the given direction for the given amount of maximum meters.
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="maxMeters"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        private bool findLine(DroneController controller, float maxMeters, FlyDirection direction)
        {
            float speed    = .1F / 3;
            float time     = maxMeters / speed * 200;
            float oldSpeed = controller.Speed;

            controller.Speed = speed;
            move(controller, direction);
            Stopwatch s = new Stopwatch();

            s.Start();
            bool lineDetected = false;

            while (!lineDetected && s.Elapsed < TimeSpan.FromMilliseconds(time))
            {
                Bitmap bmp = controller.GetBitmapFromBottomCam();
                lineDetected = LineProcessor.Instance.IsLineVisible(bmp);
            }
            controller.Speed = oldSpeed;
            s.Stop();
            return(lineDetected);
        }