UnknownBigTargetAhead.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. // objTypeCheck 目标物类型检测
  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 objTypeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  25. const targetType uint8 = 0
  26. return targetType == obj.Type
  27. }
  28. // objSizeCheck 目标物大小检测
  29. func objSizeCheck(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. // objPosCheck 判断目标物位置关系
  52. func objPosCheck(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. // isEgoStationary 判断主车是否“静止”(速度低于阈值)
  57. func isEgoStationary(shareVars *sync.Map) bool {
  58. const minSpeed = 1 // m/s
  59. VelocityXOfCicvLocation, _ := shareVars.Load("VelocityXOfCicvLocation") // float64
  60. VelocityYOfCicvLocation, _ := shareVars.Load("VelocityYOfCicvLocation")
  61. speed := math.Sqrt(math.Pow(VelocityXOfCicvLocation.(float64), 2) + math.Pow(VelocityYOfCicvLocation.(float64), 2))
  62. return speed > minSpeed
  63. }
  64. // Rule 检测前方未知大目标物
  65. func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
  66. defer func() {
  67. if r := recover(); r != nil {
  68. fmt.Println(fmt.Sprintf("Recovered from panic: [%s], [%#v]", Label(), r))
  69. }
  70. }()
  71. // 判断主车所在位置 & 行驶速度
  72. outsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
  73. if !outsideWorkshopFlag.(bool) || !isEgoStationary(shareVars) {
  74. return ""
  75. }
  76. //const Cgcs2000X = 456256.260152
  77. //const Cgcs2000Y = 4397809.886833
  78. const MinStableFrameCount = 5 // frame
  79. const MaxTimeBetweenFrame = 0.5 // second
  80. //fmt.Println("\n", time.Unix(int64(msg.Header.TimeStamp), int64(msg.Header.TimeStamp*1e9)%1e9).Format(time.StampNano))
  81. for _, obj := range msg.Objs {
  82. // 判断目标物是否满足筛选条件
  83. if objTypeCheck(&obj) && objPosCheck(&obj) && objSizeCheck(&obj) {
  84. //fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
  85. // obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-Cgcs2000X, obj.Yabs-Cgcs2000Y, obj.Speed, obj.Length, obj.Width, obj.Height))
  86. // 目标物初见存档
  87. if prevObjRecord, exists := objectsStability[obj.Id]; exists == false {
  88. objectsStability[obj.Id] = Object{
  89. ID: obj.Id,
  90. StableFrame: 1,
  91. LastExistingTime: msg.Header.TimeStamp,
  92. }
  93. //fmt.Println("---------- create ----------")
  94. } else {
  95. currObjRecord := Object{
  96. ID: obj.Id,
  97. StableFrame: 1,
  98. LastExistingTime: msg.Header.TimeStamp,
  99. }
  100. // 目标物确认/更新/重置
  101. if currObjRecord.LastExistingTime-prevObjRecord.LastExistingTime <= MaxTimeBetweenFrame { // 目标物消失不超过0.5s
  102. currObjRecord.StableFrame = prevObjRecord.StableFrame + 1
  103. if currObjRecord.StableFrame == MinStableFrameCount {
  104. delete(objectsStability, obj.Id)
  105. //fmt.Println("!!!!!!!!!! found !!!!!!!!!!")
  106. return Label()
  107. } else {
  108. //fmt.Println("---------- update ----------")
  109. }
  110. } else {
  111. //fmt.Println("---------- reset ----------")
  112. }
  113. objectsStability[obj.Id] = currObjRecord
  114. }
  115. }
  116. }
  117. return ""
  118. }