FrontVehicleCutInNear.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_ticker"
  4. "fmt"
  5. "math"
  6. "sync"
  7. "time"
  8. )
  9. // 定时任务触发器固定的
  10. func Topic() string {
  11. return pjisuv_ticker.TickerTopic
  12. }
  13. // ******* 禁止存在下划线_
  14. // 触发器标记
  15. func Label() string {
  16. return "FrontVehicleCutInNear"
  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(4) * 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 isCuttingIn(ObjectList [][]float32, AngularVelocityZ float64) bool {
  40. for i, objY := range ObjectList[1] {
  41. if math.Abs(float64(objY)) >= 1.3 && math.Abs(AngularVelocityZ) <= 0.6 && ObjectList[0][i] >= 2 {
  42. //fmt.Println(objY)
  43. for j := 0; j < len(ObjectList[1])-i-1; j++ {
  44. objX := ObjectList[0][1+i+j]
  45. if math.Abs(float64(ObjectList[1][1+i+j])) <= 0.7 && math.Abs(AngularVelocityZ) <= 0.6 && objX >= 1 && objX <= 16 {
  46. //fmt.Println(objX)
  47. return true
  48. }
  49. }
  50. }
  51. }
  52. return false
  53. }
  54. func FinalCallback(shareVars *sync.Map) {
  55. OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
  56. ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
  57. ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
  58. AngularVelocityZOfCicvLocation, _ := shareVars.Load("AngularVelocityZOfCicvLocation")
  59. AngularVelocityZ := AngularVelocityZOfCicvLocation.(float64)
  60. if ok && ok1 && OutsideWorkshopFlag.(bool) == true {
  61. for _, objValue := range ObjDic {
  62. if len(ObjDic[0]) <= 4 || !isCuttingIn(objValue, AngularVelocityZ) {
  63. continue
  64. }
  65. event_lable := "FrontVehicleCutInNear"
  66. fmt.Println(event_lable)
  67. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  68. }
  69. ObjDicOfTpperception = make(map[uint32][][]float32)
  70. shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
  71. }
  72. }