UnknownBigTargetAhead.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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) {
  74. return ""
  75. }
  76. // 判断主车行驶速度
  77. if isEgoStationary(shareVars) {
  78. return ""
  79. }
  80. //const Cgcs2000X = 456256.260152
  81. //const Cgcs2000Y = 4397809.886833
  82. const MinStableFrameCount = 5 // frame
  83. const MaxTimeBetweenFrame = 0.5 // second
  84. //fmt.Println("\n", time.Unix(int64(msg.Header.TimeStamp), int64(msg.Header.TimeStamp*1e9)%1e9).Format(time.StampNano))
  85. for _, obj := range msg.Objs {
  86. // 判断目标物是否满足筛选条件
  87. if objTypeCheck(&obj) && objPosCheck(&obj) && objSizeCheck(&obj) {
  88. //fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
  89. // obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-Cgcs2000X, obj.Yabs-Cgcs2000Y, obj.Speed, obj.Length, obj.Width, obj.Height))
  90. // 目标物初见存档
  91. if prevObjRecord, exists := objectsStability[obj.Id]; exists == false {
  92. objectsStability[obj.Id] = Object{
  93. ID: obj.Id,
  94. StableFrame: 1,
  95. LastExistingTime: msg.Header.TimeStamp,
  96. }
  97. //fmt.Println("---------- create ----------")
  98. } else {
  99. currObjRecord := Object{
  100. ID: obj.Id,
  101. StableFrame: 1,
  102. LastExistingTime: msg.Header.TimeStamp,
  103. }
  104. // 目标物确认/更新/重置
  105. if currObjRecord.LastExistingTime-prevObjRecord.LastExistingTime <= MaxTimeBetweenFrame { // 目标物消失不超过0.5s
  106. currObjRecord.StableFrame = prevObjRecord.StableFrame + 1
  107. if currObjRecord.StableFrame == MinStableFrameCount {
  108. delete(objectsStability, obj.Id)
  109. //fmt.Println("!!!!!!!!!! found !!!!!!!!!!")
  110. return Label()
  111. } else {
  112. //fmt.Println("---------- update ----------")
  113. }
  114. } else {
  115. //fmt.Println("---------- reset ----------")
  116. }
  117. objectsStability[obj.Id] = currObjRecord
  118. }
  119. }
  120. }
  121. return ""
  122. }