CBLA.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. "sync"
  7. "time"
  8. )
  9. var (
  10. ObjDicOfTpperception any
  11. objDic = make(map[uint32][][]float32)
  12. ok1 bool
  13. StartTime int64
  14. IsFollow bool
  15. )
  16. func Topic() string {
  17. return "/tpperception"
  18. }
  19. // 禁止存在下划线_
  20. func Label() string {
  21. return "CBLA"
  22. }
  23. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
  24. defer func() {
  25. if r := recover(); r != nil {
  26. fmt.Println("Recovered from panic:", r)
  27. }
  28. }()
  29. ObjDicOfTpperception, ok1 = shareVars.Load("ObjDicOfTpperception")
  30. if !ok1 {
  31. return ""
  32. }
  33. objDic = ObjDicOfTpperception.(map[uint32][][]float32)
  34. for objid, objval := range objDic {
  35. //if obj.Type == 1 && obj.X >= 2 && obj.X <= 20 && math.Abs(float64(obj.Y)) <= 1.2 {//理论条件
  36. if objval[objid][6] == 4 && objval[objid][0] >= 2 && objval[objid][0] <= 20 && math.Abs(float64(objval[objid][1])) <= 1.2 { //简化条件
  37. if StartTime == 0 {
  38. StartTime = time.Now().Unix()
  39. }
  40. // 判断是否持续超过一分钟
  41. if time.Now().Unix()-StartTime > 5 {
  42. if !IsFollow {
  43. IsFollow = true
  44. return Label()
  45. }
  46. }
  47. } else {
  48. StartTime = 0
  49. IsFollow = false
  50. }
  51. }
  52. return ""
  53. }