produce_window.go 75 KB

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