RearVehiclesFrequentChangeLane.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "RearVehiclesFrequentChangeLane"
  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 countChanges(slice [][]float32, AngularVelocityZOfCicvLocation float64) int {
  43. count := 0
  44. lable1:
  45. for i := 0; i < len(slice[1]); {
  46. xi := slice[0][i]
  47. yi := math.Abs(float64(slice[1][i]))
  48. if (yi >= 1.8 || yi < 0.7) && xi <= -2 && math.Abs(AngularVelocityZOfCicvLocation) <= 1.6 {
  49. for j := 0; j < len(slice[1])-i-1; j++ {
  50. xij := slice[0][1+i+j]
  51. yij := math.Abs(float64(slice[1][1+i+j]))
  52. if ((yi >= 1.8 && yij <= 0.7) || (yi < 0.7 && yij >= 1.8)) && xij <= -2 && math.Abs(AngularVelocityZOfCicvLocation) <= 1.6 {
  53. count++
  54. //fmt.Println("here!!")
  55. i = i + j + 1
  56. continue lable1
  57. }
  58. }
  59. break lable1
  60. } else {
  61. i++
  62. }
  63. }
  64. return count
  65. }
  66. func FinalCallback(shareVars *sync.Map) {
  67. OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
  68. ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
  69. ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
  70. AngularVelocityZOfCicvLocation, _ := shareVars.Load("AngularVelocityZOfCicvLocation")
  71. AngularVelocityZ := AngularVelocityZOfCicvLocation.(float64)
  72. if ok && ok1 && OutsideWorkshopFlag.(bool) == true {
  73. for _, objValue := range ObjDic {
  74. Maxlenobj = max(Maxlenobj, int32(len(objValue[0])))
  75. if len(ObjDic[0]) <= 10 || countChanges(objValue, AngularVelocityZ) < 2 {
  76. continue
  77. }
  78. event_lable := "RearVehiclesFrequentChangeLane"
  79. fmt.Println(event_lable)
  80. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  81. }
  82. if Maxlenobj >= 100 {
  83. ObjDicOfTpperception = make(map[uint32][][]float32)
  84. shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
  85. Maxlenobj = 0
  86. }
  87. }
  88. }