1 Star 0 Fork 1

ld_robot/hfsm2_test

forked from Alex/hfsm2_test 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
penguin_fsm.h 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
sczhou 提交于 2022-08-03 17:04 +08:00 . feat hfsm2 all done
/**
* @file penguin_fsm.h
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2022-08-03
*
* @copyright Copyright (c) 2022
*
*/
#ifndef PENGUIN_FSM_H_
#define PENGUIN_FSM_H_
#define HFSM2_ENABLE_LOG_INTERFACE
#define HFSM2_ENABLE_STRUCTURE_REPORT
#include "hfsm2/machine.hpp"
#include <iostream>
class Penguin;
/*************** 定义事件 ***************/
// 日出
struct Sunrise{};
// 日落
struct Sunset{};
// 豆豆
struct Doudou{};
/**************** 定义事件 ***************/
using M = hfsm2::MachineT<hfsm2::Config::ContextT<Penguin*>>;
#define S(s) struct s
using FSM = M::PeerRoot<S(Eatting), S(Sleep), S(BeatDoudou)>;
#undef S
struct Base : FSM::State {
template <typename TEvent>
void react(const TEvent&, FullControl&) noexcept {
std::cout << "nothing happend" << std::endl;
}
};
struct Eatting:Base{
using Base::react;
void react(const Doudou&, FullControl& f) noexcept; // NOLINT
};
struct Sleep: Base
{
using Base::react;
void react(const Sunrise&, FullControl& f) noexcept; // NOLINT
};
struct BeatDoudou: Base
{
using Base::react;
void react(const Sunset&, FullControl& f) noexcept; // NOLINT
};
// 状态变化记录
struct FSM_Logger:M::LoggerInterface{
static const char* stateName(const StateID stateId) noexcept {
switch (stateId) {
case 1:
return "Eatting";
case 2:
return "Sleep";
case 3:
return "BeatDoudou";
default:
return "###################";
}
}
void recordTransition(Context& ctx, const StateID origin,
const TransitionType,
const StateID target) noexcept override;
};
#endif // PENGUIN_FSM_H_
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ld_robot/hfsm2_test.git
git@gitee.com:ld_robot/hfsm2_test.git
ld_robot
hfsm2_test
hfsm2_test
master

搜索帮助