multiTargetAhead.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. )
  7. func Topic() string {
  8. return "/tpperception"
  9. }
  10. // Label todo 禁止存在下划线_
  11. // MultiPedestrianAhead
  12. // MultiCarAhead
  13. // MultiTruckAhead
  14. // MultiBicycleAhead
  15. // MultiTricycleAhead
  16. // MultiTrafficConeAhead
  17. func Label() string {
  18. return "MultiPedestrianAhead"
  19. }
  20. type Record struct {
  21. StableFrame int
  22. LastExistingTime float64
  23. }
  24. var record *Record = nil
  25. // typeCheck 目标物类型检测
  26. // × 金龙车:CAR_TYPE=0, TRUCK_TYPE=1, PEDESTRIAN_TYPE=2, CYCLIST_TYPE=3, UNKNOWN_TYPE=4, UNKNOWN_MOVABLE_TYPE=5, UNKNOWN_UNMOVABLE_TYPE=6
  27. // √ 多功能车:UNKNOWN TYPE=O, PEDESTRIAN TYPE=1, CAR TYPE=2, TRUCK TYPE=3, Bicycle TYPE=4, Tricycle TYPE=5, Traffic Cone TYPE=6
  28. func typeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  29. const targetType uint8 = 1
  30. return targetType == obj.Type
  31. }
  32. // posCheck 判断目标物位置关系
  33. func posCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  34. const laneWidth = 3.5 // m
  35. return obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5
  36. }
  37. // Rule 检测前方指定目标物数量
  38. func Rule(msg *pjisuv_msgs.PerceptionObjects) string {
  39. defer func() {
  40. if r := recover(); r != nil {
  41. fmt.Println("Recovered from panic:", r)
  42. }
  43. }()
  44. const Cgcs2000X = 456256.260152
  45. const Cgcs2000Y = 4397809.886833
  46. const MinStableFrameCount = 5 // frame
  47. const MaxTimeBetweenFrame = 0.5 // second
  48. const minTargetNum = 4
  49. if len(msg.Objs) >= minTargetNum {
  50. currTargetNum := 0
  51. for _, obj := range msg.Objs {
  52. // 判断目标物是否满足筛选条件
  53. if typeCheck(&obj) && posCheck(&obj) {
  54. currTargetNum++
  55. }
  56. }
  57. if currTargetNum >= minTargetNum {
  58. if nil == record {
  59. record = &Record{
  60. StableFrame: 1,
  61. LastExistingTime: msg.Header.TimeStamp,
  62. }
  63. } else {
  64. newRecord := Record{
  65. StableFrame: 1,
  66. LastExistingTime: msg.Header.TimeStamp,
  67. }
  68. if newRecord.LastExistingTime-record.LastExistingTime <= MaxTimeBetweenFrame {
  69. newRecord.StableFrame = record.StableFrame + 1
  70. if newRecord.StableFrame == MinStableFrameCount {
  71. record = nil
  72. return Label()
  73. } else {
  74. }
  75. } else {
  76. }
  77. record = &newRecord
  78. }
  79. }
  80. }
  81. return ""
  82. }