Esempio n. 1
0
		public override void Reset()
		{
			cursorTexture = null;
			hotSpot = new FsmVector2 { UseVariable = true };

			renderMode = RenderMode.Auto;
			lockMode = CurState.None;
			hideCursor = true;
		}
Esempio n. 2
0
 public void fixedUpdate()
 {
     CurState.fixedUpdate();
 }
Esempio n. 3
0
        }                                               // 默认状态

        public FSM(List <FSMState> states, FSMState defState)
        {
            _states  = states;
            CurState = DefState = defState;
            CurState.OnEnter();
        }
 protected override void InitCurState()
 {
     CurState = mStateMachineDic[ActorStateType.Idle];
     CurState.Enter(this);
 }
 private void onCycStateChange(CurState cState)
 {
     DG.Dispatcher.Invoke(new Action(delegate
     {
         setButtonsByState(cState);
     }));
 }
 private void setButtonsByState(CurState cState)
 {
     switch (cState)
     {
         case CurState.csLoaded:
             StartBtn.IsEnabled = true;
             StopBtn.IsEnabled = false;
             StepBtn.IsEnabled = true;
             StatusLabel.Content = cThread.CycFile.FileName;
             break;
         case CurState.csLoadedWithErrors:
             StartBtn.IsEnabled = false;
             StopBtn.IsEnabled = false;
             StepBtn.IsEnabled = false;
             statusText = "Ошибки в циклограмме!";
             StatusLabel.Content = statusText;
             break;
         case CurState.csNone:
             StartBtn.IsEnabled = false;
             StopBtn.IsEnabled = false;
             StepBtn.IsEnabled = false;
             StatusLabel.Content = String.Empty;
             break;
         case CurState.csRunning:
             StartBtn.IsEnabled = false;
             StopBtn.IsEnabled = true;
             StepBtn.IsEnabled = false;
             break;
     }
 }
        /// <summary>
        /// Метод изменения текущего состояния потока циклограмм
        /// </summary>
        /// <param name="newState"></param>
        private void ChangeState(CurState newState)
        {
            if (_state != newState)
            {
                _state = newState;

                // если поменяли состояние на отличное от "выполнение", поток останавливаем
                if (_state != CurState.csRunning)
                {
                    _terminated = true;
                }

                if (ChangeStateEvent != null)
                {
                    ChangeStateEvent(_state);
                }
            }
        }
Esempio n. 8
0
 void Start()
 {
     CurState.Enter(null);
 }
        /// <summary>
        /// Основной конструктор
        /// </summary>
        public CyclogramThread()
        {
            _state = CurState.csNone;
            _terminated = false;

            CycFile = new CyclogramFile();
            _cPos = new CycPosition(CycFile);

            _setNextCmd = false;
        }
Esempio n. 10
0
 public void StopCurrentAction()
 {
     ctrllog.TraceInformation("Stopping the {0} action ({1} instruments{2})", NC.App.Opstate.Action, Instruments.Active.Count, (Instruments.Active.Count == 1 ? String.Empty : "s"));
     NC.App.Opstate.SOH = NCC.OperatingState.Stopping;
     CurState.Cancel();
 }
Esempio n. 11
0
        /// <summary>
        /// Start an assay on every instrument connected, this is for a single interval only
        /// The LMMM does just one assay from it's POV, and needs to be retold by DAQ here to do the next interval
        /// </summary>
        private int StartLM_SRAssay()
        {
            collog.TraceEvent(LogLevels.Info, 0, "Starting assay...");

            CurState.Measurement.CurrentRepetition++;
            CurState.State = DAQInstrState.ReceivingData;

            numTotalBytes = 0;

            collectingFileData = NC.App.AppContext.LiveFileWrite;

            CurState.StampAssayTime();
            CurState.GenDateTimePrefix(NC.App.AppContext.RootLoc);

            foreach (Instrument active in Instruments.Active)
            {
                if (active is SRInstrument)
                {
                    ctrllog.TraceEvent(LogLevels.Verbose, 999333, "Got SR {0} here", (active as SRInstrument).id.Identifier());
                }
                active.DAQState = DAQInstrState.ReceivingData;

                Cycle cycle = new Cycle(ctrllog);
                cycle.SetUpdatedDataSourceId(active.id); // where the cycle came from, but with updated timestamp
                CurState.Measurement.Add(cycle);         // todo: this mixes the cycles from the different instruments onto one list, gotta change this now that we are at more than one instrument, well you can simply write iterators that select on specific instrument Ids, over the entire list, or use LINQ select * where dsid == whatever syntax on the list
                ctrllog.TraceEvent(LogLevels.Verbose, 93939, "Cycle {0} init", cycle.seq);

                // devnote: file writing is selectable via the UI, and raw analysis should be independently
                // start the file capture
                if (active is LMInstrument)
                {
                    NCCFile.INeutronDataFile f = (active as LMInstrument).PrepOutputFile(CurState.currentDataFilenamePrefix, Instruments.Active.IndexOf(active), collog);
                    active.RDT.StartCycle(cycle, f); // internal handler needs access to the file handle for PTR-32 and MCA-527, but not for LMMM
                    ctrllog.TraceEvent(LogLevels.Verbose, 93939, "Cycle {0}, {1}", cycle.seq, string.IsNullOrEmpty(f.Filename) ? string.Empty: "output file name " + f.Filename);
                }
                else
                {
                    active.RDT.StartCycle(cycle);
                }

                if (CurState.Measurement.CurrentRepetition == 1)
                {
                    //  devnote: with more than one active, these need to be revisited
                    if (active is LMInstrument)
                    {
                        (active as LMInstrument).RDT.SetupCountingAnalyzerHandler(NC.App.Config, active.id.source.TimeBase(active.id.SRType));
                        (active as LMInstrument).RDT.PrepareAndStartCountingAnalyzers(CurState.Measurement.AnalysisParams);
                    }

                    // todo: Measurement Detector List exists but is not integrated with associated Instrument objects here
                    if (active is SRInstrument)
                    {
                        // kick off the thread to try and init the SR
                        SRWrangler.StartSRActionAndWait((active as SRInstrument).id, SRTakeDataHandler.SROp.InitializeSR);
                    }
                    else if (active is LMInstrument && active.id.SRType == InstrType.LMMM)
                    {
                        LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.prep, 0, Instruments.All.IndexOf(active));                         // send this config message to this LMMM
                    }

                    // devnote: index might be wrong if some of multiple LMs are disabled via UI. This will require a revisit at integration time
                }
            }

            NC.App.Loggers.Flush();
            FireEvent(EventType.ActionInProgress, this);
            Thread.Sleep(250); // LMMM only: wait for last send to finish, todo could we use EventHandler<SocketAsyncEventArgs> Completed here?

            // PTR-32/MCA-527
            // This loop works for PTR-32 and MCA-527) instruments, based on an improved instrument and control design

            // devnote: rewrite SR and LMMM sections below to use the StartAssay virtual method abstraction for measurement control
            foreach (Instrument instrument in Instruments.Active)
            {
                try {
                    instrument.StartAssay(CurState.Measurement);
                }
                catch (Exception ex) {
                    collog.TraceException(ex);
                }
            }

            // The following sections are for SR and LMMM
            // LMMM
            if (Instruments.Active.HasLMMM()) // send to a plurality of thresholding units, err, I mean, LMMM Instruments
            {
                if (CurState.broadcastGo)     // send go
                {
                    // this has to be sent separately, because linux control is looking for the Arm alone.
                    LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.arm); // send to all active

                    Thread.Sleep(250);                                       // allow linux code to setup waiting socket.

                    // broadcast go message to all NCC.App.Config.Net.Subnet addresses. This is the instrument group.
                    LMMMComm.PostLMMMCommand(LMMMLingo.Tokens.go, true);
                }
                else
                {
                    LMMMComm.FormatAndSendLMMMCommand(LMMMLingo.Tokens.go);                     // send to all active
                }
            }

            // SR
            bool srgood = false, hasSR = false;
            // send the start DAQ to every active SR, probably better to do this in the event handler not here
            IEnumerator iter = Instruments.Active.GetSREnumerator();

            while (iter.MoveNext())
            {
                hasSR = true;
                SRInstrument sri = (SRInstrument)iter.Current;
                int          srStatus = 0, measStatus = 0;
                SRWrangler.GetLastStatus(sri.id, ref srStatus, ref measStatus);

                if (measStatus != INCCSR.SUCCESS) // failure means we cannot see or use the SR, so go to the next one, whereas success means it initialized correctly in the InitializeSR step
                {
                    sri.DAQState = DAQInstrState.Offline;
                    continue;
                }

                int status = SRWrangler.StartSRActionAndWait(sri.id, SRTakeDataHandler.SROp.StartSRDAQ); // NEXT: check if pending here is going to be an issue
                if (status == INCCSR.MEAS_CONTINUE)                                                      // the SR started
                {
                    srgood = true;
                    SRWrangler.SetAction(sri.id, SRTakeDataHandler.SROp.WaitForResults); // event handler will pick up results when the internal timer polling in the thread detects results and fires the event
                }
            }
            // need a better test in here to skip all this startup stuff when the SR/LM/cycle init failed
            if (Instruments.Active.Count < 1)
            {
                CurState.Measurement.CurrentRepetition--;
                ctrllog.TraceEvent(LogLevels.Warning, 46, "No active instruments available now");
            }
            else if (hasSR && !srgood)
            {
                CurState.Measurement.CurrentRepetition--;
                ctrllog.TraceEvent(LogLevels.Warning, 46, "No Shift Register is available now");
            }
            else
            {
                if (CurState.Measurement.CurrentRepetition == 1)
                {
                    if (Instruments.Active.Count > 1)
                    {
                        if (Instruments.Active.Count != Instruments.All.Count)
                        {
                            ctrllog.TraceInformation("Using " + Instruments.Active.Count + " of " + Instruments.All.Count + " instruments");
                        }
                        else
                        {
                            ctrllog.TraceInformation("Using " + Instruments.Active.Count + " instruments");
                        }
                    }
                    else
                    {
                        ctrllog.TraceInformation("Using one instrument");
                    }
                }

                string str = "Assay cycle " + CurState.Measurement.CurrentRepetition + " of ";
                if (CurState.Measurement.RequestedRepetitions == 0)
                {
                    str += "a continuous assay starting";
                }
                else
                {
                    str += (CurState.Measurement.RequestedRepetitions + " cycles starting");
                }
                ctrllog.TraceInformation(str);
            }
            if (Instruments.Active.Count > 0)
            {
                FireEvent(EventType.ActionInProgress, this);
                collog.TraceEvent(LogLevels.Verbose, 0, "Started assay with {0} instrument{1}", Instruments.Active.Count, (Instruments.Active.Count > 1 ? "s" : ""));
            }
            return(Instruments.Active.Count);
        }
Esempio n. 12
0
    public void setControllerHighlight(CurState state)
    {
        string leftPath  = "[VRTK_SDKManager]/SDKSetups/SteamVR/[CameraRig]/Controller (left)/Model";
        string rightPath = "[VRTK_SDKManager]/SDKSetups/SteamVR/[CameraRig]/Controller (right)/Model";

        if (leftHighlighter == null)
        {
            leftHighlighter = GameObject.Find(leftPath).GetComponent <VRTK_ControllerHighlighter>();
        }

        if (rightHighlighter == null)
        {
            rightHighlighter = GameObject.Find(rightPath).GetComponent <VRTK_ControllerHighlighter>();
        }

        switch (state)
        {
        case (CurState.singleAttach):
            // rightHighlighter.UnhighlightController();
            // rightHighlighter.highlightTrigger = Color.clear;

            // rightHighlighter.HighlightElement(SDK_BaseController.ControllerElements.GripLeft, Color.yellow, 0.0f);
            // rightHighlighter.HighlightElement(SDK_BaseController.ControllerElements.GripRight, Color.yellow, 0.0f);
            // rightHighlighter.highlightGrip = Color.yellow;

            StaticData.setActiveBtn(rightPath + "/trigger", "off");

            StaticData.setActiveBtn(rightPath + "/lgrip", "on");
            StaticData.setActiveBtn(rightPath + "/rgrip", "on");

            VRTK_ObjectAppearance.SetOpacity(GameObject.Find(rightPath), 0.8f);
            break;

        case (CurState.leftStep):

            // clear right highlighter
            // rightHighlighter.UnhighlightController();
            // rightHighlighter.highlightGrip = Color.clear;

            StaticData.setActiveBtn(rightPath + "/lgrip", "off");
            StaticData.setActiveBtn(rightPath + "/rgrip", "off");

            VRTK_ObjectAppearance.SetOpacity(GameObject.Find(rightPath), 1.0f);

            // set up left highlighter
            // leftHighlighter.HighlightElement(SDK_BaseController.ControllerElements.Trigger, Color.yellow, 0.0f);
            // leftHighlighter.highlightTrigger = Color.yellow;

            StaticData.setActiveBtn(leftPath + "/trigger", "on");

            VRTK_ObjectAppearance.SetOpacity(GameObject.Find(leftPath), 0.8f);
            break;

        case (CurState.rightStep):

            // clear left highlighter
            // leftHighlighter.UnhighlightController();
            // leftHighlighter.highlightTrigger = Color.clear;

            StaticData.setActiveBtn(leftPath + "/trigger", "off");

            VRTK_ObjectAppearance.SetOpacity(GameObject.Find(leftPath), 1.0f);

            // set up right highlighter
            // rightHighlighter.HighlightElement(SDK_BaseController.ControllerElements.Trigger, Color.yellow, 0.0f);
            // rightHighlighter.highlightTrigger = Color.yellow;

            StaticData.setActiveBtn(rightPath + "/trigger", "on");

            VRTK_ObjectAppearance.SetOpacity(GameObject.Find(rightPath), 0.8f);
            break;

        case (CurState.finished):       // finish taping

            // rightHighlighter.UnhighlightController();
            // rightHighlighter.highlightTrigger = Color.clear;

            StaticData.setActiveBtn(rightPath + "/trigger", "off");

            VRTK_ObjectAppearance.SetOpacity(GameObject.Find(rightPath), 1.0f);
            break;
        }
    }
Esempio n. 13
0
    protected override void DoAction(AgentAction action)
    {
        FsmState preState = CurState;

        // ------------------------------ 无要执行的action ------------------------------
        if (action == null)
        {
            //if (_blackBoard.curAction != null && _blackBoard.curAction.Type == AgentAction.ActionType.MOVE)
            if ((_blackBoard.curAction as AgentActionMove) != null)
            {
                CurState = GetState((int)FsmStateType.IDLE); // 转入idle状态
                preState.Exit();
                CurState.Enter(action);
            }
            return;
        }

        // ------------------------------ 有要执行的action ------------------------------

        // 执行同样行为

        /*if (_blackBoard.curAction != null && _blackBoard.curAction.Type == action.Type)
         * {
         *  CurState.HandleSameAction(action);
         *  return;
         * }*/
        if (CurState.HandleSameAction(action))
        {
            return;
        }


        //if (action.Type == AgentAction.ActionType.DEATH)
        if (action as AgentActionDeath != null)
        {
            CurState = GetState((int)FsmStateType.DEATH);
        }
        //else if (action.Type == AgentAction.ActionType.INJURY && _blackBoard.curAction.Type != AgentAction.ActionType.DEATH)
        else if (action as AgentActionInjury != null && _blackBoard.curAction as AgentActionDeath == null)
        {
            CurState = GetState((int)FsmStateType.INJURY);
        }
        else if (_blackBoard.curAction == null) // 当前是idle状态
        {
            switch (action.Type)
            {
            case AgentActionType.MOVE:
                CurState = GetState((int)FsmStateType.MOVE);
                break;

            case AgentActionType.ROLL:
                CurState = GetState((int)FsmStateType.ROLL);
                break;

            case AgentActionType.ATTACK_MELEE:
                CurState = GetState((int)FsmStateType.ATTACK_MELEE);
                break;

            default:
                return;
            }
        }
        //else if (_blackBoard.curAction.Type == AgentAction.ActionType.MOVE)
        else if (_blackBoard.curAction as AgentActionMove != null) // 当前是move状态
        {
            switch (action.Type)
            {
            case AgentActionType.ROLL:
                CurState = GetState((int)FsmStateType.ROLL);
                break;

            case AgentActionType.ATTACK_MELEE:
                CurState = GetState((int)FsmStateType.ATTACK_MELEE);
                break;

            default:
                return;
            }
        }
        else if (_blackBoard.curAction.Type == AgentActionType.ATTACK_MELEE) // 当前是attack状态
        {
            switch (action.Type)
            {
            case AgentActionType.ROLL:
                CurState = GetState((int)FsmStateType.ROLL);
                break;

            default:
                return;
            }
        }
        else
        {
            return;
        }

        preState.Exit();
        CurState.Enter(action);

        /*FsmState preState = CurState;
         * if (action == null && _blackBoard.curAction != null && _blackBoard.curAction.Type == AgentAction.ActionType.MOVE)
         * {
         *  CurState = GetState((int)FsmStateType.IDLE);
         *  return;
         * }
         * else if (action == null)
         * {
         *  return;
         * }
         * else if (_blackBoard.curAction != null && _blackBoard.curAction.Type == action.Type)
         * {
         *  CurState.HandleSameAction(action);
         *  return;
         * }
         * else if (action.Type == AgentAction.ActionType.DEATH)
         * {
         *  CurState = GetState((int)FsmStateType.DEATH);
         * }
         * else if (action.Type == AgentAction.ActionType.INJURY && _blackBoard.curAction.Type != AgentAction.ActionType.DEATH)
         * {
         *  CurState = GetState((int)FsmStateType.INJURY);
         * }
         * else if (CurState == DefState) // 当前是idle状态
         * {
         *  switch (action.Type)
         *  {
         *      case AgentAction.ActionType.MOVE:
         *          CurState = GetState((int)FsmStateType.MOVE);
         *          break;
         *      case AgentAction.ActionType.ROLL:
         *          CurState = GetState((int)FsmStateType.ROLL);
         *          break;
         *      case AgentAction.ActionType.ATTACK_MELEE:
         *          CurState = GetState((int)FsmStateType.ATTACK_MELEE);
         *          break;
         *      default:
         *          return;
         *  }
         * }
         * else
         * {
         *  return;
         * }
         *
         * preState.Exit();
         * CurState.Enter(action);*/
    }