multiTrafficConeAhead.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. "sync"
  7. )
  8. func Topic() string {
  9. return "/tpperception"
  10. }
  11. // Label todo 禁止存在下划线_
  12. // MultiPedestrianAhead
  13. // MultiCarAhead
  14. // MultiTruckAhead
  15. // MultiBicycleAhead
  16. // MultiTricycleAhead
  17. // MultiTrafficConeAhead
  18. func Label() string {
  19. return "MultiTrafficConeAhead"
  20. }
  21. type Record struct {
  22. StableFrame int
  23. LastExistingTime float64
  24. }
  25. var record *Record = nil
  26. // objTypeCheck 目标物类型检测
  27. // × 金龙车:CAR_TYPE=0, TRUCK_TYPE=1, PEDESTRIAN_TYPE=2, CYCLIST_TYPE=3, UNKNOWN_TYPE=4, UNKNOWN_MOVABLE_TYPE=5, UNKNOWN_UNMOVABLE_TYPE=6
  28. // √ 多功能车:UNKNOWN TYPE=O, PEDESTRIAN TYPE=1, CAR TYPE=2, TRUCK TYPE=3, Bicycle TYPE=4, Tricycle TYPE=5, Traffic Cone TYPE=6
  29. func objTypeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  30. const targetType uint8 = 6
  31. return targetType == obj.Type
  32. }
  33. // objPosCheck 判断目标物位置关系
  34. func objPosCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  35. const laneWidth = 3.5 // m
  36. return obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5
  37. }
  38. // isEgoStationary 判断主车是否“静止”(速度低于阈值)
  39. func isEgoStationary(shareVars *sync.Map) bool {
  40. const minSpeed = 1 // m/s
  41. VelocityXOfCicvLocation, _ := shareVars.Load("VelocityXOfCicvLocation") // float64
  42. VelocityYOfCicvLocation, _ := shareVars.Load("VelocityYOfCicvLocation")
  43. speed := math.Sqrt(math.Pow(VelocityXOfCicvLocation.(float64), 2) + math.Pow(VelocityYOfCicvLocation.(float64), 2))
  44. return speed > minSpeed
  45. }
  46. // Rule 检测前方指定目标物数量
  47. func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
  48. defer func() {
  49. if r := recover(); r != nil {
  50. fmt.Println("Recovered from panic:", r)
  51. }
  52. }()
  53. outsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
  54. if !outsideWorkshopFlag.(bool) || !isEgoStationary(shareVars) {
  55. return ""
  56. }
  57. //const Cgcs2000X = 456256.260152
  58. //const Cgcs2000Y = 4397809.886833
  59. const MinStableFrameCount = 5 // frame
  60. const MaxTimeBetweenFrame = 0.5 // second
  61. const minTargetNum = 3
  62. if len(msg.Objs) >= minTargetNum {
  63. currTargetNum := 0
  64. //fmt.Println("\n", time.Unix(int64(msg.Header.TimeStamp), int64(msg.Header.TimeStamp*1e9)%1e9).Format(time.StampNano))
  65. for _, obj := range msg.Objs {
  66. // 判断目标物是否满足筛选条件
  67. if objTypeCheck(&obj) && objPosCheck(&obj) {
  68. //fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
  69. // obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-Cgcs2000X, obj.Yabs-Cgcs2000Y, obj.Speed, obj.Length, obj.Width, obj.Height))
  70. currTargetNum++
  71. }
  72. }
  73. if currTargetNum >= minTargetNum {
  74. if nil == record {
  75. record = &Record{
  76. StableFrame: 1,
  77. LastExistingTime: msg.Header.TimeStamp,
  78. }
  79. //fmt.Println("---------- create ----------")
  80. } else {
  81. newRecord := Record{
  82. StableFrame: 1,
  83. LastExistingTime: msg.Header.TimeStamp,
  84. }
  85. if newRecord.LastExistingTime-record.LastExistingTime <= MaxTimeBetweenFrame {
  86. newRecord.StableFrame = record.StableFrame + 1
  87. if newRecord.StableFrame == MinStableFrameCount {
  88. record = nil
  89. //fmt.Println("!!!!!!!!!! found !!!!!!!!!!")
  90. return Label()
  91. } else {
  92. //fmt.Println("---------- update ----------")
  93. }
  94. } else {
  95. //fmt.Println("---------- reset ----------")
  96. }
  97. record = &newRecord
  98. }
  99. }
  100. }
  101. return ""
  102. }