123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986 |
- package service
- import (
- commonConfig "cicv-data-closedloop/aarch64/pjisuv/common/config"
- "cicv-data-closedloop/aarch64/pjisuv/common/service"
- masterConfig "cicv-data-closedloop/aarch64/pjisuv/master/config"
- "cicv-data-closedloop/common/config/c_log"
- commonEntity "cicv-data-closedloop/common/entity"
- "cicv-data-closedloop/common/util"
- "cicv-data-closedloop/pjisuv_msgs"
- "cicv-data-closedloop/pjisuv_param"
- "github.com/bluenviron/goroslib/v2"
- "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"
- "math"
- "sync"
- "time"
- )
- // 所有共享变量
- var (
- lastGlobalTriggerTime = time.Now()
- thisGlobalTriggerTime = time.Now()
- pjisuvParam = pjisuv_param.PjisuvParam{
- ObjDicOfTpperception: make(map[uint32][]float32),
- ObjTypeDicOfTpperception: make(map[uint32]uint8),
- ObjSpeedDicOfTpperception: make(map[uint32]float64),
- } // /cicv_location
- mutexOfCicvLocation sync.RWMutex
- // /tpperception
- mutexOfTpperception sync.RWMutex
- // /pj_control_pub
- mutexOfPjControlPub sync.RWMutex
- // /data_read
- mutexOfDataRead sync.RWMutex
- // /pj_vehicle_fdb_pub
- mutexOfPjVehicleFdbPub sync.RWMutex
- // /pj_vehicle_fdb_pub
- mutexOfCicvAmrTrajectory sync.RWMutex
- )
- // PrepareTimeWindowProducerQueue 负责监听所有主题并修改时间窗口
- func PrepareTimeWindowProducerQueue() {
- c_log.GlobalLogger.Info("订阅者 goroutine,启动。")
- var err error
- subscribers := make([]*goroslib.Subscriber, len(commonConfig.SubscribeTopics))
- subscribersTimes := make([]time.Time, len(commonConfig.SubscribeTopics))
- subscribersTimeMutexes := make([]sync.Mutex, len(commonConfig.SubscribeTopics))
- subscribersMutexes := make([]sync.Mutex, len(commonConfig.SubscribeTopics))
- for i, topic := range commonConfig.SubscribeTopics {
- // 增加了可扩展性
- if topic == masterConfig.TopicOfCicvExtend {
- go func() {
- for {
- time.Sleep(time.Duration(3500) * time.Millisecond)
- for _, f := range masterConfig.RuleOfCicvExtend {
- label := f(pjisuvParam)
- if label != "" {
- saveTimeWindow(label, util.GetNowTimeCustom(), commonEntity.GetLastTimeWindow())
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- break
- }
- }
- }
- }()
- }
- // 其他常规监听器
- c_log.GlobalLogger.Info("创建订阅者订阅话题:" + topic)
- // 1
- if topic == masterConfig.TopicOfAmrPose && (len(masterConfig.RuleOfAmrPose1) > 0 || len(masterConfig.RuleOfAmrPose2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *visualization_msgs.MarkerArray) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfAmrPose1) > 0 {
- for _, f := range masterConfig.RuleOfAmrPose1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfAmrPose2) > 0 {
- for _, f := range masterConfig.RuleOfAmrPose2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 2
- if topic == masterConfig.TopicOfBoundingBoxesFast && (len(masterConfig.RuleOfBoundingBoxesFast1) > 0 || len(masterConfig.RuleOfBoundingBoxesFast2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.BoundingBoxArray) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfBoundingBoxesFast1) > 0 {
- for _, f := range masterConfig.RuleOfBoundingBoxesFast1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfBoundingBoxesFast2) > 0 {
- for _, f := range masterConfig.RuleOfBoundingBoxesFast2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 3
- if topic == masterConfig.TopicOfCameraFault && (len(masterConfig.RuleOfCameraFault1) > 0 || len(masterConfig.RuleOfCameraFault2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.FaultVec) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCameraFault1) > 0 {
- for _, f := range masterConfig.RuleOfCameraFault1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCameraFault2) > 0 {
- for _, f := range masterConfig.RuleOfCameraFault2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 4
- if topic == masterConfig.TopicOfCanData && (len(masterConfig.RuleOfCanData1) > 0 || len(masterConfig.RuleOfCanData2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.Frame) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCanData1) > 0 {
- for _, f := range masterConfig.RuleOfCanData1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCanData2) > 0 {
- for _, f := range masterConfig.RuleOfCanData2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 5
- if topic == masterConfig.TopicOfCh128x1LslidarPointCloud && (len(masterConfig.RuleOfCh128x1LslidarPointCloud1) > 0 || len(masterConfig.RuleOfCh128x1LslidarPointCloud2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.PointCloud2) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCh128x1LslidarPointCloud1) > 0 {
- for _, f := range masterConfig.RuleOfCh128x1LslidarPointCloud1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCh128x1LslidarPointCloud2) > 0 {
- for _, f := range masterConfig.RuleOfCh128x1LslidarPointCloud2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 6
- if topic == masterConfig.TopicOfCh64wLLslidarPointCloud && (len(masterConfig.RuleOfCh64wLLslidarPointCloud1) > 0 || len(masterConfig.RuleOfCh64wLLslidarPointCloud2) > 1) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.PointCloud2) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCh64wLLslidarPointCloud1) > 0 {
- for _, f := range masterConfig.RuleOfCh64wLLslidarPointCloud1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCh64wLLslidarPointCloud2) > 0 {
- for _, f := range masterConfig.RuleOfCh64wLLslidarPointCloud2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 7
- if topic == masterConfig.TopicOfCh64wLScan && (len(masterConfig.RuleOfCh64wLScan1) > 0 || len(masterConfig.RuleOfCh64wLScan2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.LaserScan) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCh64wLScan1) > 0 {
- for _, f := range masterConfig.RuleOfCh64wLScan1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCh64wLScan2) > 0 {
- for _, f := range masterConfig.RuleOfCh64wLScan2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 8
- if topic == masterConfig.TopicOfCh64wRLslidarPointCloud && (len(masterConfig.RuleOfCh64wRLslidarPointCloud1) > 0 || len(masterConfig.RuleOfCh64wRLslidarPointCloud2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.PointCloud2) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCh64wRLslidarPointCloud1) > 0 {
- for _, f := range masterConfig.RuleOfCh64wRLslidarPointCloud1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCh64wRLslidarPointCloud2) > 0 {
- for _, f := range masterConfig.RuleOfCh64wRLslidarPointCloud2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 9
- if topic == masterConfig.TopicOfCh64wRScan && (len(masterConfig.RuleOfCh64wRScan1) > 0 || len(masterConfig.RuleOfCh64wRScan2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.LaserScan) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCh64wRScan1) > 0 {
- for _, f := range masterConfig.RuleOfCh64wRScan1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCh64wRScan2) > 0 {
- for _, f := range masterConfig.RuleOfCh64wRScan2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 10
- if topic == masterConfig.TopicOfCicvLidarclusterMovingObjects && (len(masterConfig.RuleOfCicvLidarclusterMovingObjects1) > 0 || len(masterConfig.RuleOfCicvLidarclusterMovingObjects2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.PerceptionCicvMovingObjects) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCicvLidarclusterMovingObjects1) > 0 {
- for _, f := range masterConfig.RuleOfCicvLidarclusterMovingObjects1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCicvLidarclusterMovingObjects2) > 0 {
- for _, f := range masterConfig.RuleOfCicvLidarclusterMovingObjects2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 11
- if topic == masterConfig.TopicOfCicvAmrTrajectory && (len(masterConfig.RuleOfCicvAmrTrajectory1) > 0 || len(masterConfig.RuleOfCicvAmrTrajectory2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.Trajectory) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCicvAmrTrajectory1) > 0 {
- for _, f := range masterConfig.RuleOfCicvAmrTrajectory1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCicvAmrTrajectory2) > 0 {
- for _, f := range masterConfig.RuleOfCicvAmrTrajectory2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- // 触发后更新共享变量
- mutexOfCicvAmrTrajectory.RLock()
- {
- var currentCurvateres []float64
- for _, point := range data.Trajectoryinfo.Trajectorypoints {
- currentCurvateres = append(currentCurvateres, math.Abs(float64(point.Curvature)))
- }
- pjisuvParam.LastCurvaturesOfCicvAmrTrajectory = currentCurvateres
- }
- mutexOfCicvAmrTrajectory.RUnlock()
- },
- })
- }
- // 12
- if topic == masterConfig.TopicOfCicvLocation && (len(masterConfig.RuleOfCicvLocation1) > 0 || len(masterConfig.RuleOfCicvLocation2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.PerceptionLocalization) {
- // 更新共享变量
- mutexOfCicvLocation.RLock()
- {
- 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()
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCicvLocation1) > 0 {
- for _, f := range masterConfig.RuleOfCicvLocation1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCicvLocation2) > 0 {
- for _, f := range masterConfig.RuleOfCicvLocation2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 13
- if topic == masterConfig.TopicOfCloudClusters && (len(masterConfig.RuleOfCloudClusters1) > 0 || len(masterConfig.RuleOfCloudClusters2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.AutowareCloudClusterArray) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCloudClusters1) > 0 {
- for _, f := range masterConfig.RuleOfCloudClusters1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCloudClusters2) > 0 {
- for _, f := range masterConfig.RuleOfCloudClusters2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 14
- if topic == masterConfig.TopicOfHeartbeatInfo && (len(masterConfig.RuleOfHeartbeatInfo1) > 0 || len(masterConfig.RuleOfHeartbeatInfo2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.HeartBeatInfo) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfHeartbeatInfo1) > 0 {
- for _, f := range masterConfig.RuleOfHeartbeatInfo1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfHeartbeatInfo2) > 0 {
- for _, f := range masterConfig.RuleOfHeartbeatInfo2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 15
- if topic == masterConfig.TopicOfLidarPretreatmentCost && (len(masterConfig.RuleOfLidarPretreatmentCost1) > 0 || len(masterConfig.RuleOfLidarPretreatmentCost2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *geometry_msgs.Vector3Stamped) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfLidarPretreatmentCost1) > 0 {
- for _, f := range masterConfig.RuleOfLidarPretreatmentCost1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfLidarPretreatmentCost2) > 0 {
- for _, f := range masterConfig.RuleOfLidarPretreatmentCost2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 16
- if topic == masterConfig.TopicOfLidarPretreatmentOdometry && (len(masterConfig.RuleOfLidarPretreatmentOdometry1) > 0 || len(masterConfig.RuleOfLidarPretreatmentOdometry2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *nav_msgs.Odometry) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfLidarPretreatmentOdometry1) > 0 {
- for _, f := range masterConfig.RuleOfLidarPretreatmentOdometry1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfLidarPretreatmentOdometry2) > 0 {
- for _, f := range masterConfig.RuleOfLidarPretreatmentOdometry2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 17
- if topic == masterConfig.TopicOfLidarRoi && (len(masterConfig.RuleOfLidarRoi1) > 0 || len(masterConfig.RuleOfLidarRoi2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *geometry_msgs.PolygonStamped) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfLidarRoi1) > 0 {
- for _, f := range masterConfig.RuleOfLidarRoi1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfLidarRoi2) > 0 {
- for _, f := range masterConfig.RuleOfLidarRoi2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 18
- if topic == masterConfig.TopicOfLine1 && (len(masterConfig.RuleOfLine11) > 0 || len(masterConfig.RuleOfLine12) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *nav_msgs.Path) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfLine11) > 0 {
- for _, f := range masterConfig.RuleOfLine11 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfLine12) > 0 {
- for _, f := range masterConfig.RuleOfLine12 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 19
- if topic == masterConfig.TopicOfLine2 && (len(masterConfig.RuleOfLine21) > 0 || len(masterConfig.RuleOfLine22) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *nav_msgs.Path) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfLine21) > 0 {
- for _, f := range masterConfig.RuleOfLine21 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfLine22) > 0 {
- for _, f := range masterConfig.RuleOfLine22 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 20
- if topic == masterConfig.TopicOfMapPolygon && (len(masterConfig.RuleOfMapPolygon1) > 0 || len(masterConfig.RuleOfMapPolygon2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.PolygonStamped) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfMapPolygon1) > 0 {
- for _, f := range masterConfig.RuleOfMapPolygon1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfMapPolygon2) > 0 {
- for _, f := range masterConfig.RuleOfMapPolygon2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 21
- if topic == masterConfig.TopicOfObstacleDisplay && (len(masterConfig.RuleOfObstacleDisplay1) > 0 || len(masterConfig.RuleOfObstacleDisplay2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *visualization_msgs.MarkerArray) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfObstacleDisplay1) > 0 {
- for _, f := range masterConfig.RuleOfObstacleDisplay1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfObstacleDisplay2) > 0 {
- for _, f := range masterConfig.RuleOfObstacleDisplay2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 22
- if topic == masterConfig.TopicOfPjControlPub && (len(masterConfig.RuleOfPjControlPub1) > 0 || len(masterConfig.RuleOfPjControlPub2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.CommonVehicleCmd) {
- // 更新共享变量
- mutexOfPjControlPub.RLock()
- {
- pjisuvParam.NumCountPjiControlCommandOfPjControlPub++
- if pjisuvParam.NumCountPjiControlCommandOfPjControlPub == 10 {
- pjisuvParam.EgoSteeringCmdOfPjControlPub = append(pjisuvParam.EgoSteeringCmdOfPjControlPub, data.ICPVCmdStrAngle)
- pjisuvParam.EgoThrottleCmdOfPjControlPub = append(pjisuvParam.EgoThrottleCmdOfPjControlPub, data.ICPVCmdAccPelPosAct)
- pjisuvParam.NumCountPjiControlCommandOfPjControlPub = 0
- }
- }
- mutexOfPjControlPub.RUnlock()
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfPjControlPub1) > 0 {
- for _, f := range masterConfig.RuleOfPjControlPub1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfPjControlPub2) > 0 {
- for _, f := range masterConfig.RuleOfPjControlPub2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 23
- if topic == masterConfig.TopicOfPointsCluster && (len(masterConfig.RuleOfPointsCluster1) > 0 || len(masterConfig.RuleOfPointsCluster2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.PointCloud2) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfPointsCluster1) > 0 {
- for _, f := range masterConfig.RuleOfPointsCluster1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfPointsCluster2) > 0 {
- for _, f := range masterConfig.RuleOfPointsCluster2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 24
- if topic == masterConfig.TopicOfPointsConcat && (len(masterConfig.RuleOfPointsConcat1) > 0 || len(masterConfig.RuleOfPointsConcat2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.PointCloud2) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfPointsConcat1) > 0 {
- for _, f := range masterConfig.RuleOfPointsConcat1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfPointsConcat2) > 0 {
- for _, f := range masterConfig.RuleOfPointsConcat2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 25
- if topic == masterConfig.TopicOfReferenceDisplay && (len(masterConfig.RuleOfReferenceDisplay1) > 0 || len(masterConfig.RuleOfReferenceDisplay2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *nav_msgs.Path) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfReferenceDisplay1) > 0 {
- for _, f := range masterConfig.RuleOfReferenceDisplay1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfReferenceDisplay2) > 0 {
- for _, f := range masterConfig.RuleOfReferenceDisplay2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 26
- if topic == masterConfig.TopicOfReferenceTrajectory && (len(masterConfig.RuleOfReferenceTrajectory1) > 0 || len(masterConfig.RuleOfReferenceTrajectory2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.Trajectory) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfReferenceTrajectory1) > 0 {
- for _, f := range masterConfig.RuleOfReferenceTrajectory1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfReferenceTrajectory2) > 0 {
- for _, f := range masterConfig.RuleOfReferenceTrajectory2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 27
- if topic == masterConfig.TopicOfRoiPoints && (len(masterConfig.RuleOfRoiPoints1) > 0 || len(masterConfig.RuleOfRoiPoints2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.PointCloud2) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfRoiPoints1) > 0 {
- for _, f := range masterConfig.RuleOfRoiPoints1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfRoiPoints2) > 0 {
- for _, f := range masterConfig.RuleOfRoiPoints2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 28
- if topic == masterConfig.TopicOfRoiPolygon && (len(masterConfig.RuleOfRoiPolygon1) > 0 || len(masterConfig.RuleOfRoiPolygon2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *nav_msgs.Path) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfRoiPolygon1) > 0 {
- for _, f := range masterConfig.RuleOfRoiPolygon1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfRoiPolygon2) > 0 {
- for _, f := range masterConfig.RuleOfRoiPolygon2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 29
- if topic == masterConfig.TopicOfTf && (len(masterConfig.RuleOfTf1) > 0 || len(masterConfig.RuleOfTf2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *tf2_msgs.TFMessage) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfTf1) > 0 {
- for _, f := range masterConfig.RuleOfTf1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfTf2) > 0 {
- for _, f := range masterConfig.RuleOfTf2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 30
- if topic == masterConfig.TopicOfTpperception && (len(masterConfig.RuleOfTpperception1) > 0 || len(masterConfig.RuleOfTpperception2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.PerceptionObjects) {
- // 更新共享变量
- mutexOfTpperception.RLock()
- {
- for _, obj := range data.Objs {
- if obj.X <= 5 || math.Abs(float64(obj.Y)) >= 10 {
- continue
- }
- // 检查 ObjDicOfTpperception 是否为 nil,如果是,则初始化它
- if pjisuvParam.ObjDicOfTpperception == nil {
- pjisuvParam.ObjDicOfTpperception = make(map[uint32][]float32)
- }
- if _, ok := pjisuvParam.ObjDicOfTpperception[obj.Id]; !ok {
- pjisuvParam.ObjDicOfTpperception[obj.Id] = []float32{}
- }
- pjisuvParam.ObjDicOfTpperception[obj.Id] = append(pjisuvParam.ObjDicOfTpperception[obj.Id], obj.Y)
- }
- }
- mutexOfTpperception.RUnlock()
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfTpperception1) > 0 {
- for _, f := range masterConfig.RuleOfTpperception1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfTpperception2) > 0 {
- for _, f := range masterConfig.RuleOfTpperception2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- // -------- 触发后更新共享变量
- mutexOfTpperception.RLock()
- {
- for _, obj := range data.Objs {
- pjisuvParam.ObjTypeDicOfTpperception[obj.Id] = obj.Type
- pjisuvParam.ObjSpeedDicOfTpperception[obj.Id] = math.Pow(math.Pow(float64(obj.Vxabs), 2)+math.Pow(float64(obj.Vyabs), 2), 0.5)
- }
- }
- mutexOfTpperception.RUnlock()
- },
- })
- }
- // 31
- if topic == masterConfig.TopicOfTpperceptionVis && (len(masterConfig.RuleOfTpperceptionVis1) > 0 || len(masterConfig.RuleOfTpperceptionVis2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *visualization_msgs.MarkerArray) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfTpperceptionVis1) > 0 {
- for _, f := range masterConfig.RuleOfTpperceptionVis1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfTpperceptionVis2) > 0 {
- for _, f := range masterConfig.RuleOfTpperceptionVis2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 32
- if topic == masterConfig.TopicOfTprouteplan && (len(masterConfig.RuleOfTprouteplan1) > 0 || len(masterConfig.RuleOfTprouteplan2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.RoutePlan) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfTprouteplan1) > 0 {
- for _, f := range masterConfig.RuleOfTprouteplan1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfTprouteplan2) > 0 {
- for _, f := range masterConfig.RuleOfTprouteplan2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 33
- if topic == masterConfig.TopicOfTrajectoryDisplay && (len(masterConfig.RuleOfTrajectoryDisplay1) > 0 || len(masterConfig.RuleOfTrajectoryDisplay2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *nav_msgs.Path) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfTrajectoryDisplay1) > 0 {
- for _, f := range masterConfig.RuleOfTrajectoryDisplay1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfTrajectoryDisplay2) > 0 {
- for _, f := range masterConfig.RuleOfTrajectoryDisplay2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 34
- if topic == masterConfig.TopicOfUngroundCloudpoints && (len(masterConfig.RuleOfUngroundCloudpoints1) > 0 || len(masterConfig.RuleOfUngroundCloudpoints2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.PointCloud2) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfUngroundCloudpoints1) > 0 {
- for _, f := range masterConfig.RuleOfUngroundCloudpoints1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfUngroundCloudpoints2) > 0 {
- for _, f := range masterConfig.RuleOfUngroundCloudpoints2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 35
- if topic == masterConfig.TopicOfCameraImage && (len(masterConfig.RuleOfCameraImage1) > 0 || len(masterConfig.RuleOfCameraImage2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *sensor_msgs.Image) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfCameraImage1) > 0 {
- for _, f := range masterConfig.RuleOfCameraImage1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfCameraImage2) > 0 {
- for _, f := range masterConfig.RuleOfCameraImage2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 36
- if topic == masterConfig.TopicOfDataRead && (len(masterConfig.RuleOfDataRead1) > 0 || len(masterConfig.RuleOfDataRead2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.Retrieval) {
- // 更新共享变量
- mutexOfDataRead.RLock()
- {
- pjisuvParam.NumCountDataReadOfDataRead++
- if pjisuvParam.NumCountDataReadOfDataRead == 10 {
- pjisuvParam.EgoSteeringRealOfDataRead = append(pjisuvParam.EgoSteeringRealOfDataRead, data.ActStrWhAng)
- pjisuvParam.EgoThrottleRealOfDataRead = append(pjisuvParam.EgoThrottleRealOfDataRead, data.AccPed2)
- pjisuvParam.NumCountDataReadOfDataRead = 0
- }
- pjisuvParam.StrgAngleRealValueOfDataRead = data.ActStrWhAng
- }
- mutexOfDataRead.RUnlock()
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfDataRead1) > 0 {
- for _, f := range masterConfig.RuleOfDataRead1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfDataRead2) > 0 {
- for _, f := range masterConfig.RuleOfDataRead2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 37
- if topic == masterConfig.TopicOfPjiGps && (len(masterConfig.RuleOfPjiGps1) > 0 || len(masterConfig.RuleOfPjiGps2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.PerceptionLocalization) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfPjiGps1) > 0 {
- for _, f := range masterConfig.RuleOfPjiGps1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfPjiGps2) > 0 {
- for _, f := range masterConfig.RuleOfPjiGps2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- // 39
- if topic == masterConfig.TopicOfPjVehicleFdbPub && (len(masterConfig.RuleOfPjVehicleFdbPub1) > 0 || len(masterConfig.RuleOfPjVehicleFdbPub2) > 0) {
- subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: commonConfig.RosNode,
- Topic: topic,
- Callback: func(data *pjisuv_msgs.VehicleFdb) {
- subscribersTimeMutexes[i].Lock()
- if time.Since(subscribersTimes[i]).Seconds() > 1 {
- subscribersMutexes[i].Lock()
- faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
- lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
- faultLabel := ""
- if len(masterConfig.RuleOfPjVehicleFdbPub1) > 0 {
- for _, f := range masterConfig.RuleOfPjVehicleFdbPub1 {
- faultLabel = f(data)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- if len(masterConfig.RuleOfPjVehicleFdbPub2) > 0 {
- for _, f := range masterConfig.RuleOfPjVehicleFdbPub2 {
- faultLabel = f(data, &pjisuvParam)
- if faultLabel != "" {
- saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
- lastGlobalTriggerTime = thisGlobalTriggerTime
- thisGlobalTriggerTime = time.Now()
- subscribersTimes[i] = thisGlobalTriggerTime
- goto TriggerSuccess
- }
- }
- }
- TriggerSuccess:
- subscribersMutexes[i].Unlock()
- }
- subscribersTimeMutexes[i].Unlock()
- },
- })
- }
- if err != nil {
- c_log.GlobalLogger.Info("创建订阅者报错:", err)
- continue
- }
- }
- select {
- case signal := <-service.ChannelKillWindowProducer:
- if signal == 1 {
- commonConfig.RosNode.Close()
- service.AddKillTimes("3")
- return
- }
- }
- }
- func saveTimeWindow(faultLabel string, faultHappenTime string, lastTimeWindow *commonEntity.TimeWindow) {
- masterTopics, slaveTopics := getTopicsOfNode(faultLabel)
- if lastTimeWindow == nil || util.TimeCustom1GreaterTimeCustom2(faultHappenTime, lastTimeWindow.TimeWindowEnd) { // 如果是不在旧故障窗口内,添加一个新窗口
- exceptBegin := util.TimeCustomChange(faultHappenTime, -commonConfig.PlatformConfig.TaskBeforeTime)
- earliestBegin := util.GetTimeString(lastGlobalTriggerTime) // 窗口最早时间不能早于上一次触发时间
- finalTimeWindowBegin := ""
- if util.TimeCustom1LessEqualThanTimeCustom2(exceptBegin, earliestBegin) {
- finalTimeWindowBegin = earliestBegin
- } else {
- finalTimeWindowBegin = exceptBegin
- }
- newTimeWindow := commonEntity.TimeWindow{
- FaultTime: faultHappenTime,
- TimeWindowBegin: finalTimeWindowBegin,
- TimeWindowEnd: util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime),
- Length: commonConfig.PlatformConfig.TaskBeforeTime + commonConfig.PlatformConfig.TaskAfterTime + 1,
- Labels: []string{faultLabel},
- MasterTopics: masterTopics,
- SlaveTopics: slaveTopics,
- }
- c_log.GlobalLogger.Infof("不在旧故障窗口内,向生产者队列添加一个新窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", newTimeWindow.Labels, newTimeWindow.FaultTime, newTimeWindow.Length)
- commonEntity.AddTimeWindowToTimeWindowProducerQueue(newTimeWindow)
- } else { // 如果在旧故障窗口内
- commonEntity.TimeWindowProducerQueueMutex.RLock()
- defer commonEntity.TimeWindowProducerQueueMutex.RUnlock()
- // 更新故障窗口end时间
- latestEnd := util.TimeCustomChange(lastTimeWindow.TimeWindowBegin, commonConfig.PlatformConfig.TaskMaxTime) // 窗口最晚关闭时间是窗口开启时间加上最大任务时间
- expectEnd := util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime) // 窗口期望关闭时间是触发时间加上后置时间
- if util.TimeCustom1GreaterTimeCustom2(expectEnd, latestEnd) {
- lastTimeWindow.TimeWindowEnd = latestEnd
- lastTimeWindow.Length = commonConfig.PlatformConfig.TaskMaxTime
- } else {
- if util.TimeCustom1GreaterTimeCustom2(expectEnd, lastTimeWindow.TimeWindowEnd) {
- lastTimeWindow.TimeWindowEnd = expectEnd
- lastTimeWindow.Length = util.CalculateDifferenceOfTimeCustom(lastTimeWindow.TimeWindowBegin, expectEnd)
- }
- }
- // 更新label
- labels := lastTimeWindow.Labels
- lastTimeWindow.Labels = util.AppendIfNotExists(labels, faultLabel)
- // 更新 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)
- }
- }
- func getTopicsOfNode(faultLabel string) (masterTopics []string, slaveTopics []string) {
- // 获取所有需要采集的topic
- var faultCodeTopics []string
- for _, code := range commonConfig.CloudConfig.Triggers {
- if code.Label == faultLabel {
- faultCodeTopics = code.Topics
- }
- }
- // 根据不同节点采集的topic进行分配采集
- for _, acceptTopic := range faultCodeTopics {
- for _, host := range commonConfig.CloudConfig.Hosts {
- for _, topic := range host.Topics {
- if host.Name == commonConfig.CloudConfig.Hosts[0].Name && acceptTopic == topic {
- masterTopics = append(masterTopics, acceptTopic)
- }
- if host.Name == commonConfig.CloudConfig.Hosts[1].Name && acceptTopic == topic {
- slaveTopics = append(slaveTopics, acceptTopic)
- }
- }
- }
- }
- return masterTopics, slaveTopics
- }
|