CBNAO.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_ticker"
  4. "fmt"
  5. "sync"
  6. "time"
  7. )
  8. var ()
  9. // 定时任务触发器固定的
  10. func Topic() string {
  11. return pjisuv_ticker.TickerTopic
  12. }
  13. // ******* 禁止存在下划线_
  14. // 触发器标记
  15. func Label() string {
  16. return "CBNAO"
  17. }
  18. func Rule(shareVars *sync.Map) {
  19. defer func() {
  20. if r := recover(); r != nil {
  21. fmt.Println("Recovered from panic:", r)
  22. }
  23. }()
  24. // 1 使用goroutine
  25. go func(shareVars *sync.Map) {
  26. // 2 定义触发器的间隔时间
  27. ticker := time.NewTicker(time.Duration(3) * time.Second)
  28. defer ticker.Stop()
  29. // 3 运行一个无限循环
  30. for {
  31. select {
  32. // 定时器触发时执行的代码
  33. case <-ticker.C:
  34. FinalCallback(shareVars)
  35. }
  36. }
  37. }(shareVars)
  38. }
  39. func findIndex(lst []float32, target float32) int {
  40. for i, v := range lst {
  41. if v == target {
  42. return i
  43. }
  44. }
  45. return -1
  46. }
  47. func isCrossAndOcclusion(id uint32, ObjectList [][]float32, ObjectSlice map[uint32][][]float32) bool {
  48. for i := 0; i < len(ObjectList[0]); i++ {
  49. xi := ObjectList[0][i]
  50. yi := ObjectList[1][i]
  51. diff_hi := ObjectList[7][i]
  52. Type := ObjectList[6][0]
  53. if xi >= 0 && yi <= -3 && diff_hi <= 120 && diff_hi >= 60 && Type == 4.0 {
  54. startFrame1 := ObjectList[5][i]
  55. for j := 0; j < len(ObjectList[0])-i-1; j++ {
  56. xj := ObjectList[0][j]
  57. yj := ObjectList[1][j]
  58. diff_hj := ObjectList[7][j]
  59. if xj >= 0 && xj <= 25 && yj >= 1 && diff_hj <= 120 && diff_hj >= 60 {
  60. startFrame2 := ObjectList[5][j]
  61. for this_id, objValue := range ObjectSlice {
  62. if this_id != id {
  63. this_startFrame_index1 := findIndex(objValue[3], startFrame1)
  64. this_startFrame_index2 := findIndex(objValue[3], startFrame2)
  65. this_type := objValue[6][0]
  66. //fmt.Println(objValue[0][this_startFrame_index2], xj)
  67. if this_startFrame_index1 != -1 && this_startFrame_index2 != -1 {
  68. if objValue[0][this_startFrame_index1] >= 2 && objValue[0][this_startFrame_index1] < xi-5 && objValue[1][this_startFrame_index1] < 0 && objValue[1][this_startFrame_index1] > yi && objValue[0][this_startFrame_index2] >= 1 && objValue[0][this_startFrame_index2] < xj-3 && objValue[1][this_startFrame_index2] < 0 && (this_type == 2.0 || this_type == 3.0) {
  69. return true
  70. }
  71. }
  72. } else {
  73. continue
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80. return false
  81. }
  82. func FinalCallback(shareVars *sync.Map) {
  83. OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
  84. ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
  85. ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
  86. AbsSpeed, ok2 := shareVars.Load("AbsSpeed")
  87. if ok && ok1 && ok2 && OutsideWorkshopFlag.(bool) == true && AbsSpeed.(float64) > 1 {
  88. for id, objValue := range ObjDic {
  89. if len(ObjDic[0]) <= 10 || !isCrossAndOcclusion(id, objValue, ObjDic) {
  90. continue
  91. }
  92. event_lable := "CBNAO"
  93. fmt.Println(event_lable)
  94. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  95. }
  96. }
  97. }