produce_window.go 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  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. subscribersTimeMutexes[i].Lock()
  647. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  648. subscribersMutexes[i].Lock()
  649. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  650. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  651. faultLabel := ""
  652. if len(masterConfig.RuleOfCicvLocation1) > 0 {
  653. for _, f := range masterConfig.RuleOfCicvLocation1 {
  654. faultLabel = f(data)
  655. if faultLabel != "" {
  656. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  657. subscribersTimes[i] = time.Now()
  658. goto TriggerSuccess
  659. }
  660. }
  661. }
  662. if len(masterConfig.RuleOfCicvLocation2) > 0 {
  663. for _, f := range masterConfig.RuleOfCicvLocation2 {
  664. faultLabel = f(data, &pjisuvParam)
  665. if faultLabel != "" {
  666. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  667. subscribersTimes[i] = time.Now()
  668. goto TriggerSuccess
  669. }
  670. }
  671. }
  672. if len(masterConfig.RuleOfCicvLocation3) > 0 {
  673. for _, f := range masterConfig.RuleOfCicvLocation3 {
  674. faultLabel = f(shareVars, data)
  675. if faultLabel != "" {
  676. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  677. subscribersTimes[i] = time.Now()
  678. goto TriggerSuccess
  679. }
  680. }
  681. }
  682. TriggerSuccess:
  683. subscribersMutexes[i].Unlock()
  684. }
  685. subscribersTimeMutexes[i].Unlock()
  686. // 更新共享变量
  687. mutexOfCicvLocation.RLock()
  688. {
  689. //shareVars.Store("VelocityXOfCicvLocation",data.VelocityX) pjisuvParam以后不要新加全局变量了,采用这种方式添加
  690. //value, _ := shareVars.Load("VelocityXOfCicvLocation") 在Rule函数数中通过Load方法获取全局变量,获取之后通过value.(float64)方法转换数据类型
  691. //s := value.(float64)
  692. pjisuvParam.VelocityXOfCicvLocation = data.VelocityX
  693. pjisuvParam.VelocityYOfCicvLocation = data.VelocityY
  694. pjisuvParam.VelocityZOfCicvLocation = data.VelocityZ
  695. pjisuvParam.YawOfCicvLocation = data.Yaw
  696. pjisuvParam.AngularVelocityZOfCicvLocation = data.AngularVelocityZ
  697. pjisuvParam.PositionXOfCicvLocation = data.PositionX
  698. pjisuvParam.PositionYOfCicvLocation = data.PositionY
  699. }
  700. mutexOfCicvLocation.RUnlock()
  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. // 更新共享变量
  1644. mutexOfTpperception.RLock()
  1645. {
  1646. for _, obj := range data.Objs {
  1647. if obj.X <= 5 || math.Abs(float64(obj.Y)) >= 10 {
  1648. continue
  1649. }
  1650. // 检查 ObjDicOfTpperception 是否为 nil,如果是,则初始化它
  1651. if pjisuvParam.ObjDicOfTpperception == nil {
  1652. pjisuvParam.ObjDicOfTpperception = make(map[uint32][]float32)
  1653. }
  1654. if _, ok := pjisuvParam.ObjDicOfTpperception[obj.Id]; !ok {
  1655. pjisuvParam.ObjDicOfTpperception[obj.Id] = []float32{}
  1656. }
  1657. pjisuvParam.ObjDicOfTpperception[obj.Id] = append(pjisuvParam.ObjDicOfTpperception[obj.Id], obj.Y)
  1658. pjisuvParam.ObjTypeDicOfTpperception[obj.Id] = obj.Type
  1659. pjisuvParam.ObjSpeedDicOfTpperception[obj.Id] = math.Pow(math.Pow(float64(obj.Vxabs), 2)+math.Pow(float64(obj.Vyabs), 2), 0.5)
  1660. }
  1661. }
  1662. mutexOfTpperception.RUnlock()
  1663. },
  1664. })
  1665. }
  1666. // 31
  1667. if topic == masterConfig.TopicOfTpperceptionVis &&
  1668. (len(masterConfig.RuleOfTpperceptionVis1) > 0 ||
  1669. len(masterConfig.RuleOfTpperceptionVis2) > 0 ||
  1670. len(masterConfig.RuleOfTpperceptionVis3) > 0) {
  1671. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1672. Node: commonConfig.RosNode,
  1673. Topic: topic,
  1674. Callback: func(data *visualization_msgs.MarkerArray) {
  1675. subscribersTimeMutexes[i].Lock()
  1676. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1677. subscribersMutexes[i].Lock()
  1678. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1679. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1680. faultLabel := ""
  1681. if len(masterConfig.RuleOfTpperceptionVis1) > 0 {
  1682. for _, f := range masterConfig.RuleOfTpperceptionVis1 {
  1683. faultLabel = f(data)
  1684. if faultLabel != "" {
  1685. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1686. subscribersTimes[i] = time.Now()
  1687. goto TriggerSuccess
  1688. }
  1689. }
  1690. }
  1691. if len(masterConfig.RuleOfTpperceptionVis2) > 0 {
  1692. for _, f := range masterConfig.RuleOfTpperceptionVis2 {
  1693. faultLabel = f(data, &pjisuvParam)
  1694. if faultLabel != "" {
  1695. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1696. subscribersTimes[i] = time.Now()
  1697. goto TriggerSuccess
  1698. }
  1699. }
  1700. }
  1701. if len(masterConfig.RuleOfTpperceptionVis3) > 0 {
  1702. for _, f := range masterConfig.RuleOfTpperceptionVis3 {
  1703. faultLabel = f(shareVars, data)
  1704. if faultLabel != "" {
  1705. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1706. subscribersTimes[i] = time.Now()
  1707. goto TriggerSuccess
  1708. }
  1709. }
  1710. }
  1711. TriggerSuccess:
  1712. subscribersMutexes[i].Unlock()
  1713. }
  1714. subscribersTimeMutexes[i].Unlock()
  1715. },
  1716. })
  1717. }
  1718. // 32
  1719. if topic == masterConfig.TopicOfTprouteplan &&
  1720. (len(masterConfig.RuleOfTprouteplan1) > 0 ||
  1721. len(masterConfig.RuleOfTprouteplan2) > 0 ||
  1722. len(masterConfig.RuleOfTprouteplan3) > 0) {
  1723. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1724. Node: commonConfig.RosNode,
  1725. Topic: topic,
  1726. Callback: func(data *pjisuv_msgs.RoutePlan) {
  1727. subscribersTimeMutexes[i].Lock()
  1728. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1729. subscribersMutexes[i].Lock()
  1730. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1731. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1732. faultLabel := ""
  1733. if len(masterConfig.RuleOfTprouteplan1) > 0 {
  1734. for _, f := range masterConfig.RuleOfTprouteplan1 {
  1735. faultLabel = f(data)
  1736. if faultLabel != "" {
  1737. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1738. subscribersTimes[i] = time.Now()
  1739. goto TriggerSuccess
  1740. }
  1741. }
  1742. }
  1743. if len(masterConfig.RuleOfTprouteplan2) > 0 {
  1744. for _, f := range masterConfig.RuleOfTprouteplan2 {
  1745. faultLabel = f(data, &pjisuvParam)
  1746. if faultLabel != "" {
  1747. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1748. subscribersTimes[i] = time.Now()
  1749. goto TriggerSuccess
  1750. }
  1751. }
  1752. }
  1753. if len(masterConfig.RuleOfTprouteplan3) > 0 {
  1754. for _, f := range masterConfig.RuleOfTprouteplan3 {
  1755. faultLabel = f(shareVars, data)
  1756. if faultLabel != "" {
  1757. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1758. subscribersTimes[i] = time.Now()
  1759. goto TriggerSuccess
  1760. }
  1761. }
  1762. }
  1763. TriggerSuccess:
  1764. subscribersMutexes[i].Unlock()
  1765. }
  1766. subscribersTimeMutexes[i].Unlock()
  1767. },
  1768. })
  1769. }
  1770. // 33
  1771. if topic == masterConfig.TopicOfTrajectoryDisplay &&
  1772. (len(masterConfig.RuleOfTrajectoryDisplay1) > 0 ||
  1773. len(masterConfig.RuleOfTrajectoryDisplay2) > 0 ||
  1774. len(masterConfig.RuleOfTrajectoryDisplay3) > 0) {
  1775. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1776. Node: commonConfig.RosNode,
  1777. Topic: topic,
  1778. Callback: func(data *nav_msgs.Path) {
  1779. subscribersTimeMutexes[i].Lock()
  1780. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1781. subscribersMutexes[i].Lock()
  1782. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1783. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1784. faultLabel := ""
  1785. if len(masterConfig.RuleOfTrajectoryDisplay1) > 0 {
  1786. for _, f := range masterConfig.RuleOfTrajectoryDisplay1 {
  1787. faultLabel = f(data)
  1788. if faultLabel != "" {
  1789. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1790. subscribersTimes[i] = time.Now()
  1791. goto TriggerSuccess
  1792. }
  1793. }
  1794. }
  1795. if len(masterConfig.RuleOfTrajectoryDisplay2) > 0 {
  1796. for _, f := range masterConfig.RuleOfTrajectoryDisplay2 {
  1797. faultLabel = f(data, &pjisuvParam)
  1798. if faultLabel != "" {
  1799. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1800. subscribersTimes[i] = time.Now()
  1801. goto TriggerSuccess
  1802. }
  1803. }
  1804. }
  1805. if len(masterConfig.RuleOfTrajectoryDisplay3) > 0 {
  1806. for _, f := range masterConfig.RuleOfTrajectoryDisplay3 {
  1807. faultLabel = f(shareVars, data)
  1808. if faultLabel != "" {
  1809. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1810. subscribersTimes[i] = time.Now()
  1811. goto TriggerSuccess
  1812. }
  1813. }
  1814. }
  1815. TriggerSuccess:
  1816. subscribersMutexes[i].Unlock()
  1817. }
  1818. subscribersTimeMutexes[i].Unlock()
  1819. },
  1820. })
  1821. }
  1822. // 34
  1823. if topic == masterConfig.TopicOfUngroundCloudpoints &&
  1824. (len(masterConfig.RuleOfUngroundCloudpoints1) > 0 ||
  1825. len(masterConfig.RuleOfUngroundCloudpoints2) > 0 ||
  1826. len(masterConfig.RuleOfUngroundCloudpoints3) > 0) {
  1827. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1828. Node: commonConfig.RosNode,
  1829. Topic: topic,
  1830. Callback: func(data *sensor_msgs.PointCloud2) {
  1831. subscribersTimeMutexes[i].Lock()
  1832. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1833. subscribersMutexes[i].Lock()
  1834. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1835. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1836. faultLabel := ""
  1837. if len(masterConfig.RuleOfUngroundCloudpoints1) > 0 {
  1838. for _, f := range masterConfig.RuleOfUngroundCloudpoints1 {
  1839. faultLabel = f(data)
  1840. if faultLabel != "" {
  1841. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1842. subscribersTimes[i] = time.Now()
  1843. goto TriggerSuccess
  1844. }
  1845. }
  1846. }
  1847. if len(masterConfig.RuleOfUngroundCloudpoints2) > 0 {
  1848. for _, f := range masterConfig.RuleOfUngroundCloudpoints2 {
  1849. faultLabel = f(data, &pjisuvParam)
  1850. if faultLabel != "" {
  1851. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1852. subscribersTimes[i] = time.Now()
  1853. goto TriggerSuccess
  1854. }
  1855. }
  1856. }
  1857. if len(masterConfig.RuleOfUngroundCloudpoints3) > 0 {
  1858. for _, f := range masterConfig.RuleOfUngroundCloudpoints3 {
  1859. faultLabel = f(shareVars, data)
  1860. if faultLabel != "" {
  1861. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1862. subscribersTimes[i] = time.Now()
  1863. goto TriggerSuccess
  1864. }
  1865. }
  1866. }
  1867. TriggerSuccess:
  1868. subscribersMutexes[i].Unlock()
  1869. }
  1870. subscribersTimeMutexes[i].Unlock()
  1871. },
  1872. })
  1873. }
  1874. // 35
  1875. if topic == masterConfig.TopicOfCameraImage &&
  1876. (len(masterConfig.RuleOfCameraImage1) > 0 ||
  1877. len(masterConfig.RuleOfCameraImage2) > 0 ||
  1878. len(masterConfig.RuleOfCameraImage3) > 0) {
  1879. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1880. Node: commonConfig.RosNode,
  1881. Topic: topic,
  1882. Callback: func(data *sensor_msgs.Image) {
  1883. subscribersTimeMutexes[i].Lock()
  1884. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1885. subscribersMutexes[i].Lock()
  1886. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1887. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1888. faultLabel := ""
  1889. if len(masterConfig.RuleOfCameraImage1) > 0 {
  1890. for _, f := range masterConfig.RuleOfCameraImage1 {
  1891. faultLabel = f(data)
  1892. if faultLabel != "" {
  1893. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1894. subscribersTimes[i] = time.Now()
  1895. goto TriggerSuccess
  1896. }
  1897. }
  1898. }
  1899. if len(masterConfig.RuleOfCameraImage2) > 0 {
  1900. for _, f := range masterConfig.RuleOfCameraImage2 {
  1901. faultLabel = f(data, &pjisuvParam)
  1902. if faultLabel != "" {
  1903. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1904. subscribersTimes[i] = time.Now()
  1905. goto TriggerSuccess
  1906. }
  1907. }
  1908. }
  1909. if len(masterConfig.RuleOfCameraImage3) > 0 {
  1910. for _, f := range masterConfig.RuleOfCameraImage3 {
  1911. faultLabel = f(shareVars, data)
  1912. if faultLabel != "" {
  1913. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1914. subscribersTimes[i] = time.Now()
  1915. goto TriggerSuccess
  1916. }
  1917. }
  1918. }
  1919. TriggerSuccess:
  1920. subscribersMutexes[i].Unlock()
  1921. }
  1922. subscribersTimeMutexes[i].Unlock()
  1923. },
  1924. })
  1925. }
  1926. // 36 有共享变量的订阅者必须被创建
  1927. if topic == masterConfig.TopicOfDataRead {
  1928. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1929. Node: commonConfig.RosNode,
  1930. Topic: topic,
  1931. Callback: func(data *pjisuv_msgs.Retrieval) {
  1932. // 更新共享变量
  1933. mutexOfDataRead.RLock()
  1934. {
  1935. pjisuvParam.NumCountDataReadOfDataRead++
  1936. if pjisuvParam.NumCountDataReadOfDataRead == 10 {
  1937. pjisuvParam.EgoSteeringRealOfDataRead = append(pjisuvParam.EgoSteeringRealOfDataRead, data.ActStrWhAng)
  1938. pjisuvParam.EgoThrottleRealOfDataRead = append(pjisuvParam.EgoThrottleRealOfDataRead, data.AccPed2)
  1939. pjisuvParam.NumCountDataReadOfDataRead = 0
  1940. }
  1941. pjisuvParam.StrgAngleRealValueOfDataRead = data.ActStrWhAng
  1942. }
  1943. mutexOfDataRead.RUnlock()
  1944. subscribersTimeMutexes[i].Lock()
  1945. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1946. subscribersMutexes[i].Lock()
  1947. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1948. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1949. faultLabel := ""
  1950. if len(masterConfig.RuleOfDataRead1) > 0 {
  1951. for _, f := range masterConfig.RuleOfDataRead1 {
  1952. faultLabel = f(data)
  1953. if faultLabel != "" {
  1954. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1955. subscribersTimes[i] = time.Now()
  1956. goto TriggerSuccess
  1957. }
  1958. }
  1959. }
  1960. if len(masterConfig.RuleOfDataRead2) > 0 {
  1961. for _, f := range masterConfig.RuleOfDataRead2 {
  1962. faultLabel = f(data, &pjisuvParam)
  1963. if faultLabel != "" {
  1964. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1965. subscribersTimes[i] = time.Now()
  1966. goto TriggerSuccess
  1967. }
  1968. }
  1969. }
  1970. if len(masterConfig.RuleOfDataRead3) > 0 {
  1971. for _, f := range masterConfig.RuleOfDataRead3 {
  1972. faultLabel = f(shareVars, data)
  1973. if faultLabel != "" {
  1974. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1975. subscribersTimes[i] = time.Now()
  1976. goto TriggerSuccess
  1977. }
  1978. }
  1979. }
  1980. TriggerSuccess:
  1981. subscribersMutexes[i].Unlock()
  1982. }
  1983. subscribersTimeMutexes[i].Unlock()
  1984. },
  1985. })
  1986. }
  1987. // 37
  1988. if topic == masterConfig.TopicOfPjiGps &&
  1989. (len(masterConfig.RuleOfPjiGps1) > 0 ||
  1990. len(masterConfig.RuleOfPjiGps2) > 0 ||
  1991. len(masterConfig.RuleOfPjiGps3) > 0) {
  1992. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1993. Node: commonConfig.RosNode,
  1994. Topic: topic,
  1995. Callback: func(data *pjisuv_msgs.PerceptionLocalization) {
  1996. subscribersTimeMutexes[i].Lock()
  1997. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1998. subscribersMutexes[i].Lock()
  1999. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  2000. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  2001. faultLabel := ""
  2002. if len(masterConfig.RuleOfPjiGps1) > 0 {
  2003. for _, f := range masterConfig.RuleOfPjiGps1 {
  2004. faultLabel = f(data)
  2005. if faultLabel != "" {
  2006. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2007. subscribersTimes[i] = time.Now()
  2008. goto TriggerSuccess
  2009. }
  2010. }
  2011. }
  2012. if len(masterConfig.RuleOfPjiGps2) > 0 {
  2013. for _, f := range masterConfig.RuleOfPjiGps2 {
  2014. faultLabel = f(data, &pjisuvParam)
  2015. if faultLabel != "" {
  2016. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2017. subscribersTimes[i] = time.Now()
  2018. goto TriggerSuccess
  2019. }
  2020. }
  2021. }
  2022. if len(masterConfig.RuleOfPjiGps3) > 0 {
  2023. for _, f := range masterConfig.RuleOfPjiGps3 {
  2024. faultLabel = f(shareVars, data)
  2025. if faultLabel != "" {
  2026. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2027. subscribersTimes[i] = time.Now()
  2028. goto TriggerSuccess
  2029. }
  2030. }
  2031. }
  2032. TriggerSuccess:
  2033. subscribersMutexes[i].Unlock()
  2034. }
  2035. subscribersTimeMutexes[i].Unlock()
  2036. },
  2037. })
  2038. }
  2039. // 39
  2040. if topic == masterConfig.TopicOfPjVehicleFdbPub &&
  2041. (len(masterConfig.RuleOfPjVehicleFdbPub1) > 0 ||
  2042. len(masterConfig.RuleOfPjVehicleFdbPub2) > 0 ||
  2043. len(masterConfig.RuleOfPjVehicleFdbPub3) > 0) {
  2044. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  2045. Node: commonConfig.RosNode,
  2046. Topic: topic,
  2047. Callback: func(data *pjisuv_msgs.VehicleFdb) {
  2048. shareVars.Store("Automode", data.Automode)
  2049. subscribersTimeMutexes[i].Lock()
  2050. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  2051. subscribersMutexes[i].Lock()
  2052. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  2053. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  2054. faultLabel := ""
  2055. if len(masterConfig.RuleOfPjVehicleFdbPub1) > 0 {
  2056. for _, f := range masterConfig.RuleOfPjVehicleFdbPub1 {
  2057. faultLabel = f(data)
  2058. if faultLabel != "" {
  2059. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2060. subscribersTimes[i] = time.Now()
  2061. goto TriggerSuccess
  2062. }
  2063. }
  2064. }
  2065. if len(masterConfig.RuleOfPjVehicleFdbPub2) > 0 {
  2066. for _, f := range masterConfig.RuleOfPjVehicleFdbPub2 {
  2067. faultLabel = f(data, &pjisuvParam)
  2068. if faultLabel != "" {
  2069. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2070. subscribersTimes[i] = time.Now()
  2071. goto TriggerSuccess
  2072. }
  2073. }
  2074. }
  2075. if len(masterConfig.RuleOfPjVehicleFdbPub3) > 0 {
  2076. for _, f := range masterConfig.RuleOfPjVehicleFdbPub3 {
  2077. faultLabel = f(shareVars, data)
  2078. if faultLabel != "" {
  2079. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2080. subscribersTimes[i] = time.Now()
  2081. goto TriggerSuccess
  2082. }
  2083. }
  2084. }
  2085. TriggerSuccess:
  2086. subscribersMutexes[i].Unlock()
  2087. }
  2088. subscribersTimeMutexes[i].Unlock()
  2089. },
  2090. })
  2091. }
  2092. // 40 有共享变量的订阅者必须被创建
  2093. if topic == masterConfig.TopicOfEndPointMessage {
  2094. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  2095. Node: commonConfig.RosNode,
  2096. Topic: topic,
  2097. Callback: func(data *geometry_msgs.Point) {
  2098. subscribersTimeMutexes[i].Lock()
  2099. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  2100. subscribersMutexes[i].Lock()
  2101. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  2102. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  2103. faultLabel := ""
  2104. if len(masterConfig.RuleOfEndPointMessage1) > 0 {
  2105. for _, f := range masterConfig.RuleOfEndPointMessage1 {
  2106. faultLabel = f(data)
  2107. if faultLabel != "" {
  2108. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2109. subscribersTimes[i] = time.Now()
  2110. goto TriggerSuccess
  2111. }
  2112. }
  2113. }
  2114. if len(masterConfig.RuleOfEndPointMessage2) > 0 {
  2115. for _, f := range masterConfig.RuleOfEndPointMessage2 {
  2116. faultLabel = f(data, &pjisuvParam)
  2117. if faultLabel != "" {
  2118. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2119. subscribersTimes[i] = time.Now()
  2120. goto TriggerSuccess
  2121. }
  2122. }
  2123. }
  2124. if len(masterConfig.RuleOfEndPointMessage3) > 0 {
  2125. for _, f := range masterConfig.RuleOfEndPointMessage3 {
  2126. faultLabel = f(shareVars, data)
  2127. if faultLabel != "" {
  2128. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  2129. subscribersTimes[i] = time.Now()
  2130. goto TriggerSuccess
  2131. }
  2132. }
  2133. }
  2134. TriggerSuccess:
  2135. subscribersMutexes[i].Unlock()
  2136. }
  2137. subscribersTimeMutexes[i].Unlock()
  2138. // 更新共享变量
  2139. shareVars.Store("EndPointX", data.X)
  2140. shareVars.Store("EndPointY", data.Y)
  2141. },
  2142. })
  2143. }
  2144. if err != nil {
  2145. c_log.GlobalLogger.Info("创建订阅者报错,可能由于节点未启动,再次尝试:", err)
  2146. time.Sleep(time.Duration(2) * time.Second)
  2147. continue
  2148. } else {
  2149. break
  2150. }
  2151. }
  2152. }
  2153. select {
  2154. case signal := <-service.ChannelKillWindowProducer:
  2155. if signal == 1 {
  2156. commonConfig.RosNode.Close()
  2157. service.AddKillTimes("3")
  2158. return
  2159. }
  2160. }
  2161. }
  2162. func saveTimeWindow(faultLabel string, faultHappenTime string, lastTimeWindow *commonEntity.TimeWindow) {
  2163. saveTimeWindowMutex.Lock()
  2164. defer saveTimeWindowMutex.Unlock()
  2165. masterTopics, slaveTopics := getTopicsOfNode(faultLabel)
  2166. if lastTimeWindow == nil || util.TimeCustom1GreaterTimeCustom2(faultHappenTime, lastTimeWindow.TimeWindowEnd) { // 如果是不在旧故障窗口内,添加一个新窗口
  2167. exceptBegin := util.TimeCustomChange(faultHappenTime, -commonConfig.PlatformConfig.TaskBeforeTime)
  2168. finalTimeWindowBegin := ""
  2169. if util.TimeCustom1LessEqualThanTimeCustom2(exceptBegin, latestTimeWindowEnd) { // 窗口最早时间不能早于上一个窗口结束时间
  2170. finalTimeWindowBegin = latestTimeWindowEnd
  2171. } else {
  2172. finalTimeWindowBegin = exceptBegin
  2173. }
  2174. latestTimeWindowEnd = util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime)
  2175. newTimeWindow := commonEntity.TimeWindow{
  2176. FaultTime: faultHappenTime,
  2177. TimeWindowBegin: finalTimeWindowBegin,
  2178. TimeWindowEnd: latestTimeWindowEnd,
  2179. Length: util.CalculateDifferenceOfTimeCustom(finalTimeWindowBegin, latestTimeWindowEnd),
  2180. Labels: []string{faultLabel},
  2181. MasterTopics: masterTopics,
  2182. SlaveTopics: slaveTopics,
  2183. }
  2184. c_log.GlobalLogger.Infof("不在旧故障窗口内,向生产者队列添加一个新窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", newTimeWindow.Labels, newTimeWindow.FaultTime, newTimeWindow.Length)
  2185. commonEntity.AddTimeWindowToTimeWindowProducerQueue(newTimeWindow)
  2186. } else { // 如果在旧故障窗口内
  2187. commonEntity.TimeWindowProducerQueueMutex.RLock()
  2188. defer commonEntity.TimeWindowProducerQueueMutex.RUnlock()
  2189. // 更新故障窗口end时间
  2190. expectEnd := util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime) // 窗口期望关闭时间是触发时间加上后置时间
  2191. expectLength := util.CalculateDifferenceOfTimeCustom(lastTimeWindow.TimeWindowBegin, expectEnd)
  2192. if expectLength < commonConfig.PlatformConfig.TaskMaxTime {
  2193. latestTimeWindowEnd = expectEnd
  2194. lastTimeWindow.TimeWindowEnd = latestTimeWindowEnd
  2195. lastTimeWindow.Length = util.CalculateDifferenceOfTimeCustom(lastTimeWindow.TimeWindowBegin, lastTimeWindow.TimeWindowEnd)
  2196. }
  2197. // 更新label
  2198. labels := lastTimeWindow.Labels
  2199. lastTimeWindow.Labels = util.AppendIfNotExists(labels, faultLabel)
  2200. // 更新 topic
  2201. sourceMasterTopics := lastTimeWindow.MasterTopics
  2202. lastTimeWindow.MasterTopics = util.MergeSlice(sourceMasterTopics, masterTopics)
  2203. sourceSlaveTopics := lastTimeWindow.SlaveTopics
  2204. lastTimeWindow.SlaveTopics = util.MergeSlice(sourceSlaveTopics, slaveTopics)
  2205. c_log.GlobalLogger.Infof("在旧故障窗口内,更新生产者队列最新的窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", lastTimeWindow.Labels, lastTimeWindow.FaultTime, lastTimeWindow.Length)
  2206. }
  2207. }
  2208. func getTopicsOfNode(faultLabel string) (masterTopics []string, slaveTopics []string) {
  2209. // 获取所有需要采集的topic
  2210. var faultCodeTopics []string
  2211. for _, code := range commonConfig.CloudConfig.Triggers {
  2212. if code.Label == faultLabel {
  2213. faultCodeTopics = code.Topics
  2214. }
  2215. }
  2216. // 根据不同节点采集的topic进行分配采集
  2217. for _, acceptTopic := range faultCodeTopics {
  2218. for _, host := range commonConfig.CloudConfig.Hosts {
  2219. for _, topic := range host.Topics {
  2220. if host.Name == commonConfig.CloudConfig.Hosts[0].Name && acceptTopic == topic {
  2221. masterTopics = append(masterTopics, acceptTopic)
  2222. }
  2223. if host.Name == commonConfig.CloudConfig.Hosts[1].Name && acceptTopic == topic {
  2224. slaveTopics = append(slaveTopics, acceptTopic)
  2225. }
  2226. }
  2227. }
  2228. }
  2229. return masterTopics, slaveTopics
  2230. }