浏览代码

add Creeping trigger

zwh 9 月之前
父节点
当前提交
9aa9b93a5b

+ 93 - 0
trigger/pjisuv/cicv_ticker/RearVehicleCutIn/main/RearVehicleCutIn.go

@@ -0,0 +1,93 @@
+package main
+
+import (
+	"cicv-data-closedloop/pjisuv_ticker"
+	"fmt"
+	"math"
+	"sync"
+	"time"
+)
+
+var (
+	Maxlenobj int32 = 0
+)
+
+// 定时任务触发器固定的
+func Topic() string {
+	return pjisuv_ticker.TickerTopic
+}
+
+// ******* 禁止存在下划线_
+// 触发器标记
+func Label() string {
+	return "RearVehicleCutIn"
+}
+
+func Rule(shareVars *sync.Map) {
+	defer func() {
+		if r := recover(); r != nil {
+			fmt.Println("Recovered from panic:", r)
+		}
+	}()
+	// 1 使用goroutine
+	go func(shareVars *sync.Map) {
+		// 2 定义触发器的间隔时间
+		ticker := time.NewTicker(time.Duration(2) * time.Second)
+		defer ticker.Stop()
+		// 3 运行一个无限循环
+		for {
+			select {
+			// 定时器触发时执行的代码
+			case <-ticker.C:
+				FinalCallback(shareVars)
+
+			}
+		}
+	}(shareVars)
+}
+func isCuttingIn(ObjectList [][]float32, AngularVelocityZOfCicvLocation float64) bool {
+	for i := 0; i < len(ObjectList[1]); i++ {
+		xi := ObjectList[0][i]
+		yi := ObjectList[1][i]
+		if math.Abs(float64(yi)) >= 1.8 && xi < (-2.0) && math.Abs(AngularVelocityZOfCicvLocation) <= 1.6 {
+			//fmt.Println(objY)
+			for j := 0; j < len(ObjectList[1])-i-1; j++ {
+				objxj := ObjectList[0][1+i+j]
+				objyj := ObjectList[1][1+i+j]
+				if math.Abs(float64(objyj)) <= 0.7 && objxj < (-2.0) && math.Abs(float64(AngularVelocityZOfCicvLocation)) <= 1.6 {
+					//fmt.Println(objX)
+					return true
+				}
+			}
+		}
+	}
+	return false
+}
+func FinalCallback(shareVars *sync.Map) {
+	OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
+	ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
+	ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
+	AngularVelocityZOfCicvLocation, _ := shareVars.Load("AngularVelocityZOfCicvLocation")
+	AngularVelocityZ := AngularVelocityZOfCicvLocation.(float64)
+
+	if ok && ok1 && OutsideWorkshopFlag.(bool) == true {
+
+		for _, objValue := range ObjDic {
+			Maxlenobj = max(Maxlenobj, int32(len(objValue[0])))
+			if len(ObjDic[0]) <= 4 || !isCuttingIn(objValue, AngularVelocityZ) {
+				continue
+			}
+			event_lable := "RearVehicleCutIn"
+			fmt.Println(event_lable)
+
+			pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
+		}
+
+		if Maxlenobj >= 100 {
+			ObjDicOfTpperception = make(map[uint32][][]float32)
+			shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
+			Maxlenobj = 0
+		}
+	}
+
+}

+ 93 - 0
trigger/pjisuv/cicv_ticker/RearVehicleCutOut/main/RearVehicleCutOut.go

@@ -0,0 +1,93 @@
+package main
+
+import (
+	"cicv-data-closedloop/pjisuv_ticker"
+	"fmt"
+	"math"
+	"sync"
+	"time"
+)
+
+var (
+	Maxlenobj int32 = 0
+)
+
+// 定时任务触发器固定的
+func Topic() string {
+	return pjisuv_ticker.TickerTopic
+}
+
+// ******* 禁止存在下划线_
+// 触发器标记
+func Label() string {
+	return "RearVehicleCutOut"
+}
+
+func Rule(shareVars *sync.Map) {
+	defer func() {
+		if r := recover(); r != nil {
+			fmt.Println("Recovered from panic:", r)
+		}
+	}()
+	// 1 使用goroutine
+	go func(shareVars *sync.Map) {
+		// 2 定义触发器的间隔时间
+		ticker := time.NewTicker(time.Duration(2) * time.Second)
+		defer ticker.Stop()
+		// 3 运行一个无限循环
+		for {
+			select {
+			// 定时器触发时执行的代码
+			case <-ticker.C:
+				FinalCallback(shareVars)
+
+			}
+		}
+	}(shareVars)
+}
+func isCuttingIn(ObjectList [][]float32, AngularVelocityZOfCicvLocation float64) bool {
+	for i := 0; i < len(ObjectList[1]); i++ {
+		xi := ObjectList[0][i]
+		yi := ObjectList[1][i]
+		if math.Abs(float64(yi)) < 0.9 && xi < (-2.0) && math.Abs(AngularVelocityZOfCicvLocation) <= 1.6 {
+			//fmt.Println(objY)
+			for j := 0; j < len(ObjectList[1])-i-1; j++ {
+				objxj := ObjectList[0][1+i+j]
+				objyj := ObjectList[1][1+i+j]
+				if math.Abs(float64(objyj)) > 1.8 && objxj < (-2.0) && math.Abs(float64(AngularVelocityZOfCicvLocation)) <= 1.6 {
+					//fmt.Println(objX)
+					return true
+				}
+			}
+		}
+	}
+	return false
+}
+func FinalCallback(shareVars *sync.Map) {
+	OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
+	ObjDicOfTpperception, ok1 := shareVars.Load("objDicOfTpperception")
+	ObjDic := ObjDicOfTpperception.(map[uint32][][]float32)
+	AngularVelocityZOfCicvLocation, _ := shareVars.Load("AngularVelocityZOfCicvLocation")
+	AngularVelocityZ := AngularVelocityZOfCicvLocation.(float64)
+
+	if ok && ok1 && OutsideWorkshopFlag.(bool) == true {
+
+		for _, objValue := range ObjDic {
+			Maxlenobj = max(Maxlenobj, int32(len(objValue[0])))
+			if len(ObjDic[0]) <= 4 || !isCuttingIn(objValue, AngularVelocityZ) {
+				continue
+			}
+			event_lable := "RearVehicleCutOut"
+			fmt.Println(event_lable)
+
+			pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
+		}
+
+		if Maxlenobj >= 100 {
+			ObjDicOfTpperception = make(map[uint32][][]float32)
+			shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
+			Maxlenobj = 0
+		}
+	}
+
+}

+ 35 - 0
trigger/pjisuv/data_read/Creeping/main/Creeping.go

@@ -0,0 +1,35 @@
+package main
+
+import (
+	"cicv-data-closedloop/pjisuv_msgs"
+	"fmt"
+	"sync"
+)
+
+func Topic() string {
+	return "/data_read"
+}
+
+func Label() string {
+	return "Creeping"
+}
+
+func Rule(shareVars *sync.Map, data *pjisuv_msgs.Retrieval) string {
+	defer func() {
+		if r := recover(); r != nil {
+			fmt.Println("Recovered from panic:", r)
+		}
+	}()
+	//threshold := 65.0
+	OutsideWorkshopFlag, ok1 := shareVars.Load("OutsideWorkshopFlag")
+	AbsSpeed, ok2 := shareVars.Load("AbsSpeed")
+
+	if ok1 && ok2 && OutsideWorkshopFlag.(bool) == true {
+		if data.GearPos == 2 && AbsSpeed.(float64) > 0.8 {
+			event_lable := "Creeping"
+			fmt.Println(event_lable)
+			return Label()
+		}
+	}
+	return ""
+}