CCRH.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "CCRH"
  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 isCuttingOut(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. Type := ObjectList[4][0]
  45. if xi >= 0 && yi <= 0.7 && Type != 1.0 {
  46. for j := 0; j < len(ObjectList[0])-i-1; j++ {
  47. xj := ObjectList[0][j]
  48. yj := math.Abs(float64(ObjectList[1][j]))
  49. if xj >= 0 && yj >= 2.5 {
  50. return true
  51. }
  52. }
  53. }
  54. }
  55. return false
  56. }
  57. func FinalCallback(shareVars *sync.Map) {
  58. OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
  59. ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
  60. AngularVelocityZOfCicvLocation, ok3 := shareVars.Load("AngularVelocityZOfCicvLocation")
  61. ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
  62. AbsSpeed, ok2 := shareVars.Load("AbsSpeed")
  63. if ok && ok1 && ok2 && ok3 && AngularVelocityZOfCicvLocation.(float64) < 0.6 && AbsSpeed.(float64) > 1 && OutsideWorkshopFlag.(bool) == true {
  64. for _, objValue := range ObjDic {
  65. if len(ObjDic[0]) <= 10 || !isCuttingOut(objValue) {
  66. continue
  67. }
  68. event_lable := "CCRH"
  69. fmt.Println(event_lable)
  70. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  71. }
  72. }
  73. }