lowSpdTruckAhead.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. func Label() string {
  12. return "LowSpdTruckAhead"
  13. }
  14. // speedCheck 目标物速度检测
  15. func speedCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  16. var targetMinSpeed float32 = 2 / 3.6 // m/s
  17. var targetMaxSpeed float32 = 20 / 3.6 // m/s
  18. if targetMinSpeed < obj.Speed && obj.Speed < targetMaxSpeed {
  19. return true
  20. }
  21. return false
  22. }
  23. // typeCheck 目标物类型检测
  24. // × 金龙车:CAR_TYPE=0, TRUCK_TYPE=1, PEDESTRIAN_TYPE=2, CYCLIST_TYPE=3, UNKNOWN_TYPE=4, UNKNOWN_MOVABLE_TYPE=5, UNKNOWN_UNMOVABLE_TYPE=6
  25. // √ 多功能车:UNKNOWN TYPE=O, PEDESTRIAN TYPE=1, CAR TYPE=2, TRUCK TYPE=3, Bicycle TYPE=4, Tricycle TYPE=5, Traffic Cone TYPE=6
  26. func typeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  27. var targetType uint8 = 3
  28. if targetType == obj.Type {
  29. return true
  30. }
  31. return false
  32. }
  33. // sizeCheck 目标物大小检测
  34. func sizeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  35. // 多功能车
  36. var targetMinLength float32 = 3.6 // m
  37. var targetMinWidth float32 = 1.605 // m
  38. var targetMinHeight float32 = 1.995 // m
  39. // 金龙车
  40. //targetMinLength := 5.99
  41. //targetMinWidth := 2.065
  42. //targetMinHeight := 2.82
  43. if obj.Length > targetMinLength || obj.Width > targetMinWidth || obj.Height > targetMinHeight {
  44. return true
  45. }
  46. return false
  47. }
  48. // posCheck 判断目标物位置关系
  49. func posCheck(obj *pjisuv_msgs.PerceptionObject) bool {
  50. laneWidth := 3.5 // m
  51. if obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5 {
  52. return true
  53. }
  54. return false
  55. }
  56. // Rule 感知算法识别大车、有车辆在前方车道且低速行驶
  57. func Rule(msg *pjisuv_msgs.PerceptionObjects) string {
  58. defer func() {
  59. if r := recover(); r != nil {
  60. fmt.Println("Recovered from panic:", r)
  61. }
  62. }()
  63. for _, obj := range msg.Objs {
  64. // todo: 对各判断条件单独进行稳定性校验?
  65. if speedCheck(&obj) && posCheck(&obj) && (typeCheck(&obj) || sizeCheck(&obj)) {
  66. return "LowSpdTruckAhead"
  67. }
  68. }
  69. return ""
  70. }