瀏覽代碼

Merge remote-tracking branch 'origin/master'

zwh 9 月之前
父節點
當前提交
e0ad61b067

+ 33 - 6
trigger/pjisuv/tpperception/UnknownBigTargetAhead/main/UnknownBigTargetAhead.go

@@ -60,13 +60,24 @@ func sizeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
 	return counter > 1
 }
 
-// posCheck 判断目标物位置关系
-func posCheck(obj *pjisuv_msgs.PerceptionObject) bool {
+// objPosCheck 判断目标物位置关系
+func objPosCheck(obj *pjisuv_msgs.PerceptionObject) bool {
 	const laneWidth = 3.5 // m
 
 	return obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5
 }
 
+// isEgoStationary 判断主车是否“静止”(速度低于阈值)
+func isEgoStationary(shareVars *sync.Map) bool {
+	const minSpeed = 1 // m/s
+
+	VelocityXOfCicvLocation, _ := shareVars.Load("VelocityXOfCicvLocation") // float64
+	VelocityYOfCicvLocation, _ := shareVars.Load("VelocityYOfCicvLocation")
+	speed := math.Sqrt(math.Pow(VelocityXOfCicvLocation.(float64), 2) + math.Pow(VelocityYOfCicvLocation.(float64), 2))
+
+	return speed > minSpeed
+}
+
 // Rule 检测前方未知大目标物
 func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
 	defer func() {
@@ -75,14 +86,24 @@ func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
 		}
 	}()
 
+	// 判断主车所在位置 & 行驶速度
+	outsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
+	if !outsideWorkshopFlag.(bool) || !isEgoStationary(shareVars) {
+		return ""
+	}
+
+	//const Cgcs2000X = 456256.260152
+	//const Cgcs2000Y = 4397809.886833
 	const MinStableFrameCount = 5   // frame
 	const MaxTimeBetweenFrame = 0.5 // second
-	OutsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
-	OutsideWorkshopFlag = OutsideWorkshopFlag.(bool)
+
+	//fmt.Println("\n", time.Unix(int64(msg.Header.TimeStamp), int64(msg.Header.TimeStamp*1e9)%1e9).Format(time.StampNano))
 	for _, obj := range msg.Objs {
 
 		// 判断目标物是否满足筛选条件
-		if typeCheck(&obj) && posCheck(&obj) && sizeCheck(&obj) {
+		if typeCheck(&obj) && objPosCheck(&obj) && sizeCheck(&obj) {
+			//fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
+			//	obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-Cgcs2000X, obj.Yabs-Cgcs2000Y, obj.Speed, obj.Length, obj.Width, obj.Height))
 
 			// 目标物初见存档
 			if prevObjRecord, exists := objectsStability[obj.Id]; exists == false {
@@ -91,6 +112,7 @@ func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
 					StableFrame:      1,
 					LastExistingTime: msg.Header.TimeStamp,
 				}
+				//fmt.Println("---------- create ----------")
 			} else {
 				currObjRecord := Object{
 					ID:               obj.Id,
@@ -101,10 +123,15 @@ func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
 				// 目标物确认/更新/重置
 				if currObjRecord.LastExistingTime-prevObjRecord.LastExistingTime <= MaxTimeBetweenFrame { // 目标物消失不超过0.5s
 					currObjRecord.StableFrame = prevObjRecord.StableFrame + 1
-					if currObjRecord.StableFrame == MinStableFrameCount && OutsideWorkshopFlag == true {
+					if currObjRecord.StableFrame == MinStableFrameCount {
 						delete(objectsStability, obj.Id)
+						//fmt.Println("!!!!!!!!!! found !!!!!!!!!!")
 						return Label()
+					} else {
+						//fmt.Println("---------- update ----------")
 					}
+				} else {
+					//fmt.Println("---------- reset ----------")
 				}
 				objectsStability[obj.Id] = currObjRecord
 			}

+ 37 - 10
trigger/pjisuv/tpperception/lowSpdTruckAhead/main/lowSpdTruckAhead.go

@@ -24,30 +24,41 @@ func Label() string {
 	return "LowSpdTruckAhead"
 }
 
-// speedCheck 目标物速度检测
-func speedCheck(obj *pjisuv_msgs.PerceptionObject) bool {
+// objSpeedCheck 目标物速度检测
+func objSpeedCheck(obj *pjisuv_msgs.PerceptionObject) bool {
 	const targetMinSpeed = 2 / 3.6  // m/s
 	const targetMaxSpeed = 20 / 3.6 // m/s
 
 	return targetMinSpeed < obj.Speed && obj.Speed < targetMaxSpeed
 }
 
-// typeCheck 目标物类型检测
+// objTypeCheck 目标物类型检测
 // × 金龙车:CAR_TYPE=0, TRUCK_TYPE=1, PEDESTRIAN_TYPE=2, CYCLIST_TYPE=3, UNKNOWN_TYPE=4, UNKNOWN_MOVABLE_TYPE=5, UNKNOWN_UNMOVABLE_TYPE=6
 // √ 多功能车:UNKNOWN TYPE=O, PEDESTRIAN TYPE=1, CAR TYPE=2, TRUCK TYPE=3, Bicycle TYPE=4, Tricycle TYPE=5, Traffic Cone TYPE=6
-func typeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
+func objTypeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
 	const targetType uint8 = 3
 
 	return targetType == obj.Type
 }
 
-// posCheck 判断目标物位置关系
-func posCheck(obj *pjisuv_msgs.PerceptionObject) bool {
+// objPosCheck 判断目标物位置关系
+func objPosCheck(obj *pjisuv_msgs.PerceptionObject) bool {
 	const laneWidth = 3.5 // m
 
 	return obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5
 }
 
+// isEgoStationary 判断主车是否“静止”(速度低于阈值)
+func isEgoStationary(shareVars *sync.Map) bool {
+	const minSpeed = 1 // m/s
+
+	VelocityXOfCicvLocation, _ := shareVars.Load("VelocityXOfCicvLocation") // float64
+	VelocityYOfCicvLocation, _ := shareVars.Load("VelocityYOfCicvLocation")
+	speed := math.Sqrt(math.Pow(VelocityXOfCicvLocation.(float64), 2) + math.Pow(VelocityYOfCicvLocation.(float64), 2))
+
+	return speed > minSpeed
+}
+
 // Rule 检测前方大车低速行驶
 func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
 	defer func() {
@@ -55,15 +66,25 @@ func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
 			fmt.Println(fmt.Sprintf("Recovered from panic: [%s], [%#v]", Label(), r))
 		}
 	}()
-	OutsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
-	OutsideWorkshopFlag = OutsideWorkshopFlag.(bool)
+
+	// 判断主车所在位置 & 行驶速度
+	outsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
+	if !outsideWorkshopFlag.(bool) || !isEgoStationary(shareVars) {
+		return ""
+	}
+
+	//const Cgcs2000X = 456256.260152
+	//const Cgcs2000Y = 4397809.886833
 	const MinStableFrameCount = 5
 	const MaxTimeBetweenFrame = 0.5
 
+	//fmt.Println("\n", time.Unix(int64(msg.Header.TimeStamp), int64(msg.Header.TimeStamp*1e9)%1e9).Format(time.StampNano))
 	for _, obj := range msg.Objs {
 
 		// 判断目标物是否满足筛选条件
-		if speedCheck(&obj) && posCheck(&obj) && typeCheck(&obj) {
+		if objSpeedCheck(&obj) && objPosCheck(&obj) && objTypeCheck(&obj) {
+			//fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
+			//	obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-Cgcs2000X, obj.Yabs-Cgcs2000Y, obj.Speed, obj.Length, obj.Width, obj.Height))
 
 			// 目标物初见存档
 			if prevObjRecord, exists := objectsStability[obj.Id]; exists == false {
@@ -72,6 +93,7 @@ func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
 					StableAge:     1,
 					LastExistTime: msg.Header.TimeStamp,
 				}
+				//fmt.Println("---------- create ----------")
 			} else {
 				currObjRecord := Object{
 					ID:            obj.Id,
@@ -82,10 +104,15 @@ func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
 				// 目标物确认/更新/重置
 				if currObjRecord.LastExistTime-prevObjRecord.LastExistTime <= MaxTimeBetweenFrame { // 目标物消失不超过0.5s
 					currObjRecord.StableAge = prevObjRecord.StableAge + 1
-					if currObjRecord.StableAge == MinStableFrameCount && OutsideWorkshopFlag == true {
+					if currObjRecord.StableAge == MinStableFrameCount {
 						delete(objectsStability, obj.Id)
+						//fmt.Println("!!!!!!!!!! found !!!!!!!!!!")
 						return Label()
+					} else {
+						//fmt.Println("---------- update ----------")
 					}
+				} else {
+					//fmt.Println("---------- reset ----------")
 				}
 				objectsStability[obj.Id] = currObjRecord
 			}