produce_window.go 82 KB

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