FrontVehicleCutOutNear.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_ticker"
  4. "fmt"
  5. "math"
  6. "sync"
  7. "time"
  8. )
  9. var (
  10. Maxlenobj int32 = 0
  11. )
  12. // 定时任务触发器固定的
  13. func Topic() string {
  14. return pjisuv_ticker.TickerTopic
  15. }
  16. // ******* 禁止存在下划线_
  17. // 触发器标记
  18. func Label() string {
  19. return "FrontVehicleCutOutNear"
  20. }
  21. func Rule(shareVars *sync.Map) {
  22. defer func() {
  23. if r := recover(); r != nil {
  24. fmt.Println("Recovered from panic:", r)
  25. }
  26. }()
  27. // 1 使用goroutine
  28. go func(shareVars *sync.Map) {
  29. // 2 定义触发器的间隔时间
  30. ticker := time.NewTicker(time.Duration(4) * time.Second)
  31. defer ticker.Stop()
  32. // 3 运行一个无限循环
  33. for {
  34. select {
  35. // 定时器触发时执行的代码
  36. case <-ticker.C:
  37. FinalCallback(shareVars)
  38. }
  39. }
  40. }(shareVars)
  41. }
  42. func isCuttingIn(ObjectList [][]float32, AngularVelocityZ float64) bool {
  43. for i, objY := range ObjectList[1] {
  44. if math.Abs(float64(objY)) >= 1.3 && math.Abs(AngularVelocityZ) <= 0.6 && ObjectList[0][i] >= 2 {
  45. //fmt.Println(objY)
  46. for j := 0; j < len(ObjectList[1])-i-1; j++ {
  47. objX := ObjectList[0][1+i+j]
  48. if math.Abs(float64(ObjectList[1][1+i+j])) >= 1.7 && math.Abs(AngularVelocityZ) <= 0.6 && objX >= 4 && objX <= 20 {
  49. //fmt.Println(objX)
  50. return true
  51. }
  52. }
  53. }
  54. }
  55. return false
  56. }
  57. func FinalCallback(shareVars *sync.Map) {
  58. OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
  59. ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
  60. ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
  61. AngularVelocityZOfCicvLocation, _ := shareVars.Load("AngularVelocityZOfCicvLocation")
  62. AngularVelocityZ := AngularVelocityZOfCicvLocation.(float64)
  63. if ok && ok1 && OutsideWorkshopFlag.(bool) == true {
  64. for _, objValue := range ObjDic {
  65. Maxlenobj = max(Maxlenobj, int32(len(objValue[0])))
  66. if len(ObjDic[0]) <= 10 || !isCuttingIn(objValue, AngularVelocityZ) {
  67. continue
  68. }
  69. event_lable := "FrontVehicleCutOutNear"
  70. fmt.Println(event_lable)
  71. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  72. }
  73. if Maxlenobj >= 100 {
  74. ObjDicOfTpperception = make(map[uint32][][]float32)
  75. shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
  76. Maxlenobj = 0
  77. }
  78. }
  79. }