提交 5e950222 authored 作者: blu's avatar blu

fsm and more

...@@ -22,10 +22,8 @@ namespace md{ ...@@ -22,10 +22,8 @@ namespace md{
const string kKeyM= "m"; const string kKeyM= "m";
const string kKeyN= "n"; const string kKeyN= "n";
const string kKeyP= "p"; const string kKeyP= "p";
const int kMaxCntMotionInPre = 5; // about 20s
/// helpers /// helpers
auto event_inspection(auto e, std::map<const std::string, int> &m){ auto event_inspection(auto e, std::map<std::string,int> &m){
if(std::is_same<decltype(e), people>::value){ if(std::is_same<decltype(e), people>::value){
spdlog::info("type is people: {}", ++m[kKeyP]); spdlog::info("type is people: {}", ++m[kKeyP]);
}else if(std::is_same<decltype(e), motion>::value){ }else if(std::is_same<decltype(e), motion>::value){
...@@ -109,6 +107,38 @@ namespace md{ ...@@ -109,6 +107,38 @@ namespace md{
inline auto operator()() noexcept{ inline auto operator()() noexcept{
using namespace sml; using namespace sml;
=======
}else if(std::is_same<decltype(e), none>::value){
spdlog::info("type is none: {}", ++m[kKeyN]);
}
}
auto make_guard_fn(const std::map<std::string,int> &konst){
return [&konst](auto e){
static std::map<std::string, int>guards = {{"m", 0}, {"p", 0}, {"n", 0}};
event_inspection(e, guards);
if(guards[kKeyM] != 0 && guards[kKeyP] != 0){
guards[kKeyM] = guards[kKeyP] = guards[kKeyN] = 0;
return false;
}else if(guards[kKeyP] >= konst[kKeyP]){
guards[kKeyP]=guards[kKeyN]= 0;
return true;
}else if(guards[kKeyM] >= konst[kKeyM]){
guards[kKeyM]=guards[kKeyN] = 0;
return true;
}else if(guards[kKeyN] >= konst[kKeyN]){
guards[kKeyN] = 0;
return true;
}
return false;
};
}
struct fsm {
auto operator()()const noexcept {
using namespace sml;
const auto guard_in2post = make_guard_fn(kNumIn2Post);
const auto guard_post2none = make_guard_fn(kNumPost2None);
return make_transition_table( return make_transition_table(
*"init"_s = "none"_s, *"init"_s = "none"_s,
"none"_s + event<none>/[]{spdlog::info("none -> none");} = "none"_s, "none"_s + event<none>/[]{spdlog::info("none -> none");} = "none"_s,
......
...@@ -173,6 +173,7 @@ void maq_smart_task_entry(ev_module_config_t *pArg) ...@@ -173,6 +173,7 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
extern atomic<uint64_t> frameCntTotal; extern atomic<uint64_t> frameCntTotal;
uint64_t frameCntLast = frameCntTotal.load(memory_order_relaxed); uint64_t frameCntLast = frameCntTotal.load(memory_order_relaxed);
uint64_t motionCntLast = gMotionCounter.load(memory_order_relaxed); uint64_t motionCntLast = gMotionCounter.load(memory_order_relaxed);
<<<<<<< HEAD
const float kMotionPerSecondThresh = 2.5; const float kMotionPerSecondThresh = 2.5;
const int kMotionDetectWindowSeconds = 4; const int kMotionDetectWindowSeconds = 4;
const float kMsPerMotion = 1000.0/kMotionPerSecondThresh; const float kMsPerMotion = 1000.0/kMotionPerSecondThresh;
...@@ -180,6 +181,15 @@ void maq_smart_task_entry(ev_module_config_t *pArg) ...@@ -180,6 +181,15 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
int windowSecs = kMotionDetectWindowSeconds; int windowSecs = kMotionDetectWindowSeconds;
ev_region_t last_region = {0}; ev_region_t last_region = {0};
sml::sm<md::fsm> fsm{md::fsm{}}; sml::sm<md::fsm> fsm{md::fsm{}};
=======
const int kMotionPerSecondThresh = 3;
const int kMotionDetectWindowSeconds = 4;
const float kMsPerMotion = kMotionDetectWindowSeconds*1000.0/kMotionPerSecondThresh;
int state = 0;
int windowSecs = kMotionDetectWindowSeconds;
ev_region_t last_region = {0};
sml::sm<md::fsm> fsm;
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
bool hasHuman = false; bool hasHuman = false;
bool hasMotion = false; bool hasMotion = false;
while(1) { while(1) {
...@@ -197,7 +207,11 @@ void maq_smart_task_entry(ev_module_config_t *pArg) ...@@ -197,7 +207,11 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
} }
if (stMaQueSmartTarget.targetFDNum > 0) { if (stMaQueSmartTarget.targetFDNum > 0) {
hasHuman = true; hasHuman = true;
<<<<<<< HEAD
//last_region = {stMaQueSmartTarget.aFDRect[0].s16X1, stMaQueSmartTarget.aFDRect[0].s16Y1, stMaQueSmartTarget.aFDRect[0].s16X2, stMaQueSmartTarget.aFDRect[0].s16Y2}; //last_region = {stMaQueSmartTarget.aFDRect[0].s16X1, stMaQueSmartTarget.aFDRect[0].s16Y1, stMaQueSmartTarget.aFDRect[0].s16X2, stMaQueSmartTarget.aFDRect[0].s16Y2};
=======
last_region = {stMaQueSmartTarget.aFDRect[0].s16X1, stMaQueSmartTarget.aFDRect[0].s16Y1, stMaQueSmartTarget.aFDRect[0].s16X2, stMaQueSmartTarget.aFDRect[0].s16Y2};
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
} }
if(windowSecs > 0) { if(windowSecs > 0) {
windowSecs--; windowSecs--;
...@@ -207,13 +221,17 @@ void maq_smart_task_entry(ev_module_config_t *pArg) ...@@ -207,13 +221,17 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
auto motionCnt_ = gMotionCounter.load(memory_order_relaxed); auto motionCnt_ = gMotionCounter.load(memory_order_relaxed);
float deltaTimeMs = (frameCntTotal_ - frameCntLast) * 1000/pArg->module.sys.fps; float deltaTimeMs = (frameCntTotal_ - frameCntLast) * 1000/pArg->module.sys.fps;
<<<<<<< HEAD
spdlog::info("deltaTimeMs {}", deltaTimeMs); spdlog::info("deltaTimeMs {}", deltaTimeMs);
=======
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
frameCntLast = frameCntTotal_; frameCntLast = frameCntTotal_;
int motionCntThresh = deltaTimeMs / kMsPerMotion; int motionCntThresh = deltaTimeMs / kMsPerMotion;
int deltaMotionCnt = motionCnt_ - motionCntLast; int deltaMotionCnt = motionCnt_ - motionCntLast;
motionCntLast = motionCnt_; motionCntLast = motionCnt_;
if(deltaMotionCnt >= motionCntThresh) { if(deltaMotionCnt >= motionCntThresh) {
hasMotion = true; hasMotion = true;
<<<<<<< HEAD
} }
if(hasMotion && hasHuman) { if(hasMotion && hasHuman) {
fsm.process_event(md::mpboth{}); fsm.process_event(md::mpboth{});
...@@ -225,13 +243,26 @@ void maq_smart_task_entry(ev_module_config_t *pArg) ...@@ -225,13 +243,26 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
fsm.process_event(md::people{}); fsm.process_event(md::people{});
} }
else { else {
=======
}
if(hasMotion && hasHuman){
fsm.process_event(md::mpboth{});
}else if(hasMotion){
fsm.process_event(md::motion{});
}else if(hasHuman){
fsm.process_event(md::people{});
}else{
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
fsm.process_event(md::none{}); fsm.process_event(md::none{});
} }
// reset // reset
windowSecs = kMotionDetectWindowSeconds; windowSecs = kMotionDetectWindowSeconds;
hasHuman = false; hasHuman = false;
hasMotion = false; hasMotion = false;
<<<<<<< HEAD
last_region = {0,0,0,0}; last_region = {0,0,0,0};
=======
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论