Ejemplo n.º 1
0
        private void runDecisionThread(Point puckPosition)
        {
            ThreadPool.RunAsync((s) =>
            {
                Point malletOffset;

                if (gameMode == GameMode.Mirror || mirrorMode)
                {
                    // Mirror the puck
                    double yOffset = MotorHelper.GetOffsetYFromCoordinateX(virtualWidth - puckPosition.X);
                    double xOffset = MotorHelper.GetOffsetXFromCoordinateY(puckPosition.Y);

                    if (Math.Abs(xOffset - robot.StepperX.CurrentPosition) < 50)
                    {
                        xOffset = robot.StepperX.CurrentPosition;
                    }

                    if (Math.Abs(yOffset - robot.StepperY.CurrentPosition) < 50)
                    {
                        yOffset = robot.StepperY.CurrentPosition;
                    }

                    malletOffset = new Point(xOffset, yOffset); //MotorHelper.GetOffsetFromCoordinates(puckPosition);
                }
                else
                {
                    // Figure out where the mallet should move
                    malletOffset = robot.AI.calculateMalletTarget(puckPosition, Global.Stopwatch.ElapsedMilliseconds);
                }

                if (malletOffset != CoordinateHelper.INVALID_POINT)
                {
                    // Set the destination for stepper motors

                    if (!robot.AI.DoNotInterrupt)
                    {
                        switch (robot.AI.Move)
                        {
                        case MoveType.Fast:
                            robot.MoveFastToOffset(malletOffset);
                            break;

                        case MoveType.Straight:
                            robot.MoveStraightToOffset(malletOffset);
                            break;
                        }
                    }
                }
            });
        }