LingxinMeng 10 달 전
부모
커밋
283f735a2c

+ 7 - 15
aarch64/pjisuv/master/service/produce_window.go

@@ -736,21 +736,13 @@ func ProduceWindow() {
 						}
 						subscribersTimeMutexes[i].Unlock()
 						// 更新共享变量
-						mutexOfCicvLocation.RLock()
-						{
-							//shareVars.Store("VelocityXOfCicvLocation",data.VelocityX) pjisuvParam以后不要新加全局变量了,采用这种方式添加
-							//value, _ := shareVars.Load("VelocityXOfCicvLocation") 在Rule函数数中通过Load方法获取全局变量,获取之后通过value.(float64)方法转换数据类型
-							//s := value.(float64)
-
-							pjisuvParam.VelocityXOfCicvLocation = data.VelocityX
-							pjisuvParam.VelocityYOfCicvLocation = data.VelocityY
-							pjisuvParam.VelocityZOfCicvLocation = data.VelocityZ
-							pjisuvParam.YawOfCicvLocation = data.Yaw
-							pjisuvParam.AngularVelocityZOfCicvLocation = data.AngularVelocityZ
-							pjisuvParam.PositionXOfCicvLocation = data.PositionX
-							pjisuvParam.PositionYOfCicvLocation = data.PositionY
-						}
-						mutexOfCicvLocation.RUnlock()
+						shareVars.Store("VelocityXOfCicvLocation", data.VelocityX)
+						shareVars.Store("VelocityYOfCicvLocation", data.VelocityY)
+						shareVars.Store("VelocityZOfCicvLocation", data.VelocityZ)
+						shareVars.Store("YawOfCicvLocation", data.Yaw)
+						shareVars.Store("AngularVelocityZOfCicvLocation", data.AngularVelocityZ)
+						shareVars.Store("PositionXOfCicvLocation", data.PositionX)
+						shareVars.Store("PositionYOfCicvLocation", data.PositionY)
 					},
 				})
 			}

+ 7 - 7
trigger/pjisuv/cicv_location/EnterTjunction/main/EnterTjunction.go

@@ -2,9 +2,9 @@ package main
 
 import (
 	"cicv-data-closedloop/pjisuv_msgs"
-	"cicv-data-closedloop/pjisuv_param"
 	"fmt"
 	"math"
+	"sync"
 )
 
 func Topic() string {
@@ -35,19 +35,19 @@ var (
 	pointlist = []Point{point3, point4, point5, point6, point7, point8}
 )
 
-func Rule(data *pjisuv_msgs.PerceptionLocalization, param *pjisuv_param.PjisuvParam) string {
+func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
 	defer func() {
 		if r := recover(); r != nil {
 			fmt.Println("Recovered from panic:", r)
 		}
 	}()
 	if count2%10 == 0 {
-
 		enterflag := IfEnter(pointlist, 12.0, data.Latitude, data.Longitude)
-		if enterflag && param.VelocityXOfCicvLocation >= 1 {
-			//eventLabel := "EnterTjunction"
-			//fmt.Println(eventLabel)
-			return Label()
+		velocityXOfCicvLocation, ok := shareVars.Load("VelocityXOfCicvLocation")
+		if ok {
+			if enterflag && velocityXOfCicvLocation.(float64) >= 1 {
+				return Label()
+			}
 		}
 	}
 	count2++

+ 7 - 7
trigger/pjisuv/cicv_location/FindTrafficLight/main/FindTrafficLight.go

@@ -2,9 +2,9 @@ package main
 
 import (
 	"cicv-data-closedloop/pjisuv_msgs"
-	"cicv-data-closedloop/pjisuv_param"
 	"fmt"
 	"math"
+	"sync"
 )
 
 func Topic() string {
@@ -33,19 +33,19 @@ var (
 	pointlist = []Point{point2, point3, point4, point5}
 )
 
-func Rule(data *pjisuv_msgs.PerceptionLocalization, param *pjisuv_param.PjisuvParam) string {
+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 {
-
 		enterflag := IfEnter(pointlist, 25.0, data.Latitude, data.Longitude)
-		if enterflag && param.VelocityXOfCicvLocation >= 1 {
-			//eventLabel := "FindTrafficLight"
-			//fmt.Println(eventLabel)
-			return "FindTrafficLight"
+		velocityXOfCicvLocation, ok := shareVars.Load("VelocityXOfCicvLocation")
+		if ok {
+			if enterflag && velocityXOfCicvLocation.(float64) >= 1 {
+				return Label()
+			}
 		}
 	}
 	count1++

+ 14 - 14
trigger/pjisuv/tpperception/NumTargetsExceedThreshold/main/NumTargetsExceedThreshold.go

@@ -2,38 +2,38 @@ package main
 
 import (
 	"cicv-data-closedloop/pjisuv_msgs"
-	"cicv-data-closedloop/pjisuv_param"
 	"fmt"
+	"sync"
 )
 
 func Topic() string {
 	return "/tpperception"
 }
 
-// Label todo 禁止存在下划线_
+// 禁止存在下划线_
 func Label() string {
 	return "NumTargetsExceedThreshold"
 }
-func Rule(data *pjisuv_msgs.PerceptionObjects, param *pjisuv_param.PjisuvParam) string {
+func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
 	NumTargets := 0
 	defer func() {
 		if r := recover(); r != nil {
 			fmt.Println("Recovered from panic:", r)
 		}
 	}()
-
-	if param.VelocityXOfCicvLocation > 2.5 && len(data.Objs) > 6 {
-		for _, obj := range data.Objs {
-			if obj.Type != 0 && obj.X >= 2 {
-				NumTargets++
+	velocityXOfCicvLocation, ok := shareVars.Load("VelocityXOfCicvLocation")
+	if ok {
+		if velocityXOfCicvLocation.(float64) > 2.5 && len(data.Objs) > 6 {
+			for _, obj := range data.Objs {
+				if obj.Type != 0 && obj.X >= 2 {
+					NumTargets++
+				}
+			}
+			if NumTargets >= 5 {
+				return Label()
 			}
-		}
-		//fmt.Println(NumTargets)
-		if NumTargets >= 5 {
-			//event_lable := "NumTargetsExceedThreshold"
-			fmt.Printf("NumTargetsExceedThreshold,%d Targets were found\n", NumTargets)
-			return "NumTargetsExceedThreshold"
 		}
 	}
+
 	return ""
 }

+ 14 - 8
trigger/pjisuv/tpperception/TTC/main/TTC.go

@@ -2,9 +2,9 @@ package main
 
 import (
 	"cicv-data-closedloop/pjisuv_msgs"
-	"cicv-data-closedloop/pjisuv_param"
 	"fmt"
 	"math"
+	"sync"
 )
 
 /*
@@ -31,24 +31,30 @@ func Topic() string {
 	return "/tpperception"
 }
 
-// Label todo 禁止存在下划线_
+// 禁止存在下划线_
 func Label() string {
 	return "TTC"
 }
 
-func Rule(data *pjisuv_msgs.PerceptionObjects, param *pjisuv_param.PjisuvParam) string {
+func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
 	defer func() {
 		if r := recover(); r != nil {
 			fmt.Println("Recovered from panic:", r)
 		}
 	}()
-	for _, obj := range data.Objs {
-		if math.Abs(float64(obj.Y)) <= 2 && obj.X >= 6 && param.VelocityXOfCicvLocation > 0.5 {
-			ttc := -((float64(obj.X) - 4) / (float64(obj.Vxrel) + 0.001))
-			if ttc >= 0 && ttc <= 3 {
-				return "TTC"
+
+	velocityXOfCicvLocation, ok := shareVars.Load("VelocityXOfCicvLocation")
+	if ok {
+		value := velocityXOfCicvLocation.(float64)
+		for _, obj := range data.Objs {
+			if math.Abs(float64(obj.Y)) <= 2 && obj.X >= 6 && value > 0.5 {
+				ttc := -((float64(obj.X) - 4) / (float64(obj.Vxrel) + 0.001))
+				if ttc >= 0 && ttc <= 3 {
+					return Label()
+				}
 			}
 		}
 	}
+
 	return ""
 }

+ 13 - 8
trigger/pjisuv/tpperception/TargetAhead/main/TargetAhead.go

@@ -2,32 +2,37 @@ package main
 
 import (
 	"cicv-data-closedloop/pjisuv_msgs"
-	"cicv-data-closedloop/pjisuv_param"
 	"fmt"
 	"math"
+	"sync"
 )
 
 func Topic() string {
 	return "/tpperception"
 }
 
-// Label todo 禁止存在下划线_
+// 禁止存在下划线_
 func Label() string {
 	return "TargetAhead"
 }
 
-func Rule(data *pjisuv_msgs.PerceptionObjects, param *pjisuv_param.PjisuvParam) string {
+func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
 	defer func() {
 		if r := recover(); r != nil {
 			fmt.Println("Recovered from panic:", r)
 		}
 	}()
-	for _, obj := range data.Objs {
-		if math.Abs(float64(obj.Y)) <= 2.3 && obj.X >= 0 && obj.X <= 13 && param.AngularVelocityZOfCicvLocation < 5.5 && math.Abs(param.VelocityXOfCicvLocation) >= 0.5 {
-			//event_label := "TargetAhead" //测试车正前方10米范围内有目标物(过滤掉测试车转弯的情况)
-			//fmt.Println(event_label)
-			return "TargetAhead"
+	velocityXOfCicvLocation, ok1 := shareVars.Load("VelocityXOfCicvLocation")
+	angularVelocityZOfCicvLocation, ok2 := shareVars.Load("AngularVelocityZOfCicvLocation")
+	if ok1 && ok2 {
+		value1 := velocityXOfCicvLocation.(float64)
+		value2 := angularVelocityZOfCicvLocation.(float64)
+		for _, obj := range data.Objs {
+			if math.Abs(float64(obj.Y)) <= 2.3 && obj.X >= 0 && obj.X <= 13 && value1 < 5.5 && math.Abs(value2) >= 0.5 {
+				return Label()
+			}
 		}
 	}
+
 	return ""
 }

+ 11 - 8
trigger/pjisuv/tpperception/TargetTooClose/main/TargetTooClose.go

@@ -2,31 +2,34 @@ package main
 
 import (
 	"cicv-data-closedloop/pjisuv_msgs"
-	"cicv-data-closedloop/pjisuv_param"
 	"fmt"
 	"math"
+	"sync"
 )
 
 func Topic() string {
 	return "/tpperception"
 }
 
-// Label todo 禁止存在下划线_
 func Label() string {
 	return "TargetTooClose"
 }
 
-func Rule(data *pjisuv_msgs.PerceptionObjects, param *pjisuv_param.PjisuvParam) string {
+func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
 	defer func() {
 		if r := recover(); r != nil {
 			fmt.Println("Recovered from panic:", r)
 		}
 	}()
-	for _, obj := range data.Objs {
-		if math.Abs(float64(obj.Y)) <= 1.5 && obj.X >= 0 && obj.X <= 6 && param.AngularVelocityZOfCicvLocation < 5.5 && math.Abs(param.VelocityXOfCicvLocation) >= 0.5 {
-			//event_label := "TargetAhead" //测试车正前方10米范围内有目标物(过滤掉测试车转弯的情况)
-			//fmt.Println(event_label)
-			return "TargetTooClose"
+	velocityXOfCicvLocation, ok1 := shareVars.Load("VelocityXOfCicvLocation")
+	angularVelocityZOfCicvLocation, ok2 := shareVars.Load("AngularVelocityZOfCicvLocation")
+	if ok1 && ok2 {
+		for _, obj := range data.Objs {
+			value1 := velocityXOfCicvLocation.(float64)
+			value2 := angularVelocityZOfCicvLocation.(float64)
+			if math.Abs(float64(obj.Y)) <= 1.5 && obj.X >= 0 && obj.X <= 6 && value1 < 5.5 && math.Abs(value2) >= 0.5 {
+				return Label()
+			}
 		}
 	}
 	return ""

+ 12 - 11
trigger/pjisuv/tpperception/TrafficCongestion/main/TrafficCongestion.go

@@ -2,9 +2,9 @@ package main
 
 import (
 	"cicv-data-closedloop/pjisuv_msgs"
-	"cicv-data-closedloop/pjisuv_param"
 	"fmt"
 	"math"
+	"sync"
 )
 
 func Topic() string {
@@ -15,24 +15,25 @@ func Topic() string {
 func Label() string {
 	return "TrafficCongestion"
 }
-func Rule(data *pjisuv_msgs.PerceptionObjects, param *pjisuv_param.PjisuvParam) string {
+func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
 	NumTargets := 0
 	defer func() {
 		if r := recover(); r != nil {
 			fmt.Println("Recovered from panic:", r)
 		}
 	}()
-
-	if param.VelocityXOfCicvLocation < 3.5 && len(data.Objs) > 3 {
-		for _, obj := range data.Objs {
-			if (obj.Type == 2 || obj.Type == 3) && math.Abs(float64(obj.Y)) <= 2.5 && math.Abs(float64(obj.X)) <= 20 && obj.Speed <= 4 {
-				NumTargets++
+	velocityXOfCicvLocation, ok := shareVars.Load("VelocityXOfCicvLocation")
+	if ok {
+		if velocityXOfCicvLocation.(float64) < 3.5 && len(data.Objs) > 3 {
+			for _, obj := range data.Objs {
+				if (obj.Type == 2 || obj.Type == 3) && math.Abs(float64(obj.Y)) <= 2.5 && math.Abs(float64(obj.X)) <= 20 && obj.Speed <= 4 {
+					NumTargets++
+				}
 			}
-		}
-		//fmt.Println(NumTargets)
-		if NumTargets >= 3 {
-			return "TrafficCongestion"
+			if NumTargets >= 3 {
+				return Label()
 
+			}
 		}
 	}