状态id
/*!
\typedef StateID
Unique identifier of the statemachine
*/
typedef unsigned int StateID;
/*!
\def STATEID_NULL
Initial State of the system once the HSM is created
*/
#define STATEID_NULL 0
/*!
\def STATE_START
Macro indicating user stateID start
*/
#define STATE_START STATEID_NULL+1
enum statelist_SampleHSM
{
ROOT_STATE = STATE_START,
STATE_1,
STATE1_1,
STATE1_2,
STATE_2,
STATE2_1,
STATE2_1_1,
STATE_3,
State4,
MAX_STATEID
};
事件id
/*! \enum EventID
* ID of the minimum required Events.
*/
typedef enum
{
EV_NULL,
EV_DEFAULT,
EV_BASE_MAX // Always keep this as the last value in the base class
}EventID;
enum EventIDList_SampleHSM
{
EV2 = EV_BASE_MAX,
EV_1,
EV5,
EV3,
EV4,
MAX_EVENTS
};
无动作定义
/*!\def noAction
no Action in the transition
*/
#define noAction 0
无条件定义
/*!
\def noCondition
no condition in the transition
*/
#define noCondition 0
/*!
\def NULL_TRANSTION
no Transition
*/
#define NULL_TRANSITION 0,0
1、跳转表
hsm中状态之间转换条件包含状态转换的触发事件id、跳转条件、跳转动作、初始状态id、目的状态id。
每个状态都有与之相应的一个 state Transition table
/*! \struct Transition* state Transition elements
*/
typedef struct Transition
{
EventID triggerID;//Event creating the transition
int (*condition)();//condition for the transition
void (*action)();//Transition action
StateID fromState;//Source StateID
StateID toState;//Destination StateID
}Transition;
/*! \struct TransitionTable
* state Transition table for each state
*/
typedef struct TransitionTable
{
Transition* transition;
unsigned int transitionCount; //表示该状态跳转到其他状态的次数
}TransitionTable;
2、状态
state的结构体成员信息当前状态id、parent状态id、对应的状态转换表(1中介绍的state Transition table)、状态入口动作/出口动作、行为动作
/*! \struct State
* Elements of a state
*/
typedef struct State
{
StateID stateID;/