FindLongCurve.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. "sync"
  7. )
  8. func Topic() string {
  9. return "/cicv_location"
  10. }
  11. // todo 禁止存在下划线_
  12. func Label() string {
  13. return "FindLongCurve"
  14. }
  15. type Point struct {
  16. Latitude float64
  17. Longitude float64
  18. }
  19. var (
  20. count1 int = 0
  21. //定义弯道坐标
  22. point = Point{39.73004426154644, 116.49248639463602}
  23. )
  24. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
  25. defer func() {
  26. if r := recover(); r != nil {
  27. fmt.Println("Recovered from panic:", r)
  28. }
  29. }()
  30. if count1%10 == 0 {
  31. enterflag := IfEnter(point, 25.0, data.Latitude, data.Longitude)
  32. AbsSpeed, _ := shareVars.Load("AbsSpeed")
  33. if enterflag && AbsSpeed.(float64) > 1 {
  34. //eventLabel := "FindTrafficLight"
  35. //fmt.Println(eventLabel)
  36. return "FindLongCurve"
  37. }
  38. }
  39. count1++
  40. return ""
  41. }
  42. func IfEnter(point Point, radius float64, lat, lon float64) bool {
  43. // 判断是否进入点列表中的区域
  44. point1 := Point{Latitude: lat, Longitude: lon}
  45. d := distance(point1, point)
  46. if d <= radius {
  47. return true
  48. }
  49. return false
  50. }
  51. // 计算两点之间的距离(米)
  52. func distance(point1, point2 Point) float64 {
  53. // 经纬度转弧度
  54. lat1 := point1.Latitude * math.Pi / 180
  55. lon1 := point1.Longitude * math.Pi / 180
  56. lat2 := point2.Latitude * math.Pi / 180
  57. lon2 := point2.Longitude * math.Pi / 180
  58. // 计算距离
  59. dlon := lon2 - lon1
  60. dlat := lat2 - lat1
  61. a := math.Sin(dlat/2)*math.Sin(dlat/2) + math.Sin(dlon/2)*math.Sin(dlon/2)*math.Cos(lat1)*math.Cos(lat2)
  62. c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
  63. d := 6371000 * c
  64. return d
  65. }