12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package main
- import (
- "cicv-data-closedloop/pjisuv_ticker"
- "fmt"
- "math"
- "sync"
- "time"
- )
- var ()
- // 定时任务触发器固定的
- func Topic() string {
- return pjisuv_ticker.TickerTopic
- }
- // ******* 禁止存在下划线_
- // 触发器标记
- func Label() string {
- return "CCRH"
- }
- 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(3) * time.Second)
- defer ticker.Stop()
- // 3 运行一个无限循环
- for {
- select {
- // 定时器触发时执行的代码
- case <-ticker.C:
- FinalCallback(shareVars)
- }
- }
- }(shareVars)
- }
- func isCuttingOut(ObjectList [][]float32) bool {
- for i := 0; i < len(ObjectList[0]); i++ {
- xi := ObjectList[0][i]
- yi := math.Abs(float64(ObjectList[1][i]))
- Type := ObjectList[4][0]
- if xi >= 0 && yi <= 0.7 && Type != 1.0 {
- for j := 0; j < len(ObjectList[0])-i-1; j++ {
- xj := ObjectList[0][j]
- yj := math.Abs(float64(ObjectList[1][j]))
- if xj >= 0 && yj >= 2.5 {
- return true
- }
- }
- }
- }
- return false
- }
- func FinalCallback(shareVars *sync.Map) {
- OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
- ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
- AngularVelocityZOfCicvLocation, ok3 := shareVars.Load("AngularVelocityZOfCicvLocation")
- ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
- AbsSpeed, ok2 := shareVars.Load("AbsSpeed")
- if ok && ok1 && ok2 && ok3 && AngularVelocityZOfCicvLocation.(float64) < 0.6 && AbsSpeed.(float64) > 1 && OutsideWorkshopFlag.(bool) == true {
- for _, objValue := range ObjDic {
- if len(ObjDic[0]) <= 10 || !isCuttingOut(objValue) {
- continue
- }
- event_lable := "CCRH"
- fmt.Println(event_lable)
- pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
- }
- }
- }
|