Beispiel #1
0
    private static ApproachState _instance; //only declared one time. can only be created from within the state class.

    private ApproachState()
    {
        if (_instance != null)
        {
            return;
        }


        _instance = this;
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (moving)
        {
            switch (approachState)
            {
            case ApproachState.approaching:
                // Check if reached range
                if (PlayerDistance() <= approachDistance)
                {
                    approachState = ApproachState.activating;
                    SetTarget(actChargeUpTime);
                }
                else
                {
                    MoveTowards();
                }
                break;

            case ApproachState.activating:
                if (OnTarget())
                {
                    approachState = ApproachState.cooldown;
                    SetTarget(actCooldownTime);
                }
                // Stop moving
                myBase.myRigid.velocity = Vector2.zero;
                break;

            case ApproachState.cooldown:
                if (OnTarget())
                {
                    approachState = ApproachState.approaching;
                }
                // Stop moving
                myBase.myRigid.velocity = Vector2.zero;
                break;
            }
        }
    }
Beispiel #3
0
        public void TaskRun()
        {
            Program.Pilot.OnPilotReceive += PilotReceive;
            Program.Vis.OnLostCone += Vis_OnLostCone;
            Program.Vis.OnFoundCone += Vis_OnFoundCone;

            // if finished, exit task
            while (Program.State != RobotState.Shutdown)
            {
                if (Program.State == RobotState.Approach)
                    switch (subState)
                    {
                        case ApproachState.Start:
                            Trace.t(cc.Status, "Approach.Start");
                            if (Program.Vis.coneFlag != Vision.ConeState.Found)
                                Sweep();
                            else
                            {
                                Program.Pilot.Send(new { Cmd = "Mov", M1 = 0, M2 = 0 });

                                Trace.t(cc.Status, "Approach Rotating");
                                Program.Pilot.Send(new { Cmd = "ROT", Hdg = coneHeading });
                                Program.Pilot.waitForEvent();

                                approachStartedAt = DateTime.Now;
                                var a = new { Cmd = "Mov", Hdg = coneHeading, M1 = approachSpeed, M2 = approachSpeed };
                                Program.Pilot.Send(a);
                                //Console.WriteLine(a);
                                subState = ApproachState.Progress;
                                Trace.t(cc.Status, "Approach Moving");
                            }
                            break;

                        case ApproachState.Progress:
                            if (DateTime.Now > approachStartedAt + waitForTouch)
                            {
                                subState = ApproachState.Fail1;
                                Program.Pilot.Send(new { Cmd = "Mov", M1 = 0, M2 = 0 });
                                break;
                            }
                            var b = new { Cmd = "Mov", Hdg = coneHeading, Pwr = approachSpeed };
                            Program.Pilot.Send(b);
                            //Console.WriteLine(b);
                            break;

                        case ApproachState.Fail1:
                            Trace.t(cc.Bad, "Approach.Fail1");
                            if (DateTime.Now > approachStartedAt + waitForTouch)
                                subState = ApproachState.Fail2;
                            break;

                        case ApproachState.Fail2:
                            Trace.t(cc.Bad, "Approach.Fail2");
                            subState = ApproachState.Complete;
                            break;
                    }

                if (subState == ApproachState.Complete)
                {
                    Program.Pilot.Send(new { Cmd = "Mov", Pwr = -approachSpeed, Dist = .2F });
                    Program.Pilot.waitForEvent();
                    Program.State = RobotState.Idle;
                    break;
                }

                // throttle loops
                Program.Delay(100).Wait();
            }

            Trace.t(cc.Warn, "Approach exiting");
        }
Beispiel #4
0
 void OnBumperEvent(dynamic json)
 {
     if (((string)json.V).Equals("1")) // todo this is why we are here:)
     {
         Trace.t(cc.Good, "Expected Bumper");
         subState = ApproachState.Complete;
     }
 }
Beispiel #5
0
 private void Awake()
 {
     evadeState    = new EvadeState(this);
     approachState = new ApproachState(this);
     wanderState   = new WanderState(this);
 }
Beispiel #6
0
 public override void SetState(int newState)
 {
     this.approachState = (ApproachState)newState;
 }