/* * fsm.c * * Created on: 2025年7月14日 * Author: akeguo */ #include "fsm_state.h" #include "stdint.h" void fsm_state_run(transition_t* p_this) //执行状态机当前状态 { // turnstile_pass(&turnstile) if (p_this->p_state->robotRun!= NULL) { p_this->p_state->robotRun(p_this); } } //修改状态机状态,若状态机修改后,则查看是否有enter 和 exit命令进行运动 void fsm_state_set(transition_t* p_this, transition_state_t* p_new_state) { if(p_this==NULL){return;} // turnstile_pass(&turnstile) if (p_this->p_state!= p_new_state) /* 状态不等 */ { if (p_this->p_state->robotExit!=NULL) { p_this->p_state->robotExit(p_this); // 1、执行旧状态的退出函数 } p_this->p_state = p_new_state; // 2、切换状态指针 if (p_this->p_state->robotEnter != NULL) { p_this->p_state->robotEnter(p_this); //3、执行新状态的进入函数 } //exit } } //状态机初始化设定 void fsm_state_init(transition_t* p_this,transition_state_t* inti_state) { p_this->p_state =inti_state; }