Ejemplo n.º 1
0
        /// <summary>
        /// In case the drone is right or left or the line, the drone will fly in the opposite direction.
        /// Otherwise if theres a successor the successor will handle the positioning.
        /// </summary>
        /// <param name="newState"></param>
        /// <param name="oldState"></param>
        /// <param name="isForward"></param>
        /// <returns></returns>
        public override bool HandlePositioningChange(PositioningState newState, PositioningState oldState, bool isForward)
        {
            bool result = true;

            if (newState == PositioningState.Left || newState == PositioningState.Right)
            {
                float oldSpeed = controller.Speed;
                controller.Speed = 0.1F / 6; // Make the drone fly slower when it corrects itself
                                             //so that it will not go too far
                if (newState == PositioningState.Left)
                {
                    controller.Right();
                }
                else
                {
                    controller.Left();
                }
                controller.Speed = oldSpeed;
            }
            else if (successor != null)
            {
                result = successor.HandlePositioningChange(newState, oldState, isForward);
            }
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Converts a positioningstate to a corresponding direction
 /// </summary>
 /// <param name="state"></param>
 /// <param name="isForward"></param>
 /// <returns></returns>
 private FlyDirection getDirection(PositioningState state)
 {
     if (state == PositioningState.Left)
     {
         return(FlyDirection.Right);
     }
     else if (state == PositioningState.Right)
     {
         return(FlyDirection.Left);
     }
     else
     {
         return(FlyDirection.None);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// In case the positioningstate is lost, the drone will try to fly back in the opposite direction from
        /// where it came. If it's not lost and theres a successor, the successor will handle the positioning.
        /// </summary>
        /// <param name="newState"></param>
        /// <param name="oldState"></param>
        /// <param name="isForward"></param>
        /// <returns></returns>
        public override bool HandlePositioningChange(PositioningState newState, PositioningState oldState, bool isForward)
        {
            bool result = true;

            if (newState == PositioningState.Lost)
            {
                FlyDirection direction = getDirection(oldState);
                result = LineNavigator.Instance.FindLine(controller, 2, direction); //Try to find back the line
            }
            else if (successor != null)
            {
                result = successor.HandlePositioningChange(newState, oldState, isForward);
            }
            return(result);
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// In case the position is correct the drone will fly forwards or backwards
        /// If it's not correct the successor will handle the positioning.
        /// </summary>
        /// <param name="newState"></param>
        /// <param name="oldState"></param>
        /// <param name="isForward"></param>
        /// <returns></returns>
        public override bool HandlePositioningChange(PositioningState newState, PositioningState oldState, bool isForward)
        {
            bool result = true;

            if (newState == PositioningState.Correct)
            {
                if (isForward)
                {
                    controller.Forward();
                }
                else
                {
                    controller.Backward();
                }
            }
            else if (successor != null)
            {
                result = successor.HandlePositioningChange(newState, oldState, isForward);
            }
            return(result);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Implementations should control the drone based on the change and should return false if they land.
 /// If the drone is still flying it should return true.
 /// </summary>
 /// <param name="newState"></param>
 /// <param name="oldState"></param>
 /// <param name="isForward"></param>
 /// <returns></returns>
 public abstract bool HandlePositioningChange(PositioningState newState, PositioningState oldState, bool isForward);