RearVehicleCutOut.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "RearVehicleCutOut"
  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(2) * 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, AngularVelocityZOfCicvLocation float64) bool {
  43. for i := 0; i < len(ObjectList[1]); i++ {
  44. xi := ObjectList[0][i]
  45. yi := ObjectList[1][i]
  46. if math.Abs(float64(yi)) < 0.9 && xi < (-2.0) && math.Abs(AngularVelocityZOfCicvLocation) <= 1.6 {
  47. //fmt.Println(objY)
  48. for j := 0; j < len(ObjectList[1])-i-1; j++ {
  49. objxj := ObjectList[0][1+i+j]
  50. objyj := ObjectList[1][1+i+j]
  51. if math.Abs(float64(objyj)) > 1.8 && objxj < (-2.0) && math.Abs(float64(AngularVelocityZOfCicvLocation)) <= 1.6 {
  52. //fmt.Println(objX)
  53. return true
  54. }
  55. }
  56. }
  57. }
  58. return false
  59. }
  60. func FinalCallback(shareVars *sync.Map) {
  61. OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
  62. ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
  63. ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
  64. AngularVelocityZOfCicvLocation, _ := shareVars.Load("AngularVelocityZOfCicvLocation")
  65. AngularVelocityZ := AngularVelocityZOfCicvLocation.(float64)
  66. if ok && ok1 && OutsideWorkshopFlag.(bool) == true {
  67. for _, objValue := range ObjDic {
  68. Maxlenobj = max(Maxlenobj, int32(len(objValue[0])))
  69. if len(ObjDic[0]) <= 4 || !isCuttingIn(objValue, AngularVelocityZ) {
  70. continue
  71. }
  72. event_lable := "RearVehicleCutOut"
  73. fmt.Println(event_lable)
  74. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  75. }
  76. if Maxlenobj >= 100 {
  77. ObjDicOfTpperception = make(map[uint32][][]float32)
  78. shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
  79. Maxlenobj = 0
  80. }
  81. }
  82. }