produce_window.go 72 KB

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