unknownBigTargetAhead.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. )
  7. type Object struct {
  8. ID uint32
  9. StableFrame int
  10. LastExistingTime float64
  11. }
  12. var objectsStability = make(map[uint32]Object)
  13. const (
  14. Cgcs2000X = 456256.260152
  15. Cgcs2000Y = 4397809.886833
  16. MinStableFrameCount = 5
  17. MaxTimeBetweenFrame = 0.5
  18. )
  19. func Topic() string {
  20. return "/tpperception"
  21. }
  22. // Label todo 禁止存在下划线_
  23. func Label() string {
  24. return "UnknownBigTargetAhead"
  25. }
  26. // typeCheck 目标物类型检测
  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 typeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  30. const targetType uint8 = 0
  31. return targetType == obj.Type
  32. }
  33. // sizeCheck 目标物大小检测
  34. func sizeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  35. // 多功能车
  36. const targetMinLength = 3.6 // m
  37. const targetMinWidth = 1.605 // m
  38. const targetMinHeight = 1.995 // m
  39. // 金龙车
  40. //targetMinLength := 5.99
  41. //targetMinWidth := 2.065
  42. //targetMinHeight := 2.82
  43. // 至少满足两个条件
  44. counter := 0
  45. if obj.Length >= targetMinLength {
  46. counter++
  47. }
  48. if obj.Width >= targetMinWidth {
  49. counter++
  50. }
  51. if obj.Height >= targetMinHeight {
  52. counter++
  53. }
  54. return counter > 1
  55. }
  56. // posCheck 判断目标物位置关系
  57. func posCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  58. const laneWidth = 3.5 // m
  59. return obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5
  60. }
  61. // Rule 检测前方未知大目标物
  62. func Rule(msg *pjisuv_msgs.PerceptionObjects) string {
  63. defer func() {
  64. if r := recover(); r != nil {
  65. fmt.Println("Recovered from panic:", r)
  66. }
  67. }()
  68. for _, obj := range msg.Objs {
  69. // 判断目标物是否满足筛选条件
  70. if typeCheck(&obj) && posCheck(&obj) && sizeCheck(&obj) {
  71. // 目标物初见存档
  72. if prevObjRecord, exists := objectsStability[obj.Id]; exists == false {
  73. objectsStability[obj.Id] = Object{
  74. ID: obj.Id,
  75. StableFrame: 1,
  76. LastExistingTime: msg.Header.TimeStamp,
  77. }
  78. } else {
  79. currObjRecord := Object{
  80. ID: obj.Id,
  81. StableFrame: 1,
  82. LastExistingTime: msg.Header.TimeStamp,
  83. }
  84. // 目标物确认/更新/重置
  85. if currObjRecord.LastExistingTime-prevObjRecord.LastExistingTime <= MaxTimeBetweenFrame { // 目标物消失不超过0.5s
  86. currObjRecord.StableFrame = prevObjRecord.StableFrame + 1
  87. if currObjRecord.StableFrame == MinStableFrameCount {
  88. delete(objectsStability, obj.Id)
  89. return "UnknownBigTargetAhead"
  90. } else {
  91. objectsStability[obj.Id] = currObjRecord
  92. }
  93. } else {
  94. objectsStability[obj.Id] = currObjRecord
  95. }
  96. }
  97. }
  98. }
  99. return ""
  100. }