2016-07-28 4 views
0

부울 msm 1_60을 사용하여 어떻게 서브 머신의 current_state (s)를 얻을 수 있습니까? (예를 들어 두 노란색 조명 번갈아 표준 빨간색, 노란색, 초록색 및 다른) 두 가지 신호등 사이 chosing 허용 외부 상태 머신 기술에 다음 코드를 고려부스트 상태에 액세스하기위한 부스트 msm 서브 시스템 current_state

class SMBigMom : public msmf::state_machine_def<SMBigMom> 
{ 
public: 
SMBigMom() {}; 

using initial_state = SMSelectorState; 

class SMLightBase : public msmf::state_machine_def<SMLightBase> 
{ 
public: 
    SMLightBase() {}; 

    using initial_state = BaseState; 
    struct transition_table : mpl::vector<> {}; 
}; 
using SMBaseBackend = msm::back::state_machine<SMLightBase>; 

class SMCommonRYG : public SMLightBase 
{ 
public: 
    SMCommonRYG() = default; 
    ~SMCommonRYG() {}; 

    using initial_state = Red; // init state 

    struct transition_table : mpl::vector< 
     //   Start, Event, Target, Action, Guard 
     msmf::Row< Red, evNext, RedYellow, msmf::none, msmf::none >, 
     msmf::Row< RedYellow, evNext, Green, msmf::none, msmf::none >, 
     msmf::Row< Green, evNext, Yellow, msmf::none, msmf::none >, 
     msmf::Row< Yellow, evNext, Red, msmf::none, msmf::none > 
    > {}; 
}; 
using SMCommonRYGBackend = msm::back::state_machine<SMCommonRYG>; 

class SMYellowAlternate : public SMLightBase 
{ 
public: 
    SMYellowAlternate() = default; 
    ~SMYellowAlternate() {}; 

    using initial_state = Yellow; // init state 

    struct transition_table : mpl::vector< 
     //   Start, Event, Target, Action, Guard 
     msmf::Row< Yellow, evNext, Yellow2, msmf::none, msmf::none >, 
     msmf::Row< Yellow2, evNext, Yellow, msmf::none, msmf::none > 
    > {}; 
}; 
using SMYellowAlternateBackend = msm::back::state_machine<SMYellowAlternate>; 

struct transition_table : mpl::vector< 
    msmf::Row< SMSelectorState, evSelectCommonRYG, SMCommonRYGBackend, msmf::none, msmf::none >, 
    msmf::Row< SMSelectorState, evSelectYellowAlternate, SMYellowAlternateBackend, msmf::none, msmf::none > 
> {}; 

을};

using SMBackend = msm::back::state_machine<SMBigMom>; 

지금, 나는

SMBackend oSM. oSM.process_event(evSelectCommonRYG()); 

를 통해 RYG로 건너 뛸 수 있습니다하지만 어떻게 내가이 RYG의 기관단총의 현재 상태를받을 수 있나요?

oSM.current_state()[0] 

만 반환 1 (이 그대로 외부 상태 머신 BigMom ...을의 상태) ... 도움을

감사합니다!

답변

0

나는 해결책을 찾았는데 그 해결책은 매우 간단합니다. 단지의 펑 프론트 엔드를 사용하여, 다음과 같이 호출 기능 (연속 4 열) 작업을 추가

여러 "마스터"기계가 실행하고 submachineAction라는 어느 알 필요가있는 경우
struct submachineAction 
{ 
    toNext() {}; 
    ~toNext() {}; 
    template<class TFsm, class TEvent, class TStateIn, class TStateOut> 
    void operator() (const TEvent& p_rEV, const TFsm& p_rFSM, TStateIn& p_rStateIn, TStateOut& p_rStateOut) 
    { 
    std::cout << "Substate: " << p_rFSM.current_state()[0] << std::endl; 
    } 
}; 

추가 식별자 (문자열, int, 사용자 이름)를 가진 기본 프런트 엔드 클래스를 정의하고 해당 클래스의 하위 시스템을 파생시킬 수 있습니다. 그런 다음이 스레드 다음에 위의 펑터에서 p_rFSM을 통해 액세스 할 수있는 식별자를 설정할 수 있습니다. How to Pass data to the current boost meta state machine(MSM) substate

희망이 있으면 다른 사람에게 도움이되기를 바랍니다.