produce_window.go 84 KB

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