produce_window.go 74 KB

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