produce_window.go 74 KB

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