produce_window.go 73 KB

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