CPLA.go 1.3 KB

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