FrontCarRetrogradeOnJunction.go 2.8 KB

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