Example #1
0
        public MainLogicProcessor()
        {
            VisionData = new VisionData();
            SensorData = new SensorData();

            stateMachine = new StateMachine<State, Trigger>(State.LookingForBall);

            stateMachine.Configure(State.LookingForBall)
                .Permit(Trigger.CameraLockedOnBall, State.ClosingInOnBall)
                .Permit(Trigger.BallCaught, State.FindingGoal)
                .OnEntry(StopTimer);

            stateMachine.Configure(State.ClosingInOnBall)
                .Permit(Trigger.CameraLostBall, State.LookingForBall)
                .Permit(Trigger.BallCaught, State.FindingGoal)
                .Permit(Trigger.Timeout, State.LookingForBall)
                .OnEntry(() => StartTimer(10000, Trigger.Timeout))
                .OnExit(StopTimer);

            stateMachine.Configure(State.FindingGoal)
                .Permit(Trigger.CoilgunLaunched, State.LookingForBall)
                .Permit(Trigger.BallLost, State.LookingForBall)
                .Permit(Trigger.Timeout, State.LookingForBall)
                .OnEntry(() => StartTimer(5000, Trigger.Timeout))
                .OnExit(StopTimer);
        }
Example #2
0
        public VisionData ToVisionData()
        {
            var data = new VisionData();

            data.TrackingBall = TrackingBall;
            data.TrackedBallLocation = TrackWindow.Center();
            data.FrontBallPathObstructed = false; // TODO: implement!

            if (GoalRectangles != null)
            {
                var bestGoal = GoalRectangles.OrderByDescending(x => x.Width).FirstOrDefault();
                data.OpponentGoalRectangle = bestGoal;
                if (bestGoal == Rectangle.Empty)
                    data.OpponentGoalOffset = null;
                else
                    data.OpponentGoalOffset = (short) ((VisionData.FrameSize.Width / 2) - bestGoal.Center().X);
            }
            return data;
        }
Example #3
0
        public MainLogicProcessor()
        {
            VisionData = new VisionData();
            SensorData = new SensorData();
            LogicState = new LogicState();

            stateMachine = new StateMachine<State, Trigger>(State.Idle);

            stateMachine.OnUnhandledTrigger((state, trigger) => { });

            stateMachine.Configure(State.Idle)
                .Permit(Trigger.PoweredUp, State.Starting)
                .OnEntry(() => Commander.SetColors(Colors.Yellow));

            stateMachine.Configure(State.Starting)
                .Permit(Trigger.Finished, State.LookingForBall)
                .Permit(Trigger.BallCaught, State.FindingGoal)
                .OnEntry(() =>
                {
                    stopwatchTime = stopwatch.ElapsedMilliseconds;
                    SoundClipPlayer.PlayIntro();
                    Commander.SetColors(Colors.Cyan);
                });

            stateMachine.Configure(State.LookingForBall)
                .Permit(Trigger.CameraLockedOnBall, State.ClosingInOnBall)
                .Permit(Trigger.BallCaught, State.FindingGoal)
                .OnEntry(
                () =>
                {
                    Commander.SetColors(Colors.Blue);
                    stopwatchTime = stopwatch.ElapsedMilliseconds;
                });

            stateMachine.Configure(State.ClosingInOnBall)
                .Permit(Trigger.CameraLostBall, State.LookingForBall)
                .Permit(Trigger.BallCaught, State.FindingGoal)
                .Permit(Trigger.Timeout, State.LookingForBall)
                .OnEntry(() =>
                {
                    StartTimer(10000, Trigger.Timeout);
                    Commander.SetColors(Colors.Red);
                })
                .OnExit(StopTimer);

            stateMachine.Configure(State.FindingGoal)
                .Permit(Trigger.CoilgunLaunched, State.LookingForBall)
                .Permit(Trigger.BallLost, State.LookingForBall)
                .Permit(Trigger.Timeout, State.LookingForBall)
                .OnEntry(() =>
                {
                    LogicState.FindingGoal = true;
                    StartTimer(5000, LaunchBall);
                    Commander.SetColors(Colors.Magenta);
                })
                .OnExit(
                () =>
                {
                    LogicState.FindingGoal = false;
                    StopTimer();
                });

            stopwatch.Start();
        }