CurveOverspeed.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 = 10
  14. IsCurve bool
  15. count1 int64
  16. pointcurve = Point{39.73004426154644, 116.49248639463602}
  17. pointlist1 = []Point{pointcurve}
  18. )
  19. func Topic() string {
  20. return "/cicv_location"
  21. }
  22. // 禁止存在下划线_
  23. func Label() string {
  24. return "CurveOverspeed"
  25. }
  26. func IfEnter(pointlist []Point, radius float64, lat, lon float64) bool {
  27. // 判断是否进入点列表中的区域
  28. point1 := Point{Latitude: lat, Longitude: lon}
  29. for _, point := range pointlist {
  30. d := distance(point1, point)
  31. if d <= radius {
  32. return true
  33. }
  34. }
  35. return false
  36. }
  37. // 计算两点之间的距离(米)
  38. func distance(point1, point2 Point) float64 {
  39. // 经纬度转弧度
  40. lat1 := point1.Latitude * math.Pi / 180
  41. lon1 := point1.Longitude * math.Pi / 180
  42. lat2 := point2.Latitude * math.Pi / 180
  43. lon2 := point2.Longitude * math.Pi / 180
  44. // 计算距离
  45. dlon := lon2 - lon1
  46. dlat := lat2 - lat1
  47. a := math.Sin(dlat/2)*math.Sin(dlat/2) + math.Sin(dlon/2)*math.Sin(dlon/2)*math.Cos(lat1)*math.Cos(lat2)
  48. c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
  49. d := 6371000 * c
  50. return d
  51. }
  52. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
  53. defer func() {
  54. if r := recover(); r != nil {
  55. fmt.Println("Recovered from panic:", r)
  56. }
  57. }()
  58. if count1%10 == 0 {
  59. Automode, _ := shareVars.Load("AutomodeOfPjVehicleFdbPub")
  60. Automode = Automode.(int16)
  61. IsCurve = IfEnter(pointlist1, 30.0, data.Latitude, data.Longitude)
  62. if Automode == 1 && IsCurve {
  63. absspeed := math.Sqrt(math.Pow(data.VelocityX, 2) + math.Pow(data.VelocityY, 2))
  64. if absspeed >= threshold {
  65. eventLabel := "CurveOverspeed"
  66. fmt.Println(eventLabel)
  67. count1 = 1
  68. return Label()
  69. }
  70. }
  71. }
  72. count1++
  73. return ""
  74. }