|
@@ -0,0 +1,92 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "cicv-data-closedloop/pjisuv_ticker"
|
|
|
+ "fmt"
|
|
|
+ "math"
|
|
|
+ "sync"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ Maxlenobj int32 = 0
|
|
|
+ threshold float64 = 5.0
|
|
|
+)
|
|
|
+
|
|
|
+// 定时任务触发器固定的
|
|
|
+func Topic() string {
|
|
|
+ return pjisuv_ticker.TickerTopic
|
|
|
+}
|
|
|
+
|
|
|
+// ******* 禁止存在下划线_
|
|
|
+// 触发器标记
|
|
|
+func Label() string {
|
|
|
+ return "BeOvertakenWithHighSpeed"
|
|
|
+}
|
|
|
+
|
|
|
+func Rule(shareVars *sync.Map) {
|
|
|
+ defer func() {
|
|
|
+ if r := recover(); r != nil {
|
|
|
+ fmt.Println("Recovered from panic:", r)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ // 1 使用goroutine
|
|
|
+ go func(shareVars *sync.Map) {
|
|
|
+ // 2 定义触发器的间隔时间
|
|
|
+ ticker := time.NewTicker(time.Duration(2) * time.Second)
|
|
|
+ defer ticker.Stop()
|
|
|
+ // 3 运行一个无限循环
|
|
|
+ for {
|
|
|
+ select {
|
|
|
+ // 定时器触发时执行的代码
|
|
|
+ case <-ticker.C:
|
|
|
+ FinalCallback(shareVars)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }(shareVars)
|
|
|
+}
|
|
|
+func IsOvertaken(ObjectList [][]float32) bool {
|
|
|
+ //fmt.Println("yes")
|
|
|
+ //fmt.Println(ObjectList)
|
|
|
+ for i, objX := range ObjectList[0] {
|
|
|
+
|
|
|
+ if math.Abs(float64(ObjectList[1][i])) <= 4 && objX <= -2 {
|
|
|
+ for j := 0; j < len(ObjectList[0])-i-1; j++ {
|
|
|
+ if math.Abs(float64(ObjectList[1][1+i+j])) <= 4 && ObjectList[0][1+i+j] >= 2.5 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+func FinalCallback(shareVars *sync.Map) {
|
|
|
+ OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
|
|
|
+ AbsSpeed, ok3 := shareVars.Load("AbsSpeed")
|
|
|
+
|
|
|
+ if ok && ok3 && AbsSpeed.(float64) >= threshold {
|
|
|
+ ObjDicOfTpperception, okn := shareVars.Load("objDicOfTpperception")
|
|
|
+ ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
|
|
|
+
|
|
|
+ if okn && OutsideWorkshopFlag.(bool) == true {
|
|
|
+ for _, objValue := range ObjDic {
|
|
|
+ Maxlenobj = max(Maxlenobj, int32(len(objValue[0])))
|
|
|
+ if len(ObjDic[0]) <= 10 || !IsOvertaken(objValue) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ event_lable := "BeOvertakenWithHighSpeed"
|
|
|
+ fmt.Println(event_lable)
|
|
|
+ pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
|
|
|
+ }
|
|
|
+ if Maxlenobj >= 100 {
|
|
|
+ ObjDicOfTpperception = make(map[uint32][][]float32)
|
|
|
+ shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
|
|
|
+ Maxlenobj = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|