produce_window.go 73 KB

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