EnterTjunction.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "cicv-data-closedloop/pjisuv_param"
  5. "fmt"
  6. "math"
  7. )
  8. func Topic() string {
  9. return "/cicv_location"
  10. }
  11. // Label todo 禁止存在下划线_
  12. func Label() string {
  13. return "EnterTjunction"
  14. }
  15. type Point struct {
  16. Latitude float64
  17. Longitude float64
  18. }
  19. var (
  20. count2 int = 0
  21. //定义园区部门T字路口的经纬度坐标值
  22. point3 = Point{39.73040966605621, 116.48995329696209}
  23. point4 = Point{39.73083727413453, 116.49079780188244}
  24. point5 = Point{39.72976753711939, 116.49043130389033}
  25. point6 = Point{39.73012466515933, 116.49128381717591}
  26. point7 = Point{39.729251498328246, 116.49077484625299}
  27. point8 = Point{39.72964529630643, 116.49164592200161}
  28. pointlist = []Point{point3, point4, point5, point6, point7, point8}
  29. )
  30. func Rule(data *pjisuv_msgs.PerceptionLocalization, param *pjisuv_param.PjisuvParam) string {
  31. defer func() {
  32. if r := recover(); r != nil {
  33. fmt.Println("Recovered from panic:", r)
  34. }
  35. }()
  36. if count2%10 == 0 {
  37. enterflag := IfEnter(pointlist, 12.0, data.Latitude, data.Longitude)
  38. if enterflag && param.VelocityXOfCicvLocation >= 1 {
  39. //eventLabel := "EnterTjunction"
  40. //fmt.Println(eventLabel)
  41. return Label()
  42. }
  43. }
  44. count2++
  45. return ""
  46. }
  47. func IfEnter(pointlist []Point, radius float64, lat, lon float64) bool {
  48. // 判断是否进入点列表中的区域
  49. point1 := Point{Latitude: lat, Longitude: lon}
  50. for _, point := range pointlist {
  51. d := distance(point1, point)
  52. if d <= radius {
  53. return true
  54. }
  55. }
  56. return false
  57. }
  58. // 计算两点之间的距离(米)
  59. func distance(point1, point2 Point) float64 {
  60. // 经纬度转弧度
  61. lat1 := point1.Latitude * math.Pi / 180
  62. lon1 := point1.Longitude * math.Pi / 180
  63. lat2 := point2.Latitude * math.Pi / 180
  64. lon2 := point2.Longitude * math.Pi / 180
  65. // 计算距离
  66. dlon := lon2 - lon1
  67. dlat := lat2 - lat1
  68. a := math.Sin(dlat/2)*math.Sin(dlat/2) + math.Sin(dlon/2)*math.Sin(dlon/2)*math.Cos(lat1)*math.Cos(lat2)
  69. c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
  70. d := 6371000 * c
  71. return d
  72. }