LingxinMeng 10 months ago
parent
commit
b87b47f6b6

+ 2 - 1
aarch64/pjisuv/master/config/trigger_init.go

@@ -12,6 +12,7 @@ import (
 	"github.com/bluenviron/goroslib/v2/pkg/msgs/tf2_msgs"
 	"github.com/bluenviron/goroslib/v2/pkg/msgs/visualization_msgs"
 	"plugin"
+	"slices"
 )
 
 func InitTriggerConfig() {
@@ -24,7 +25,7 @@ func InitTriggerConfig() {
 	// 3 对比触发器列表,本地没有的则下载
 	for _, trigger := range *cloudTriggers {
 		id := util.ToString(trigger.TriggerId)
-		hasIdDir, _ := util.ContainsElement(localTriggerIds, id)
+		hasIdDir := slices.Contains(localTriggerIds, id) // 改成了 slices 工具库
 		triggerLocalDir := config.CloudConfig.TriggersDir + id + "/"
 		hasLabelSo, soPaths := util.CheckSoFilesInDirectory(triggerLocalDir)
 		var triggerLocalPath string

+ 0 - 10
common/util/u_map.go

@@ -2,18 +2,8 @@ package util
 
 import (
 	"sync"
-	"time"
 )
 
-// 函数名为 ContainsKey,参数为一个 map 和一个 key
-func ContainsKey2(m map[string]time.Time, key string) bool {
-	// 通过 map[key] 来访问 map 中的值
-	// 如果 map[key] 返回的值存在,则表示该 key 存在于 map 中,返回 true
-	// 如果 map[key] 返回的值不存在,则表示该 key 不存在于 map 中,返回 false
-	_, exists := m[key]
-	return exists
-}
-
 func ContainsKey(m *sync.Map, key string) bool {
 	_, found := m.Load(key)
 	return found

+ 0 - 19
common/util/u_slice.go

@@ -1,10 +1,5 @@
 package util
 
-import (
-	"errors"
-	"reflect"
-)
-
 // AppendIfNotExists 向切片中追加元素,如果元素已存在则不添加
 func AppendIfNotExists(slice []string, element string) []string {
 	for _, item := range slice {
@@ -31,17 +26,3 @@ func MergeSlice(slice1 []string, slice2 []string) []string {
 	}
 	return slice1
 }
-
-func ContainsElement(slice interface{}, element interface{}) (bool, error) {
-	sliceValue := reflect.ValueOf(slice)
-	if sliceValue.Kind() != reflect.Slice {
-		return false, errors.New("没有输入切片。")
-	}
-	for i := 0; i < sliceValue.Len(); i++ {
-		currentElement := sliceValue.Index(i).Interface()
-		if reflect.DeepEqual(currentElement, element) {
-			return true, nil
-		}
-	}
-	return false, nil
-}

+ 3 - 18
trigger/pjisuv/tpperception/perceptionspeeddiffer/main/perceptionspeeddiffer.go

@@ -4,7 +4,6 @@ import (
 	"cicv-data-closedloop/pjisuv_msgs"
 	"cicv-data-closedloop/pjisuv_param"
 	"math"
-	"reflect"
 )
 
 /*
@@ -28,34 +27,20 @@ func Topic() string {
 
 // Label todo 禁止存在下划线_
 func Label() string {
-	return "perceptionspeeddiffer"
+	return "PerceptionSpeedDiffer"
 }
 
 func Rule(data *pjisuv_msgs.PerceptionObjects, param pjisuv_param.PjisuvParam) string {
 	for _, obj := range data.Objs {
 		if len(param.ObjSpeedDicOfTpperception) != 0 {
-			if ContainsElement(param.ObjSpeedDicOfTpperception, obj.Id) {
+			if _, exist := param.ObjSpeedDicOfTpperception[obj.Id]; exist {
 				objSpeed := math.Pow(math.Pow(float64(obj.Vxabs), 2)+math.Pow(float64(obj.Vyabs), 2), 0.5)
 				diffRate := math.Abs(objSpeed-param.ObjSpeedDicOfTpperception[obj.Id]) / (param.ObjSpeedDicOfTpperception[obj.Id] + 0.0001)
 				if diffRate > 0.1 && objSpeed > 0.5 && param.ObjSpeedDicOfTpperception[obj.Id] > 0.5 {
-					return "perceptionspeeddiffer"
+					return "PerceptionSpeedDiffer"
 				}
 			}
 		}
 	}
 	return ""
 }
-
-func ContainsElement(slice interface{}, element interface{}) bool {
-	sliceValue := reflect.ValueOf(slice)
-	if sliceValue.Kind() != reflect.Slice {
-		return false
-	}
-	for i := 0; i < sliceValue.Len(); i++ {
-		currentElement := sliceValue.Index(i).Interface()
-		if reflect.DeepEqual(currentElement, element) {
-			return true
-		}
-	}
-	return false
-}