produce_window.go 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  1. package service
  2. import (
  3. commonConfig "cicv-data-closedloop/aarch64/pjisuv/common/config"
  4. "cicv-data-closedloop/aarch64/pjisuv/common/service"
  5. masterConfig "cicv-data-closedloop/aarch64/pjisuv/master/config"
  6. "cicv-data-closedloop/common/config/c_log"
  7. commonEntity "cicv-data-closedloop/common/entity"
  8. "cicv-data-closedloop/common/util"
  9. "cicv-data-closedloop/pjisuv_msgs"
  10. "cicv-data-closedloop/pjisuv_param"
  11. "cicv-data-closedloop/pjisuv_ticker"
  12. "github.com/bluenviron/goroslib/v2"
  13. "github.com/bluenviron/goroslib/v2/pkg/msgs/geometry_msgs"
  14. "github.com/bluenviron/goroslib/v2/pkg/msgs/nav_msgs"
  15. "github.com/bluenviron/goroslib/v2/pkg/msgs/sensor_msgs"
  16. "github.com/bluenviron/goroslib/v2/pkg/msgs/tf2_msgs"
  17. "github.com/bluenviron/goroslib/v2/pkg/msgs/visualization_msgs"
  18. "math"
  19. "sync"
  20. "time"
  21. )
  22. // 所有共享变量
  23. var (
  24. tickChan = make(chan string)
  25. pjisuvParam = pjisuv_param.PjisuvParam{
  26. ObjDicOfTpperception: make(map[uint32][]float32),
  27. ObjTypeDicOfTpperception: make(map[uint32]uint8),
  28. ObjSpeedDicOfTpperception: make(map[uint32]float64),
  29. }
  30. shareVars = new(sync.Map)
  31. // 保存时间窗口需要锁,防止数据竟态
  32. saveTimeWindowMutex sync.Mutex
  33. // /cicv_location
  34. mutexOfCicvLocation sync.RWMutex
  35. // /tpperception
  36. mutexOfTpperception sync.RWMutex
  37. // /pj_control_pub
  38. mutexOfPjControlPub sync.RWMutex
  39. // /data_read
  40. mutexOfDataRead sync.RWMutex
  41. // /pj_vehicle_fdb_pub
  42. mutexOfCicvAmrTrajectory sync.RWMutex
  43. latestTimeWindowEnd = util.GetTimeCustom(time.Now())
  44. // 每个触发器5秒触发一次
  45. triggerInterval = 3.0
  46. )
  47. // 负责监听所有主题并修改时间窗口
  48. func ProduceWindow() {
  49. c_log.GlobalLogger.Info("订阅者 goroutine,启动。")
  50. var err error
  51. subscribers := make([]*goroslib.Subscriber, len(commonConfig.SubscribeTopics))
  52. subscribersTimes := make([]time.Time, len(commonConfig.SubscribeTopics))
  53. subscribersTimeMutexes := make([]sync.Mutex, len(commonConfig.SubscribeTopics))
  54. subscribersMutexes := make([]sync.Mutex, len(commonConfig.SubscribeTopics))
  55. for i, topic := range commonConfig.SubscribeTopics {
  56. for {
  57. // 定时器,区别于订阅者
  58. if topic == pjisuv_ticker.TickerTopic {
  59. // 1 把所有触发器函数执行一遍,触发器内部创建额外的定时任务goroutine
  60. for _, f := range masterConfig.RuleOfCicvTicker {
  61. f(shareVars)
  62. }
  63. // 2 创建goroutine接收定时任务触发器返回的Label和Time,执行触发逻辑
  64. go func() {
  65. for {
  66. time.Sleep(time.Duration(1)) // 降低循环频率
  67. select {
  68. case tickInfo := <-pjisuv_ticker.TickerChan:
  69. faultLabel := tickInfo.FaultLabel
  70. faultHappenTime := tickInfo.FaultHappenTime
  71. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  72. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  73. default:
  74. }
  75. }
  76. }()
  77. }
  78. // 其他常规监听器
  79. c_log.GlobalLogger.Info("创建订阅者订阅话题:" + topic)
  80. // 1
  81. if topic == masterConfig.TopicOfAmrPose && (len(masterConfig.RuleOfAmrPose1) > 0 || len(masterConfig.RuleOfAmrPose2) > 0 || len(masterConfig.RuleOfAmrPose3) > 0) {
  82. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  83. Node: commonConfig.RosNode,
  84. Topic: topic,
  85. Callback: func(data *visualization_msgs.MarkerArray) {
  86. subscribersTimeMutexes[i].Lock()
  87. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  88. subscribersMutexes[i].Lock()
  89. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  90. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  91. faultLabel := ""
  92. if len(masterConfig.RuleOfAmrPose1) > 0 {
  93. for _, f := range masterConfig.RuleOfAmrPose1 {
  94. faultLabel = f(data)
  95. if faultLabel != "" {
  96. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  97. subscribersTimes[i] = time.Now()
  98. goto TriggerSuccess
  99. }
  100. }
  101. }
  102. if len(masterConfig.RuleOfAmrPose2) > 0 {
  103. for _, f := range masterConfig.RuleOfAmrPose2 {
  104. faultLabel = f(data, &pjisuvParam)
  105. if faultLabel != "" {
  106. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  107. subscribersTimes[i] = time.Now()
  108. goto TriggerSuccess
  109. }
  110. }
  111. }
  112. TriggerSuccess:
  113. subscribersMutexes[i].Unlock()
  114. }
  115. subscribersTimeMutexes[i].Unlock()
  116. },
  117. })
  118. }
  119. // 2
  120. if topic == masterConfig.TopicOfBoundingBoxesFast &&
  121. (len(masterConfig.RuleOfBoundingBoxesFast1) > 0 ||
  122. len(masterConfig.RuleOfBoundingBoxesFast2) > 0 ||
  123. len(masterConfig.RuleOfBoundingBoxesFast3) > 0) {
  124. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  125. Node: commonConfig.RosNode,
  126. Topic: topic,
  127. Callback: func(data *pjisuv_msgs.BoundingBoxArray) {
  128. subscribersTimeMutexes[i].Lock()
  129. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  130. subscribersMutexes[i].Lock()
  131. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  132. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  133. faultLabel := ""
  134. if len(masterConfig.RuleOfBoundingBoxesFast1) > 0 {
  135. for _, f := range masterConfig.RuleOfBoundingBoxesFast1 {
  136. faultLabel = f(data)
  137. if faultLabel != "" {
  138. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  139. subscribersTimes[i] = time.Now()
  140. goto TriggerSuccess
  141. }
  142. }
  143. }
  144. if len(masterConfig.RuleOfBoundingBoxesFast2) > 0 {
  145. for _, f := range masterConfig.RuleOfBoundingBoxesFast2 {
  146. faultLabel = f(data, &pjisuvParam)
  147. if faultLabel != "" {
  148. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  149. subscribersTimes[i] = time.Now()
  150. goto TriggerSuccess
  151. }
  152. }
  153. }
  154. if len(masterConfig.RuleOfBoundingBoxesFast3) > 0 {
  155. for _, f := range masterConfig.RuleOfBoundingBoxesFast3 {
  156. faultLabel = f(shareVars, data)
  157. if faultLabel != "" {
  158. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  159. subscribersTimes[i] = time.Now()
  160. goto TriggerSuccess
  161. }
  162. }
  163. }
  164. TriggerSuccess:
  165. subscribersMutexes[i].Unlock()
  166. }
  167. subscribersTimeMutexes[i].Unlock()
  168. },
  169. })
  170. }
  171. // 3
  172. if topic == masterConfig.TopicOfCameraFault &&
  173. (len(masterConfig.RuleOfCameraFault1) > 0 ||
  174. len(masterConfig.RuleOfCameraFault2) > 0 ||
  175. len(masterConfig.RuleOfCameraFault3) > 0) {
  176. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  177. Node: commonConfig.RosNode,
  178. Topic: topic,
  179. Callback: func(data *pjisuv_msgs.FaultVec) {
  180. subscribersTimeMutexes[i].Lock()
  181. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  182. subscribersMutexes[i].Lock()
  183. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  184. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  185. faultLabel := ""
  186. if len(masterConfig.RuleOfCameraFault1) > 0 {
  187. for _, f := range masterConfig.RuleOfCameraFault1 {
  188. faultLabel = f(data)
  189. if faultLabel != "" {
  190. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  191. subscribersTimes[i] = time.Now()
  192. goto TriggerSuccess
  193. }
  194. }
  195. }
  196. if len(masterConfig.RuleOfCameraFault2) > 0 {
  197. for _, f := range masterConfig.RuleOfCameraFault2 {
  198. faultLabel = f(data, &pjisuvParam)
  199. if faultLabel != "" {
  200. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  201. subscribersTimes[i] = time.Now()
  202. goto TriggerSuccess
  203. }
  204. }
  205. }
  206. if len(masterConfig.RuleOfCameraFault3) > 0 {
  207. for _, f := range masterConfig.RuleOfCameraFault3 {
  208. faultLabel = f(shareVars, data)
  209. if faultLabel != "" {
  210. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  211. subscribersTimes[i] = time.Now()
  212. goto TriggerSuccess
  213. }
  214. }
  215. }
  216. TriggerSuccess:
  217. subscribersMutexes[i].Unlock()
  218. }
  219. subscribersTimeMutexes[i].Unlock()
  220. },
  221. })
  222. }
  223. // 4
  224. if topic == masterConfig.TopicOfCanData &&
  225. (len(masterConfig.RuleOfCanData1) > 0 ||
  226. len(masterConfig.RuleOfCanData2) > 0 ||
  227. len(masterConfig.RuleOfCanData3) > 0) {
  228. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  229. Node: commonConfig.RosNode,
  230. Topic: topic,
  231. Callback: func(data *pjisuv_msgs.Frame) {
  232. subscribersTimeMutexes[i].Lock()
  233. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  234. subscribersMutexes[i].Lock()
  235. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  236. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  237. faultLabel := ""
  238. if len(masterConfig.RuleOfCanData1) > 0 {
  239. for _, f := range masterConfig.RuleOfCanData1 {
  240. faultLabel = f(data)
  241. if faultLabel != "" {
  242. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  243. subscribersTimes[i] = time.Now()
  244. goto TriggerSuccess
  245. }
  246. }
  247. }
  248. if len(masterConfig.RuleOfCanData2) > 0 {
  249. for _, f := range masterConfig.RuleOfCanData2 {
  250. faultLabel = f(data, &pjisuvParam)
  251. if faultLabel != "" {
  252. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  253. subscribersTimes[i] = time.Now()
  254. goto TriggerSuccess
  255. }
  256. }
  257. }
  258. if len(masterConfig.RuleOfCanData3) > 0 {
  259. for _, f := range masterConfig.RuleOfCanData3 {
  260. faultLabel = f(shareVars, data)
  261. if faultLabel != "" {
  262. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  263. subscribersTimes[i] = time.Now()
  264. goto TriggerSuccess
  265. }
  266. }
  267. }
  268. TriggerSuccess:
  269. subscribersMutexes[i].Unlock()
  270. }
  271. subscribersTimeMutexes[i].Unlock()
  272. },
  273. })
  274. }
  275. // 5
  276. if topic == masterConfig.TopicOfCh128x1LslidarPointCloud &&
  277. (len(masterConfig.RuleOfCh128x1LslidarPointCloud1) > 0 ||
  278. len(masterConfig.RuleOfCh128x1LslidarPointCloud2) > 0 ||
  279. len(masterConfig.RuleOfCh128x1LslidarPointCloud3) > 0) {
  280. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  281. Node: commonConfig.RosNode,
  282. Topic: topic,
  283. Callback: func(data *sensor_msgs.PointCloud2) {
  284. subscribersTimeMutexes[i].Lock()
  285. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  286. subscribersMutexes[i].Lock()
  287. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  288. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  289. faultLabel := ""
  290. if len(masterConfig.RuleOfCh128x1LslidarPointCloud1) > 0 {
  291. for _, f := range masterConfig.RuleOfCh128x1LslidarPointCloud1 {
  292. faultLabel = f(data)
  293. if faultLabel != "" {
  294. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  295. subscribersTimes[i] = time.Now()
  296. goto TriggerSuccess
  297. }
  298. }
  299. }
  300. if len(masterConfig.RuleOfCh128x1LslidarPointCloud2) > 0 {
  301. for _, f := range masterConfig.RuleOfCh128x1LslidarPointCloud2 {
  302. faultLabel = f(data, &pjisuvParam)
  303. if faultLabel != "" {
  304. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  305. subscribersTimes[i] = time.Now()
  306. goto TriggerSuccess
  307. }
  308. }
  309. }
  310. if len(masterConfig.RuleOfCh128x1LslidarPointCloud3) > 0 {
  311. for _, f := range masterConfig.RuleOfCh128x1LslidarPointCloud3 {
  312. faultLabel = f(shareVars, data)
  313. if faultLabel != "" {
  314. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  315. subscribersTimes[i] = time.Now()
  316. goto TriggerSuccess
  317. }
  318. }
  319. }
  320. TriggerSuccess:
  321. subscribersMutexes[i].Unlock()
  322. }
  323. subscribersTimeMutexes[i].Unlock()
  324. },
  325. })
  326. }
  327. // 6
  328. if topic == masterConfig.TopicOfCh64wLLslidarPointCloud &&
  329. (len(masterConfig.RuleOfCh64wLLslidarPointCloud1) > 0 ||
  330. len(masterConfig.RuleOfCh64wLLslidarPointCloud2) > 0 ||
  331. len(masterConfig.RuleOfCh64wLLslidarPointCloud3) > 0) {
  332. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  333. Node: commonConfig.RosNode,
  334. Topic: topic,
  335. Callback: func(data *sensor_msgs.PointCloud2) {
  336. subscribersTimeMutexes[i].Lock()
  337. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  338. subscribersMutexes[i].Lock()
  339. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  340. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  341. faultLabel := ""
  342. if len(masterConfig.RuleOfCh64wLLslidarPointCloud1) > 0 {
  343. for _, f := range masterConfig.RuleOfCh64wLLslidarPointCloud1 {
  344. faultLabel = f(data)
  345. if faultLabel != "" {
  346. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  347. subscribersTimes[i] = time.Now()
  348. goto TriggerSuccess
  349. }
  350. }
  351. }
  352. if len(masterConfig.RuleOfCh64wLLslidarPointCloud2) > 0 {
  353. for _, f := range masterConfig.RuleOfCh64wLLslidarPointCloud2 {
  354. faultLabel = f(data, &pjisuvParam)
  355. if faultLabel != "" {
  356. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  357. subscribersTimes[i] = time.Now()
  358. goto TriggerSuccess
  359. }
  360. }
  361. }
  362. if len(masterConfig.RuleOfCh64wLLslidarPointCloud3) > 0 {
  363. for _, f := range masterConfig.RuleOfCh64wLLslidarPointCloud3 {
  364. faultLabel = f(shareVars, data)
  365. if faultLabel != "" {
  366. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  367. subscribersTimes[i] = time.Now()
  368. goto TriggerSuccess
  369. }
  370. }
  371. }
  372. TriggerSuccess:
  373. subscribersMutexes[i].Unlock()
  374. }
  375. subscribersTimeMutexes[i].Unlock()
  376. },
  377. })
  378. }
  379. // 7
  380. if topic == masterConfig.TopicOfCh64wLScan &&
  381. (len(masterConfig.RuleOfCh64wLScan1) > 0 ||
  382. len(masterConfig.RuleOfCh64wLScan2) > 0 ||
  383. len(masterConfig.RuleOfCh64wLScan3) > 0) {
  384. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  385. Node: commonConfig.RosNode,
  386. Topic: topic,
  387. Callback: func(data *sensor_msgs.LaserScan) {
  388. subscribersTimeMutexes[i].Lock()
  389. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  390. subscribersMutexes[i].Lock()
  391. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  392. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  393. faultLabel := ""
  394. if len(masterConfig.RuleOfCh64wLScan1) > 0 {
  395. for _, f := range masterConfig.RuleOfCh64wLScan1 {
  396. faultLabel = f(data)
  397. if faultLabel != "" {
  398. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  399. subscribersTimes[i] = time.Now()
  400. goto TriggerSuccess
  401. }
  402. }
  403. }
  404. if len(masterConfig.RuleOfCh64wLScan2) > 0 {
  405. for _, f := range masterConfig.RuleOfCh64wLScan2 {
  406. faultLabel = f(data, &pjisuvParam)
  407. if faultLabel != "" {
  408. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  409. subscribersTimes[i] = time.Now()
  410. goto TriggerSuccess
  411. }
  412. }
  413. }
  414. if len(masterConfig.RuleOfCh64wLScan3) > 0 {
  415. for _, f := range masterConfig.RuleOfCh64wLScan3 {
  416. faultLabel = f(shareVars, data)
  417. if faultLabel != "" {
  418. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  419. subscribersTimes[i] = time.Now()
  420. goto TriggerSuccess
  421. }
  422. }
  423. }
  424. TriggerSuccess:
  425. subscribersMutexes[i].Unlock()
  426. }
  427. subscribersTimeMutexes[i].Unlock()
  428. },
  429. })
  430. }
  431. // 8
  432. if topic == masterConfig.TopicOfCh64wRLslidarPointCloud &&
  433. (len(masterConfig.RuleOfCh64wRLslidarPointCloud1) > 0 ||
  434. len(masterConfig.RuleOfCh64wRLslidarPointCloud2) > 0 ||
  435. len(masterConfig.RuleOfCh64wRLslidarPointCloud3) > 0) {
  436. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  437. Node: commonConfig.RosNode,
  438. Topic: topic,
  439. Callback: func(data *sensor_msgs.PointCloud2) {
  440. subscribersTimeMutexes[i].Lock()
  441. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  442. subscribersMutexes[i].Lock()
  443. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  444. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  445. faultLabel := ""
  446. if len(masterConfig.RuleOfCh64wRLslidarPointCloud1) > 0 {
  447. for _, f := range masterConfig.RuleOfCh64wRLslidarPointCloud1 {
  448. faultLabel = f(data)
  449. if faultLabel != "" {
  450. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  451. subscribersTimes[i] = time.Now()
  452. goto TriggerSuccess
  453. }
  454. }
  455. }
  456. if len(masterConfig.RuleOfCh64wRLslidarPointCloud2) > 0 {
  457. for _, f := range masterConfig.RuleOfCh64wRLslidarPointCloud2 {
  458. faultLabel = f(data, &pjisuvParam)
  459. if faultLabel != "" {
  460. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  461. subscribersTimes[i] = time.Now()
  462. goto TriggerSuccess
  463. }
  464. }
  465. }
  466. if len(masterConfig.RuleOfCh64wRLslidarPointCloud3) > 0 {
  467. for _, f := range masterConfig.RuleOfCh64wRLslidarPointCloud3 {
  468. faultLabel = f(shareVars, data)
  469. if faultLabel != "" {
  470. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  471. subscribersTimes[i] = time.Now()
  472. goto TriggerSuccess
  473. }
  474. }
  475. }
  476. TriggerSuccess:
  477. subscribersMutexes[i].Unlock()
  478. }
  479. subscribersTimeMutexes[i].Unlock()
  480. },
  481. })
  482. }
  483. // 9
  484. if topic == masterConfig.TopicOfCh64wRScan &&
  485. (len(masterConfig.RuleOfCh64wRScan1) > 0 ||
  486. len(masterConfig.RuleOfCh64wRScan2) > 0 ||
  487. len(masterConfig.RuleOfCh64wRScan3) > 0) {
  488. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  489. Node: commonConfig.RosNode,
  490. Topic: topic,
  491. Callback: func(data *sensor_msgs.LaserScan) {
  492. subscribersTimeMutexes[i].Lock()
  493. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  494. subscribersMutexes[i].Lock()
  495. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  496. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  497. faultLabel := ""
  498. if len(masterConfig.RuleOfCh64wRScan1) > 0 {
  499. for _, f := range masterConfig.RuleOfCh64wRScan1 {
  500. faultLabel = f(data)
  501. if faultLabel != "" {
  502. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  503. subscribersTimes[i] = time.Now()
  504. goto TriggerSuccess
  505. }
  506. }
  507. }
  508. if len(masterConfig.RuleOfCh64wRScan2) > 0 {
  509. for _, f := range masterConfig.RuleOfCh64wRScan2 {
  510. faultLabel = f(data, &pjisuvParam)
  511. if faultLabel != "" {
  512. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  513. subscribersTimes[i] = time.Now()
  514. goto TriggerSuccess
  515. }
  516. }
  517. }
  518. if len(masterConfig.RuleOfCh64wRScan3) > 0 {
  519. for _, f := range masterConfig.RuleOfCh64wRScan3 {
  520. faultLabel = f(shareVars, data)
  521. if faultLabel != "" {
  522. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  523. subscribersTimes[i] = time.Now()
  524. goto TriggerSuccess
  525. }
  526. }
  527. }
  528. TriggerSuccess:
  529. subscribersMutexes[i].Unlock()
  530. }
  531. subscribersTimeMutexes[i].Unlock()
  532. },
  533. })
  534. }
  535. // 10
  536. if topic == masterConfig.TopicOfCicvLidarclusterMovingObjects &&
  537. (len(masterConfig.RuleOfCicvLidarclusterMovingObjects1) > 0 ||
  538. len(masterConfig.RuleOfCicvLidarclusterMovingObjects2) > 0 ||
  539. len(masterConfig.RuleOfCicvLidarclusterMovingObjects3) > 0) {
  540. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  541. Node: commonConfig.RosNode,
  542. Topic: topic,
  543. Callback: func(data *pjisuv_msgs.PerceptionCicvMovingObjects) {
  544. subscribersTimeMutexes[i].Lock()
  545. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  546. subscribersMutexes[i].Lock()
  547. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  548. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  549. faultLabel := ""
  550. if len(masterConfig.RuleOfCicvLidarclusterMovingObjects1) > 0 {
  551. for _, f := range masterConfig.RuleOfCicvLidarclusterMovingObjects1 {
  552. faultLabel = f(data)
  553. if faultLabel != "" {
  554. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  555. subscribersTimes[i] = time.Now()
  556. goto TriggerSuccess
  557. }
  558. }
  559. }
  560. if len(masterConfig.RuleOfCicvLidarclusterMovingObjects2) > 0 {
  561. for _, f := range masterConfig.RuleOfCicvLidarclusterMovingObjects2 {
  562. faultLabel = f(data, &pjisuvParam)
  563. if faultLabel != "" {
  564. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  565. subscribersTimes[i] = time.Now()
  566. goto TriggerSuccess
  567. }
  568. }
  569. }
  570. if len(masterConfig.RuleOfCicvLidarclusterMovingObjects3) > 0 {
  571. for _, f := range masterConfig.RuleOfCicvLidarclusterMovingObjects3 {
  572. faultLabel = f(shareVars, data)
  573. if faultLabel != "" {
  574. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  575. subscribersTimes[i] = time.Now()
  576. goto TriggerSuccess
  577. }
  578. }
  579. }
  580. TriggerSuccess:
  581. subscribersMutexes[i].Unlock()
  582. }
  583. subscribersTimeMutexes[i].Unlock()
  584. },
  585. })
  586. }
  587. // 11 有共享变量的订阅者必须被创建
  588. if topic == masterConfig.TopicOfCicvAmrTrajectory {
  589. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  590. Node: commonConfig.RosNode,
  591. Topic: topic,
  592. Callback: func(data *pjisuv_msgs.Trajectory) {
  593. subscribersTimeMutexes[i].Lock()
  594. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  595. subscribersMutexes[i].Lock()
  596. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  597. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  598. faultLabel := ""
  599. if len(masterConfig.RuleOfCicvAmrTrajectory1) > 0 {
  600. for _, f := range masterConfig.RuleOfCicvAmrTrajectory1 {
  601. faultLabel = f(data)
  602. if faultLabel != "" {
  603. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  604. subscribersTimes[i] = time.Now()
  605. goto TriggerSuccess
  606. }
  607. }
  608. }
  609. if len(masterConfig.RuleOfCicvAmrTrajectory2) > 0 {
  610. for _, f := range masterConfig.RuleOfCicvAmrTrajectory2 {
  611. faultLabel = f(data, &pjisuvParam)
  612. if faultLabel != "" {
  613. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  614. subscribersTimes[i] = time.Now()
  615. goto TriggerSuccess
  616. }
  617. }
  618. }
  619. if len(masterConfig.RuleOfCicvAmrTrajectory3) > 0 {
  620. for _, f := range masterConfig.RuleOfCicvAmrTrajectory3 {
  621. faultLabel = f(shareVars, data)
  622. if faultLabel != "" {
  623. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  624. subscribersTimes[i] = time.Now()
  625. goto TriggerSuccess
  626. }
  627. }
  628. }
  629. TriggerSuccess:
  630. subscribersMutexes[i].Unlock()
  631. }
  632. subscribersTimeMutexes[i].Unlock()
  633. // 触发后更新共享变量
  634. mutexOfCicvAmrTrajectory.RLock()
  635. {
  636. var currentCurvateres []float64
  637. for _, point := range data.Trajectoryinfo.Trajectorypoints {
  638. currentCurvateres = append(currentCurvateres, math.Abs(float64(point.Curvature)))
  639. }
  640. pjisuvParam.LastCurvaturesOfCicvAmrTrajectory = currentCurvateres
  641. pjisuvParam.DecisionType = data.Trajectoryinfo.DecisionType
  642. }
  643. mutexOfCicvAmrTrajectory.RUnlock()
  644. },
  645. })
  646. }
  647. // 12 有共享变量的订阅者必须被创建
  648. if topic == masterConfig.TopicOfCicvLocation {
  649. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  650. Node: commonConfig.RosNode,
  651. Topic: topic,
  652. Callback: func(data *pjisuv_msgs.PerceptionLocalization) {
  653. subscribersTimeMutexes[i].Lock()
  654. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  655. subscribersMutexes[i].Lock()
  656. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  657. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  658. faultLabel := ""
  659. if len(masterConfig.RuleOfCicvLocation1) > 0 {
  660. for _, f := range masterConfig.RuleOfCicvLocation1 {
  661. faultLabel = f(data)
  662. if faultLabel != "" {
  663. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  664. subscribersTimes[i] = time.Now()
  665. goto TriggerSuccess
  666. }
  667. }
  668. }
  669. if len(masterConfig.RuleOfCicvLocation2) > 0 {
  670. for _, f := range masterConfig.RuleOfCicvLocation2 {
  671. faultLabel = f(data, &pjisuvParam)
  672. if faultLabel != "" {
  673. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  674. subscribersTimes[i] = time.Now()
  675. goto TriggerSuccess
  676. }
  677. }
  678. }
  679. if len(masterConfig.RuleOfCicvLocation3) > 0 {
  680. for _, f := range masterConfig.RuleOfCicvLocation3 {
  681. faultLabel = f(shareVars, data)
  682. if faultLabel != "" {
  683. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  684. subscribersTimes[i] = time.Now()
  685. goto TriggerSuccess
  686. }
  687. }
  688. }
  689. TriggerSuccess:
  690. subscribersMutexes[i].Unlock()
  691. }
  692. subscribersTimeMutexes[i].Unlock()
  693. // 更新共享变量
  694. shareVars.Store("VelocityXOfCicvLocation", data.VelocityX)
  695. shareVars.Store("VelocityYOfCicvLocation", data.VelocityY)
  696. shareVars.Store("VelocityZOfCicvLocation", data.VelocityZ)
  697. shareVars.Store("YawOfCicvLocation", data.Yaw)
  698. shareVars.Store("AngularVelocityZOfCicvLocation", data.AngularVelocityZ)
  699. shareVars.Store("PositionXOfCicvLocation", data.PositionX)
  700. shareVars.Store("PositionYOfCicvLocation", data.PositionY)
  701. },
  702. })
  703. }
  704. // 13
  705. if topic == masterConfig.TopicOfCloudClusters &&
  706. (len(masterConfig.RuleOfCloudClusters1) > 0 ||
  707. len(masterConfig.RuleOfCloudClusters2) > 0 ||
  708. len(masterConfig.RuleOfCloudClusters3) > 0) {
  709. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  710. Node: commonConfig.RosNode,
  711. Topic: topic,
  712. Callback: func(data *pjisuv_msgs.AutowareCloudClusterArray) {
  713. subscribersTimeMutexes[i].Lock()
  714. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  715. subscribersMutexes[i].Lock()
  716. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  717. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  718. faultLabel := ""
  719. if len(masterConfig.RuleOfCloudClusters1) > 0 {
  720. for _, f := range masterConfig.RuleOfCloudClusters1 {
  721. faultLabel = f(data)
  722. if faultLabel != "" {
  723. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  724. subscribersTimes[i] = time.Now()
  725. goto TriggerSuccess
  726. }
  727. }
  728. }
  729. if len(masterConfig.RuleOfCloudClusters2) > 0 {
  730. for _, f := range masterConfig.RuleOfCloudClusters2 {
  731. faultLabel = f(data, &pjisuvParam)
  732. if faultLabel != "" {
  733. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  734. subscribersTimes[i] = time.Now()
  735. goto TriggerSuccess
  736. }
  737. }
  738. }
  739. if len(masterConfig.RuleOfCloudClusters3) > 0 {
  740. for _, f := range masterConfig.RuleOfCloudClusters3 {
  741. faultLabel = f(shareVars, data)
  742. if faultLabel != "" {
  743. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  744. subscribersTimes[i] = time.Now()
  745. goto TriggerSuccess
  746. }
  747. }
  748. }
  749. TriggerSuccess:
  750. subscribersMutexes[i].Unlock()
  751. }
  752. subscribersTimeMutexes[i].Unlock()
  753. },
  754. })
  755. }
  756. // 14
  757. if topic == masterConfig.TopicOfHeartbeatInfo &&
  758. (len(masterConfig.RuleOfHeartbeatInfo1) > 0 ||
  759. len(masterConfig.RuleOfHeartbeatInfo2) > 0 ||
  760. len(masterConfig.RuleOfHeartbeatInfo3) > 0) {
  761. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  762. Node: commonConfig.RosNode,
  763. Topic: topic,
  764. Callback: func(data *pjisuv_msgs.HeartBeatInfo) {
  765. subscribersTimeMutexes[i].Lock()
  766. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  767. subscribersMutexes[i].Lock()
  768. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  769. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  770. faultLabel := ""
  771. if len(masterConfig.RuleOfHeartbeatInfo1) > 0 {
  772. for _, f := range masterConfig.RuleOfHeartbeatInfo1 {
  773. faultLabel = f(data)
  774. if faultLabel != "" {
  775. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  776. subscribersTimes[i] = time.Now()
  777. goto TriggerSuccess
  778. }
  779. }
  780. }
  781. if len(masterConfig.RuleOfHeartbeatInfo2) > 0 {
  782. for _, f := range masterConfig.RuleOfHeartbeatInfo2 {
  783. faultLabel = f(data, &pjisuvParam)
  784. if faultLabel != "" {
  785. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  786. subscribersTimes[i] = time.Now()
  787. goto TriggerSuccess
  788. }
  789. }
  790. }
  791. if len(masterConfig.RuleOfHeartbeatInfo3) > 0 {
  792. for _, f := range masterConfig.RuleOfHeartbeatInfo3 {
  793. faultLabel = f(shareVars, data)
  794. if faultLabel != "" {
  795. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  796. subscribersTimes[i] = time.Now()
  797. goto TriggerSuccess
  798. }
  799. }
  800. }
  801. TriggerSuccess:
  802. subscribersMutexes[i].Unlock()
  803. }
  804. subscribersTimeMutexes[i].Unlock()
  805. },
  806. })
  807. }
  808. // 15
  809. if topic == masterConfig.TopicOfLidarPretreatmentCost &&
  810. (len(masterConfig.RuleOfLidarPretreatmentCost1) > 0 ||
  811. len(masterConfig.RuleOfLidarPretreatmentCost2) > 0 ||
  812. len(masterConfig.RuleOfLidarPretreatmentCost3) > 0) {
  813. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  814. Node: commonConfig.RosNode,
  815. Topic: topic,
  816. Callback: func(data *geometry_msgs.Vector3Stamped) {
  817. subscribersTimeMutexes[i].Lock()
  818. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  819. subscribersMutexes[i].Lock()
  820. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  821. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  822. faultLabel := ""
  823. if len(masterConfig.RuleOfLidarPretreatmentCost1) > 0 {
  824. for _, f := range masterConfig.RuleOfLidarPretreatmentCost1 {
  825. faultLabel = f(data)
  826. if faultLabel != "" {
  827. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  828. subscribersTimes[i] = time.Now()
  829. goto TriggerSuccess
  830. }
  831. }
  832. }
  833. if len(masterConfig.RuleOfLidarPretreatmentCost2) > 0 {
  834. for _, f := range masterConfig.RuleOfLidarPretreatmentCost2 {
  835. faultLabel = f(data, &pjisuvParam)
  836. if faultLabel != "" {
  837. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  838. subscribersTimes[i] = time.Now()
  839. goto TriggerSuccess
  840. }
  841. }
  842. }
  843. if len(masterConfig.RuleOfLidarPretreatmentCost3) > 0 {
  844. for _, f := range masterConfig.RuleOfLidarPretreatmentCost3 {
  845. faultLabel = f(shareVars, data)
  846. if faultLabel != "" {
  847. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  848. subscribersTimes[i] = time.Now()
  849. goto TriggerSuccess
  850. }
  851. }
  852. }
  853. TriggerSuccess:
  854. subscribersMutexes[i].Unlock()
  855. }
  856. subscribersTimeMutexes[i].Unlock()
  857. },
  858. })
  859. }
  860. // 16
  861. if topic == masterConfig.TopicOfLidarPretreatmentOdometry &&
  862. (len(masterConfig.RuleOfLidarPretreatmentOdometry1) > 0 ||
  863. len(masterConfig.RuleOfLidarPretreatmentOdometry2) > 0 ||
  864. len(masterConfig.RuleOfLidarPretreatmentOdometry3) > 0) {
  865. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  866. Node: commonConfig.RosNode,
  867. Topic: topic,
  868. Callback: func(data *nav_msgs.Odometry) {
  869. subscribersTimeMutexes[i].Lock()
  870. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  871. subscribersMutexes[i].Lock()
  872. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  873. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  874. faultLabel := ""
  875. if len(masterConfig.RuleOfLidarPretreatmentOdometry1) > 0 {
  876. for _, f := range masterConfig.RuleOfLidarPretreatmentOdometry1 {
  877. faultLabel = f(data)
  878. if faultLabel != "" {
  879. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  880. subscribersTimes[i] = time.Now()
  881. goto TriggerSuccess
  882. }
  883. }
  884. }
  885. if len(masterConfig.RuleOfLidarPretreatmentOdometry2) > 0 {
  886. for _, f := range masterConfig.RuleOfLidarPretreatmentOdometry2 {
  887. faultLabel = f(data, &pjisuvParam)
  888. if faultLabel != "" {
  889. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  890. subscribersTimes[i] = time.Now()
  891. goto TriggerSuccess
  892. }
  893. }
  894. }
  895. if len(masterConfig.RuleOfLidarPretreatmentOdometry3) > 0 {
  896. for _, f := range masterConfig.RuleOfLidarPretreatmentOdometry3 {
  897. faultLabel = f(shareVars, data)
  898. if faultLabel != "" {
  899. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  900. subscribersTimes[i] = time.Now()
  901. goto TriggerSuccess
  902. }
  903. }
  904. }
  905. TriggerSuccess:
  906. subscribersMutexes[i].Unlock()
  907. }
  908. subscribersTimeMutexes[i].Unlock()
  909. },
  910. })
  911. }
  912. // 17
  913. if topic == masterConfig.TopicOfLidarRoi &&
  914. (len(masterConfig.RuleOfLidarRoi1) > 0 ||
  915. len(masterConfig.RuleOfLidarRoi2) > 0 ||
  916. len(masterConfig.RuleOfLidarRoi3) > 0) {
  917. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  918. Node: commonConfig.RosNode,
  919. Topic: topic,
  920. Callback: func(data *geometry_msgs.PolygonStamped) {
  921. subscribersTimeMutexes[i].Lock()
  922. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  923. subscribersMutexes[i].Lock()
  924. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  925. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  926. faultLabel := ""
  927. if len(masterConfig.RuleOfLidarRoi1) > 0 {
  928. for _, f := range masterConfig.RuleOfLidarRoi1 {
  929. faultLabel = f(data)
  930. if faultLabel != "" {
  931. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  932. subscribersTimes[i] = time.Now()
  933. goto TriggerSuccess
  934. }
  935. }
  936. }
  937. if len(masterConfig.RuleOfLidarRoi2) > 0 {
  938. for _, f := range masterConfig.RuleOfLidarRoi2 {
  939. faultLabel = f(data, &pjisuvParam)
  940. if faultLabel != "" {
  941. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  942. subscribersTimes[i] = time.Now()
  943. goto TriggerSuccess
  944. }
  945. }
  946. }
  947. if len(masterConfig.RuleOfLidarRoi3) > 0 {
  948. for _, f := range masterConfig.RuleOfLidarRoi3 {
  949. faultLabel = f(shareVars, data)
  950. if faultLabel != "" {
  951. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  952. subscribersTimes[i] = time.Now()
  953. goto TriggerSuccess
  954. }
  955. }
  956. }
  957. TriggerSuccess:
  958. subscribersMutexes[i].Unlock()
  959. }
  960. subscribersTimeMutexes[i].Unlock()
  961. },
  962. })
  963. }
  964. // 18
  965. if topic == masterConfig.TopicOfLine1 &&
  966. (len(masterConfig.RuleOfLine11) > 0 ||
  967. len(masterConfig.RuleOfLine12) > 0 ||
  968. len(masterConfig.RuleOfLine13) > 0) {
  969. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  970. Node: commonConfig.RosNode,
  971. Topic: topic,
  972. Callback: func(data *nav_msgs.Path) {
  973. subscribersTimeMutexes[i].Lock()
  974. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  975. subscribersMutexes[i].Lock()
  976. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  977. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  978. faultLabel := ""
  979. if len(masterConfig.RuleOfLine11) > 0 {
  980. for _, f := range masterConfig.RuleOfLine11 {
  981. faultLabel = f(data)
  982. if faultLabel != "" {
  983. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  984. subscribersTimes[i] = time.Now()
  985. goto TriggerSuccess
  986. }
  987. }
  988. }
  989. if len(masterConfig.RuleOfLine12) > 0 {
  990. for _, f := range masterConfig.RuleOfLine12 {
  991. faultLabel = f(data, &pjisuvParam)
  992. if faultLabel != "" {
  993. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  994. subscribersTimes[i] = time.Now()
  995. goto TriggerSuccess
  996. }
  997. }
  998. }
  999. if len(masterConfig.RuleOfLine13) > 0 {
  1000. for _, f := range masterConfig.RuleOfLine13 {
  1001. faultLabel = f(shareVars, data)
  1002. if faultLabel != "" {
  1003. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1004. subscribersTimes[i] = time.Now()
  1005. goto TriggerSuccess
  1006. }
  1007. }
  1008. }
  1009. TriggerSuccess:
  1010. subscribersMutexes[i].Unlock()
  1011. }
  1012. subscribersTimeMutexes[i].Unlock()
  1013. },
  1014. })
  1015. }
  1016. // 19
  1017. if topic == masterConfig.TopicOfLine2 &&
  1018. (len(masterConfig.RuleOfLine21) > 0 ||
  1019. len(masterConfig.RuleOfLine22) > 0 ||
  1020. len(masterConfig.RuleOfLine23) > 0) {
  1021. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1022. Node: commonConfig.RosNode,
  1023. Topic: topic,
  1024. Callback: func(data *nav_msgs.Path) {
  1025. subscribersTimeMutexes[i].Lock()
  1026. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1027. subscribersMutexes[i].Lock()
  1028. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1029. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1030. faultLabel := ""
  1031. if len(masterConfig.RuleOfLine21) > 0 {
  1032. for _, f := range masterConfig.RuleOfLine21 {
  1033. faultLabel = f(data)
  1034. if faultLabel != "" {
  1035. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1036. subscribersTimes[i] = time.Now()
  1037. goto TriggerSuccess
  1038. }
  1039. }
  1040. }
  1041. if len(masterConfig.RuleOfLine22) > 0 {
  1042. for _, f := range masterConfig.RuleOfLine22 {
  1043. faultLabel = f(data, &pjisuvParam)
  1044. if faultLabel != "" {
  1045. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1046. subscribersTimes[i] = time.Now()
  1047. goto TriggerSuccess
  1048. }
  1049. }
  1050. }
  1051. if len(masterConfig.RuleOfLine23) > 0 {
  1052. for _, f := range masterConfig.RuleOfLine23 {
  1053. faultLabel = f(shareVars, data)
  1054. if faultLabel != "" {
  1055. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1056. subscribersTimes[i] = time.Now()
  1057. goto TriggerSuccess
  1058. }
  1059. }
  1060. }
  1061. TriggerSuccess:
  1062. subscribersMutexes[i].Unlock()
  1063. }
  1064. subscribersTimeMutexes[i].Unlock()
  1065. },
  1066. })
  1067. }
  1068. // 20
  1069. if topic == masterConfig.TopicOfMapPolygon &&
  1070. (len(masterConfig.RuleOfMapPolygon1) > 0 ||
  1071. len(masterConfig.RuleOfMapPolygon2) > 0 ||
  1072. len(masterConfig.RuleOfMapPolygon3) > 0) {
  1073. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1074. Node: commonConfig.RosNode,
  1075. Topic: topic,
  1076. Callback: func(data *pjisuv_msgs.PolygonStamped) {
  1077. subscribersTimeMutexes[i].Lock()
  1078. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1079. subscribersMutexes[i].Lock()
  1080. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1081. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1082. faultLabel := ""
  1083. if len(masterConfig.RuleOfMapPolygon1) > 0 {
  1084. for _, f := range masterConfig.RuleOfMapPolygon1 {
  1085. faultLabel = f(data)
  1086. if faultLabel != "" {
  1087. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1088. subscribersTimes[i] = time.Now()
  1089. goto TriggerSuccess
  1090. }
  1091. }
  1092. }
  1093. if len(masterConfig.RuleOfMapPolygon2) > 0 {
  1094. for _, f := range masterConfig.RuleOfMapPolygon2 {
  1095. faultLabel = f(data, &pjisuvParam)
  1096. if faultLabel != "" {
  1097. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1098. subscribersTimes[i] = time.Now()
  1099. goto TriggerSuccess
  1100. }
  1101. }
  1102. }
  1103. if len(masterConfig.RuleOfMapPolygon3) > 0 {
  1104. for _, f := range masterConfig.RuleOfMapPolygon3 {
  1105. faultLabel = f(shareVars, data)
  1106. if faultLabel != "" {
  1107. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1108. subscribersTimes[i] = time.Now()
  1109. goto TriggerSuccess
  1110. }
  1111. }
  1112. }
  1113. TriggerSuccess:
  1114. subscribersMutexes[i].Unlock()
  1115. }
  1116. subscribersTimeMutexes[i].Unlock()
  1117. },
  1118. })
  1119. }
  1120. // 21
  1121. if topic == masterConfig.TopicOfObstacleDisplay &&
  1122. (len(masterConfig.RuleOfObstacleDisplay1) > 0 ||
  1123. len(masterConfig.RuleOfObstacleDisplay2) > 0 ||
  1124. len(masterConfig.RuleOfObstacleDisplay3) > 0) {
  1125. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1126. Node: commonConfig.RosNode,
  1127. Topic: topic,
  1128. Callback: func(data *visualization_msgs.MarkerArray) {
  1129. subscribersTimeMutexes[i].Lock()
  1130. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1131. subscribersMutexes[i].Lock()
  1132. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1133. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1134. faultLabel := ""
  1135. if len(masterConfig.RuleOfObstacleDisplay1) > 0 {
  1136. for _, f := range masterConfig.RuleOfObstacleDisplay1 {
  1137. faultLabel = f(data)
  1138. if faultLabel != "" {
  1139. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1140. subscribersTimes[i] = time.Now()
  1141. goto TriggerSuccess
  1142. }
  1143. }
  1144. }
  1145. if len(masterConfig.RuleOfObstacleDisplay2) > 0 {
  1146. for _, f := range masterConfig.RuleOfObstacleDisplay2 {
  1147. faultLabel = f(data, &pjisuvParam)
  1148. if faultLabel != "" {
  1149. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1150. subscribersTimes[i] = time.Now()
  1151. goto TriggerSuccess
  1152. }
  1153. }
  1154. }
  1155. if len(masterConfig.RuleOfObstacleDisplay3) > 0 {
  1156. for _, f := range masterConfig.RuleOfObstacleDisplay3 {
  1157. faultLabel = f(shareVars, data)
  1158. if faultLabel != "" {
  1159. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1160. subscribersTimes[i] = time.Now()
  1161. goto TriggerSuccess
  1162. }
  1163. }
  1164. }
  1165. TriggerSuccess:
  1166. subscribersMutexes[i].Unlock()
  1167. }
  1168. subscribersTimeMutexes[i].Unlock()
  1169. },
  1170. })
  1171. }
  1172. // 22 有共享变量的订阅者必须被创建
  1173. if topic == masterConfig.TopicOfPjControlPub {
  1174. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1175. Node: commonConfig.RosNode,
  1176. Topic: topic,
  1177. Callback: func(data *pjisuv_msgs.CommonVehicleCmd) {
  1178. subscribersTimeMutexes[i].Lock()
  1179. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1180. subscribersMutexes[i].Lock()
  1181. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1182. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1183. faultLabel := ""
  1184. if len(masterConfig.RuleOfPjControlPub1) > 0 {
  1185. for _, f := range masterConfig.RuleOfPjControlPub1 {
  1186. faultLabel = f(data)
  1187. if faultLabel != "" {
  1188. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1189. subscribersTimes[i] = time.Now()
  1190. goto TriggerSuccess
  1191. }
  1192. }
  1193. }
  1194. if len(masterConfig.RuleOfPjControlPub2) > 0 {
  1195. for _, f := range masterConfig.RuleOfPjControlPub2 {
  1196. faultLabel = f(data, &pjisuvParam)
  1197. if faultLabel != "" {
  1198. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1199. subscribersTimes[i] = time.Now()
  1200. goto TriggerSuccess
  1201. }
  1202. }
  1203. }
  1204. if len(masterConfig.RuleOfPjControlPub3) > 0 {
  1205. for _, f := range masterConfig.RuleOfPjControlPub3 {
  1206. faultLabel = f(shareVars, data)
  1207. if faultLabel != "" {
  1208. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1209. subscribersTimes[i] = time.Now()
  1210. goto TriggerSuccess
  1211. }
  1212. }
  1213. }
  1214. TriggerSuccess:
  1215. subscribersMutexes[i].Unlock()
  1216. }
  1217. subscribersTimeMutexes[i].Unlock()
  1218. // 更新共享变量
  1219. mutexOfPjControlPub.RLock()
  1220. {
  1221. pjisuvParam.NumCountPjiControlCommandOfPjControlPub++
  1222. if pjisuvParam.NumCountPjiControlCommandOfPjControlPub == 10 {
  1223. pjisuvParam.EgoSteeringCmdOfPjControlPub = append(pjisuvParam.EgoSteeringCmdOfPjControlPub, data.ICPVCmdStrAngle)
  1224. pjisuvParam.EgoThrottleCmdOfPjControlPub = append(pjisuvParam.EgoThrottleCmdOfPjControlPub, data.ICPVCmdAccPelPosAct)
  1225. pjisuvParam.NumCountPjiControlCommandOfPjControlPub = 0
  1226. }
  1227. }
  1228. mutexOfPjControlPub.RUnlock()
  1229. },
  1230. })
  1231. }
  1232. // 23
  1233. if topic == masterConfig.TopicOfPointsCluster &&
  1234. (len(masterConfig.RuleOfPointsCluster1) > 0 ||
  1235. len(masterConfig.RuleOfPointsCluster2) > 0 ||
  1236. len(masterConfig.RuleOfPointsCluster3) > 0) {
  1237. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1238. Node: commonConfig.RosNode,
  1239. Topic: topic,
  1240. Callback: func(data *sensor_msgs.PointCloud2) {
  1241. subscribersTimeMutexes[i].Lock()
  1242. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1243. subscribersMutexes[i].Lock()
  1244. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1245. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1246. faultLabel := ""
  1247. if len(masterConfig.RuleOfPointsCluster1) > 0 {
  1248. for _, f := range masterConfig.RuleOfPointsCluster1 {
  1249. faultLabel = f(data)
  1250. if faultLabel != "" {
  1251. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1252. subscribersTimes[i] = time.Now()
  1253. goto TriggerSuccess
  1254. }
  1255. }
  1256. }
  1257. if len(masterConfig.RuleOfPointsCluster2) > 0 {
  1258. for _, f := range masterConfig.RuleOfPointsCluster2 {
  1259. faultLabel = f(data, &pjisuvParam)
  1260. if faultLabel != "" {
  1261. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1262. subscribersTimes[i] = time.Now()
  1263. goto TriggerSuccess
  1264. }
  1265. }
  1266. }
  1267. if len(masterConfig.RuleOfPointsCluster3) > 0 {
  1268. for _, f := range masterConfig.RuleOfPointsCluster3 {
  1269. faultLabel = f(shareVars, data)
  1270. if faultLabel != "" {
  1271. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1272. subscribersTimes[i] = time.Now()
  1273. goto TriggerSuccess
  1274. }
  1275. }
  1276. }
  1277. TriggerSuccess:
  1278. subscribersMutexes[i].Unlock()
  1279. }
  1280. subscribersTimeMutexes[i].Unlock()
  1281. },
  1282. })
  1283. }
  1284. // 24
  1285. if topic == masterConfig.TopicOfPointsConcat &&
  1286. (len(masterConfig.RuleOfPointsConcat1) > 0 ||
  1287. len(masterConfig.RuleOfPointsConcat2) > 0 ||
  1288. len(masterConfig.RuleOfPointsConcat3) > 0) {
  1289. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1290. Node: commonConfig.RosNode,
  1291. Topic: topic,
  1292. Callback: func(data *sensor_msgs.PointCloud2) {
  1293. subscribersTimeMutexes[i].Lock()
  1294. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1295. subscribersMutexes[i].Lock()
  1296. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1297. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1298. faultLabel := ""
  1299. if len(masterConfig.RuleOfPointsConcat1) > 0 {
  1300. for _, f := range masterConfig.RuleOfPointsConcat1 {
  1301. faultLabel = f(data)
  1302. if faultLabel != "" {
  1303. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1304. subscribersTimes[i] = time.Now()
  1305. goto TriggerSuccess
  1306. }
  1307. }
  1308. }
  1309. if len(masterConfig.RuleOfPointsConcat2) > 0 {
  1310. for _, f := range masterConfig.RuleOfPointsConcat2 {
  1311. faultLabel = f(data, &pjisuvParam)
  1312. if faultLabel != "" {
  1313. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1314. subscribersTimes[i] = time.Now()
  1315. goto TriggerSuccess
  1316. }
  1317. }
  1318. }
  1319. if len(masterConfig.RuleOfPointsConcat3) > 0 {
  1320. for _, f := range masterConfig.RuleOfPointsConcat3 {
  1321. faultLabel = f(shareVars, data)
  1322. if faultLabel != "" {
  1323. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1324. subscribersTimes[i] = time.Now()
  1325. goto TriggerSuccess
  1326. }
  1327. }
  1328. }
  1329. TriggerSuccess:
  1330. subscribersMutexes[i].Unlock()
  1331. }
  1332. subscribersTimeMutexes[i].Unlock()
  1333. },
  1334. })
  1335. }
  1336. // 25
  1337. if topic == masterConfig.TopicOfReferenceDisplay &&
  1338. (len(masterConfig.RuleOfReferenceDisplay1) > 0 ||
  1339. len(masterConfig.RuleOfReferenceDisplay2) > 0 ||
  1340. len(masterConfig.RuleOfReferenceDisplay3) > 0) {
  1341. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1342. Node: commonConfig.RosNode,
  1343. Topic: topic,
  1344. Callback: func(data *nav_msgs.Path) {
  1345. subscribersTimeMutexes[i].Lock()
  1346. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1347. subscribersMutexes[i].Lock()
  1348. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1349. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1350. faultLabel := ""
  1351. if len(masterConfig.RuleOfReferenceDisplay1) > 0 {
  1352. for _, f := range masterConfig.RuleOfReferenceDisplay1 {
  1353. faultLabel = f(data)
  1354. if faultLabel != "" {
  1355. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1356. subscribersTimes[i] = time.Now()
  1357. goto TriggerSuccess
  1358. }
  1359. }
  1360. }
  1361. if len(masterConfig.RuleOfReferenceDisplay2) > 0 {
  1362. for _, f := range masterConfig.RuleOfReferenceDisplay2 {
  1363. faultLabel = f(data, &pjisuvParam)
  1364. if faultLabel != "" {
  1365. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1366. subscribersTimes[i] = time.Now()
  1367. goto TriggerSuccess
  1368. }
  1369. }
  1370. }
  1371. if len(masterConfig.RuleOfReferenceDisplay3) > 0 {
  1372. for _, f := range masterConfig.RuleOfReferenceDisplay3 {
  1373. faultLabel = f(shareVars, data)
  1374. if faultLabel != "" {
  1375. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1376. subscribersTimes[i] = time.Now()
  1377. goto TriggerSuccess
  1378. }
  1379. }
  1380. }
  1381. TriggerSuccess:
  1382. subscribersMutexes[i].Unlock()
  1383. }
  1384. subscribersTimeMutexes[i].Unlock()
  1385. },
  1386. })
  1387. }
  1388. // 26
  1389. if topic == masterConfig.TopicOfReferenceTrajectory &&
  1390. (len(masterConfig.RuleOfReferenceTrajectory1) > 0 ||
  1391. len(masterConfig.RuleOfReferenceTrajectory2) > 0 ||
  1392. len(masterConfig.RuleOfReferenceTrajectory3) > 0) {
  1393. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1394. Node: commonConfig.RosNode,
  1395. Topic: topic,
  1396. Callback: func(data *pjisuv_msgs.Trajectory) {
  1397. subscribersTimeMutexes[i].Lock()
  1398. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1399. subscribersMutexes[i].Lock()
  1400. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1401. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1402. faultLabel := ""
  1403. if len(masterConfig.RuleOfReferenceTrajectory1) > 0 {
  1404. for _, f := range masterConfig.RuleOfReferenceTrajectory1 {
  1405. faultLabel = f(data)
  1406. if faultLabel != "" {
  1407. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1408. subscribersTimes[i] = time.Now()
  1409. goto TriggerSuccess
  1410. }
  1411. }
  1412. }
  1413. if len(masterConfig.RuleOfReferenceTrajectory2) > 0 {
  1414. for _, f := range masterConfig.RuleOfReferenceTrajectory2 {
  1415. faultLabel = f(data, &pjisuvParam)
  1416. if faultLabel != "" {
  1417. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1418. subscribersTimes[i] = time.Now()
  1419. goto TriggerSuccess
  1420. }
  1421. }
  1422. }
  1423. if len(masterConfig.RuleOfReferenceTrajectory3) > 0 {
  1424. for _, f := range masterConfig.RuleOfReferenceTrajectory3 {
  1425. faultLabel = f(shareVars, data)
  1426. if faultLabel != "" {
  1427. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1428. subscribersTimes[i] = time.Now()
  1429. goto TriggerSuccess
  1430. }
  1431. }
  1432. }
  1433. TriggerSuccess:
  1434. subscribersMutexes[i].Unlock()
  1435. }
  1436. subscribersTimeMutexes[i].Unlock()
  1437. },
  1438. })
  1439. }
  1440. // 27
  1441. if topic == masterConfig.TopicOfRoiPoints &&
  1442. (len(masterConfig.RuleOfRoiPoints1) > 0 ||
  1443. len(masterConfig.RuleOfRoiPoints2) > 0 ||
  1444. len(masterConfig.RuleOfRoiPoints3) > 0) {
  1445. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1446. Node: commonConfig.RosNode,
  1447. Topic: topic,
  1448. Callback: func(data *sensor_msgs.PointCloud2) {
  1449. subscribersTimeMutexes[i].Lock()
  1450. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1451. subscribersMutexes[i].Lock()
  1452. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1453. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1454. faultLabel := ""
  1455. if len(masterConfig.RuleOfRoiPoints1) > 0 {
  1456. for _, f := range masterConfig.RuleOfRoiPoints1 {
  1457. faultLabel = f(data)
  1458. if faultLabel != "" {
  1459. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1460. subscribersTimes[i] = time.Now()
  1461. goto TriggerSuccess
  1462. }
  1463. }
  1464. }
  1465. if len(masterConfig.RuleOfRoiPoints2) > 0 {
  1466. for _, f := range masterConfig.RuleOfRoiPoints2 {
  1467. faultLabel = f(data, &pjisuvParam)
  1468. if faultLabel != "" {
  1469. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1470. subscribersTimes[i] = time.Now()
  1471. goto TriggerSuccess
  1472. }
  1473. }
  1474. }
  1475. if len(masterConfig.RuleOfRoiPoints3) > 0 {
  1476. for _, f := range masterConfig.RuleOfRoiPoints3 {
  1477. faultLabel = f(shareVars, data)
  1478. if faultLabel != "" {
  1479. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1480. subscribersTimes[i] = time.Now()
  1481. goto TriggerSuccess
  1482. }
  1483. }
  1484. }
  1485. TriggerSuccess:
  1486. subscribersMutexes[i].Unlock()
  1487. }
  1488. subscribersTimeMutexes[i].Unlock()
  1489. },
  1490. })
  1491. }
  1492. // 28
  1493. if topic == masterConfig.TopicOfRoiPolygon &&
  1494. (len(masterConfig.RuleOfRoiPolygon1) > 0 ||
  1495. len(masterConfig.RuleOfRoiPolygon2) > 0 ||
  1496. len(masterConfig.RuleOfRoiPolygon3) > 0) {
  1497. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1498. Node: commonConfig.RosNode,
  1499. Topic: topic,
  1500. Callback: func(data *nav_msgs.Path) {
  1501. subscribersTimeMutexes[i].Lock()
  1502. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1503. subscribersMutexes[i].Lock()
  1504. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1505. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1506. faultLabel := ""
  1507. if len(masterConfig.RuleOfRoiPolygon1) > 0 {
  1508. for _, f := range masterConfig.RuleOfRoiPolygon1 {
  1509. faultLabel = f(data)
  1510. if faultLabel != "" {
  1511. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1512. subscribersTimes[i] = time.Now()
  1513. goto TriggerSuccess
  1514. }
  1515. }
  1516. }
  1517. if len(masterConfig.RuleOfRoiPolygon2) > 0 {
  1518. for _, f := range masterConfig.RuleOfRoiPolygon2 {
  1519. faultLabel = f(data, &pjisuvParam)
  1520. if faultLabel != "" {
  1521. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1522. subscribersTimes[i] = time.Now()
  1523. goto TriggerSuccess
  1524. }
  1525. }
  1526. }
  1527. if len(masterConfig.RuleOfRoiPolygon3) > 0 {
  1528. for _, f := range masterConfig.RuleOfRoiPolygon3 {
  1529. faultLabel = f(shareVars, data)
  1530. if faultLabel != "" {
  1531. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1532. subscribersTimes[i] = time.Now()
  1533. goto TriggerSuccess
  1534. }
  1535. }
  1536. }
  1537. TriggerSuccess:
  1538. subscribersMutexes[i].Unlock()
  1539. }
  1540. subscribersTimeMutexes[i].Unlock()
  1541. },
  1542. })
  1543. }
  1544. // 29
  1545. if topic == masterConfig.TopicOfTf &&
  1546. (len(masterConfig.RuleOfTf1) > 0 ||
  1547. len(masterConfig.RuleOfTf2) > 0 ||
  1548. len(masterConfig.RuleOfTf3) > 0) {
  1549. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1550. Node: commonConfig.RosNode,
  1551. Topic: topic,
  1552. Callback: func(data *tf2_msgs.TFMessage) {
  1553. subscribersTimeMutexes[i].Lock()
  1554. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1555. subscribersMutexes[i].Lock()
  1556. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1557. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1558. faultLabel := ""
  1559. if len(masterConfig.RuleOfTf1) > 0 {
  1560. for _, f := range masterConfig.RuleOfTf1 {
  1561. faultLabel = f(data)
  1562. if faultLabel != "" {
  1563. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1564. subscribersTimes[i] = time.Now()
  1565. goto TriggerSuccess
  1566. }
  1567. }
  1568. }
  1569. if len(masterConfig.RuleOfTf2) > 0 {
  1570. for _, f := range masterConfig.RuleOfTf2 {
  1571. faultLabel = f(data, &pjisuvParam)
  1572. if faultLabel != "" {
  1573. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1574. subscribersTimes[i] = time.Now()
  1575. goto TriggerSuccess
  1576. }
  1577. }
  1578. }
  1579. if len(masterConfig.RuleOfTf3) > 0 {
  1580. for _, f := range masterConfig.RuleOfTf3 {
  1581. faultLabel = f(shareVars, data)
  1582. if faultLabel != "" {
  1583. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1584. subscribersTimes[i] = time.Now()
  1585. goto TriggerSuccess
  1586. }
  1587. }
  1588. }
  1589. TriggerSuccess:
  1590. subscribersMutexes[i].Unlock()
  1591. }
  1592. subscribersTimeMutexes[i].Unlock()
  1593. },
  1594. })
  1595. }
  1596. // 30 有共享变量的订阅者必须被创建
  1597. if topic == masterConfig.TopicOfTpperception {
  1598. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1599. Node: commonConfig.RosNode,
  1600. Topic: topic,
  1601. Callback: func(data *pjisuv_msgs.PerceptionObjects) {
  1602. subscribersTimeMutexes[i].Lock()
  1603. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1604. subscribersMutexes[i].Lock()
  1605. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1606. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1607. faultLabel := ""
  1608. if len(masterConfig.RuleOfTpperception1) > 0 {
  1609. for _, f := range masterConfig.RuleOfTpperception1 {
  1610. faultLabel = f(data)
  1611. if faultLabel != "" {
  1612. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1613. subscribersTimes[i] = time.Now()
  1614. goto TriggerSuccess
  1615. }
  1616. }
  1617. }
  1618. if len(masterConfig.RuleOfTpperception2) > 0 {
  1619. for _, f := range masterConfig.RuleOfTpperception2 {
  1620. faultLabel = f(data, &pjisuvParam)
  1621. if faultLabel != "" {
  1622. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1623. subscribersTimes[i] = time.Now()
  1624. goto TriggerSuccess
  1625. }
  1626. }
  1627. }
  1628. if len(masterConfig.RuleOfTpperception3) > 0 {
  1629. for _, f := range masterConfig.RuleOfTpperception3 {
  1630. faultLabel = f(shareVars, data)
  1631. if faultLabel != "" {
  1632. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1633. subscribersTimes[i] = time.Now()
  1634. goto TriggerSuccess
  1635. }
  1636. }
  1637. }
  1638. TriggerSuccess:
  1639. subscribersMutexes[i].Unlock()
  1640. }
  1641. subscribersTimeMutexes[i].Unlock()
  1642. // 更新共享变量
  1643. mutexOfTpperception.RLock()
  1644. {
  1645. for _, obj := range data.Objs {
  1646. if obj.X <= 5 || math.Abs(float64(obj.Y)) >= 10 {
  1647. continue
  1648. }
  1649. // 检查 ObjDicOfTpperception 是否为 nil,如果是,则初始化它
  1650. if pjisuvParam.ObjDicOfTpperception == nil {
  1651. pjisuvParam.ObjDicOfTpperception = make(map[uint32][]float32)
  1652. }
  1653. if _, ok := pjisuvParam.ObjDicOfTpperception[obj.Id]; !ok {
  1654. pjisuvParam.ObjDicOfTpperception[obj.Id] = []float32{}
  1655. }
  1656. pjisuvParam.ObjDicOfTpperception[obj.Id] = append(pjisuvParam.ObjDicOfTpperception[obj.Id], obj.Y)
  1657. pjisuvParam.ObjTypeDicOfTpperception[obj.Id] = obj.Type
  1658. pjisuvParam.ObjSpeedDicOfTpperception[obj.Id] = math.Pow(math.Pow(float64(obj.Vxabs), 2)+math.Pow(float64(obj.Vyabs), 2), 0.5)
  1659. }
  1660. }
  1661. mutexOfTpperception.RUnlock()
  1662. },
  1663. })
  1664. }
  1665. // 31
  1666. if topic == masterConfig.TopicOfTpperceptionVis &&
  1667. (len(masterConfig.RuleOfTpperceptionVis1) > 0 ||
  1668. len(masterConfig.RuleOfTpperceptionVis2) > 0 ||
  1669. len(masterConfig.RuleOfTpperceptionVis3) > 0) {
  1670. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1671. Node: commonConfig.RosNode,
  1672. Topic: topic,
  1673. Callback: func(data *visualization_msgs.MarkerArray) {
  1674. subscribersTimeMutexes[i].Lock()
  1675. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1676. subscribersMutexes[i].Lock()
  1677. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1678. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1679. faultLabel := ""
  1680. if len(masterConfig.RuleOfTpperceptionVis1) > 0 {
  1681. for _, f := range masterConfig.RuleOfTpperceptionVis1 {
  1682. faultLabel = f(data)
  1683. if faultLabel != "" {
  1684. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1685. subscribersTimes[i] = time.Now()
  1686. goto TriggerSuccess
  1687. }
  1688. }
  1689. }
  1690. if len(masterConfig.RuleOfTpperceptionVis2) > 0 {
  1691. for _, f := range masterConfig.RuleOfTpperceptionVis2 {
  1692. faultLabel = f(data, &pjisuvParam)
  1693. if faultLabel != "" {
  1694. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1695. subscribersTimes[i] = time.Now()
  1696. goto TriggerSuccess
  1697. }
  1698. }
  1699. }
  1700. if len(masterConfig.RuleOfTpperceptionVis3) > 0 {
  1701. for _, f := range masterConfig.RuleOfTpperceptionVis3 {
  1702. faultLabel = f(shareVars, data)
  1703. if faultLabel != "" {
  1704. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1705. subscribersTimes[i] = time.Now()
  1706. goto TriggerSuccess
  1707. }
  1708. }
  1709. }
  1710. TriggerSuccess:
  1711. subscribersMutexes[i].Unlock()
  1712. }
  1713. subscribersTimeMutexes[i].Unlock()
  1714. },
  1715. })
  1716. }
  1717. // 32
  1718. if topic == masterConfig.TopicOfTprouteplan &&
  1719. (len(masterConfig.RuleOfTprouteplan1) > 0 ||
  1720. len(masterConfig.RuleOfTprouteplan2) > 0 ||
  1721. len(masterConfig.RuleOfTprouteplan3) > 0) {
  1722. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1723. Node: commonConfig.RosNode,
  1724. Topic: topic,
  1725. Callback: func(data *pjisuv_msgs.RoutePlan) {
  1726. subscribersTimeMutexes[i].Lock()
  1727. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1728. subscribersMutexes[i].Lock()
  1729. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1730. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1731. faultLabel := ""
  1732. if len(masterConfig.RuleOfTprouteplan1) > 0 {
  1733. for _, f := range masterConfig.RuleOfTprouteplan1 {
  1734. faultLabel = f(data)
  1735. if faultLabel != "" {
  1736. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1737. subscribersTimes[i] = time.Now()
  1738. goto TriggerSuccess
  1739. }
  1740. }
  1741. }
  1742. if len(masterConfig.RuleOfTprouteplan2) > 0 {
  1743. for _, f := range masterConfig.RuleOfTprouteplan2 {
  1744. faultLabel = f(data, &pjisuvParam)
  1745. if faultLabel != "" {
  1746. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1747. subscribersTimes[i] = time.Now()
  1748. goto TriggerSuccess
  1749. }
  1750. }
  1751. }
  1752. if len(masterConfig.RuleOfTprouteplan3) > 0 {
  1753. for _, f := range masterConfig.RuleOfTprouteplan3 {
  1754. faultLabel = f(shareVars, data)
  1755. if faultLabel != "" {
  1756. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1757. subscribersTimes[i] = time.Now()
  1758. goto TriggerSuccess
  1759. }
  1760. }
  1761. }
  1762. TriggerSuccess:
  1763. subscribersMutexes[i].Unlock()
  1764. }
  1765. subscribersTimeMutexes[i].Unlock()
  1766. },
  1767. })
  1768. }
  1769. // 33
  1770. if topic == masterConfig.TopicOfTrajectoryDisplay &&
  1771. (len(masterConfig.RuleOfTrajectoryDisplay1) > 0 ||
  1772. len(masterConfig.RuleOfTrajectoryDisplay2) > 0 ||
  1773. len(masterConfig.RuleOfTrajectoryDisplay3) > 0) {
  1774. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1775. Node: commonConfig.RosNode,
  1776. Topic: topic,
  1777. Callback: func(data *nav_msgs.Path) {
  1778. subscribersTimeMutexes[i].Lock()
  1779. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1780. subscribersMutexes[i].Lock()
  1781. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1782. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1783. faultLabel := ""
  1784. if len(masterConfig.RuleOfTrajectoryDisplay1) > 0 {
  1785. for _, f := range masterConfig.RuleOfTrajectoryDisplay1 {
  1786. faultLabel = f(data)
  1787. if faultLabel != "" {
  1788. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1789. subscribersTimes[i] = time.Now()
  1790. goto TriggerSuccess
  1791. }
  1792. }
  1793. }
  1794. if len(masterConfig.RuleOfTrajectoryDisplay2) > 0 {
  1795. for _, f := range masterConfig.RuleOfTrajectoryDisplay2 {
  1796. faultLabel = f(data, &pjisuvParam)
  1797. if faultLabel != "" {
  1798. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1799. subscribersTimes[i] = time.Now()
  1800. goto TriggerSuccess
  1801. }
  1802. }
  1803. }
  1804. if len(masterConfig.RuleOfTrajectoryDisplay3) > 0 {
  1805. for _, f := range masterConfig.RuleOfTrajectoryDisplay3 {
  1806. faultLabel = f(shareVars, data)
  1807. if faultLabel != "" {
  1808. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1809. subscribersTimes[i] = time.Now()
  1810. goto TriggerSuccess
  1811. }
  1812. }
  1813. }
  1814. TriggerSuccess:
  1815. subscribersMutexes[i].Unlock()
  1816. }
  1817. subscribersTimeMutexes[i].Unlock()
  1818. },
  1819. })
  1820. }
  1821. // 34
  1822. if topic == masterConfig.TopicOfUngroundCloudpoints &&
  1823. (len(masterConfig.RuleOfUngroundCloudpoints1) > 0 ||
  1824. len(masterConfig.RuleOfUngroundCloudpoints2) > 0 ||
  1825. len(masterConfig.RuleOfUngroundCloudpoints3) > 0) {
  1826. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1827. Node: commonConfig.RosNode,
  1828. Topic: topic,
  1829. Callback: func(data *sensor_msgs.PointCloud2) {
  1830. subscribersTimeMutexes[i].Lock()
  1831. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1832. subscribersMutexes[i].Lock()
  1833. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1834. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1835. faultLabel := ""
  1836. if len(masterConfig.RuleOfUngroundCloudpoints1) > 0 {
  1837. for _, f := range masterConfig.RuleOfUngroundCloudpoints1 {
  1838. faultLabel = f(data)
  1839. if faultLabel != "" {
  1840. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1841. subscribersTimes[i] = time.Now()
  1842. goto TriggerSuccess
  1843. }
  1844. }
  1845. }
  1846. if len(masterConfig.RuleOfUngroundCloudpoints2) > 0 {
  1847. for _, f := range masterConfig.RuleOfUngroundCloudpoints2 {
  1848. faultLabel = f(data, &pjisuvParam)
  1849. if faultLabel != "" {
  1850. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1851. subscribersTimes[i] = time.Now()
  1852. goto TriggerSuccess
  1853. }
  1854. }
  1855. }
  1856. if len(masterConfig.RuleOfUngroundCloudpoints3) > 0 {
  1857. for _, f := range masterConfig.RuleOfUngroundCloudpoints3 {
  1858. faultLabel = f(shareVars, data)
  1859. if faultLabel != "" {
  1860. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1861. subscribersTimes[i] = time.Now()
  1862. goto TriggerSuccess
  1863. }
  1864. }
  1865. }
  1866. TriggerSuccess:
  1867. subscribersMutexes[i].Unlock()
  1868. }
  1869. subscribersTimeMutexes[i].Unlock()
  1870. },
  1871. })
  1872. }
  1873. // 35
  1874. if topic == masterConfig.TopicOfCameraImage &&
  1875. (len(masterConfig.RuleOfCameraImage1) > 0 ||
  1876. len(masterConfig.RuleOfCameraImage2) > 0 ||
  1877. len(masterConfig.RuleOfCameraImage3) > 0) {
  1878. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1879. Node: commonConfig.RosNode,
  1880. Topic: topic,
  1881. Callback: func(data *sensor_msgs.Image) {
  1882. subscribersTimeMutexes[i].Lock()
  1883. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1884. subscribersMutexes[i].Lock()
  1885. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1886. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1887. faultLabel := ""
  1888. if len(masterConfig.RuleOfCameraImage1) > 0 {
  1889. for _, f := range masterConfig.RuleOfCameraImage1 {
  1890. faultLabel = f(data)
  1891. if faultLabel != "" {
  1892. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1893. subscribersTimes[i] = time.Now()
  1894. goto TriggerSuccess
  1895. }
  1896. }
  1897. }
  1898. if len(masterConfig.RuleOfCameraImage2) > 0 {
  1899. for _, f := range masterConfig.RuleOfCameraImage2 {
  1900. faultLabel = f(data, &pjisuvParam)
  1901. if faultLabel != "" {
  1902. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1903. subscribersTimes[i] = time.Now()
  1904. goto TriggerSuccess
  1905. }
  1906. }
  1907. }
  1908. if len(masterConfig.RuleOfCameraImage3) > 0 {
  1909. for _, f := range masterConfig.RuleOfCameraImage3 {
  1910. faultLabel = f(shareVars, data)
  1911. if faultLabel != "" {
  1912. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1913. subscribersTimes[i] = time.Now()
  1914. goto TriggerSuccess
  1915. }
  1916. }
  1917. }
  1918. TriggerSuccess:
  1919. subscribersMutexes[i].Unlock()
  1920. }
  1921. subscribersTimeMutexes[i].Unlock()
  1922. },
  1923. })
  1924. }
  1925. // 36 有共享变量的订阅者必须被创建
  1926. if topic == masterConfig.TopicOfDataRead {
  1927. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1928. Node: commonConfig.RosNode,
  1929. Topic: topic,
  1930. Callback: func(data *pjisuv_msgs.Retrieval) {
  1931. // 更新共享变量
  1932. mutexOfDataRead.RLock()
  1933. {
  1934. pjisuvParam.NumCountDataReadOfDataRead++
  1935. if pjisuvParam.NumCountDataReadOfDataRead == 10 {
  1936. pjisuvParam.EgoSteeringRealOfDataRead = append(pjisuvParam.EgoSteeringRealOfDataRead, data.ActStrWhAng)
  1937. pjisuvParam.EgoThrottleRealOfDataRead = append(pjisuvParam.EgoThrottleRealOfDataRead, data.AccPed2)
  1938. pjisuvParam.NumCountDataReadOfDataRead = 0
  1939. }
  1940. pjisuvParam.StrgAngleRealValueOfDataRead = data.ActStrWhAng
  1941. }
  1942. mutexOfDataRead.RUnlock()
  1943. subscribersTimeMutexes[i].Lock()
  1944. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1945. subscribersMutexes[i].Lock()
  1946. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1947. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1948. faultLabel := ""
  1949. if len(masterConfig.RuleOfDataRead1) > 0 {
  1950. for _, f := range masterConfig.RuleOfDataRead1 {
  1951. faultLabel = f(data)
  1952. if faultLabel != "" {
  1953. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1954. subscribersTimes[i] = time.Now()
  1955. goto TriggerSuccess
  1956. }
  1957. }
  1958. }
  1959. if len(masterConfig.RuleOfDataRead2) > 0 {
  1960. for _, f := range masterConfig.RuleOfDataRead2 {
  1961. faultLabel = f(data, &pjisuvParam)
  1962. if faultLabel != "" {
  1963. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1964. subscribersTimes[i] = time.Now()
  1965. goto TriggerSuccess
  1966. }
  1967. }
  1968. }
  1969. if len(masterConfig.RuleOfDataRead3) > 0 {
  1970. for _, f := range masterConfig.RuleOfDataRead3 {
  1971. faultLabel = f(shareVars, data)
  1972. if faultLabel != "" {
  1973. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1974. subscribersTimes[i] = time.Now()
  1975. goto TriggerSuccess
  1976. }
  1977. }
  1978. }
  1979. TriggerSuccess:
  1980. subscribersMutexes[i].Unlock()
  1981. }
  1982. subscribersTimeMutexes[i].Unlock()
  1983. },
  1984. })
  1985. }
  1986. // 37
  1987. if topic == masterConfig.TopicOfPjiGps &&
  1988. (len(masterConfig.RuleOfPjiGps1) > 0 ||
  1989. len(masterConfig.RuleOfPjiGps2) > 0 ||
  1990. len(masterConfig.RuleOfPjiGps3) > 0) {
  1991. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1992. Node: commonConfig.RosNode,
  1993. Topic: topic,
  1994. Callback: func(data *pjisuv_msgs.PerceptionLocalization) {
  1995. subscribersTimeMutexes[i].Lock()
  1996. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1997. subscribersMutexes[i].Lock()
  1998. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1999. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  2000. faultLabel := ""
  2001. if len(masterConfig.RuleOfPjiGps1) > 0 {
  2002. for _, f := range masterConfig.RuleOfPjiGps1 {
  2003. faultLabel = f(data)
  2004. if faultLabel != "" {
  2005. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2006. subscribersTimes[i] = time.Now()
  2007. goto TriggerSuccess
  2008. }
  2009. }
  2010. }
  2011. if len(masterConfig.RuleOfPjiGps2) > 0 {
  2012. for _, f := range masterConfig.RuleOfPjiGps2 {
  2013. faultLabel = f(data, &pjisuvParam)
  2014. if faultLabel != "" {
  2015. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2016. subscribersTimes[i] = time.Now()
  2017. goto TriggerSuccess
  2018. }
  2019. }
  2020. }
  2021. if len(masterConfig.RuleOfPjiGps3) > 0 {
  2022. for _, f := range masterConfig.RuleOfPjiGps3 {
  2023. faultLabel = f(shareVars, data)
  2024. if faultLabel != "" {
  2025. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2026. subscribersTimes[i] = time.Now()
  2027. goto TriggerSuccess
  2028. }
  2029. }
  2030. }
  2031. TriggerSuccess:
  2032. subscribersMutexes[i].Unlock()
  2033. }
  2034. subscribersTimeMutexes[i].Unlock()
  2035. },
  2036. })
  2037. }
  2038. // 39 有共享变量的订阅者必须被创建
  2039. if topic == masterConfig.TopicOfPjVehicleFdbPub {
  2040. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  2041. Node: commonConfig.RosNode,
  2042. Topic: topic,
  2043. Callback: func(data *pjisuv_msgs.VehicleFdb) {
  2044. subscribersTimeMutexes[i].Lock()
  2045. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  2046. subscribersMutexes[i].Lock()
  2047. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  2048. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  2049. faultLabel := ""
  2050. if len(masterConfig.RuleOfPjVehicleFdbPub1) > 0 {
  2051. for _, f := range masterConfig.RuleOfPjVehicleFdbPub1 {
  2052. faultLabel = f(data)
  2053. if faultLabel != "" {
  2054. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2055. subscribersTimes[i] = time.Now()
  2056. goto TriggerSuccess
  2057. }
  2058. }
  2059. }
  2060. if len(masterConfig.RuleOfPjVehicleFdbPub2) > 0 {
  2061. for _, f := range masterConfig.RuleOfPjVehicleFdbPub2 {
  2062. faultLabel = f(data, &pjisuvParam)
  2063. if faultLabel != "" {
  2064. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2065. subscribersTimes[i] = time.Now()
  2066. goto TriggerSuccess
  2067. }
  2068. }
  2069. }
  2070. if len(masterConfig.RuleOfPjVehicleFdbPub3) > 0 {
  2071. for _, f := range masterConfig.RuleOfPjVehicleFdbPub3 {
  2072. faultLabel = f(shareVars, data)
  2073. if faultLabel != "" {
  2074. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2075. subscribersTimes[i] = time.Now()
  2076. goto TriggerSuccess
  2077. }
  2078. }
  2079. }
  2080. TriggerSuccess:
  2081. subscribersMutexes[i].Unlock()
  2082. }
  2083. subscribersTimeMutexes[i].Unlock()
  2084. // 更新共享变量
  2085. shareVars.Store("Automode", data.Automode)
  2086. shareVars.Store("AutomodeOfPjVehicleFdbPub", data.Automode)
  2087. },
  2088. })
  2089. }
  2090. // 40 有共享变量的订阅者必须被创建
  2091. if topic == masterConfig.TopicOfEndPointMessage {
  2092. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  2093. Node: commonConfig.RosNode,
  2094. Topic: topic,
  2095. Callback: func(data *geometry_msgs.Point) {
  2096. subscribersTimeMutexes[i].Lock()
  2097. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  2098. subscribersMutexes[i].Lock()
  2099. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  2100. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  2101. faultLabel := ""
  2102. if len(masterConfig.RuleOfEndPointMessage1) > 0 {
  2103. for _, f := range masterConfig.RuleOfEndPointMessage1 {
  2104. faultLabel = f(data)
  2105. if faultLabel != "" {
  2106. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2107. subscribersTimes[i] = time.Now()
  2108. goto TriggerSuccess
  2109. }
  2110. }
  2111. }
  2112. if len(masterConfig.RuleOfEndPointMessage2) > 0 {
  2113. for _, f := range masterConfig.RuleOfEndPointMessage2 {
  2114. faultLabel = f(data, &pjisuvParam)
  2115. if faultLabel != "" {
  2116. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2117. subscribersTimes[i] = time.Now()
  2118. goto TriggerSuccess
  2119. }
  2120. }
  2121. }
  2122. if len(masterConfig.RuleOfEndPointMessage3) > 0 {
  2123. for _, f := range masterConfig.RuleOfEndPointMessage3 {
  2124. faultLabel = f(shareVars, data)
  2125. if faultLabel != "" {
  2126. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2127. subscribersTimes[i] = time.Now()
  2128. goto TriggerSuccess
  2129. }
  2130. }
  2131. }
  2132. TriggerSuccess:
  2133. subscribersMutexes[i].Unlock()
  2134. }
  2135. subscribersTimeMutexes[i].Unlock()
  2136. // 更新共享变量
  2137. shareVars.Store("EndPointX", data.X)
  2138. shareVars.Store("EndPointY", data.Y)
  2139. },
  2140. })
  2141. }
  2142. if err != nil {
  2143. c_log.GlobalLogger.Info("创建订阅者报错,可能由于节点未启动,再次尝试:", err)
  2144. time.Sleep(time.Duration(2) * time.Second)
  2145. continue
  2146. } else {
  2147. break
  2148. }
  2149. }
  2150. }
  2151. select {
  2152. case signal := <-service.ChannelKillWindowProducer:
  2153. if signal == 1 {
  2154. commonConfig.RosNode.Close()
  2155. service.AddKillTimes("3")
  2156. return
  2157. }
  2158. }
  2159. }
  2160. func saveTimeWindow(faultLabel string, faultHappenTime string, lastTimeWindow *commonEntity.TimeWindow) {
  2161. saveTimeWindowMutex.Lock()
  2162. defer saveTimeWindowMutex.Unlock()
  2163. masterTopics, slaveTopics := getTopicsOfNode(faultLabel)
  2164. if lastTimeWindow == nil || util.TimeCustom1GreaterTimeCustom2(faultHappenTime, lastTimeWindow.TimeWindowEnd) { // 如果是不在旧故障窗口内,添加一个新窗口
  2165. exceptBegin := util.TimeCustomChange(faultHappenTime, -commonConfig.PlatformConfig.TaskBeforeTime)
  2166. finalTimeWindowBegin := ""
  2167. if util.TimeCustom1LessEqualThanTimeCustom2(exceptBegin, latestTimeWindowEnd) { // 窗口最早时间不能早于上一个窗口结束时间
  2168. finalTimeWindowBegin = latestTimeWindowEnd
  2169. } else {
  2170. finalTimeWindowBegin = exceptBegin
  2171. }
  2172. latestTimeWindowEnd = util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime)
  2173. newTimeWindow := commonEntity.TimeWindow{
  2174. FaultTime: faultHappenTime,
  2175. TimeWindowBegin: finalTimeWindowBegin,
  2176. TimeWindowEnd: latestTimeWindowEnd,
  2177. Length: util.CalculateDifferenceOfTimeCustom(finalTimeWindowBegin, latestTimeWindowEnd),
  2178. Labels: []string{faultLabel},
  2179. MasterTopics: masterTopics,
  2180. SlaveTopics: slaveTopics,
  2181. }
  2182. c_log.GlobalLogger.Infof("不在旧故障窗口内,向生产者队列添加一个新窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", newTimeWindow.Labels, newTimeWindow.FaultTime, newTimeWindow.Length)
  2183. commonEntity.AddTimeWindowToTimeWindowProducerQueue(newTimeWindow)
  2184. } else { // 如果在旧故障窗口内
  2185. commonEntity.TimeWindowProducerQueueMutex.RLock()
  2186. defer commonEntity.TimeWindowProducerQueueMutex.RUnlock()
  2187. // 更新故障窗口end时间
  2188. expectEnd := util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime) // 窗口期望关闭时间是触发时间加上后置时间
  2189. expectLength := util.CalculateDifferenceOfTimeCustom(lastTimeWindow.TimeWindowBegin, expectEnd)
  2190. if expectLength < commonConfig.PlatformConfig.TaskMaxTime {
  2191. latestTimeWindowEnd = expectEnd
  2192. lastTimeWindow.TimeWindowEnd = latestTimeWindowEnd
  2193. lastTimeWindow.Length = util.CalculateDifferenceOfTimeCustom(lastTimeWindow.TimeWindowBegin, lastTimeWindow.TimeWindowEnd)
  2194. }
  2195. // 更新label
  2196. labels := lastTimeWindow.Labels
  2197. lastTimeWindow.Labels = util.AppendIfNotExists(labels, faultLabel)
  2198. // 更新 topic
  2199. sourceMasterTopics := lastTimeWindow.MasterTopics
  2200. lastTimeWindow.MasterTopics = util.MergeSlice(sourceMasterTopics, masterTopics)
  2201. sourceSlaveTopics := lastTimeWindow.SlaveTopics
  2202. lastTimeWindow.SlaveTopics = util.MergeSlice(sourceSlaveTopics, slaveTopics)
  2203. c_log.GlobalLogger.Infof("在旧故障窗口内,更新生产者队列最新的窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", lastTimeWindow.Labels, lastTimeWindow.FaultTime, lastTimeWindow.Length)
  2204. }
  2205. }
  2206. func getTopicsOfNode(faultLabel string) (masterTopics []string, slaveTopics []string) {
  2207. // 获取所有需要采集的topic
  2208. var faultCodeTopics []string
  2209. for _, code := range commonConfig.CloudConfig.Triggers {
  2210. if code.Label == faultLabel {
  2211. faultCodeTopics = code.Topics
  2212. }
  2213. }
  2214. // 根据不同节点采集的topic进行分配采集
  2215. for _, acceptTopic := range faultCodeTopics {
  2216. for _, host := range commonConfig.CloudConfig.Hosts {
  2217. for _, topic := range host.Topics {
  2218. if host.Name == commonConfig.CloudConfig.Hosts[0].Name && acceptTopic == topic {
  2219. masterTopics = append(masterTopics, acceptTopic)
  2220. }
  2221. if host.Name == commonConfig.CloudConfig.Hosts[1].Name && acceptTopic == topic {
  2222. slaveTopics = append(slaveTopics, acceptTopic)
  2223. }
  2224. }
  2225. }
  2226. }
  2227. return masterTopics, slaveTopics
  2228. }