CCFhos.go 1.9 KB

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