예제 #1
0
        public static IBallControlStrategy ContinuousBouncing(int duration, ITiltController tiltController,
                                                              float lowPos = 0.5f, float highPos = 0.6f, float moveTime = 0.1f, Action action = null)
        {
            return(new BallControlStrategy((ballData, machineController, instructionCount) =>
            {
                if (ballData.CurrentPositionVector.z < 150f)
                {
                    var tilt = tiltController.CalculateTilt(
                        ballData.CurrentPositionVector,
                        ballData.CurrentVelocityVector,
                        Vector2.zero,
                        ballData.CalculatedOnBounceDownwardsVelocity,
                        ballData.AirborneTime
                        );

                    var xCorrection = Mathf.Clamp(tilt.xTilt, c.MinTiltAngle, c.MaxTiltAngle);
                    var yCorrection = Mathf.Clamp(tilt.yTilt, c.MinTiltAngle, c.MaxTiltAngle);

                    machineController.SendInstructions(new List <HLInstruction>()
                    {
                        new HLInstruction(0.06f, xCorrection, yCorrection, moveTime),
                        new HLInstruction(0.05f, 0f, 0f, moveTime),
                    });

                    return true;
                }

                return false;
            }, duration, onStrategyExecutionStart: action));
        }
예제 #2
0
        public static IBallControlStrategy Balancing(float height, int duration, Vector2 target,
                                                     ITiltController tiltController)
        {
            return(new BallControlStrategy((ballData, machineController, instructionCount) =>
            {
                if (ballData.CurrentPositionVector.z < float.MaxValue)
                {
                    var tilt = tiltController.CalculateTilt(
                        ballData.CurrentPositionVector,
                        new Vector2(ballData.CurrentVelocityVector.x, ballData.CurrentVelocityVector.y),
                        target,
                        ballData.CalculatedOnBounceDownwardsVelocity,
                        ballData.AirborneTime);

                    var xCorrection = Mathf.Clamp(tilt.xTilt, c.MinTiltAngle, c.MaxTiltAngle);
                    var yCorrection = Mathf.Clamp(tilt.yTilt, c.MinTiltAngle, c.MaxTiltAngle);

                    var moveTime = 0.1f;
                    machineController.SendInstructions(new List <HLInstruction>()
                    {
                        new HLInstruction(height, xCorrection, yCorrection, moveTime),
                    });

                    return true;
                }

                return false;
            }, duration));
        }
        // NOTE: Duration needs to be a multiple of 2 since both the upwards motion and the downwards motion
        //       count as 1 instructionSent
        public static IBallControlStrategy TwoStepBouncing(int duration, ITiltController tiltController,
                                                           Vector2?target = null, float lowPos = 0.05f, float highPos = 0.058f, float moveTime = 0.1f,
                                                           Action action  = null)
        {
            var currentPositionIsUp = false;

            return(new BallControlStrategy((ballData, machineController, instructionCount) =>
            {
                if (!ballData.BallIsMovingUp && ballData.CurrentPositionVector.z < 140f && !currentPositionIsUp)
                {
                    // if we're in here, the ball is coming downwards

                    BallControlling.MoveToHeightWithAlternatingXYTiltCorrection(machineController, tiltController,
                                                                                ballData, highPos, moveTime, instructionCount, target);

                    currentPositionIsUp = true;
                    return true;
                }

                if (ballData.BallIsMovingUp && currentPositionIsUp)
                {
                    // if we're in here, the ball is moving upwards
                    // so if the ball IS moving up, and the last thing we did was hitting the ball, then we should move down again

                    BallControlling.MoveToHeightWithAlternatingXYTiltCorrection(machineController, tiltController,
                                                                                ballData, lowPos, moveTime, instructionCount, target);

                    currentPositionIsUp = false;
                    return true;
                }

                // instructionSent: false
                return false;
            }, duration, true, onStrategyExecutionStart: action));
        }
예제 #4
0
 public DeviceController(IMotorController motorController, IHallEffectController hallEffectController, IObjectDetectionController objectDetectionController, ITiltController tiltController, ITofController tofController, IButtonController buttonController)
 {
     this.motorController           = motorController;
     this.hallEffectController      = hallEffectController;
     this.objectDetectionController = objectDetectionController;
     this.tiltController            = tiltController;
     this.tofController             = tofController;
     this.buttonController          = buttonController;
 }
        public static IBallControlStrategy StepBouncing_Up(ITiltController tiltController,
                                                           Vector2?target = null, float highPos = 0.058f, float moveTime = 0.1f,
                                                           Action action  = null)
        {
            return(new BallControlStrategy((ballData, machineController, instructionCount) =>
            {
                if (!ballData.BallIsMovingUp && ballData.CurrentPositionVector.z < 140f)
                {
                    // if we're in here, the ball is coming downwards
                    BallControlling.MoveToHeightWithXYTiltCorrection(machineController, tiltController,
                                                                     ballData, highPos, moveTime, target);

                    return true;
                }
                return false;
            }, 1, true, onStrategyExecutionStart: action));
        }
        public static IBallControlStrategy StepBouncing_Down(ITiltController tiltController,
                                                             Vector2?target = null, float lowPos = 0.05f, float moveTime = 0.1f,
                                                             Action action  = null)
        {
            return(new BallControlStrategy((ballData, machineController, instructionCount) =>
            {
                if (ballData.BallIsMovingUp)
                {
                    // if we're in here, the ball is moving upwards
                    // so if the ball IS moving up, and the last thing we did was hitting the ball, then we should move down again
                    BallControlling.MoveToHeightWithXYTiltCorrection(machineController, tiltController,
                                                                     ballData, lowPos, moveTime, target);

                    return true;
                }
                return false;
            }, 1, true, onStrategyExecutionStart: action));
        }
        public static void MoveToHeightWithXYTiltCorrection(MachineController machineController,
                                                            ITiltController tiltController, BallData ballData, float height, float moveTime,
                                                            Vector2?target)
        {
            var tilt = tiltController.CalculateTilt(
                new Vector2(ballData.CurrentPositionVector.x, ballData.CurrentPositionVector.y),
                new Vector2(ballData.CurrentVelocityVector.x, ballData.CurrentVelocityVector.y),
                target ?? Vector2.zero,
                ballData.CalculatedOnBounceDownwardsVelocity,
                ballData.AirborneTime);

            var xCorrection = Mathf.Clamp(tilt.xTilt, c.MinTiltAngle, c.MaxTiltAngle);
            var yCorrection = Mathf.Clamp(tilt.yTilt, c.MinTiltAngle, c.MaxTiltAngle);

            machineController.SendInstructions(new List <HLInstruction>()
            {
                new HLInstruction(height, xCorrection, yCorrection, moveTime),
            });
        }
예제 #8
0
        public static IBallControlStrategy Continuous2StepBouncing(int duration, ITiltController tiltController,
                                                                   Vector2?target = null, float lowPos = 0.05f, float highPos = 0.058f, float moveTime = 0.1f)
        {
            var currentPositionIsUp = false;

            return(new BallControlStrategy((ballData, machineController, instructionCount) =>
            {
                if (!ballData.BallIsMovingUp && ballData.CurrentPositionVector.z < 140f && !currentPositionIsUp)
                {
                    // if we're in here, the ball is coming downwards

                    var tilt = tiltController.CalculateTilt(
                        new Vector2(ballData.CurrentPositionVector.x, ballData.CurrentPositionVector.y),
                        new Vector2(ballData.CurrentVelocityVector.x, ballData.CurrentVelocityVector.y),
                        target ?? Vector2.zero,
                        ballData.CalculatedOnBounceDownwardsVelocity,
                        ballData.AirborneTime);

                    var xCorrection = instructionCount % 2 == 1
                        ? Mathf.Clamp(tilt.xTilt, c.MinTiltAngle, c.MaxTiltAngle)
                        : 0f;
                    var yCorrection = instructionCount % 2 == 0
                        ? Mathf.Clamp(tilt.yTilt, c.MinTiltAngle, c.MaxTiltAngle)
                        : 0f;

                    machineController.SendInstructions(new List <HLInstruction>()
                    {
                        new HLInstruction(highPos, xCorrection, yCorrection, moveTime),
                    });

                    currentPositionIsUp = true;
                    // instructionSent: true
                    return true;
                }

                if (ballData.BallIsMovingUp && currentPositionIsUp)
                {
                    // if we're in here, the ball is moving upwards
                    // so if the ball IS moving up, and the last thing we did was hitting the ball, then we should move down again

                    var tilt = tiltController.CalculateTilt(
                        ballData.PredictedPositionVectorOnHit,
                        new Vector2(ballData.CurrentVelocityVector.x, ballData.CurrentVelocityVector.y),
                        target ?? Vector2.zero,
                        ballData.CalculatedOnBounceDownwardsVelocity,
                        ballData.AirborneTime);

                    var xCorrection = instructionCount % 2 == 1
                        ? Mathf.Clamp(tilt.xTilt, c.MinTiltAngle, c.MaxTiltAngle)
                        : 0f;
                    var yCorrection = instructionCount % 2 == 0
                        ? Mathf.Clamp(tilt.yTilt, c.MinTiltAngle, c.MaxTiltAngle)
                        : 0f;

                    machineController.SendInstructions(new List <HLInstruction>()
                    {
                        new HLInstruction(lowPos, xCorrection, yCorrection, moveTime),
                    });

                    currentPositionIsUp = false;
                    // instructionSent: false (even though we DID send a instruction.
                    // This is because we don't want to count this instruction as a bounce instruction)
                    return false;
                }

                // instructionSent: false
                return false;
            }, duration, true));
        }
예제 #9
0
 // stable bouncing with low height
 public static IBallControlStrategy Continuous2StepBouncingLow(int duration, ITiltController tiltController)
 {
     return(Continuous2StepBouncing(duration, tiltController, null, 0.05f, 0.055f, 0.06f));
 }
 // TODO: fix this ControlStrategy. Bouncing isn't stable.
 public static IBallControlStrategy TwoStepBouncingLow(int duration,
                                                       ITiltController tiltController, Vector2?target, Action action = null)
 {
     return(TwoStepBouncing(duration, tiltController, target, 0.05f, 0.054f, 0.07f, action));
 }