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