FrontCarDrivingWrongDirection.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "FrontCarDrivingWrongDirection"
  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 isWrongDirection(ObjectList [][]float32, AngularVelocityZ float64, YawOfCicvLocation float32) bool {
  43. for i, heading := range ObjectList[4] {
  44. objXi := ObjectList[0][i]
  45. objYi := ObjectList[1][i]
  46. Anglei := math.Abs(float64(heading - YawOfCicvLocation))
  47. if math.Abs(float64(objYi)) <= 1.8 && math.Abs(AngularVelocityZ) <= 0.6 && objXi > 15 && Anglei <= 200 && Anglei >= 160 {
  48. //fmt.Println(objY)
  49. for j := 0; j < len(ObjectList[1])-i-1; j++ {
  50. objXij := ObjectList[0][1+i+j]
  51. objYij := ObjectList[1][1+i+j]
  52. if math.Abs(float64(objYij)) <= 1.8 && math.Abs(AngularVelocityZ) <= 0.6 && objXij <= 10 {
  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. YawOfCicvLocation, ok2 := shareVars.Load("YawOfCicvLocation")
  64. ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
  65. AngularVelocityZOfCicvLocation, _ := shareVars.Load("AngularVelocityZOfCicvLocation")
  66. AngularVelocityZ := AngularVelocityZOfCicvLocation.(float64)
  67. if ok && ok1 && ok2 && OutsideWorkshopFlag.(bool) == true {
  68. for _, objValue := range ObjDic {
  69. Maxlenobj = max(Maxlenobj, int32(len(objValue[0])))
  70. if len(ObjDic[0]) <= 10 || !isWrongDirection(objValue, AngularVelocityZ, YawOfCicvLocation.(float32)) {
  71. continue
  72. }
  73. event_lable := "FrontCarDrivingWrongDirection"
  74. fmt.Println(event_lable)
  75. ObjDicOfTpperception = make(map[uint32][][]float32)
  76. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  77. }
  78. if Maxlenobj >= 100 {
  79. ObjDicOfTpperception = make(map[uint32][][]float32)
  80. shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
  81. Maxlenobj = 0
  82. }
  83. }
  84. }