FrontCarSideBySide.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. "sync"
  7. )
  8. // 该程序存在的意义是为cicv_ticker中的FrontCarSideBySide触发器提供countSideBySide的全局变量
  9. func Topic() string {
  10. return "/tpperception"
  11. }
  12. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
  13. defer func() {
  14. if r := recover(); r != nil {
  15. fmt.Println("Recovered from panic:", r)
  16. }
  17. }()
  18. count1 := 0
  19. AbsSpeed, ok := shareVars.Load("AbsSpeed")
  20. OutsideWorkshopFlag, ok1 := shareVars.Load("OutsideWorkshopFlag")
  21. OutsideWorkshopFlag = OutsideWorkshopFlag.(bool)
  22. countSideBySide, ok2 := shareVars.Load("CountSideBySide")
  23. if ok && ok1 && ok2 {
  24. lable1:
  25. for _, obj := range data.Objs {
  26. if !(obj.Type != 2 || obj.Type != 3 || obj.Type != 4 || !(obj.X >= 3 && obj.X <= 17) || math.Abs(float64(obj.Y)) > 10) {
  27. //fmt.Println("here")
  28. obj1ID := obj.Id
  29. obj1x := obj.X
  30. obj1y := obj.Y
  31. //fmt.Println(obj1ID, obj1x, obj1y)
  32. for _, obj1 := range data.Objs {
  33. if !(obj1.Type != 2 || obj1.Type != 3 || obj1.Type != 4 || !(obj1.X >= 3 && obj1.X <= 17) || math.Abs(float64(obj1.Y)) > 10) {
  34. obj2ID := obj1.Id
  35. obj2x := obj1.X
  36. obj2y := obj1.Y
  37. if obj2ID != obj1ID && math.Abs(float64(obj2x-obj1x)) <= 2.2 && math.Abs(float64(obj2y-obj1y)) >= 2 && math.Abs(float64(obj2y-obj1y)) <= 4.0 && AbsSpeed.(float64) > 2 {
  38. count1 = countSideBySide.(int) + 1
  39. shareVars.Store("countSideBySide", count1)
  40. break lable1
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }
  47. return ""
  48. }