示例#1
0
        /// <summary>
        /// Move around the green block (obstacle).
        /// </summary>
        protected void GoAroundBlock()
        {
            if (greenBlockState == GreenBlockState.InitialAproach)
            {
                if (IsObstacleSeen() && obstacleRectangle.Height < cameraDimensions.Y - (cameraDimensions.Y / 5))
                {
                    MoveForward(1, 1);
                }
                else if (IsObstacleSeen())
                {
                    greenBlockState = GreenBlockState.StrafeAround;
                }
                else
                {
                    trackingState = PredatorState.SearchingForPrey;
                }
            }
            else if (greenBlockState == GreenBlockState.StrafeAround)
            {
                if ((IsObstacleSeen() && obstacleRectangle.Width > 15))
                {
                    Strafe(4, strafingDirection);
                    lock (commandLock)
                    {
                        if (Odometry.LeftWheelTicks == 0 && Odometry.RearWheelTicks == 0 && Odometry.RightWheelTicks == 0)
                        {
                            odometryCount++;
                        }
                        else
                        {
                            odometryCount = 0;
                        }

                        if (odometryCount > 2)
                        {
                            MoveForward(4, -2);
                            strafingDirection = -strafingDirection;
                            greenBlockState   = GreenBlockState.InitialAproach;
                        }
                    }
                }
                else
                {
                    greenBlockState = GreenBlockState.MoveForwardSome;
                }
            }
            else if (greenBlockState == GreenBlockState.MoveForwardSome)
            {
                MoveForward(28, 1);
                greenBlockState = GreenBlockState.Rotate;
            }
            else if (greenBlockState == GreenBlockState.Rotate)
            {
                RotateByAngle(2, 2);
                greenBlockState = GreenBlockState.InitialAproach;
                trackingState   = PredatorState.SearchingForPrey;
            }
        }
示例#2
0
        /// <summary>
        /// Move around the green block (obstacle).
        /// </summary>
        protected void GoAroundBlock()
        {
            if (greenBlockState == GreenBlockState.InitialAproach)
            {
                if (IsObstacleSeen() && obstacleRectangle.Height < cameraDimensions.Y - (cameraDimensions.Y / 5))
                    MoveForward(1, 1);
                else if (IsObstacleSeen())
                    greenBlockState = GreenBlockState.StrafeAround;
                else
                    trackingState = PredatorState.SearchingForPrey;
            }
            else if (greenBlockState == GreenBlockState.StrafeAround)
            {
                if ((IsObstacleSeen() && obstacleRectangle.Width > 15))
                {
                    Strafe(4, strafingDirection);
                    lock (commandLock)
                    {
                        if (Odometry.LeftWheelTicks == 0 && Odometry.RearWheelTicks == 0 && Odometry.RightWheelTicks == 0)
                            odometryCount++;
                        else
                            odometryCount = 0;

                        if (odometryCount > 2)
                        {
                            MoveForward(4, -2);
                            strafingDirection = -strafingDirection;
                            greenBlockState = GreenBlockState.InitialAproach;
                        }
                    }
                }
                else
                    greenBlockState = GreenBlockState.MoveForwardSome;
            }
            else if (greenBlockState == GreenBlockState.MoveForwardSome)
            {
                MoveForward(28, 1);
                greenBlockState = GreenBlockState.Rotate;
            }
            else if (greenBlockState == GreenBlockState.Rotate)
            {
                RotateByAngle(2, 2);
                greenBlockState = GreenBlockState.InitialAproach;
                trackingState = PredatorState.SearchingForPrey;
            }
        }