123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package main
- import (
- "cicv-data-closedloop/pjisuv_msgs"
- "fmt"
- "math"
- "sync"
- )
- type Point struct {
- Latitude float64
- Longitude float64
- }
- var (
- threshold float64 = 4.0
- IsSpeedBump bool
- count1 int64
- //定义园减速带经纬度
- point3 = Point{39.73002669559404, 116.49020088105833}
- point4 = Point{39.728688903362254, 116.4896802037327}
- point5 = Point{39.728406077854494, 116.48901074348075}
- point6 = Point{39.7287051534828, 116.48822784823321}
- point7 = Point{39.72925799042968, 116.49074368869654}
- pointlist1 = []Point{point3, point4, point5, point6, point7}
- )
- func Topic() string {
- return "/cicv_location"
- }
- // 禁止存在下划线_
- func Label() string {
- return "SpeedBumpOverspeed"
- }
- func IfEnter(pointlist []Point, radius float64, lat, lon float64) bool {
- // 判断是否进入点列表中的区域
- point1 := Point{Latitude: lat, Longitude: lon}
- for _, point := range pointlist {
- d := distance(point1, point)
- if d <= radius {
- return true
- }
- }
- return false
- }
- // 计算两点之间的距离(米)
- func distance(point1, point2 Point) float64 {
- // 经纬度转弧度
- lat1 := point1.Latitude * math.Pi / 180
- lon1 := point1.Longitude * math.Pi / 180
- lat2 := point2.Latitude * math.Pi / 180
- lon2 := point2.Longitude * math.Pi / 180
- // 计算距离
- dlon := lon2 - lon1
- dlat := lat2 - lat1
- a := math.Sin(dlat/2)*math.Sin(dlat/2) + math.Sin(dlon/2)*math.Sin(dlon/2)*math.Cos(lat1)*math.Cos(lat2)
- c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
- d := 6371000 * c
- return d
- }
- func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
- defer func() {
- if r := recover(); r != nil {
- fmt.Println("Recovered from panic:", r)
- }
- }()
- if count1%10 == 0 {
- Automode, _ := shareVars.Load("AutomodeOfPjVehicleFdbPub")
- Automode = Automode.(int16)
- IsSpeedBump = IfEnter(pointlist1, 7.0, data.Latitude, data.Longitude)
- if Automode == 1 && IsSpeedBump {
- absspeed, ok := shareVars.Load("AbsSpeed")
- if ok && absspeed.(float64) >= threshold {
- eventLabel := "SpeedBumpOverspeed"
- fmt.Println(eventLabel)
- count1 = 1
- return Label()
- }
- }
- }
- count1++
- return ""
- }
|