SpeedBumpOverspeed.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. "sync"
  7. )
  8. type Point struct {
  9. Latitude float64
  10. Longitude float64
  11. }
  12. var (
  13. threshold float64 = 4.0
  14. IsSpeedBump bool
  15. count1 int64
  16. //定义园减速带经纬度
  17. point3 = Point{39.73002669559404, 116.49020088105833}
  18. point4 = Point{39.728688903362254, 116.4896802037327}
  19. point5 = Point{39.728406077854494, 116.48901074348075}
  20. point6 = Point{39.7287051534828, 116.48822784823321}
  21. point7 = Point{39.72925799042968, 116.49074368869654}
  22. pointlist1 = []Point{point3, point4, point5, point6, point7}
  23. )
  24. func Topic() string {
  25. return "/cicv_location"
  26. }
  27. // 禁止存在下划线_
  28. func Label() string {
  29. return "SpeedBumpOverspeed"
  30. }
  31. func IfEnter(pointlist []Point, radius float64, lat, lon float64) bool {
  32. // 判断是否进入点列表中的区域
  33. point1 := Point{Latitude: lat, Longitude: lon}
  34. for _, point := range pointlist {
  35. d := distance(point1, point)
  36. if d <= radius {
  37. return true
  38. }
  39. }
  40. return false
  41. }
  42. // 计算两点之间的距离(米)
  43. func distance(point1, point2 Point) float64 {
  44. // 经纬度转弧度
  45. lat1 := point1.Latitude * math.Pi / 180
  46. lon1 := point1.Longitude * math.Pi / 180
  47. lat2 := point2.Latitude * math.Pi / 180
  48. lon2 := point2.Longitude * math.Pi / 180
  49. // 计算距离
  50. dlon := lon2 - lon1
  51. dlat := lat2 - lat1
  52. a := math.Sin(dlat/2)*math.Sin(dlat/2) + math.Sin(dlon/2)*math.Sin(dlon/2)*math.Cos(lat1)*math.Cos(lat2)
  53. c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
  54. d := 6371000 * c
  55. return d
  56. }
  57. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
  58. defer func() {
  59. if r := recover(); r != nil {
  60. fmt.Println("Recovered from panic:", r)
  61. }
  62. }()
  63. if count1%10 == 0 {
  64. Automode, _ := shareVars.Load("AutomodeOfPjVehicleFdbPub")
  65. Automode = Automode.(int16)
  66. IsSpeedBump = IfEnter(pointlist1, 7.0, data.Latitude, data.Longitude)
  67. if Automode == 1 && IsSpeedBump {
  68. absspeed, ok := shareVars.Load("AbsSpeed")
  69. if ok && absspeed.(float64) >= threshold {
  70. eventLabel := "SpeedBumpOverspeed"
  71. fmt.Println(eventLabel)
  72. count1 = 1
  73. return Label()
  74. }
  75. }
  76. }
  77. count1++
  78. return ""
  79. }