Skip to content
Andrew Gresyk edited this page May 10, 2019 · 18 revisions

hfsm.dev API Cheat Sheet

Globals

Machine and MachineT<>

Using default settings:

using M = hfsm2::Machine;

Customizable version:

using M = hfsm2::MachineT<
              TContext,                // data shared between states and external code
              Config<>,                // optional: config, see below
              TPayload                 // optional: transition payload
          >;

Config<>

hfsm2::Config<
    TUtility,                          // optional: customizable Expected Utility Value type (default: float)
    NMaxPlanTasks,                     // optional: max number of plans' entries across the entire FSM
                                       //                   (default: 2x number of sub-states in all regions)
    NMaxSubstitutions = 4              // optional: max number of guard substitutions
>

Regions

Abbreviations:

  • H => Head
  • SS => SubStates
Type Root Headless Root Region Headless Region
Composite M::Root<H, SS> M::PeerRoot<SS> M::Composite<H, SS> M::CompositePeers<SS>
Resumable M::ResumableRoot<H, SS> M::ResumablePeerRoot<SS> M::Resumable<H, SS> M::ResumablePeers<SS>
Utilitarian M::UtilitarianRoot<H, SS> M::UtilitarianPeerRoot<SS> M::Utilitarian<H, SS> M::UtilitarianPeers<SS>
Orthogonal M::OrthogonalRoot<H, SS> M::OrthogonalPeerRoot<SS> M::Orthogonal<H, SS> M::OrthogonalPeers<SS>

FSM Stucture Declaration

#define S(s) struct s

using FSM = M::Root<S(..),
               ..
            >;

#undef S

States

Overridable M::State Methods

Group Methods
Pre-Conditions Config::Utility utility(const Control&)
Guards void entryGuard(GuardControl&)
void exitGuard(GuardControl&)
Transition Events void enter(PlanControl&)
void exit(PlanControl&)
Periodic Updates void update(FullControl&)
Event Reactions void react(const TEvent&, FullControl&)
Plan Events void planSucceeded(FullControl&)
void planFailed(FullControl&)

Additional Overridable Region Head M::State Methods

Group Methods
Plan Events void planSucceeded(FullControl&)
void planFailed(FullControl&)

State Bases

Default:

struct UserState
    : FSM::State
{}

Inject shared code (see Injections below for more details)

struct UserState
    : FSM::StateT<TInjection1, TInjection2>
{}

Injections

struct UserInjection
    : FSM::Bare
{}

Overridable Injection Methods

Group Methods
Guards void preEntryGuard(Context&)
void preExitGuard(Context&)
Bounds void preEnter(Context&)
void postExit(Context&)
Periodic Updates void preUpdate(Context&)
Event Reactions void preReact(const TEvent&, Context&)

Controls

Control Inheritance Graph

GuardControl -> FullControl -> PlanControl -> Control

Functional Overview

Type Additional Functionality
Control Inspect
PlanControl Modify plans
FullControl Issue transitions
Succeed and fail plans
GuardControl Cancel in-flight transitions

Control Interface

Used in:

  • M::State::utility()
Group Methods
Inspect Structure StateID stateId<TState>()
RegionID regionId<TRegion>()
Access Context Context& _()
Context& context()
Query State Activity bool isActive<TState>()
bool isResumable<TState>()
bool isScheduled<TState>()
bool isActive(StateID)
bool isResumable(StateID)
bool isScheduled(StateID)
Inspect Own Plan ConstPlan plan()
Inspect Plans ConstPlan plan<TRegion>() ConstPlan plan(RegionID)

Additional PlanControl Interface

Used in:

  • void enter(PlanControl&)
  • void exit(PlanControl&)
Group Methods
Modify Own Plan Plan plan()
Modify Plans Plan plan<TRegion>() Plan plan(RegionID)

Additional FullControl Interface

Used in:

  • void update(FullControl&)
  • void react(const TEvent&, FullControl&)
  • void planSucceeded(FullControl&)
  • void planFailed(FullControl&)
Group Methods
Initiate Transitions void changeTo<TState>()
void restart<TState>()
void resume<TState>()
void utilize<TState>()
void schedule<TState>()
void changeTo(StateID)
void restart(StateID)
void resume(StateID)
void utilize(StateID)
void schedule(StateID)
Succeed / Fail Plans void succeed()
void fail()

Additional GuardControl Interface

Used in:

  • void entryGuard(GuardControl&)
  • void exitGuard(GuardControl&)
Group Methods
Cancel In-Flight Transitions void cancel()