produce_window.go 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090
  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. objTypeDicOfTpperception[obj.Id] = obj.Type
  1443. objSpeedDicOfTpperception[obj.Id] = math.Pow(math.Pow(float64(obj.Vxabs), 2)+math.Pow(float64(obj.Vyabs), 2), 0.5)
  1444. }
  1445. shareVars.Store("ObjDicOfTpperception", ObjDicOfTpperception)
  1446. shareVars.Store("ObjTypeDicOfTpperception", objTypeDicOfTpperception)
  1447. shareVars.Store("ObjSpeedDicOfTpperception", objSpeedDicOfTpperception)
  1448. },
  1449. })
  1450. if err == nil {
  1451. create = true
  1452. }
  1453. }
  1454. // 31
  1455. if topic == masterConfig.TopicOfTpperceptionVis &&
  1456. (len(masterConfig.RuleOfTpperceptionVis1) > 0 ||
  1457. len(masterConfig.RuleOfTpperceptionVis3) > 0) {
  1458. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1459. Node: commonConfig.RosNode,
  1460. Topic: topic,
  1461. Callback: func(data *visualization_msgs.MarkerArray) {
  1462. subscribersTimeMutexes[i].Lock()
  1463. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1464. subscribersMutexes[i].Lock()
  1465. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1466. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1467. faultLabel := ""
  1468. if len(masterConfig.RuleOfTpperceptionVis1) > 0 {
  1469. for _, f := range masterConfig.RuleOfTpperceptionVis1 {
  1470. faultLabel = f(data)
  1471. if faultLabel != "" {
  1472. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1473. subscribersTimes[i] = time.Now()
  1474. goto TriggerSuccess
  1475. }
  1476. }
  1477. }
  1478. if len(masterConfig.RuleOfTpperceptionVis3) > 0 {
  1479. for _, f := range masterConfig.RuleOfTpperceptionVis3 {
  1480. faultLabel = f(shareVars, data)
  1481. if faultLabel != "" {
  1482. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1483. subscribersTimes[i] = time.Now()
  1484. goto TriggerSuccess
  1485. }
  1486. }
  1487. }
  1488. TriggerSuccess:
  1489. subscribersMutexes[i].Unlock()
  1490. }
  1491. subscribersTimeMutexes[i].Unlock()
  1492. },
  1493. })
  1494. if err == nil {
  1495. create = true
  1496. }
  1497. }
  1498. // 32
  1499. if topic == masterConfig.TopicOfTprouteplan &&
  1500. (len(masterConfig.RuleOfTprouteplan1) > 0 ||
  1501. len(masterConfig.RuleOfTprouteplan3) > 0) {
  1502. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1503. Node: commonConfig.RosNode,
  1504. Topic: topic,
  1505. Callback: func(data *pjisuv_msgs.RoutePlan) {
  1506. subscribersTimeMutexes[i].Lock()
  1507. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1508. subscribersMutexes[i].Lock()
  1509. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1510. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1511. faultLabel := ""
  1512. if len(masterConfig.RuleOfTprouteplan1) > 0 {
  1513. for _, f := range masterConfig.RuleOfTprouteplan1 {
  1514. faultLabel = f(data)
  1515. if faultLabel != "" {
  1516. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1517. subscribersTimes[i] = time.Now()
  1518. goto TriggerSuccess
  1519. }
  1520. }
  1521. }
  1522. if len(masterConfig.RuleOfTprouteplan3) > 0 {
  1523. for _, f := range masterConfig.RuleOfTprouteplan3 {
  1524. faultLabel = f(shareVars, data)
  1525. if faultLabel != "" {
  1526. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1527. subscribersTimes[i] = time.Now()
  1528. goto TriggerSuccess
  1529. }
  1530. }
  1531. }
  1532. TriggerSuccess:
  1533. subscribersMutexes[i].Unlock()
  1534. }
  1535. subscribersTimeMutexes[i].Unlock()
  1536. },
  1537. })
  1538. if err == nil {
  1539. create = true
  1540. }
  1541. }
  1542. // 33
  1543. if topic == masterConfig.TopicOfTrajectoryDisplay &&
  1544. (len(masterConfig.RuleOfTrajectoryDisplay1) > 0 ||
  1545. len(masterConfig.RuleOfTrajectoryDisplay3) > 0) {
  1546. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1547. Node: commonConfig.RosNode,
  1548. Topic: topic,
  1549. Callback: func(data *nav_msgs.Path) {
  1550. subscribersTimeMutexes[i].Lock()
  1551. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1552. subscribersMutexes[i].Lock()
  1553. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1554. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1555. faultLabel := ""
  1556. if len(masterConfig.RuleOfTrajectoryDisplay1) > 0 {
  1557. for _, f := range masterConfig.RuleOfTrajectoryDisplay1 {
  1558. faultLabel = f(data)
  1559. if faultLabel != "" {
  1560. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1561. subscribersTimes[i] = time.Now()
  1562. goto TriggerSuccess
  1563. }
  1564. }
  1565. }
  1566. if len(masterConfig.RuleOfTrajectoryDisplay3) > 0 {
  1567. for _, f := range masterConfig.RuleOfTrajectoryDisplay3 {
  1568. faultLabel = f(shareVars, data)
  1569. if faultLabel != "" {
  1570. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1571. subscribersTimes[i] = time.Now()
  1572. goto TriggerSuccess
  1573. }
  1574. }
  1575. }
  1576. TriggerSuccess:
  1577. subscribersMutexes[i].Unlock()
  1578. }
  1579. subscribersTimeMutexes[i].Unlock()
  1580. },
  1581. })
  1582. if err == nil {
  1583. create = true
  1584. }
  1585. }
  1586. // 34
  1587. if topic == masterConfig.TopicOfUngroundCloudpoints &&
  1588. (len(masterConfig.RuleOfUngroundCloudpoints1) > 0 ||
  1589. len(masterConfig.RuleOfUngroundCloudpoints3) > 0) {
  1590. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1591. Node: commonConfig.RosNode,
  1592. Topic: topic,
  1593. Callback: func(data *sensor_msgs.PointCloud2) {
  1594. subscribersTimeMutexes[i].Lock()
  1595. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1596. subscribersMutexes[i].Lock()
  1597. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1598. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1599. faultLabel := ""
  1600. if len(masterConfig.RuleOfUngroundCloudpoints1) > 0 {
  1601. for _, f := range masterConfig.RuleOfUngroundCloudpoints1 {
  1602. faultLabel = f(data)
  1603. if faultLabel != "" {
  1604. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1605. subscribersTimes[i] = time.Now()
  1606. goto TriggerSuccess
  1607. }
  1608. }
  1609. }
  1610. if len(masterConfig.RuleOfUngroundCloudpoints3) > 0 {
  1611. for _, f := range masterConfig.RuleOfUngroundCloudpoints3 {
  1612. faultLabel = f(shareVars, data)
  1613. if faultLabel != "" {
  1614. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1615. subscribersTimes[i] = time.Now()
  1616. goto TriggerSuccess
  1617. }
  1618. }
  1619. }
  1620. TriggerSuccess:
  1621. subscribersMutexes[i].Unlock()
  1622. }
  1623. subscribersTimeMutexes[i].Unlock()
  1624. },
  1625. })
  1626. if err == nil {
  1627. create = true
  1628. }
  1629. }
  1630. // 35
  1631. if topic == masterConfig.TopicOfCameraImage &&
  1632. (len(masterConfig.RuleOfCameraImage1) > 0 ||
  1633. len(masterConfig.RuleOfCameraImage3) > 0) {
  1634. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1635. Node: commonConfig.RosNode,
  1636. Topic: topic,
  1637. Callback: func(data *sensor_msgs.Image) {
  1638. subscribersTimeMutexes[i].Lock()
  1639. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1640. subscribersMutexes[i].Lock()
  1641. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1642. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1643. faultLabel := ""
  1644. if len(masterConfig.RuleOfCameraImage1) > 0 {
  1645. for _, f := range masterConfig.RuleOfCameraImage1 {
  1646. faultLabel = f(data)
  1647. if faultLabel != "" {
  1648. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1649. subscribersTimes[i] = time.Now()
  1650. goto TriggerSuccess
  1651. }
  1652. }
  1653. }
  1654. if len(masterConfig.RuleOfCameraImage3) > 0 {
  1655. for _, f := range masterConfig.RuleOfCameraImage3 {
  1656. faultLabel = f(shareVars, data)
  1657. if faultLabel != "" {
  1658. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1659. subscribersTimes[i] = time.Now()
  1660. goto TriggerSuccess
  1661. }
  1662. }
  1663. }
  1664. TriggerSuccess:
  1665. subscribersMutexes[i].Unlock()
  1666. }
  1667. subscribersTimeMutexes[i].Unlock()
  1668. },
  1669. })
  1670. if err == nil {
  1671. create = true
  1672. }
  1673. }
  1674. // 36 有共享变量的订阅者必须被创建
  1675. if topic == masterConfig.TopicOfDataRead {
  1676. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1677. Node: commonConfig.RosNode,
  1678. Topic: topic,
  1679. Callback: func(data *pjisuv_msgs.Retrieval) {
  1680. subscribersTimeMutexes[i].Lock()
  1681. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1682. subscribersMutexes[i].Lock()
  1683. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1684. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1685. faultLabel := ""
  1686. if len(masterConfig.RuleOfDataRead1) > 0 {
  1687. for _, f := range masterConfig.RuleOfDataRead1 {
  1688. faultLabel = f(data)
  1689. if faultLabel != "" {
  1690. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1691. subscribersTimes[i] = time.Now()
  1692. goto TriggerSuccess
  1693. }
  1694. }
  1695. }
  1696. if len(masterConfig.RuleOfDataRead3) > 0 {
  1697. for _, f := range masterConfig.RuleOfDataRead3 {
  1698. faultLabel = f(shareVars, data)
  1699. if faultLabel != "" {
  1700. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1701. subscribersTimes[i] = time.Now()
  1702. goto TriggerSuccess
  1703. }
  1704. }
  1705. }
  1706. TriggerSuccess:
  1707. subscribersMutexes[i].Unlock()
  1708. }
  1709. subscribersTimeMutexes[i].Unlock()
  1710. // 更新共享变量
  1711. numCountDataReadOfDataRead++
  1712. if numCountDataReadOfDataRead == 10 {
  1713. egoSteeringRealOfDataRead = append(egoSteeringRealOfDataRead, data.ActStrWhAng)
  1714. egoThrottleRealOfDataRead = append(egoThrottleRealOfDataRead, data.AccPed2)
  1715. numCountDataReadOfDataRead = 0
  1716. }
  1717. GearPosSlice = append(GearPosSlice, data.GearPos)
  1718. shareVars.Store("NumCountDataReadOfDataRead", numCountDataReadOfDataRead)
  1719. shareVars.Store("EgoSteeringRealOfDataRead", egoSteeringRealOfDataRead)
  1720. shareVars.Store("EgoThrottleRealOfDataRead", egoThrottleRealOfDataRead)
  1721. shareVars.Store("ActStrWhAngOfDataRead", data.ActStrWhAng)
  1722. shareVars.Store("GearPosSlice", GearPosSlice)
  1723. },
  1724. })
  1725. if err == nil {
  1726. create = true
  1727. }
  1728. }
  1729. // 37
  1730. if topic == masterConfig.TopicOfPjiGps &&
  1731. (len(masterConfig.RuleOfPjiGps1) > 0 ||
  1732. len(masterConfig.RuleOfPjiGps3) > 0) {
  1733. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1734. Node: commonConfig.RosNode,
  1735. Topic: topic,
  1736. Callback: func(data *pjisuv_msgs.PerceptionLocalization) {
  1737. subscribersTimeMutexes[i].Lock()
  1738. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1739. subscribersMutexes[i].Lock()
  1740. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1741. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1742. faultLabel := ""
  1743. if len(masterConfig.RuleOfPjiGps1) > 0 {
  1744. for _, f := range masterConfig.RuleOfPjiGps1 {
  1745. faultLabel = f(data)
  1746. if faultLabel != "" {
  1747. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1748. subscribersTimes[i] = time.Now()
  1749. goto TriggerSuccess
  1750. }
  1751. }
  1752. }
  1753. if len(masterConfig.RuleOfPjiGps3) > 0 {
  1754. for _, f := range masterConfig.RuleOfPjiGps3 {
  1755. faultLabel = f(shareVars, data)
  1756. if faultLabel != "" {
  1757. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1758. subscribersTimes[i] = time.Now()
  1759. goto TriggerSuccess
  1760. }
  1761. }
  1762. }
  1763. TriggerSuccess:
  1764. subscribersMutexes[i].Unlock()
  1765. }
  1766. subscribersTimeMutexes[i].Unlock()
  1767. },
  1768. })
  1769. if err == nil {
  1770. create = true
  1771. }
  1772. }
  1773. // 39 有共享变量的订阅者必须被创建
  1774. if topic == masterConfig.TopicOfPjVehicleFdbPub {
  1775. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1776. Node: commonConfig.RosNode,
  1777. Topic: topic,
  1778. Callback: func(data *pjisuv_msgs.VehicleFdb) {
  1779. subscribersTimeMutexes[i].Lock()
  1780. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1781. subscribersMutexes[i].Lock()
  1782. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1783. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1784. faultLabel := ""
  1785. if len(masterConfig.RuleOfPjVehicleFdbPub1) > 0 {
  1786. for _, f := range masterConfig.RuleOfPjVehicleFdbPub1 {
  1787. faultLabel = f(data)
  1788. if faultLabel != "" {
  1789. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1790. subscribersTimes[i] = time.Now()
  1791. goto TriggerSuccess
  1792. }
  1793. }
  1794. }
  1795. if len(masterConfig.RuleOfPjVehicleFdbPub3) > 0 {
  1796. for _, f := range masterConfig.RuleOfPjVehicleFdbPub3 {
  1797. faultLabel = f(shareVars, data)
  1798. if faultLabel != "" {
  1799. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1800. subscribersTimes[i] = time.Now()
  1801. goto TriggerSuccess
  1802. }
  1803. }
  1804. }
  1805. TriggerSuccess:
  1806. subscribersMutexes[i].Unlock()
  1807. }
  1808. subscribersTimeMutexes[i].Unlock()
  1809. // 更新共享变量
  1810. shareVars.Store("AutomodeOfPjVehicleFdbPub", data.Automode)
  1811. },
  1812. })
  1813. if err == nil {
  1814. create = true
  1815. }
  1816. }
  1817. // 40 有共享变量的订阅者必须被创建
  1818. if topic == masterConfig.TopicOfEndPointMessage {
  1819. subscribers[i], err = goroslib.NewSubscriber(goroslib.SubscriberConf{
  1820. Node: commonConfig.RosNode,
  1821. Topic: topic,
  1822. Callback: func(data *geometry_msgs.Point) {
  1823. subscribersTimeMutexes[i].Lock()
  1824. if time.Since(subscribersTimes[i]).Seconds() > triggerInterval {
  1825. subscribersMutexes[i].Lock()
  1826. faultHappenTime := util.GetNowTimeCustom() // 获取当前故障发生时间
  1827. lastTimeWindow := commonEntity.GetLastTimeWindow() // 获取最后一个时间窗口
  1828. faultLabel := ""
  1829. if len(masterConfig.RuleOfEndPointMessage1) > 0 {
  1830. for _, f := range masterConfig.RuleOfEndPointMessage1 {
  1831. faultLabel = f(data)
  1832. if faultLabel != "" {
  1833. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1834. subscribersTimes[i] = time.Now()
  1835. goto TriggerSuccess
  1836. }
  1837. }
  1838. }
  1839. if len(masterConfig.RuleOfEndPointMessage3) > 0 {
  1840. for _, f := range masterConfig.RuleOfEndPointMessage3 {
  1841. faultLabel = f(shareVars, data)
  1842. if faultLabel != "" {
  1843. saveTimeWindow(faultLabel, faultHappenTime, lastTimeWindow)
  1844. subscribersTimes[i] = time.Now()
  1845. goto TriggerSuccess
  1846. }
  1847. }
  1848. }
  1849. TriggerSuccess:
  1850. subscribersMutexes[i].Unlock()
  1851. }
  1852. subscribersTimeMutexes[i].Unlock()
  1853. // 更新共享变量
  1854. shareVars.Store("EndPointX", data.X)
  1855. shareVars.Store("EndPointY", data.Y)
  1856. },
  1857. })
  1858. if err == nil {
  1859. create = true
  1860. }
  1861. }
  1862. if err != nil {
  1863. c_log.GlobalLogger.Infof("创建订阅者报错,可能由于节点未启动,再次尝试【%v】", err)
  1864. time.Sleep(time.Duration(2) * time.Second)
  1865. continue
  1866. } else {
  1867. if create {
  1868. c_log.GlobalLogger.Infof("创建订阅者订阅话题【%v】", topic)
  1869. }
  1870. break
  1871. }
  1872. }
  1873. }
  1874. c_log.GlobalLogger.Infof("全部订阅者创建完成。")
  1875. select {
  1876. case signal := <-service.ChannelKillWindowProducer:
  1877. if signal == 1 {
  1878. commonConfig.RosNode.Close()
  1879. service.AddKillTimes("3")
  1880. return
  1881. }
  1882. }
  1883. }
  1884. func saveTimeWindow(faultLabel string, faultHappenTime string, lastTimeWindow *commonEntity.TimeWindow) {
  1885. saveTimeWindowMutex.Lock()
  1886. defer saveTimeWindowMutex.Unlock()
  1887. masterTopics, slaveTopics := getTopicsOfNode(faultLabel)
  1888. if lastTimeWindow == nil || util.TimeCustom1GreaterTimeCustom2(faultHappenTime, lastTimeWindow.TimeWindowEnd) { // 如果是不在旧故障窗口内,添加一个新窗口
  1889. exceptBegin := util.TimeCustomChange(faultHappenTime, -commonConfig.PlatformConfig.TaskBeforeTime)
  1890. finalTimeWindowBegin := ""
  1891. if util.TimeCustom1LessEqualThanTimeCustom2(exceptBegin, latestTimeWindowEnd) { // 窗口最早时间不能早于上一个窗口结束时间
  1892. finalTimeWindowBegin = latestTimeWindowEnd
  1893. } else {
  1894. finalTimeWindowBegin = exceptBegin
  1895. }
  1896. latestTimeWindowEnd = util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime)
  1897. newTimeWindow := commonEntity.TimeWindow{
  1898. FaultTime: faultHappenTime,
  1899. TimeWindowBegin: finalTimeWindowBegin,
  1900. TimeWindowEnd: latestTimeWindowEnd,
  1901. Length: util.CalculateDifferenceOfTimeCustom(finalTimeWindowBegin, latestTimeWindowEnd),
  1902. Labels: []string{faultLabel},
  1903. MasterTopics: masterTopics,
  1904. SlaveTopics: slaveTopics,
  1905. }
  1906. c_log.GlobalLogger.Infof("不在旧故障窗口内,向生产者队列添加一个新窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", newTimeWindow.Labels, newTimeWindow.FaultTime, newTimeWindow.Length)
  1907. commonEntity.AddTimeWindowToTimeWindowProducerQueue(newTimeWindow)
  1908. } else { // 如果在旧故障窗口内
  1909. commonEntity.TimeWindowProducerQueueMutex.RLock()
  1910. defer commonEntity.TimeWindowProducerQueueMutex.RUnlock()
  1911. // 更新故障窗口end时间
  1912. expectEnd := util.TimeCustomChange(faultHappenTime, commonConfig.PlatformConfig.TaskAfterTime) // 窗口期望关闭时间是触发时间加上后置时间
  1913. expectLength := util.CalculateDifferenceOfTimeCustom(lastTimeWindow.TimeWindowBegin, expectEnd)
  1914. if expectLength < commonConfig.PlatformConfig.TaskMaxTime {
  1915. latestTimeWindowEnd = expectEnd
  1916. lastTimeWindow.TimeWindowEnd = latestTimeWindowEnd
  1917. lastTimeWindow.Length = util.CalculateDifferenceOfTimeCustom(lastTimeWindow.TimeWindowBegin, lastTimeWindow.TimeWindowEnd)
  1918. }
  1919. // 更新label
  1920. labels := lastTimeWindow.Labels
  1921. lastTimeWindow.Labels = util.AppendIfNotExists(labels, faultLabel)
  1922. // 更新 topic
  1923. sourceMasterTopics := lastTimeWindow.MasterTopics
  1924. lastTimeWindow.MasterTopics = util.MergeSlice(sourceMasterTopics, masterTopics)
  1925. sourceSlaveTopics := lastTimeWindow.SlaveTopics
  1926. lastTimeWindow.SlaveTopics = util.MergeSlice(sourceSlaveTopics, slaveTopics)
  1927. c_log.GlobalLogger.Infof("在旧故障窗口内,更新生产者队列最新的窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", lastTimeWindow.Labels, lastTimeWindow.FaultTime, lastTimeWindow.Length)
  1928. }
  1929. }
  1930. func getTopicsOfNode(faultLabel string) (masterTopics []string, slaveTopics []string) {
  1931. // 获取所有需要采集的topic
  1932. var faultCodeTopics []string
  1933. for _, code := range commonConfig.CloudConfig.Triggers {
  1934. if code.Label == faultLabel {
  1935. faultCodeTopics = code.Topics
  1936. }
  1937. }
  1938. // 根据不同节点采集的topic进行分配采集
  1939. for _, acceptTopic := range faultCodeTopics {
  1940. for _, host := range commonConfig.CloudConfig.Hosts {
  1941. for _, topic := range host.Topics {
  1942. if host.Name == commonConfig.CloudConfig.Hosts[0].Name && acceptTopic == topic {
  1943. masterTopics = append(masterTopics, acceptTopic)
  1944. }
  1945. if host.Name == commonConfig.CloudConfig.Hosts[1].Name && acceptTopic == topic {
  1946. slaveTopics = append(slaveTopics, acceptTopic)
  1947. }
  1948. }
  1949. }
  1950. }
  1951. return masterTopics, slaveTopics
  1952. }
  1953. func isPointInPolygon(p Point, vertices []Point) bool {
  1954. intersections := 0
  1955. for i := 0; i < len(vertices); i++ {
  1956. j := (i + 1) % len(vertices)
  1957. if rayIntersectsSegment(p, vertices[i], vertices[j]) {
  1958. intersections++
  1959. }
  1960. }
  1961. return !(intersections%2 == 1)
  1962. }
  1963. func rayIntersectsSegment(p, p1, p2 Point) bool {
  1964. if p1.y > p2.y {
  1965. p1, p2 = p2, p1
  1966. }
  1967. if p.y == p1.y || p.y == p2.y {
  1968. p.y += 0.0001
  1969. }
  1970. if p.y < p1.y || p.y > p2.y {
  1971. return false
  1972. }
  1973. if p.x > max(p1.x, p2.x) {
  1974. return false
  1975. }
  1976. if p.x < min(p1.x, p2.x) {
  1977. return true
  1978. }
  1979. blueSlope := (p.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y) + p1.x
  1980. return p.x < blueSlope
  1981. }
  1982. func min(a, b float64) float64 {
  1983. if a < b {
  1984. return a
  1985. }
  1986. return b
  1987. }
  1988. func max(a, b float64) float64 {
  1989. if a > b {
  1990. return a
  1991. }
  1992. return b
  1993. }