produce_window.go 74 KB

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