LingxinMeng 10 ماه پیش
والد
کامیت
4712acb1b2

+ 0 - 1
aarch64/pjisuv/common/config/c_cloud.go

@@ -58,7 +58,6 @@ type cloudConfig struct {
 	TriggersDir           string        `yaml:"triggers-dir"`
 	TcpPort               string        `yaml:"tcp-port"`
 	RpcPort               string        `yaml:"rpc-port"`
-	TriggersOnline        bool          `yaml:"triggers-online"`
 	Triggers              []trigger     `yaml:"triggers"`
 	Hosts                 []hostStruct  `yaml:"hosts"`
 	Ros                   ros           `yaml:"ros"`

+ 0 - 1
aarch64/pjisuv/common/config/yaml/通用-cloud-config.yaml

@@ -22,7 +22,6 @@ disk:
 bag-data-dir: /mnt/media/sda1/cicv-data-closedloop/data/
 bag-copy-dir: /mnt/media/sda1/cicv-data-closedloop/copy/
 time-to-label-json-path: /mnt/media/sda1/cicv-data-closedloop/timeToLabel.json
-triggers-online: false
 triggers-dir: /mnt/media/sda1/cicv-data-closedloop/triggers/
 time-window-send-gap: 6
 tcp-port: 12340

+ 23 - 191
aarch64/pjisuv/master/config/master_trigger_config.go → aarch64/pjisuv/master/config/trigger_init.go

@@ -12,204 +12,36 @@ import (
 	"github.com/bluenviron/goroslib/v2/pkg/msgs/tf2_msgs"
 	"github.com/bluenviron/goroslib/v2/pkg/msgs/visualization_msgs"
 	"plugin"
-	"strconv"
-	"sync"
-)
-
-var (
-	// 扩展
-	TopicOfCicvExtend = "/cicv_extend"
-	RuleOfCicvExtend  []func(param entity.PjisuvParam) string
-
-	//1
-	TopicOfAmrPose = "/amr_pose"
-	RuleOfAmrPose  []func(data *visualization_msgs.MarkerArray) string
-
-	//2
-	TopicOfBoundingBoxesFast = "/bounding_boxes_fast"
-	RuleOfBoundingBoxesFast  []func(data *pjisuv_msgs.BoundingBoxArray) string
-
-	//3
-	TopicOfCameraFault = "/camera_fault"
-	RuleOfCameraFault  []func(data *pjisuv_msgs.FaultVec) string
-
-	//4
-	TopicOfCanData = "/can_data"
-	RuleOfCanData  []func(data *pjisuv_msgs.Frame) string
-
-	//5
-	TopicOfCh128x1LslidarPointCloud = "/ch128x1/lslidar_point_cloud"
-	RuleOfCh128x1LslidarPointCloud  []func(data *sensor_msgs.PointCloud2) string
-
-	//6
-	TopicOfCh64wLLslidarPointCloud = "/ch64w_l/lslidar_point_cloud"
-	RuleOfCh64wLLslidarPointCloud  []func(data *sensor_msgs.PointCloud2) string
-
-	//7
-	TopicOfCh64wLScan = "/ch64w_l/scan"
-	RuleOfCh64wLScan  []func(data *sensor_msgs.LaserScan) string
-
-	//8
-	TopicOfCh64wRLslidarPointCloud = "/ch64w_r/lslidar_point_cloud"
-	RuleOfCh64wRLslidarPointCloud  []func(data *sensor_msgs.PointCloud2) string
-
-	//9
-	TopicOfCh64wRScan = "/ch64w_r/scan"
-	RuleOfCh64wRScan  []func(data *sensor_msgs.LaserScan) string
-
-	//10
-	TopicOfCicvLidarclusterMovingObjects = "/cicv/lidarcluster_moving_objects"
-	RuleOfCicvLidarclusterMovingObjects  []func(data *pjisuv_msgs.PerceptionCicvMovingObjects) string
-
-	//11
-	TopicOfCicvAmrTrajectory = "/cicv_amr_trajectory"
-	RuleOfCicvAmrTrajectory  []func(data *pjisuv_msgs.Trajectory, param entity.PjisuvParam) string
-
-	//12
-	TopicOfCicvLocation = "/cicv_location"
-	RuleOfCicvLocation  []func(data *pjisuv_msgs.PerceptionLocalization) string
-
-	//13
-	TopicOfCloudClusters = "/cloud_clusters"
-	RuleOfCloudClusters  []func(data *pjisuv_msgs.AutowareCloudClusterArray) string
-
-	//14
-	TopicOfHeartbeatInfo = "/heartbeat_info"
-	RuleOfHeartbeatInfo  []func(data *pjisuv_msgs.HeartBeatInfo) string
-
-	//15
-	TopicOfLidarPretreatmentCost = "/lidarPretreatment_Cost"
-	RuleOfLidarPretreatmentCost  []func(data *geometry_msgs.Vector3Stamped) string
-
-	//16
-	TopicOfLidarPretreatmentOdometry = "/lidar_pretreatment/odometry"
-	RuleOfLidarPretreatmentOdometry  []func(data *nav_msgs.Odometry) string
-
-	//17
-	TopicOfLidarRoi = "/lidar_roi"
-	RuleOfLidarRoi  []func(data *geometry_msgs.PolygonStamped) string
-
-	//18
-	TopicOfLine1 = "/line_1"
-	RuleOfLine1  []func(data *nav_msgs.Path) string
-
-	//19
-	TopicOfLine2 = "/line_2"
-	RuleOfLine2  []func(data *nav_msgs.Path) string
-
-	//20
-	TopicOfMapPolygon = "/map_polygon"
-	RuleOfMapPolygon  []func(data *pjisuv_msgs.PolygonStamped) string
-
-	//21
-	TopicOfObstacleDisplay = "/obstacle_display"
-	RuleOfObstacleDisplay  []func(data *visualization_msgs.MarkerArray) string
-
-	//22
-	TopicOfPjControlPub = "/pj_control_pub"
-	RuleOfPjControlPub  []func(data *pjisuv_msgs.CommonVehicleCmd) string
-
-	//23
-	TopicOfPointsCluster = "/points_cluster"
-	RuleOfPointsCluster  []func(data *sensor_msgs.PointCloud2) string
-
-	//24
-	TopicOfPointsConcat = "/points_concat"
-	RuleOfPointsConcat  []func(data *sensor_msgs.PointCloud2) string
-
-	//25
-	TopicOfReferenceDisplay = "/reference_display"
-	RuleOfReferenceDisplay  []func(data *nav_msgs.Path) string
-
-	//26
-	TopicOfReferenceTrajectory = "/reference_trajectory"
-	RuleOfReferenceTrajectory  []func(data *pjisuv_msgs.Trajectory) string
-
-	//27
-	TopicOfRoiPoints = "/roi/points"
-	RuleOfRoiPoints  []func(data *sensor_msgs.PointCloud2) string
-
-	//28
-	TopicOfRoiPolygon = "/roi/polygon"
-	RuleOfRoiPolygon  []func(data *nav_msgs.Path) string
-
-	//29
-	TopicOfTf = "/tf"
-	RuleOfTf  []func(data *tf2_msgs.TFMessage) string
-
-	//30
-	TopicOfTpperception = "/tpperception"
-	RuleOfTpperception  []func(data *pjisuv_msgs.PerceptionObjects, extendParam entity.PjisuvParam) string
-
-	//31
-	TopicOfTpperceptionVis = "/tpperception/vis"
-	RuleOfTpperceptionVis  []func(data *visualization_msgs.MarkerArray) string
-
-	//32
-	TopicOfTprouteplan = "/tprouteplan"
-	RuleOfTprouteplan  []func(data *pjisuv_msgs.RoutePlan) string
-
-	//33
-	TopicOfTrajectoryDisplay = "/trajectory_display"
-	RuleOfTrajectoryDisplay  []func(data *nav_msgs.Path) string
-
-	//34
-	TopicOfUngroundCloudpoints = "/unground_cloudpoints"
-	RuleOfUngroundCloudpoints  []func(data *sensor_msgs.PointCloud2) string
-
-	//35
-	TopicOfCameraImage = "/camera_image"
-	RuleOfCameraImage  []func(data *sensor_msgs.Image) string
-
-	//36
-	TopicOfDataRead = "/data_read"
-	RuleOfDataRead  []func(data *pjisuv_msgs.Retrieval) string
-
-	//37
-	TopicOfPjiGps = "/pji_gps"
-	RuleOfPjiGps  []func(data *pjisuv_msgs.PerceptionLocalization) string
-
-	//38
-	TopicOfFaultInfo = "/fault_info"
-	//RuleOfFaultInfo  []func(data *pjisuv_msgs.FaultVec) string
-
-	//39
-	TopicOfPjVehicleFdbPub = "/pj_vehicle_fdb_pub"
-	RuleOfPjVehicleFdbPub  []func(data *pjisuv_msgs.VehicleFdb, param *entity.PjisuvParam) string
-
-	LabelMapTriggerId sync.Map
 )
 
 func InitTriggerConfig() {
-	c_log.GlobalLogger.Info("主节点加载触发器插件 - 开始。")
 	var triggerLocalPaths []string
-	if config.CloudConfig.TriggersOnline { // 在线方案
-		for _, trigger := range config.PlatformConfig.TaskTriggers {
-			triggerLocalPath := config.CloudConfig.TriggersDir + trigger.TriggerScriptPath
-			_ = util.CreateParentDir(triggerLocalPath)
-			config.OssMutex.Lock()
-			err := config.OssBucket.GetObjectToFile(trigger.TriggerScriptPath, triggerLocalPath)
-			config.OssMutex.Unlock()
-			if err != nil {
-				c_log.GlobalLogger.Error("下载 oss 上的触发器插件失败:", err)
-				continue
-			}
-			c_log.GlobalLogger.Info("下载触发器插件从 ", trigger.TriggerScriptPath, " 到 ", triggerLocalPath)
-			triggerLocalPaths = append(triggerLocalPaths, triggerLocalPath)
+	c_log.GlobalLogger.Info("主节点加载触发器插件 - 开始。")
+	// 1 获取数采任务的触发器列表
+	cloudTriggers := &config.PlatformConfig.TaskTriggers
+	// 2 获取本地触发器列表(触发器目录的一级子目录为【触发器ID_触发器Label】)
+	localTriggerIds := util.GetFirstLevelSubdirectories(config.CloudConfig.TriggersDir)
+	// 3 对比触发器列表,本地没有的则下载
+	for _, trigger := range *cloudTriggers {
+		label := util.GetFileNameWithoutExtension(config.CloudConfig.TriggersDir + trigger.TriggerScriptPath)
+		id := util.ToString(trigger.TriggerId)
+		triggerLocalPath := config.CloudConfig.TriggersDir + label + "_" + id + "/" + label + ".so"
+		triggerLocalPaths = append(triggerLocalPaths, triggerLocalPath)
+		_ = util.CreateParentDir(triggerLocalPath)
+		contains, _ := util.ContainsElement(localTriggerIds, id)
+		if contains { // 已存在的触发器不需要再次下载
+			continue
 		}
-	} else { // 离线方案
-		triggerLocalPaths = util.GetSoFilePaths(config.CloudConfig.TriggersDir)
-		// 绑定 triggerId 和 triggerLabel
-		for _, path := range triggerLocalPaths {
-			name1 := util.GetFileNameWithoutExtension(path)
-			for _, trigger := range config.PlatformConfig.TaskTriggers {
-				name2 := util.GetFileNameWithoutExtension(config.CloudConfig.TriggersDir + trigger.TriggerScriptPath)
-				if name1 == name2 {
-					LabelMapTriggerId.Store(name1, strconv.Itoa(trigger.TriggerId))
-				}
-			}
+		config.OssMutex.Lock()
+		err := config.OssBucket.GetObjectToFile(trigger.TriggerScriptPath, triggerLocalPath)
+		config.OssMutex.Unlock()
+		if err != nil {
+			c_log.GlobalLogger.Error("下载 oss 上的触发器插件失败:", err)
+			continue
 		}
+		c_log.GlobalLogger.Info("下载触发器插件从 ", trigger.TriggerScriptPath, " 到 ", triggerLocalPath)
 	}
+
 	// 下载所有触发器的文件
 	for _, triggerLocalPath := range triggerLocalPaths {
 		// 载入插件到数组

+ 175 - 0
aarch64/pjisuv/master/config/trigger_var.go

@@ -0,0 +1,175 @@
+package config
+
+import (
+	"cicv-data-closedloop/pjisuv_msgs"
+	entity "cicv-data-closedloop/pjisuv_param"
+	"github.com/bluenviron/goroslib/v2/pkg/msgs/geometry_msgs"
+	"github.com/bluenviron/goroslib/v2/pkg/msgs/nav_msgs"
+	"github.com/bluenviron/goroslib/v2/pkg/msgs/sensor_msgs"
+	"github.com/bluenviron/goroslib/v2/pkg/msgs/tf2_msgs"
+	"github.com/bluenviron/goroslib/v2/pkg/msgs/visualization_msgs"
+	"sync"
+)
+
+var (
+	LabelMapTriggerId *sync.Map
+	// 扩展
+	TopicOfCicvExtend = "/cicv_extend"
+	RuleOfCicvExtend  []func(param entity.PjisuvParam) string
+
+	//1
+	TopicOfAmrPose = "/amr_pose"
+	RuleOfAmrPose  []func(data *visualization_msgs.MarkerArray) string
+
+	//2
+	TopicOfBoundingBoxesFast = "/bounding_boxes_fast"
+	RuleOfBoundingBoxesFast  []func(data *pjisuv_msgs.BoundingBoxArray) string
+
+	//3
+	TopicOfCameraFault = "/camera_fault"
+	RuleOfCameraFault  []func(data *pjisuv_msgs.FaultVec) string
+
+	//4
+	TopicOfCanData = "/can_data"
+	RuleOfCanData  []func(data *pjisuv_msgs.Frame) string
+
+	//5
+	TopicOfCh128x1LslidarPointCloud = "/ch128x1/lslidar_point_cloud"
+	RuleOfCh128x1LslidarPointCloud  []func(data *sensor_msgs.PointCloud2) string
+
+	//6
+	TopicOfCh64wLLslidarPointCloud = "/ch64w_l/lslidar_point_cloud"
+	RuleOfCh64wLLslidarPointCloud  []func(data *sensor_msgs.PointCloud2) string
+
+	//7
+	TopicOfCh64wLScan = "/ch64w_l/scan"
+	RuleOfCh64wLScan  []func(data *sensor_msgs.LaserScan) string
+
+	//8
+	TopicOfCh64wRLslidarPointCloud = "/ch64w_r/lslidar_point_cloud"
+	RuleOfCh64wRLslidarPointCloud  []func(data *sensor_msgs.PointCloud2) string
+
+	//9
+	TopicOfCh64wRScan = "/ch64w_r/scan"
+	RuleOfCh64wRScan  []func(data *sensor_msgs.LaserScan) string
+
+	//10
+	TopicOfCicvLidarclusterMovingObjects = "/cicv/lidarcluster_moving_objects"
+	RuleOfCicvLidarclusterMovingObjects  []func(data *pjisuv_msgs.PerceptionCicvMovingObjects) string
+
+	//11
+	TopicOfCicvAmrTrajectory = "/cicv_amr_trajectory"
+	RuleOfCicvAmrTrajectory  []func(data *pjisuv_msgs.Trajectory, param entity.PjisuvParam) string
+
+	//12
+	TopicOfCicvLocation = "/cicv_location"
+	RuleOfCicvLocation  []func(data *pjisuv_msgs.PerceptionLocalization) string
+
+	//13
+	TopicOfCloudClusters = "/cloud_clusters"
+	RuleOfCloudClusters  []func(data *pjisuv_msgs.AutowareCloudClusterArray) string
+
+	//14
+	TopicOfHeartbeatInfo = "/heartbeat_info"
+	RuleOfHeartbeatInfo  []func(data *pjisuv_msgs.HeartBeatInfo) string
+
+	//15
+	TopicOfLidarPretreatmentCost = "/lidarPretreatment_Cost"
+	RuleOfLidarPretreatmentCost  []func(data *geometry_msgs.Vector3Stamped) string
+
+	//16
+	TopicOfLidarPretreatmentOdometry = "/lidar_pretreatment/odometry"
+	RuleOfLidarPretreatmentOdometry  []func(data *nav_msgs.Odometry) string
+
+	//17
+	TopicOfLidarRoi = "/lidar_roi"
+	RuleOfLidarRoi  []func(data *geometry_msgs.PolygonStamped) string
+
+	//18
+	TopicOfLine1 = "/line_1"
+	RuleOfLine1  []func(data *nav_msgs.Path) string
+
+	//19
+	TopicOfLine2 = "/line_2"
+	RuleOfLine2  []func(data *nav_msgs.Path) string
+
+	//20
+	TopicOfMapPolygon = "/map_polygon"
+	RuleOfMapPolygon  []func(data *pjisuv_msgs.PolygonStamped) string
+
+	//21
+	TopicOfObstacleDisplay = "/obstacle_display"
+	RuleOfObstacleDisplay  []func(data *visualization_msgs.MarkerArray) string
+
+	//22
+	TopicOfPjControlPub = "/pj_control_pub"
+	RuleOfPjControlPub  []func(data *pjisuv_msgs.CommonVehicleCmd) string
+
+	//23
+	TopicOfPointsCluster = "/points_cluster"
+	RuleOfPointsCluster  []func(data *sensor_msgs.PointCloud2) string
+
+	//24
+	TopicOfPointsConcat = "/points_concat"
+	RuleOfPointsConcat  []func(data *sensor_msgs.PointCloud2) string
+
+	//25
+	TopicOfReferenceDisplay = "/reference_display"
+	RuleOfReferenceDisplay  []func(data *nav_msgs.Path) string
+
+	//26
+	TopicOfReferenceTrajectory = "/reference_trajectory"
+	RuleOfReferenceTrajectory  []func(data *pjisuv_msgs.Trajectory) string
+
+	//27
+	TopicOfRoiPoints = "/roi/points"
+	RuleOfRoiPoints  []func(data *sensor_msgs.PointCloud2) string
+
+	//28
+	TopicOfRoiPolygon = "/roi/polygon"
+	RuleOfRoiPolygon  []func(data *nav_msgs.Path) string
+
+	//29
+	TopicOfTf = "/tf"
+	RuleOfTf  []func(data *tf2_msgs.TFMessage) string
+
+	//30
+	TopicOfTpperception = "/tpperception"
+	RuleOfTpperception  []func(data *pjisuv_msgs.PerceptionObjects, extendParam entity.PjisuvParam) string
+
+	//31
+	TopicOfTpperceptionVis = "/tpperception/vis"
+	RuleOfTpperceptionVis  []func(data *visualization_msgs.MarkerArray) string
+
+	//32
+	TopicOfTprouteplan = "/tprouteplan"
+	RuleOfTprouteplan  []func(data *pjisuv_msgs.RoutePlan) string
+
+	//33
+	TopicOfTrajectoryDisplay = "/trajectory_display"
+	RuleOfTrajectoryDisplay  []func(data *nav_msgs.Path) string
+
+	//34
+	TopicOfUngroundCloudpoints = "/unground_cloudpoints"
+	RuleOfUngroundCloudpoints  []func(data *sensor_msgs.PointCloud2) string
+
+	//35
+	TopicOfCameraImage = "/camera_image"
+	RuleOfCameraImage  []func(data *sensor_msgs.Image) string
+
+	//36
+	TopicOfDataRead = "/data_read"
+	RuleOfDataRead  []func(data *pjisuv_msgs.Retrieval) string
+
+	//37
+	TopicOfPjiGps = "/pji_gps"
+	RuleOfPjiGps  []func(data *pjisuv_msgs.PerceptionLocalization) string
+
+	//38
+	TopicOfFaultInfo = "/fault_info"
+	//RuleOfFaultInfo  []func(data *pjisuv_msgs.FaultVec) string
+
+	//39
+	TopicOfPjVehicleFdbPub = "/pj_vehicle_fdb_pub"
+	RuleOfPjVehicleFdbPub  []func(data *pjisuv_msgs.VehicleFdb, param *entity.PjisuvParam) string
+)

+ 5 - 8
aarch64/pjisuv/master/service/produce_window.go

@@ -1182,8 +1182,7 @@ func PrepareTimeWindowProducerQueue() {
 
 func saveTimeWindow(faultLabel string, faultHappenTime string, lastTimeWindow *commonEntity.TimeWindow) {
 	masterTopics, slaveTopics := getTopicsOfNode(faultLabel)
-	if lastTimeWindow == nil || util.TimeCustom1GreaterTimeCustom2(faultHappenTime, lastTimeWindow.TimeWindowEnd) {
-		// 2-1 如果是不在旧故障窗口内,添加一个新窗口
+	if lastTimeWindow == nil || util.TimeCustom1GreaterTimeCustom2(faultHappenTime, lastTimeWindow.TimeWindowEnd) { // 如果是不在旧故障窗口内,添加一个新窗口
 		newTimeWindow := commonEntity.TimeWindow{
 			FaultTime:       faultHappenTime,
 			TimeWindowBegin: util.TimeCustomChange(faultHappenTime, -commonConfig.PlatformConfig.TaskBeforeTime),
@@ -1196,11 +1195,10 @@ func saveTimeWindow(faultLabel string, faultHappenTime string, lastTimeWindow *c
 		c_log.GlobalLogger.Infof("不在旧故障窗口内,向生产者队列添加一个新窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", newTimeWindow.Labels, newTimeWindow.FaultTime, newTimeWindow.Length)
 
 		commonEntity.AddTimeWindowToTimeWindowProducerQueue(newTimeWindow)
-	} else {
-		// 2-2 如果在旧故障窗口内
+	} else { // 如果在旧故障窗口内
 		commonEntity.TimeWindowProducerQueueMutex.RLock()
 		defer commonEntity.TimeWindowProducerQueueMutex.RUnlock()
-		// 2-2-1 更新故障窗口end时间
+		// 更新故障窗口end时间
 		maxEnd := util.TimeCustomChange(lastTimeWindow.TimeWindowBegin, commonConfig.PlatformConfig.TaskMaxTime)
 		expectEnd := util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime)
 		if util.TimeCustom1GreaterTimeCustom2(expectEnd, maxEnd) {
@@ -1212,16 +1210,15 @@ func saveTimeWindow(faultLabel string, faultHappenTime string, lastTimeWindow *c
 				lastTimeWindow.Length = util.CalculateDifferenceOfTimeCustom(lastTimeWindow.TimeWindowBegin, expectEnd)
 			}
 		}
-		// 2-2-2 更新label
+		// 更新label
 		labels := lastTimeWindow.Labels
 		lastTimeWindow.Labels = util.AppendIfNotExists(labels, faultLabel)
-		// 2-2-3 更新 topic
+		// 更新 topic
 		sourceMasterTopics := lastTimeWindow.MasterTopics
 		lastTimeWindow.MasterTopics = util.MergeSlice(sourceMasterTopics, masterTopics)
 		sourceSlaveTopics := lastTimeWindow.SlaveTopics
 		lastTimeWindow.SlaveTopics = util.MergeSlice(sourceSlaveTopics, slaveTopics)
 		c_log.GlobalLogger.Infof("在旧故障窗口内,更新生产者队列最新的窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", lastTimeWindow.Labels, lastTimeWindow.FaultTime, lastTimeWindow.Length)
-
 	}
 }
 

+ 11 - 0
common/util/u_io.go

@@ -9,6 +9,17 @@ import (
 	"strings"
 )
 
+func GetFirstLevelSubdirectories(dirPath string) []string {
+	dirEntries, _ := os.ReadDir(dirPath)
+	subdirectories := make([]string, 0)
+	for _, entry := range dirEntries {
+		if entry.IsDir() {
+			subdirectories = append(subdirectories, entry.Name())
+		}
+	}
+	return subdirectories
+}
+
 func GetFileNameWithoutExtension(absPath string) string {
 	file := filepath.Base(absPath)
 	ext := filepath.Ext(file)