|
@@ -28,24 +28,43 @@ type Weather struct {
|
|
|
type Point struct {
|
|
|
x, y float64
|
|
|
}
|
|
|
+type Location struct {
|
|
|
+ Latitude float64
|
|
|
+ Longitude float64
|
|
|
+}
|
|
|
|
|
|
var (
|
|
|
+ LeftCurveFlag bool = false
|
|
|
+ RightCurveFlag bool = false //用来判断车辆是左转还是右转
|
|
|
//定义了车间四个边界点,将车间抽象成一个四边形
|
|
|
- vertices = []Point{
|
|
|
+ LocationCount = 0
|
|
|
+ vertices = []Point{
|
|
|
{x: 456128.413, y: 4397847.78},
|
|
|
{x: 456288.257, y: 4397953.51},
|
|
|
{x: 456359.022, y: 4397822.84},
|
|
|
{x: 456191.065, y: 4397733.3},
|
|
|
}
|
|
|
+ //定义园区部门T字路口的经纬度坐标值
|
|
|
+ point3 = Location{39.73040966605621, 116.48995329696209}
|
|
|
+ point4 = Location{39.73083727413453, 116.49079780188244}
|
|
|
+ point5 = Location{39.72976753711939, 116.49043130389033}
|
|
|
+ point6 = Location{39.73012466515933, 116.49128381717591}
|
|
|
+ point7 = Location{39.729251498328246, 116.49077484625299}
|
|
|
+ point8 = Location{39.72964529630643, 116.49164592200161}
|
|
|
+
|
|
|
+ pointlist = []Location{point3, point4, point5, point6, point7, point8}
|
|
|
+
|
|
|
cicvLocationTime = time.Now()
|
|
|
// -----------------------------共享变量
|
|
|
//cicv_location
|
|
|
//NumOfCicvLocation = 0
|
|
|
- SpeedSlice = []float64{}
|
|
|
- AccelXSlice = []float64{}
|
|
|
+ SpeedSlice = []float64{}
|
|
|
+ AccelXSlice = []float64{}
|
|
|
+ JunctionFlag = false
|
|
|
//Yowslice = make([]float64, 0)
|
|
|
//AngleSlice = make([][]float64, 0)
|
|
|
// /tpperception
|
|
|
+ countSideBySide int = 0
|
|
|
Frame float32 = 0.0
|
|
|
ObjDicOfTpperception = make(map[uint32][][]float32)
|
|
|
objTypeDicOfTpperception = make(map[uint32]uint8)
|
|
@@ -592,6 +611,34 @@ func ProduceWindow() {
|
|
|
}
|
|
|
subscribersTimeMutexes[i].Unlock()
|
|
|
// 更新共享变量
|
|
|
+
|
|
|
+ Trajectorypoints := data.Trajectoryinfo.Trajectorypoints
|
|
|
+ if len(Trajectorypoints) > 2 {
|
|
|
+ StartHeading := Trajectorypoints[0].Heading
|
|
|
+ EndHeading := Trajectorypoints[len(Trajectorypoints)-1].Heading
|
|
|
+ diffHeading := StartHeading - EndHeading
|
|
|
+ //fmt.Println(diffHeading)
|
|
|
+
|
|
|
+ if diffHeading < -1.0 && diffHeading > -3.0 {
|
|
|
+ LeftCurveFlag = true
|
|
|
+ //fmt.Println(diffHeading)
|
|
|
+ } else {
|
|
|
+ LeftCurveFlag = false
|
|
|
+ }
|
|
|
+ if diffHeading > 1.0 && diffHeading < 3.0 {
|
|
|
+ RightCurveFlag = true
|
|
|
+ //fmt.Println(diffHeading)
|
|
|
+ } else {
|
|
|
+ RightCurveFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ LeftCurveFlag = false
|
|
|
+ RightCurveFlag = false
|
|
|
+ }
|
|
|
+ shareVars.Store("LeftCurveFlag", LeftCurveFlag)
|
|
|
+ shareVars.Store("RightCurveFlag", RightCurveFlag)
|
|
|
+
|
|
|
currentCurvateres := make([]float64, 0)
|
|
|
for _, point := range data.Trajectoryinfo.Trajectorypoints {
|
|
|
currentCurvateres = append(currentCurvateres, math.Abs(float64(point.Curvature)))
|
|
@@ -607,6 +654,7 @@ func ProduceWindow() {
|
|
|
|
|
|
// 12 有共享变量的订阅者必须被创建
|
|
|
if topic == masterConfig.TopicOfCicvLocation {
|
|
|
+ LocationCount++
|
|
|
subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
|
|
|
Node: commonConfig.RosNode,
|
|
|
Topic: topic,
|
|
@@ -643,6 +691,12 @@ func ProduceWindow() {
|
|
|
}
|
|
|
subscribersTimeMutexes[i].Unlock()
|
|
|
// 更新共享变量
|
|
|
+ if LocationCount%10 == 0 {
|
|
|
+ enterflag := IfEnter(pointlist, 12.0, data.Latitude, data.Longitude)
|
|
|
+ shareVars.Store("EnterJunctionFlag", enterflag)
|
|
|
+ LocationCount = 0
|
|
|
+ }
|
|
|
+
|
|
|
AbsSpeed := math.Sqrt(math.Pow(data.VelocityX, 2) + math.Pow(data.VelocityY, 2))
|
|
|
AccelXSlice = append(AccelXSlice, data.AccelX)
|
|
|
shareVars.Store("AbsSpeed", AbsSpeed)
|
|
@@ -1532,11 +1586,21 @@ func ProduceWindow() {
|
|
|
|
|
|
// 更新共享变量
|
|
|
for _, obj := range data.Objs {
|
|
|
+ YawOfCicvLocation, _ := shareVars.Load("YawOfCicvLocation")
|
|
|
+ diffh := (float64(obj.Heading - YawOfCicvLocation.(float32)))
|
|
|
+ if diffh < -180.0 {
|
|
|
+ diffh = 360.0 + diffh
|
|
|
+ } else if diffh > 180.0 {
|
|
|
+ diffh = 360.0 - diffh
|
|
|
+ } else {
|
|
|
+ diffh = math.Abs(diffh)
|
|
|
+ }
|
|
|
+
|
|
|
if math.Abs(float64(obj.X)) >= 30 || math.Abs(float64(obj.Y)) >= 30 {
|
|
|
continue
|
|
|
}
|
|
|
if _, ok := ObjDicOfTpperception[obj.Id]; !ok {
|
|
|
- ObjDicOfTpperception[obj.Id] = [][]float32{{}, {}, {}, {}, {}, {}}
|
|
|
+ ObjDicOfTpperception[obj.Id] = [][]float32{{}, {}, {}, {}, {}, {}, {}, {}}
|
|
|
}
|
|
|
ObjDicOfTpperception[obj.Id][0] = append(ObjDicOfTpperception[obj.Id][0], obj.X)
|
|
|
ObjDicOfTpperception[obj.Id][1] = append(ObjDicOfTpperception[obj.Id][1], obj.Y)
|
|
@@ -1545,6 +1609,18 @@ func ProduceWindow() {
|
|
|
ObjDicOfTpperception[obj.Id][3] = append(ObjDicOfTpperception[obj.Id][3], float32(absspeed))
|
|
|
ObjDicOfTpperception[obj.Id][4] = append(ObjDicOfTpperception[obj.Id][4], obj.Heading)
|
|
|
ObjDicOfTpperception[obj.Id][5] = append(ObjDicOfTpperception[obj.Id][5], Frame)
|
|
|
+ ObjDicOfTpperception[obj.Id][6] = append(ObjDicOfTpperception[obj.Id][6], float32(obj.Type))
|
|
|
+ ObjDicOfTpperception[obj.Id][7] = append(ObjDicOfTpperception[obj.Id][7], float32(diffh))
|
|
|
+ if len(ObjDicOfTpperception[obj.Id][0]) >= 100 {
|
|
|
+ ObjDicOfTpperception[obj.Id][0] = ObjDicOfTpperception[obj.Id][0][1:]
|
|
|
+ ObjDicOfTpperception[obj.Id][1] = ObjDicOfTpperception[obj.Id][1][1:]
|
|
|
+ ObjDicOfTpperception[obj.Id][2] = ObjDicOfTpperception[obj.Id][2][1:]
|
|
|
+ ObjDicOfTpperception[obj.Id][3] = ObjDicOfTpperception[obj.Id][3][1:]
|
|
|
+ ObjDicOfTpperception[obj.Id][4] = ObjDicOfTpperception[obj.Id][4][1:]
|
|
|
+ ObjDicOfTpperception[obj.Id][5] = ObjDicOfTpperception[obj.Id][5][1:]
|
|
|
+ ObjDicOfTpperception[obj.Id][6] = ObjDicOfTpperception[obj.Id][6][1:]
|
|
|
+ ObjDicOfTpperception[obj.Id][7] = ObjDicOfTpperception[obj.Id][7][1:]
|
|
|
+ }
|
|
|
|
|
|
objTypeDicOfTpperception[obj.Id] = obj.Type
|
|
|
objSpeedDicOfTpperception[obj.Id] = math.Pow(math.Pow(float64(obj.Vxabs), 2)+math.Pow(float64(obj.Vyabs), 2), 0.5)
|
|
@@ -1552,6 +1628,8 @@ func ProduceWindow() {
|
|
|
shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
|
|
|
shareVars.Store("ObjTypeDicOfTpperception", objTypeDicOfTpperception)
|
|
|
shareVars.Store("ObjSpeedDicOfTpperception", objSpeedDicOfTpperception)
|
|
|
+ shareVars.Store("countSideBySide", countSideBySide)
|
|
|
+
|
|
|
Frame++
|
|
|
},
|
|
|
})
|
|
@@ -2128,3 +2206,33 @@ func max(a, b float64) float64 {
|
|
|
}
|
|
|
return b
|
|
|
}
|
|
|
+
|
|
|
+// 判断Ego是否在交叉口,在的话返回true
|
|
|
+func IfEnter(pointlist []Location, radius float64, lat, lon float64) bool {
|
|
|
+ // 判断是否进入点列表中的区域
|
|
|
+ point1 := Location{Latitude: lat, Longitude: lon}
|
|
|
+ for _, point := range pointlist {
|
|
|
+ d := distance(point1, point)
|
|
|
+ if d <= radius {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+// 计算两点之间的距离(米)
|
|
|
+func distance(point1, point2 Location) 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
|
|
|
+}
|