JunctionOverspeed.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 = 5
  14. IsCurve bool
  15. count1 int64
  16. //定义园区T字路口的经纬度坐标值
  17. point3 = Point{39.73040966605621, 116.48995329696209}
  18. point4 = Point{39.73083727413453, 116.49079780188244}
  19. point5 = Point{39.72976753711939, 116.49043130389033}
  20. point6 = Point{39.73012466515933, 116.49128381717591}
  21. point7 = Point{39.729251498328246, 116.49077484625299}
  22. point8 = Point{39.72964529630643, 116.49164592200161}
  23. pointlist = []Point{point3, point4, point5, point6, point7, point8}
  24. )
  25. func Topic() string {
  26. return "/cicv_location"
  27. }
  28. // 禁止存在下划线_
  29. func Label() string {
  30. return "JunctionOverspeed"
  31. }
  32. func IfEnter(pointlist []Point, radius float64, lat, lon float64) bool {
  33. // 判断是否进入点列表中的区域
  34. point1 := Point{Latitude: lat, Longitude: lon}
  35. for _, point := range pointlist {
  36. d := distance(point1, point)
  37. if d <= radius {
  38. return true
  39. }
  40. }
  41. return false
  42. }
  43. // 计算两点之间的距离(米)
  44. func distance(point1, point2 Point) float64 {
  45. // 经纬度转弧度
  46. lat1 := point1.Latitude * math.Pi / 180
  47. lon1 := point1.Longitude * math.Pi / 180
  48. lat2 := point2.Latitude * math.Pi / 180
  49. lon2 := point2.Longitude * math.Pi / 180
  50. // 计算距离
  51. dlon := lon2 - lon1
  52. dlat := lat2 - lat1
  53. a := math.Sin(dlat/2)*math.Sin(dlat/2) + math.Sin(dlon/2)*math.Sin(dlon/2)*math.Cos(lat1)*math.Cos(lat2)
  54. c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
  55. d := 6371000 * c
  56. return d
  57. }
  58. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
  59. defer func() {
  60. if r := recover(); r != nil {
  61. fmt.Println("Recovered from panic:", r)
  62. }
  63. }()
  64. if count1%10 == 0 {
  65. Automode, _ := shareVars.Load("AutomodeOfPjVehicleFdbPub")
  66. Automode = Automode.(int16)
  67. IsCurve = IfEnter(pointlist, 16.0, data.Latitude, data.Longitude)
  68. if Automode == 1 && IsCurve {
  69. absspeed, ok := shareVars.Load("AbsSpeed")
  70. if ok && absspeed.(float64) >= threshold {
  71. eventLabel := "JunctionOverspeed"
  72. fmt.Println(eventLabel)
  73. count1 = 1
  74. return Label()
  75. }
  76. }
  77. }
  78. count1++
  79. return ""
  80. }