UnknownBigTargetAhead.go 2.9 KB

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