CutinWithSightBblock.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "CutinWithSightBblock"
  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, AngularVelocityZ float64) (bool, float32, float32, float64) {
  43. for i, objY := range ObjectList[1] {
  44. if math.Abs(float64(objY)) >= 1.8 && math.Abs(AngularVelocityZ) <= 0.6 && ObjectList[0][i] >= 2 {
  45. //fmt.Println(objY)
  46. for j := 0; j < len(ObjectList[1])-i-1; j++ {
  47. objX := ObjectList[0][1+i+j]
  48. if math.Abs(float64(ObjectList[1][1+i+j])) <= 0.7 && math.Abs(AngularVelocityZ) <= 0.6 && objX >= 1 {
  49. //fmt.Println(objX)
  50. return true, ObjectList[5][1+i+j], ObjectList[0][1+i+j], math.Abs(float64(ObjectList[1][1+i+j]))
  51. }
  52. }
  53. }
  54. }
  55. return false, 0.0, 0.0, 0.0
  56. }
  57. func SightBlock(cutobjx float32, cutobjy float64, objId uint32, cutinframe float32, ObjectSlice map[uint32][][]float32) bool {
  58. for Id, objValue := range ObjectSlice {
  59. if Id != objId {
  60. for i := 0; i < len(objValue[1]); i++ {
  61. if objValue[2][i] == cutinframe {
  62. //fmt.Println("yes")
  63. objx := objValue[0][i]
  64. objy := math.Abs(float64(objValue[1][i]))
  65. //fmt.Println(objx)
  66. //fmt.Println(objy)
  67. diffx := cutobjx - objx
  68. diffy := math.Abs(cutobjy - objy)
  69. if diffx >= 0 && diffx <= 6 && diffy <= 4.0 {
  70. return true
  71. }
  72. }
  73. }
  74. }
  75. }
  76. return false
  77. }
  78. func FinalCallback(shareVars *sync.Map) {
  79. OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
  80. ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
  81. ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
  82. AngularVelocityZOfCicvLocation, _ := shareVars.Load("AngularVelocityZOfCicvLocation")
  83. AngularVelocityZ := AngularVelocityZOfCicvLocation.(float64)
  84. if ok && ok1 && OutsideWorkshopFlag.(bool) == true {
  85. for objId, objValue := range ObjDic {
  86. Maxlenobj = max(Maxlenobj, int32(len(objValue[0])))
  87. cutinflag, cutinframe, cutobjx, cutobjy := isCuttingIn(objValue, AngularVelocityZ)
  88. if cutinflag {
  89. if SightBlock(cutobjx, cutobjy, objId, cutinframe, ObjDic) {
  90. event_lable := "CutinWithSightBblock"
  91. fmt.Println(event_lable)
  92. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  93. }
  94. }
  95. if Maxlenobj >= 100 {
  96. ObjDicOfTpperception = make(map[uint32][][]float32)
  97. shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
  98. Maxlenobj = 0
  99. }
  100. }
  101. }
  102. }