Vehicle.cs 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using FluentResults;
  9. using GSG.NET.Concurrent;
  10. using GSG.NET.Extensions;
  11. using GSG.NET.LINQ;
  12. using GSG.NET.Logging;
  13. using GSG.NET.Quartz;
  14. using GSG.NET.Utils;
  15. using OHV.Common.Events;
  16. using OHV.Common.Model;
  17. using OHV.Common.Shareds;
  18. using OHV.SqliteDAL;
  19. using Prism.Events;
  20. using VehicleControlSystem.ControlLayer.Actuator.Cylinder;
  21. using VehicleControlSystem.ControlLayer.Drive;
  22. using VehicleControlSystem.ControlLayer.IO;
  23. using VehicleControlSystem.ControlLayer.MQ;
  24. using VehicleControlSystem.ControlLayer.Serial.BatteryTabos;
  25. using VehicleControlSystem.ControlLayer.Serial.DataModel;
  26. using VehicleControlSystem.Managers;
  27. using static VehicleControlSystem.ControlLayer.Drive.GSIDrive;
  28. namespace VehicleControlSystem.ControlLayer
  29. {
  30. public class VehicleRefObjects
  31. {
  32. public GSIDrive Drive { get; set; }
  33. public Clamp Clamp { get; set; }
  34. public Conveyor Conveyor { get; set; }
  35. public EzIO IO { get; set; }
  36. public Steering Steering { get; set; }
  37. public BMUManager BMUManager { get; set; }
  38. public ZmqManager ZmqManager { get; set; }
  39. public List<Alarm> Alarms { get; set; }
  40. public HostManager HostManager { get; set; }
  41. public SqliteManager Sqlite { get; set; }
  42. public AutoManager AutoManager { get; set; }
  43. }
  44. /// <summary>
  45. /// Control Layer 의 자원을 여기서 사용하자.
  46. /// </summary>
  47. public class Vehicle : ControlObjectBase, IDisposable
  48. {
  49. /// <summary>
  50. /// OCS Report Code
  51. /// 목적지에 도착해서 Load, Unload 시 발생하는 Alarm
  52. /// </summary>
  53. public enum eFailCode
  54. {
  55. Load_PortHasNotCarrier = 1,
  56. Load_VehicleHasCarrier,
  57. Unload_PortHasCarrier,
  58. Unload_VehicleHasNotCarrier,
  59. LoadPIOInterlockTimeout,
  60. UnlaodPIOInterlockTimeout,
  61. }
  62. static Logger logger = Logger.GetLogger();
  63. static Logger loggerPIO = Logger.GetLogger( "PIO" );
  64. #region Properties
  65. /// <summary>
  66. /// Tag 위치
  67. /// </summary>
  68. private int currentTag = 0;
  69. public int CurrentTag
  70. {
  71. get { return currentTag; }
  72. set
  73. {
  74. if ( SetField( ref this.currentTag, value ) )
  75. {
  76. var info = this.refObjects.Sqlite.VehicleInfoDAL.GetAll().FirstOrDefault();
  77. info.CurrentTag = value.ToString();
  78. this.refObjects.Sqlite.VehicleInfoDAL.Update( info );
  79. this.OnCurrentTagChanged?.Invoke( value );
  80. }
  81. }
  82. }
  83. /// <summary>
  84. /// Scale Value
  85. /// </summary>
  86. private double currentPosition;
  87. public double CurrentPosition
  88. {
  89. get { return currentPosition; }
  90. set
  91. {
  92. if ( SetField( ref this.currentPosition, value ) )
  93. {
  94. }
  95. }
  96. }
  97. private double currentSpeed;
  98. public double CurrentSpeed
  99. {
  100. get { return currentSpeed; }
  101. set { SetField( ref this.currentSpeed, value ); }
  102. }
  103. private double currentTorque;
  104. public double CurrentTorque
  105. {
  106. get { return currentTorque; }
  107. set { SetField( ref this.currentTorque, value ); }
  108. }
  109. private bool isContain;
  110. public bool IsContain
  111. {
  112. get { return isContain; }
  113. set { SetField( ref this.isContain, value ); }
  114. }
  115. eClampState _clampState;
  116. public eClampState ClampState
  117. {
  118. get { return this._clampState; }
  119. set { this.SetField( ref this._clampState, value ); }
  120. }
  121. private eSteeringState steeringState;
  122. public eSteeringState SteeringState
  123. {
  124. get { return steeringState; }
  125. set
  126. {
  127. if ( SetField( ref this.steeringState, value ) )
  128. {
  129. this.refObjects.ZmqManager.SetCurrentSteeringState( value );
  130. }
  131. }
  132. }
  133. private int _obstacleDrive;
  134. public int ObstacleDrive { get { return this._obstacleDrive; } set { SetField( ref this._obstacleDrive, value ); } }
  135. private int _obstacleCurve;
  136. public int ObstacleCurve { get { return this._obstacleCurve; } set { SetField( ref this._obstacleCurve, value ); } }
  137. private int obstacleCurrent;
  138. public int ObstacleCurrent { get { return this.ObstacleCurrent; } set { SetField( ref this.obstacleCurrent, value ); } }
  139. private eObstacleState obstacleState = eObstacleState.Normal;
  140. public eObstacleState ObstacleStateProperty
  141. {
  142. get { return obstacleState; }
  143. set
  144. {
  145. if ( SetField( ref this.obstacleState, value ) )
  146. {
  147. if ( value == eObstacleState.Blocked )
  148. this.VehicleStateProperty = eVehicleState.Blocked;
  149. }
  150. }
  151. }
  152. private eVehicleState vehicleState = eVehicleState.None;
  153. public eVehicleState VehicleStateProperty
  154. {
  155. get { return vehicleState; }
  156. set
  157. {
  158. if ( SetField( ref this.vehicleState, value ) )
  159. {
  160. var info = this.refObjects.Sqlite.VehicleInfoDAL.GetAll().FirstOrDefault();
  161. info.VehicleState = value;
  162. this.refObjects.Sqlite.VehicleInfoDAL.Update( info );
  163. }
  164. }
  165. }
  166. private eMachineMode machineMode = eMachineMode.LocalMode;
  167. public eMachineMode MachineMode
  168. {
  169. get { return machineMode; }
  170. set
  171. {
  172. if ( SetField( ref this.machineMode, value ) )
  173. {
  174. var info = this.refObjects.Sqlite.VehicleInfoDAL.GetAll().FirstOrDefault();
  175. info.MachineMode = value;
  176. this.refObjects.Sqlite.VehicleInfoDAL.Update( info );
  177. }
  178. }
  179. }
  180. private int obstaclePattern;
  181. public int ObstaclePattern
  182. {
  183. get { return obstaclePattern; }
  184. set { SetField( ref this.obstaclePattern, value ); }
  185. }
  186. private DriveState frontDriveState;
  187. public DriveState FrontDriveState
  188. {
  189. get { return frontDriveState; }
  190. set { SetField( ref this.frontDriveState, value ); }
  191. }
  192. private DriveState rearDriveState;
  193. public DriveState RearDriveState
  194. {
  195. get { return rearDriveState; }
  196. set { SetField( ref this.rearDriveState, value ); }
  197. }
  198. private eVehicleAutoReadyState autoReadyState;
  199. public eVehicleAutoReadyState AutoReadyState
  200. {
  201. get { return autoReadyState; }
  202. set { SetField(ref this.autoReadyState, value);}
  203. }
  204. //이동
  205. public bool Busy
  206. {
  207. get
  208. {
  209. return this.CurrentSubCommand == null ? false : true;
  210. }
  211. set { }
  212. }
  213. public bool IsMoving { get => this.refObjects.Drive.IsDriveMoving(); }
  214. private bool batteryChargeState;
  215. public bool BatteryChargeState
  216. {
  217. get { return batteryChargeState; }
  218. set
  219. {
  220. if ( SetField( ref batteryChargeState, value ) )
  221. {
  222. if ( value )
  223. {
  224. this.OnChargingStart?.Invoke();
  225. LockUtils.Wait( 200 );
  226. this.OnCharging?.Invoke();
  227. QuartzUtils.Invoke( "BatterLogger", QuartzUtils.GetExpnMinute( 1 ), () => { batteryLogger.I( $"SOC - {this.BatteryStateOfCharge} / Current - {this.BatteryCurrent} / Voltage - {this.BatteryVoltage} / Capacity - {this.BatteryCapacity} / Energy - {this.BatteryEnergy}" ); } );
  228. }
  229. else
  230. QuartzUtils.StopSchedule( "BatterLogger" );
  231. }
  232. }
  233. }
  234. #region Battery Property
  235. double batteryVoltage;
  236. public double BatteryVoltage
  237. {
  238. get { return this.batteryVoltage; }
  239. set
  240. {
  241. //var d = Math.Truncate( value * 10 ) / 10;
  242. //this.SetField( ref this.batteryVoltage, d );
  243. this.SetField( ref this.batteryVoltage, value );
  244. }
  245. }
  246. double batteryCurrent;
  247. public double BatteryCurrent
  248. {
  249. get { return this.batteryCurrent; }
  250. set { this.SetField( ref this.batteryCurrent, value ); }
  251. }
  252. double batteryState;
  253. public double BatteryState
  254. {
  255. get { return this.batteryState; }
  256. set { this.SetField( ref this.batteryState, value ); }
  257. }
  258. double batteryChargeTime;
  259. public double BatteryChargeTime
  260. {
  261. get { return this.batteryChargeTime; }
  262. set { this.SetField( ref this.batteryChargeTime, value ); }
  263. }
  264. double batteryDisChargeTime;
  265. public double BatteryDisChargeTime
  266. {
  267. get { return this.batteryDisChargeTime; }
  268. set { this.SetField( ref this.batteryDisChargeTime, value ); }
  269. }
  270. double batteryStateOfCharge;
  271. public double BatteryStateOfCharge
  272. {
  273. get { return this.batteryStateOfCharge; }
  274. set { if ( this.SetField( ref this.batteryStateOfCharge, value ) ) { this.BatteryChargeStateLED( value ); } }
  275. }
  276. double batteryStateOfHealth;
  277. public double BatteryStateOfHealth
  278. {
  279. get { return this.batteryStateOfHealth; }
  280. set
  281. {
  282. if ( this.SetField( ref this.batteryStateOfHealth, value ) ) { }
  283. }
  284. }
  285. double batteryCapacity;
  286. public double BatteryCapacity
  287. {
  288. get { return this.batteryCapacity; }
  289. set { this.SetField( ref this.batteryCapacity, value ); }
  290. }
  291. double batteryEnergy;
  292. public double BatteryEnergy
  293. {
  294. get { return this.batteryEnergy; }
  295. set
  296. {
  297. var d = Math.Truncate( value * 10 ) / 10;
  298. this.SetField( ref this.batteryEnergy, d );
  299. }
  300. }
  301. double batteryTemperature;
  302. public double BatteryTemperature
  303. {
  304. get { return this.batteryTemperature; }
  305. set { this.SetField( ref this.batteryTemperature, value ); }
  306. }
  307. bool batteryIsConnect;
  308. public bool BatteryIsConnect
  309. {
  310. get
  311. {
  312. return batteryIsConnect;
  313. }
  314. set { this.SetField( ref this.batteryIsConnect, value ); }
  315. }
  316. #endregion
  317. public bool IsError { get; set; }
  318. public SubCmd CurrentSubCommand { get; private set; }
  319. double frontLoadFactor = 0;
  320. public double FrontLoadFactor
  321. {
  322. get { return this.frontLoadFactor; }
  323. set { SetField( ref this.frontLoadFactor, value ); }
  324. }
  325. double frontRpm = 0;
  326. public double FrontRpm
  327. {
  328. get { return this.frontRpm; }
  329. set { SetField( ref this.frontRpm, value ); }
  330. }
  331. double frontSpeed = 0;
  332. public double FrontSpeed
  333. {
  334. get { return this.frontSpeed; }
  335. set { SetField( ref this.frontSpeed, value ); }
  336. }
  337. double frontTorque = 0;
  338. public double FrontTorque
  339. {
  340. get { return this.frontTorque; }
  341. set { SetField( ref this.frontTorque, value ); }
  342. }
  343. double rearLoadFactor = 0;
  344. public double RearLoadFactor
  345. {
  346. get { return this.rearLoadFactor; }
  347. set { SetField( ref this.rearLoadFactor, value ); }
  348. }
  349. double rearRpm = 0;
  350. public double RearRpm
  351. {
  352. get { return this.rearRpm; }
  353. set { SetField( ref this.rearRpm, value ); }
  354. }
  355. double rearSpeed = 0;
  356. public double RearSpeed
  357. {
  358. get { return this.rearSpeed; }
  359. set { SetField( ref this.rearSpeed, value ); }
  360. }
  361. double rearTorque = 0;
  362. public double RearTorque
  363. {
  364. get { return this.rearTorque; }
  365. set { SetField( ref this.rearTorque, value ); }
  366. }
  367. private double linearSpeed;
  368. public double LinearSpeed
  369. {
  370. get { return linearSpeed; }
  371. set { SetField(ref this.linearSpeed, value); }
  372. }
  373. private double curveSpeed;
  374. public double CurveSpeed
  375. {
  376. get { return curveSpeed; }
  377. set { SetField(ref this.curveSpeed, value); }
  378. }
  379. private double accelSpeed;
  380. public double AccelSpeed
  381. {
  382. get { return accelSpeed; }
  383. set { SetField(ref this.accelSpeed , value); }
  384. }
  385. private double decelSpeed;
  386. public double DecelSpeed
  387. {
  388. get { return decelSpeed; }
  389. set { SetField(ref this.decelSpeed, value); }
  390. }
  391. private double creepSpeed;
  392. public double CreepSpeed
  393. {
  394. get { return creepSpeed; }
  395. set { SetField(ref this.creepSpeed, value); }
  396. }
  397. private double creepDistance;
  398. public double CreepDistance
  399. {
  400. get { return creepDistance; }
  401. set { SetField(ref this.creepDistance , value); }
  402. }
  403. private double jogSpeed;
  404. public double JogSPeed
  405. {
  406. get { return jogSpeed; }
  407. set { SetField(ref this.jogSpeed , value); }
  408. }
  409. #endregion
  410. #region Event
  411. public event Action OnMoveReady;
  412. public event Action OnMoving;
  413. public event Action OnMoveFinish;
  414. public event Action OnChargingStart;
  415. public event Action OnCharging;
  416. public event Action OnChargingFull;
  417. public event Action<double> OnBatteryVelueChanged;
  418. public event Action<bool> OnPIOStart;
  419. public event Action<bool> OnConveyorStart;
  420. public event Action<bool> OnConveyorStop;
  421. public event Action<bool> OnCarrierDetected;
  422. public event Action OnLoadComplete;
  423. public event Action OnUnloadComplete;
  424. public event Action<int> OnCurrentTagChanged;
  425. public event Action<eFailCode> OnFailReport;
  426. #endregion
  427. #region List.
  428. List<ICylinder> cylinders = new List<ICylinder>();
  429. List<string> obstacleBitList = new List<string>();
  430. #endregion
  431. VehicleRefObjects refObjects = null;
  432. //SqliteManager sql = null;
  433. //AutoManager autoManager = null;
  434. ThreadCancel cancel = new ThreadCancel();
  435. TaskCancel taskCancel = new TaskCancel();
  436. TaskCancel taskMoveCancel = new TaskCancel();
  437. IEventAggregator eventAggregator;
  438. public Vehicle( IEventAggregator ea )
  439. {
  440. this.obstacleBitList.AddRange( new string[]
  441. {
  442. "OUT_OBSTRUCTION_PATTERN_00",
  443. "OUT_OBSTRUCTION_PATTERN_01",
  444. "OUT_OBSTRUCTION_PATTERN_02",
  445. "OUT_OBSTRUCTION_PATTERN_03",
  446. "OUT_OBSTRUCTION_PATTERN_04",
  447. } );
  448. this.eventAggregator = ea;
  449. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Unsubscribe( ReceiveDriveControlEvent );
  450. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Subscribe( ReceiveDriveControlEvent );
  451. this.eventAggregator.GetEvent<ObstacleControlPubSubEvent>().Unsubscribe( ObstacleReceiveEvent );
  452. this.eventAggregator.GetEvent<ObstacleControlPubSubEvent>().Subscribe( ObstacleReceiveEvent );
  453. }
  454. public void DependencyInjection( VehicleRefObjects vehicleRefObjects )
  455. {
  456. this.refObjects = vehicleRefObjects;
  457. this.refObjects.IO.OnChangedIO += IO_OnChangedIO;
  458. this.refObjects.BMUManager.OnConnect += BMUManager_OnConnect;
  459. this.refObjects.BMUManager.OnDisconnect += BMUManager_OnDisconnect;
  460. this.refObjects.BMUManager.OnChangedReceivedData += BMUManager_OnChangedReceivedData;
  461. this.refObjects.BMUManager.OnFirstColtd += BMUManager_OnFirstColtd;
  462. this.refObjects.Drive.PropertyChanged += Motion_PropertyChanged;
  463. this.refObjects.Clamp.PropertyChanged += Clamp_PropertyChanged;
  464. this.refObjects.Steering.OnSteeringError += Steering_OnSteeringError;
  465. this.refObjects.Steering.PropertyChanged += Steering_PropertyChanged;
  466. this.refObjects.ZmqManager.PropertyChanged += ZmqManager_PropertyChanged;
  467. this.refObjects.AutoManager.OnOperationModeChanged += AutoManager_OnOperationModeChanged;
  468. }
  469. private void ObstacleReceiveEvent( ObstacleControlEventArgs obj )
  470. {
  471. if ( this.refObjects.AutoManager.OperationModeProperty != eOperatationMode.ManualMode )
  472. return;
  473. if ( obj.EventDir == ObstacleControlEventArgs.eEventDir.ToBack )
  474. {
  475. switch ( obj.ControlKind )
  476. {
  477. case ObstacleControlEventArgs.eControlKind.NONE:
  478. break;
  479. case ObstacleControlEventArgs.eControlKind.DRIVE:
  480. //this.ChgObstacleDetectPattern( new Random().Next( 0 , 40 ) );
  481. break;
  482. case ObstacleControlEventArgs.eControlKind.CURVE:
  483. //this.ChgObstacleDetectPattern( new Random().Next( 0 , 40 ) );
  484. break;
  485. case ObstacleControlEventArgs.eControlKind.STATE:
  486. //var value = this.GetObstacleDetectPattern();
  487. break;
  488. case ObstacleControlEventArgs.eControlKind.INFO:
  489. {
  490. var msg = new ObstacleControlEventArgs
  491. {
  492. ControlKind = ObstacleControlEventArgs.eControlKind.INFO,
  493. Drive = this.ObstacleDrive,
  494. Curve = this.ObstacleCurve,
  495. Current = this.GetObstacleDetectPattern(),
  496. ObstacleState = this.ObstacleStateProperty.ToString()
  497. };
  498. this.ObstacleControlEventPublish( msg );
  499. }
  500. break;
  501. case ObstacleControlEventArgs.eControlKind.SAVE:
  502. {
  503. this.ObstacleCurve = obj.Curve;
  504. this.ObstacleDrive = obj.Drive;
  505. var reply = new ObstacleControlEventArgs
  506. {
  507. ControlKind = ObstacleControlEventArgs.eControlKind.SAVE
  508. };
  509. reply.Result = Results.Ok( ObstacleControlEventArgs.eControlKind.SAVE );
  510. this.ObstacleControlEventPublish( reply );
  511. }
  512. break;
  513. }
  514. }
  515. }
  516. private void ObstacleControlEventPublish( ObstacleControlEventArgs args )
  517. {
  518. args.EventDir = ObstacleControlEventArgs.eEventDir.ToFront;
  519. this.eventAggregator.GetEvent<ObstacleControlPubSubEvent>().Publish( args );
  520. }
  521. private void ReceiveDriveControlEvent( DriveControlEventArgs _args )
  522. {
  523. var msg = _args;
  524. if ( msg.EventDir == DriveControlEventArgs.eEventDir.ToBack )
  525. {
  526. switch ( msg.ControlKind )
  527. {
  528. case DriveControlEventArgs.eControlKind.MOVE:
  529. this.ReqMoveToPos( _args );
  530. break;
  531. case DriveControlEventArgs.eControlKind.STOP:
  532. break;
  533. case DriveControlEventArgs.eControlKind.Steering:
  534. if ( msg.MoveDir == DriveControlEventArgs.eMoveDir.LEFT )
  535. this.refObjects.Steering.ControlSteering( true );
  536. else
  537. this.refObjects.Steering.ControlSteering();
  538. break;
  539. case DriveControlEventArgs.eControlKind.SteeringState:
  540. {
  541. var reply = new DriveControlEventArgs();
  542. reply.ControlKind = DriveControlEventArgs.eControlKind.SteeringState;
  543. if ( this.refObjects.Steering.IsLeft() )
  544. {
  545. reply.Args = eSteeringState.Left;
  546. reply.Result = FluentResults.Results.Ok();
  547. }
  548. else if ( this.refObjects.Steering.IsRight() )
  549. {
  550. reply.Args = eSteeringState.Right;
  551. reply.Result = FluentResults.Results.Ok();
  552. }
  553. else
  554. reply.Result = FluentResults.Results.Fail( new Error() );
  555. this.DriveControlEventPublish( reply );
  556. }
  557. break;
  558. case DriveControlEventArgs.eControlKind.ReqCurrentPos:
  559. //this.ReqCurrentPos();
  560. break;
  561. case DriveControlEventArgs.eControlKind.ReqStopCurrentPos:
  562. //this.taskCancel.Cancel();
  563. //this.taskCancel.WaitAll();
  564. break;
  565. case DriveControlEventArgs.eControlKind.FaultReset:
  566. this.ReqFaultReset( _args );
  567. break;
  568. case DriveControlEventArgs.eControlKind.DriveON:
  569. this.ReqDriveOn( _args );
  570. break;
  571. case DriveControlEventArgs.eControlKind.DriveOFF:
  572. this.ReqDriveOff( _args );
  573. break;
  574. case DriveControlEventArgs.eControlKind.JOG:
  575. this.ReqJog( _args );
  576. break;
  577. case DriveControlEventArgs.eControlKind.VehicleState:
  578. ReqVehicleState( _args );
  579. break;
  580. default:
  581. break;
  582. }
  583. }
  584. }
  585. public void ReqConveyorMove( string dir )
  586. {
  587. if ( dir.Equals( "CW" ) )
  588. this.refObjects.Conveyor.OnOffConveyor( true, false );
  589. else if ( dir.Equals( "CCW" ) )
  590. this.refObjects.Conveyor.OnOffConveyor( true, true );
  591. else if ( dir.Equals( "STOP" ) )
  592. this.refObjects.Conveyor.OnOffConveyor( false, false );
  593. }
  594. private void DriveControlEventPublish( DriveControlEventArgs args )
  595. {
  596. args.EventDir = DriveControlEventArgs.eEventDir.ToFront;
  597. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Publish( args );
  598. }
  599. public void Init()
  600. {
  601. ThreadStart();
  602. //TimerUtils.Once(5000, () => { this.CurrentPosition = 1000; });
  603. var v = refObjects.Sqlite.VehicleInfoDAL.GetAll().FirstOrDefault();
  604. v.CurrentTag = "0000";
  605. v.VehicleState = eVehicleState.None;
  606. v.MachineMode = eMachineMode.LocalMode;
  607. refObjects.Sqlite.VehicleInfoDAL.Update( v );
  608. }
  609. public int InitializationVehicle()
  610. {
  611. #if SIMULATION
  612. this.VehicleStateProperty = eVehicleState.Idle;
  613. return 0;
  614. #else
  615. int result = 0;
  616. //PIOClear();
  617. //PIOSensorOff();
  618. result = this.refObjects.Clamp.IsAllAxisOriginReturn();
  619. if ( result != ConstInt.EXECUTE_SUCCESS )
  620. {
  621. this.refObjects.Clamp.AllOriginReturn();
  622. LockUtils.Wait( 2000 );
  623. }
  624. if ( this.refObjects.Conveyor.IsDetectedCenter() ) //자제가 있으면 Lock
  625. result = this.refObjects.Clamp.Lock_Sync();
  626. else
  627. result = this.refObjects.Clamp.Unlock_Sync();
  628. result = 0;
  629. if ( result != 0 )
  630. {
  631. this.VehicleStateProperty = eVehicleState.Abnormal;
  632. return result;
  633. }
  634. if ( this.refObjects.Drive.IsErrorOn )
  635. return 22;
  636. this.VehicleStateProperty = eVehicleState.Idle;
  637. return result;
  638. #endif
  639. }
  640. public void Dispose()
  641. {
  642. this.taskCancel.Cancel();
  643. this.cancel.Cancel();
  644. this.cancel.StopWaitAll();
  645. //this.bMUManager.Disconnect();
  646. //this.drive.Dispose();
  647. }
  648. #region Request Method
  649. private void ReqVehicleState( DriveControlEventArgs args )
  650. {
  651. VehicleInfo state = new VehicleInfo();
  652. state.CurrentPosition = this.CurrentPosition;
  653. state.CurrentSpeed = this.CurrentSpeed;
  654. state.CurrentTag = this.CurrentTag.ToString();
  655. state.CurrentTorque = this.CurrentTorque;
  656. var msg = new DriveControlEventArgs();
  657. msg.ControlKind = args.ControlKind;
  658. msg.Args = state;
  659. DriveControlEventPublish( msg );
  660. }
  661. private void ReqMoveToPos( DriveControlEventArgs args )
  662. {
  663. //var result = drive.Move( args.PositionTag );
  664. //this.MoveTo( "1111" );
  665. var reply = new DriveControlEventArgs();
  666. int targetTag = args.TargetRouteID;
  667. var route = this.refObjects.Sqlite.RouteDal.Get( x => x.Name.Equals( targetTag ) ).FirstOrDefault();
  668. if ( route == null )
  669. {
  670. reply.Result = Results.Fail( "Not Found Route" );
  671. this.DriveControlEventPublish( reply );
  672. return;
  673. }
  674. var subCommand = new SubCmd();
  675. subCommand.TargetID = route.Name;
  676. this.MoveTo( subCommand );
  677. reply.Result = Results.Ok( "Position Move" );
  678. this.DriveControlEventPublish( reply );
  679. }
  680. void ReqFaultReset( DriveControlEventArgs _args )
  681. {
  682. var drive = 0;
  683. //var result = drive.ResetAmpFault();
  684. var msg = new DriveControlEventArgs
  685. {
  686. ControlKind = DriveControlEventArgs.eControlKind.FaultReset
  687. };
  688. msg.Result = Results.Ok( "Drive On" );
  689. this.DriveControlEventPublish( msg );
  690. }
  691. void ReqJog( DriveControlEventArgs _args )
  692. {
  693. if ( _args.JogDir == DriveControlEventArgs.eJogMoveDir.Positive )
  694. this.refObjects.Drive.JogForword();
  695. else
  696. this.refObjects.Drive.JogBackword();
  697. }
  698. Logger batteryLogger = Logger.GetLogger( "BatteryLogger" );
  699. void ReqCurrentPos()
  700. {
  701. var task = Task.Factory.StartNew( () =>
  702. {
  703. while ( !this.taskCancel.Canceled )
  704. {
  705. LockUtils.Wait( 1000 );
  706. batteryLogger.I( $"SOC - {this.BatteryStateOfCharge} / Current - {this.BatteryCurrent} / Voltage - {this.BatteryVoltage} / Capacity - {this.BatteryCapacity} / Energy - {this.BatteryEnergy}" );
  707. //var msg = new DriveControlEventArgs
  708. //{
  709. // EventDir = DriveControlEventArgs.eEventDir.ToFront,
  710. // ControlKind = DriveControlEventArgs.eControlKind.ReqCurrentPos,
  711. // CurrentPosition = new Random().Next( 0, 1000 ),
  712. //};
  713. //this.DriveControlEventPublish( msg );
  714. }
  715. } );
  716. this.taskCancel.Add( task );
  717. }
  718. void ReqDriveOn( DriveControlEventArgs _args )
  719. {
  720. var ll = this.refObjects.ZmqManager.SetDriveControl( eDriveControl.ServoOn );
  721. if(ll == 38)
  722. {
  723. logger.E( $"Servo On Error" );
  724. }
  725. var msg = new DriveControlEventArgs
  726. {
  727. ControlKind = DriveControlEventArgs.eControlKind.DriveON
  728. };
  729. msg.Result = Results.Ok( "Drive On" );
  730. this.DriveControlEventPublish( msg );
  731. }
  732. void ReqDriveOff( DriveControlEventArgs _args )
  733. {
  734. var ll = this.refObjects.ZmqManager.SetDriveControl( eDriveControl.ServoOff );
  735. if ( ll == 38 )
  736. {
  737. logger.E( $"Servo Off Error" );
  738. }
  739. var msg = new DriveControlEventArgs
  740. {
  741. ControlKind = DriveControlEventArgs.eControlKind.DriveOFF
  742. };
  743. msg.Result = Results.Ok( "Drive On" );
  744. this.DriveControlEventPublish( msg );
  745. }
  746. #endregion
  747. #region Thread
  748. void ThreadStart()
  749. {
  750. this.cancel.AddGo( new Action( this._ThSubCmdWorker ) );
  751. this.cancel.AddGo( new Action( this._ThVehicleStateCheck ) );
  752. }
  753. //장애물 감지 Thread
  754. //장애물 감지 패턴 변경도 여기 하자.
  755. private void _ThVehicleStateCheck()
  756. {
  757. while ( !this.cancel.Canceled )
  758. {
  759. try
  760. {
  761. //if ( this.autoManager.OperationModeProperty == eOperatationMode.AutoMode )
  762. //this.CheckObstacle();
  763. //this.CheckIOState();
  764. }
  765. catch ( ThreadInterruptedException threadInterruptedException )
  766. {
  767. }
  768. catch ( Exception exception )
  769. {
  770. logger.E( exception );
  771. }
  772. finally
  773. {
  774. LockUtils.Wait( 5 );
  775. }
  776. }
  777. logger.D( "Vehicle - _ThObstacleChecker Dispose" );
  778. }
  779. /// <summary>
  780. /// Scheduler 가 주는 Sub Command 를 이용하여 동작하자.
  781. /// </summary>
  782. public void _ThSubCmdWorker()
  783. {
  784. while ( !this.cancel.Canceled )
  785. {
  786. try
  787. {
  788. if ( this.ObstacleStateProperty != eObstacleState.Normal ) //장애물 감지 상태 시 조그 동작만 가능하게.
  789. continue;
  790. if ( this.refObjects.AutoManager.AutoModeStateProperty != eAutoModeState.Run ) //
  791. continue;
  792. var subCmd = this.refObjects.Sqlite.SubCmdDAL.GetAll().FirstOrDefault();
  793. if ( subCmd == null ) continue;
  794. if ( !this.refObjects.Sqlite.CommandDAL.GetAll().Any( x => x.CommandID.Equals( subCmd.CmdID ) ) )
  795. {
  796. if ( subCmd.CmdType == SubCmd.eCmdType.Auto ) //자동 명령중 Main Command 가 없으면 삭제.
  797. {
  798. this.refObjects.Sqlite.SubCmdDAL.Delete( subCmd.ID );
  799. logger.I( $"SubCmd Deleted - ID={subCmd.ID}, CommandID={subCmd.CmdID}" );
  800. }
  801. }
  802. switch ( subCmd.Type )
  803. {
  804. case eSubCommandType.Move:
  805. this.CurrentSubCommand = subCmd;
  806. this.Move( subCmd );
  807. break;
  808. case eSubCommandType.Load:
  809. this.CurrentSubCommand = subCmd;
  810. this.LoadCarrier( subCmd );
  811. break;
  812. case eSubCommandType.Unload:
  813. this.CurrentSubCommand = subCmd;
  814. this.UnloadCarrier( subCmd );
  815. break;
  816. case eSubCommandType.Charge:
  817. this.CurrentSubCommand = subCmd;
  818. this.BatteryCharge( subCmd );
  819. break;
  820. case eSubCommandType.Cancel:
  821. this.CurrentSubCommand = subCmd;
  822. CancelCommand( subCmd );
  823. break;
  824. default:
  825. break;
  826. }
  827. }
  828. catch ( Exception exception )
  829. {
  830. logger.E( exception );
  831. }
  832. finally
  833. {
  834. LockUtils.Wait( 500 );
  835. }
  836. }
  837. logger.D( "Vehicle - _ThSubCmdWorker Dispose" );
  838. }
  839. private void CancelCommand( SubCmd subCmd )
  840. {
  841. this.refObjects.Drive.CancelCommand( subCmd );
  842. var cmd = this.refObjects.Sqlite.CommandDAL.GetById( subCmd.CmdID );
  843. cmd.State = eCommandState.Complete;
  844. this.refObjects.Sqlite.CommandDAL.Update( cmd );
  845. this.refObjects.Sqlite.SubCmdDAL.Clean();
  846. logger.D( $"[Cancel Command] {cmd.TargetID} / {cmd.Type}" );
  847. }
  848. #endregion
  849. #region Control Action Method
  850. public void EStop()
  851. {
  852. this.refObjects.Conveyor.OnOffConveyor( false );
  853. //Clamp EStop
  854. this.refObjects.Clamp.ClampEStop();
  855. //this.drive.EStop();
  856. this.OccurVehicleAlarm( 23 );
  857. }
  858. #region For Moving
  859. void Move( SubCmd sub )
  860. {
  861. logger.I( $"[SubCommand Start] - Target : {sub.TargetID} / Type : {sub.Type}" );
  862. //Move 시작 시 충전 중이면 충전 중지 실행.
  863. int result = 0;
  864. if ( this.CheckBatteryCharge() || this.VehicleStateProperty == eVehicleState.Charge || this.BatteryChargeState )
  865. {
  866. result = this.StopBatteryCharge();
  867. if ( result != 0 )
  868. {
  869. OccurVehicleAlarm( result );
  870. return;
  871. }
  872. }
  873. var iTarget = Convert.ToInt32( sub.TargetID );
  874. if ( iTarget != CurrentTag ) //하나의 목표 위치로 왔을때 현재 위치와 동일 하면 이동안함.
  875. {
  876. result = this.MoveTo( sub );
  877. if ( result != ConstInt.EXECUTE_SUCCESS )
  878. {
  879. OccurVehicleAlarm( result );
  880. }
  881. }
  882. this.refObjects.Sqlite.SubCmdDAL.Clean();
  883. this.taskMoveCancel.Cancel();
  884. this.taskMoveCancel.WaitAll();
  885. this.CheckOCSConnectionState();
  886. logger.I( $"[SubCommand Complete] - Target : {sub.TargetID} / Type : {sub.Type}" );
  887. }
  888. int MoveTo( SubCmd sub )
  889. {
  890. if ( this.VehicleStateProperty == eVehicleState.Idle )
  891. {
  892. this.OnMoveReady?.Invoke();
  893. var moveReadyBuzzerTime = Convert.ToInt32( this.refObjects.Sqlite.ConfigDal.GetById( ConstString.BuzzerStartReadyTime ).Value );
  894. Thread.Sleep( moveReadyBuzzerTime );
  895. this.VehicleStateProperty = eVehicleState.Move;
  896. }
  897. this.OnMoving?.Invoke();
  898. //이전에 있던 작업들 종료 및 삭제
  899. this.taskMoveCancel.Cancel();
  900. this.taskMoveCancel.WaitAll();
  901. this.taskMoveCancel.Add( CheckCrossPoint() );
  902. this.VehicleStateProperty = eVehicleState.Move;
  903. int result = this.refObjects.Drive.MoveToPoint( sub, 100 );
  904. if ( result != ConstInt.EXECUTE_SUCCESS )
  905. return result;
  906. result = this.Wait4MoveDone();
  907. if ( result != ConstInt.EXECUTE_SUCCESS )
  908. return result;
  909. //Drive 에서 정지 확인 후 상태 변경
  910. if ( this.refObjects.Drive.IsDriveStop() )
  911. {
  912. this.OnMoveFinish?.Invoke();
  913. this.VehicleStateProperty = eVehicleState.Idle;
  914. logger.D( "Move Finish" );
  915. }
  916. return result;
  917. }
  918. int Wait4MoveDone()
  919. {
  920. int waitTime = ConstUtils.ONE_HOUR; //설정 할 수있게.
  921. long st = SwUtils.CurrentTimeMillis;
  922. //Todo: 이동시 확인 사항들.
  923. while ( true )
  924. {
  925. Thread.Sleep( 5 );
  926. if ( SwUtils.Gt( st, waitTime ) )
  927. {
  928. logger.D( "Wait4MoveDone Time Over" );
  929. return 39;
  930. }
  931. //Todo: 이동중 명령이 삭제 되면 처리 할일들.
  932. //이동중 메인 명력이 없어진다면 정지 후
  933. if ( null == this.refObjects.Sqlite.CommandDAL.GetById( this.CurrentSubCommand.CmdID ) )
  934. {
  935. logger.D( "[Wait Move Done] - 메인 명령 사라짐" );
  936. var cmd = this.refObjects.Sqlite.CommandDAL.GetAll();
  937. if ( cmd == null )
  938. {
  939. logger.D( "[Wait Move Done] - Main Command not Exist Motion Stop" );
  940. this.refObjects.Drive.Stop();
  941. return 40;
  942. }
  943. else
  944. {
  945. logger.D( "[Wait Move Done] - Main Command not Exist Motion command, New Command Exist" );
  946. break;
  947. }
  948. }
  949. if ( this.refObjects.Drive.IsDriveStop() ) //Move Stop
  950. break;
  951. }
  952. return ConstInt.EXECUTE_SUCCESS;
  953. }
  954. Task CheckCrossPoint()
  955. {
  956. var task = Task.Run( () =>
  957. {
  958. long sTime = SwUtils.CurrentTimeMillis;
  959. while ( !this.taskMoveCancel.Canceled )
  960. {
  961. Thread.Sleep( 10 );
  962. //ToDo: approach Cross Point Check
  963. //ToDo: Obstacle Laser Sensor Pattern Change Method 구현 필요.
  964. }
  965. } );
  966. return task;
  967. }
  968. #endregion
  969. public bool LoadCarrier( SubCmd sub )
  970. {
  971. logger.I( $"[SubCommand Start] - Target : {sub.TargetID} / Type : {sub.Type}" );
  972. this.VehicleStateProperty = eVehicleState.Load;
  973. //var route = sql.RouteDal.GetRoute( sub.TargetID );
  974. //if ( !CorrectPosition( route, this.CurrentPosition ) )
  975. //{
  976. // this.OccurVehicleAlarm( 20 );
  977. // return false; //Alarm
  978. //}
  979. int result = 0;
  980. result = this.PIOAndLoad( sub.TargetID );
  981. if ( result != 0 )
  982. {
  983. this.PIOSensorOff();
  984. this.OccurVehicleAlarm( result );
  985. return false;
  986. }
  987. this.PIOSensorOff();
  988. //Load, Unload 가 끝나면 메인 Command 를 완료 했다고 판단.
  989. logger.I( $"[SubCommand Complete] - Target : {sub.TargetID} / Type : {sub.Type}" );
  990. this.refObjects.Sqlite.SubCmdDAL.Clean();
  991. var cmd = this.refObjects.Sqlite.CommandDAL.GetById( sub.CmdID );
  992. if ( cmd != null )
  993. {
  994. cmd.State = eCommandState.Complete;
  995. this.refObjects.Sqlite.CommandDAL.Update( cmd );
  996. }
  997. TimerUtils.Once( 1000, this.OnLoadComplete );
  998. //LockUtils.Wait( 1000 );
  999. //this.OnLoadComplete?.Invoke(); //일찍 주면 다음 명령을 500ms 안에 주는 현상 있음. 그러니까 천천히 주자
  1000. this.VehicleStateProperty = eVehicleState.Idle;
  1001. return true;
  1002. }
  1003. public bool UnloadCarrier( SubCmd sub )
  1004. {
  1005. logger.I( $"[SubCommand Start] - Target : {sub.TargetID} / Type : {sub.Type}" );
  1006. this.VehicleStateProperty = eVehicleState.Unload;
  1007. var targetNo = Convert.ToInt32( sub.TargetID );
  1008. if ( this.CurrentTag != targetNo )
  1009. {
  1010. this.OccurVehicleAlarm( 21 );
  1011. return false; //Alarm
  1012. }
  1013. //var route = sql.RouteDal.GetRoute( sub.TargetID );
  1014. //if ( !CorrectPosition( route, this.CurrentPosition ) )
  1015. //{
  1016. // this.OccurVehicleAlarm( 21 );
  1017. // return false; //Alarm
  1018. //}
  1019. //PIO 내부로 이동.
  1020. //int result = this.clamp.Unlock_Sync();
  1021. //if ( result != 0 )
  1022. //{
  1023. // this.OccurVehicleAlarm( result );
  1024. // return false;
  1025. //}
  1026. int result = 0;
  1027. result = this.PIOAndUnload( sub.TargetID );
  1028. if ( result != 0 )
  1029. {
  1030. this.refObjects.IO.OutputOn( "OUT_PIO_SENSOR_ONOFF" );
  1031. this.OccurVehicleAlarm( result );
  1032. return false;
  1033. }
  1034. this.PIOSensorOff();
  1035. logger.I( $"[SubCommand Complete] - Target : {sub.TargetID} / Type : {sub.Type}" );
  1036. this.refObjects.Sqlite.SubCmdDAL.Clean();
  1037. var cmd = this.refObjects.Sqlite.CommandDAL.GetById( sub.CmdID );
  1038. if ( cmd != null )
  1039. {
  1040. cmd.State = eCommandState.Complete;
  1041. this.refObjects.Sqlite.CommandDAL.Update( cmd );
  1042. }
  1043. TimerUtils.Once( 1000, this.OnUnloadComplete );
  1044. //LockUtils.Wait( 1000 );
  1045. //this.OnUnloadComplete?.Invoke(); //일찍 주면 다음 명령을 500ms 안에 주는 현상 있음. 그러니까 천천히 주자
  1046. this.VehicleStateProperty = eVehicleState.Idle;
  1047. return true;
  1048. }
  1049. public void BatteryCharge( SubCmd subCmd )
  1050. {
  1051. int result = 0;
  1052. result = this.StartBatteryCharge();
  1053. if ( result != ConstInt.EXECUTE_SUCCESS )
  1054. this.OccurVehicleAlarm( result );
  1055. this.refObjects.Sqlite.SubCmdDAL.Clean();
  1056. var cmd = this.refObjects.Sqlite.CommandDAL.GetById( subCmd.CmdID );
  1057. if ( cmd == null )
  1058. return;
  1059. cmd.State = eCommandState.Complete;
  1060. this.refObjects.Sqlite.CommandDAL.Update( cmd );
  1061. }
  1062. /// <summary>
  1063. /// Battery Charge
  1064. /// 충전 시 PIO 를 해야 함.
  1065. /// </summary>
  1066. /// <param name="sub"></param>
  1067. /// <returns></returns>
  1068. int PIOBatteryCharge( SubCmd sub )
  1069. {
  1070. var route = this.refObjects.Sqlite.RouteDal.GetById( sub.TargetID );
  1071. if ( !CorrectPosition( route, this.CurrentPosition ) )
  1072. {
  1073. this.OccurVehicleAlarm( 21 );
  1074. return 0; //Alarm
  1075. }
  1076. var pioTimeout = CastTo<int>.From<string>( this.refObjects.Sqlite.ConfigDal.GetById( ConstString.PIOTimeOut ).Value );
  1077. PIOClear();
  1078. loggerPIO.I( $"Start Charge PIO - [{sub.TargetID}]" );
  1079. if ( !this.refObjects.IO.IsOn( "IN_PIO_READY" ) )
  1080. {
  1081. loggerPIO.E( "[Port] - 1 Ready not On" );
  1082. this.OccurVehicleAlarm( 25 );
  1083. return 0;
  1084. }
  1085. this.refObjects.IO.WriteOutputIO( "OUT_PIO_READY", true );
  1086. loggerPIO.I( "[Vehicle] - 1 Ready On" );
  1087. if ( !this.refObjects.IO.WaitChangeInputIO( true, pioTimeout, "IN_PIO_RECEIVE_RUN" ) )
  1088. {
  1089. PIOClear();
  1090. loggerPIO.E( "[Port] - 2 Receive CV Run Timeout" );
  1091. this.OccurVehicleAlarm( 26 );
  1092. return 0;
  1093. }
  1094. this.refObjects.IO.WriteOutputIO( "OUT_PIO_SENDING_RUN", true );
  1095. loggerPIO.I( "[Vehicle] - 2 Send Run On" );
  1096. var sTime = SwUtils.CurrentTimeMillis;
  1097. while ( true )
  1098. {
  1099. Thread.Sleep( 5 );
  1100. if ( !this.refObjects.IO.IsOn( "IN_PIO_READY" ) || this.refObjects.IO.IsOn( "IN_PIO_RECEIVE_RUN" ) )
  1101. break;
  1102. if ( null == this.refObjects.Sqlite.CommandDAL.GetById( this.CurrentSubCommand.CmdID ) )
  1103. {
  1104. PIOClear();
  1105. logger.D( "[Wait Charging] - 메인 명령 사라짐" );
  1106. break;
  1107. }
  1108. }
  1109. if ( !this.refObjects.IO.WaitChangeInputIO( true, pioTimeout, "IN_PIO_RECEIVE_COMPLITE" ) )
  1110. {
  1111. PIOClear();
  1112. loggerPIO.E( "[Port] - 3 Receive Complete Timeout" );
  1113. this.OccurVehicleAlarm( 26 );
  1114. return 0;
  1115. }
  1116. PIOClear();
  1117. this.refObjects.IO.WriteOutputIO( "OUT_PIO_SEND_COMPLITE", true );
  1118. Thread.Sleep( 1000 );
  1119. this.refObjects.IO.WriteOutputIO( "OUT_PIO_SEND_COMPLITE", false );
  1120. return 0;
  1121. }
  1122. public int StartBatteryCharge()
  1123. {
  1124. #if SIMULATION
  1125. this.PIOSensorOn();
  1126. var pioTimeout = CastTo<int>.From<string>( sql.ConfigDal.GetById( ConstString.PIOTimeOut ).Value );
  1127. PIOClear();
  1128. loggerPIO.I( $"Start Battery Charge PIO" );
  1129. //if ( !this.iO.WaitChangeInputIO( true, pioTimeout, "IN_PIO_SENDABLE" ) )
  1130. //{
  1131. // PIOClear();
  1132. // loggerPIO.E( "[Port] - 4 Ready Time Out" );
  1133. // return 34;
  1134. //}
  1135. Thread.Sleep( 1000 );
  1136. loggerPIO.E( "[Port] - 4 Ready On" );
  1137. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECEIVABLE", true );
  1138. loggerPIO.I( "[Vehicle] - 4 Receivable" );
  1139. //if ( !this.iO.WaitChangeInputIO( true, 20000, "IN_PIO_SEND_RUN" ) )
  1140. //{
  1141. // PIOClear();
  1142. // loggerPIO.E( "[Port] - 5 Sending Run Time Out" );
  1143. // return 35;
  1144. //}
  1145. Thread.Sleep( 1000 );
  1146. loggerPIO.I( "[Port] - 5 Sending Run On" );
  1147. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECEIVE_RUN", true );
  1148. loggerPIO.I( "[Vehicle] - 5 Receive Run On" );
  1149. this.VehicleStateProperty = eVehicleState.Charge;
  1150. this.OnChargingStart?.Invoke();
  1151. Thread.Sleep( 1000 );
  1152. this.OnCharging?.Invoke();
  1153. return 0;
  1154. #else
  1155. this.PIOSensorOn();
  1156. LockUtils.Wait( 500 );
  1157. var pioTimeout = Convert.ToInt32( this.refObjects.Sqlite.ConfigDal.GetById( ConstString.PIOTimeOut ).Value );
  1158. PIOClear();
  1159. loggerPIO.I( $"Start Battery Charge PIO" );
  1160. if ( !this.refObjects.IO.WaitChangeInputIO( true, pioTimeout, "IN_PIO_SENDABLE" ) )
  1161. {
  1162. PIOClear();
  1163. loggerPIO.E( "[Port] - 4 Ready Time Out" );
  1164. return 34;
  1165. }
  1166. loggerPIO.E( "[Port] - 4 Ready On" );
  1167. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECEIVABLE", true );
  1168. loggerPIO.I( "[Vehicle] - 4 Receivable" );
  1169. if ( !this.refObjects.IO.WaitChangeInputIO( true, 5000, "IN_PIO_SEND_RUN" ) )
  1170. {
  1171. PIOClear();
  1172. loggerPIO.E( "[Port] - 5 Sending Run Time Out" );
  1173. return 35;
  1174. }
  1175. loggerPIO.I( "[Port] - 5 Sending Run On" );
  1176. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECEIVE_RUN", true );
  1177. loggerPIO.I( "[Vehicle] - 5 Receive Run On" );
  1178. this.VehicleStateProperty = eVehicleState.Charge;
  1179. return 0;
  1180. #endif
  1181. }
  1182. public int StopBatteryCharge()
  1183. {
  1184. #if SIMULATION
  1185. loggerPIO.I( $"Stop Battery Charge PIO" );
  1186. var pioTimeout = CastTo<int>.From<string>( sql.ConfigDal.GetById( ConstString.PIOTimeOut ).Value );
  1187. this.PIOClear();
  1188. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", true );
  1189. loggerPIO.I( "[Vehicle] Receive Complete On" );
  1190. //if ( !this.iO.WaitChangeInputIO( true, 20000, "IN_PIO_SEND_COMPLITE" ) )
  1191. //{
  1192. // this.iO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", false );
  1193. // loggerPIO.E( "[Port] IN_PIO_SEND_COMPLITE On Time Out" );
  1194. // return 36;
  1195. //}
  1196. Thread.Sleep( 1000 );
  1197. loggerPIO.I( "[Port] Send Complete On" );
  1198. Thread.Sleep( 1000 );
  1199. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", false );
  1200. this.OnChargingFull?.Invoke();
  1201. this.PIOSensorOff();
  1202. this.VehicleStateProperty = eVehicleState.Idle;
  1203. return 0;
  1204. #else
  1205. loggerPIO.I( $"Stop Battery Charge PIO" );
  1206. var pioTimeout = Convert.ToInt32( this.refObjects.Sqlite.ConfigDal.GetById( ConstString.PIOTimeOut ).Value );
  1207. this.PIOClear();
  1208. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", true );
  1209. loggerPIO.I( "[Vehicle] Receive Complete On" );
  1210. if ( !this.refObjects.IO.WaitChangeInputIO( true, 5000, "IN_PIO_SEND_COMPLITE" ) )
  1211. {
  1212. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", false );
  1213. loggerPIO.E( "[Port] IN_PIO_SEND_COMPLITE On Time Out" );
  1214. return 36;
  1215. }
  1216. loggerPIO.I( "[Port] Send Complete On" );
  1217. Thread.Sleep( 1000 );
  1218. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", false );
  1219. this.PIOSensorOff();
  1220. this.OnChargingFull?.Invoke();
  1221. this.VehicleStateProperty = eVehicleState.Idle;
  1222. return 0;
  1223. #endif
  1224. }
  1225. #endregion
  1226. #region Check Method
  1227. bool CheckObstacle()
  1228. {
  1229. if ( this.refObjects.IO.IsOff( "IN_OBSTRUCTION_DETECT_SAFETY" ) || this.refObjects.IO.IsOff( "IN_OBSTRUCTION_DETECT_ERROR" ) )
  1230. {
  1231. this.ObstacleStateProperty = eObstacleState.Abnormal;
  1232. //this.OccurVehicleAlarm( 42 );
  1233. }
  1234. else if ( this.refObjects.IO.IsOff( "IN_OBSTRUCTION_DETECT_STOP" ) )
  1235. {
  1236. this.ObstacleStateProperty = eObstacleState.Blocked;
  1237. }
  1238. else if ( this.refObjects.IO.IsOff( "IN_OBSTRUCTION_DETECT_SLOW" ) )
  1239. {
  1240. this.ObstacleStateProperty = eObstacleState.Decelerate;
  1241. }
  1242. else
  1243. {
  1244. this.ObstacleStateProperty = eObstacleState.Normal;
  1245. }
  1246. this.refObjects.Drive.SetObstacleState( this.ObstacleStateProperty );
  1247. return false;
  1248. }
  1249. #endregion
  1250. #region Mechanical Method
  1251. #region IO
  1252. /// <summary>
  1253. /// Out Put 을 On 이면 Sensor Off
  1254. /// </summary>
  1255. public void PIOSensorOn() => this.refObjects.IO.OutputOff( "OUT_PIO_SENSOR_ONOFF" );
  1256. /// <summary>
  1257. /// Out Put 을 Off 이면 Sensor On
  1258. /// </summary>
  1259. public void PIOSensorOff() => this.refObjects.IO.OutputOn( "OUT_PIO_SENSOR_ONOFF" );
  1260. /// <summary>
  1261. /// 충전 중일때 MTL PIO Bit 가 살아 있다
  1262. /// 이걸 보고 판단 하자. 충전 단자 전진 상태임.
  1263. /// </summary>
  1264. /// <returns></returns>
  1265. public bool CheckBatteryCharge()
  1266. {
  1267. this.PIOSensorOn();
  1268. LockUtils.Wait( 500 );
  1269. if ( this.BatteryChargeState || this.VehicleStateProperty == eVehicleState.Charge )
  1270. {
  1271. }
  1272. //var ret = this.refObjects.IO.IsOn( "OUT_PIO_RECEIVABLE", false )
  1273. // && this.refObjects.IO.IsOn( "OUT_PIO_RECEIVE_RUN", false )
  1274. // && this.refObjects.IO.IsOn( "IN_PIO_SEND_RUN" );
  1275. var ret = this.refObjects.IO.IsOn( "IN_PIO_SEND_RUN" );
  1276. //this.PIOSensorOff();
  1277. return ret;
  1278. }
  1279. #endregion
  1280. #region Conveyor
  1281. public void ConveyorOff() => this.refObjects.Conveyor.OnOffConveyor( false );
  1282. public int ConveyorLoad() => this.refObjects.Conveyor.ConveyorLoad();
  1283. public int ConveyorUnload() => this.refObjects.Conveyor.ConveyorUnload();
  1284. public int PIOAndLoad( string targetName )
  1285. {
  1286. #if SIMULATION
  1287. PIOClear();
  1288. loggerPIO.I( $"Start Load PIO - [{targetName}]" );
  1289. this.OnPIOStart?.Invoke( true );
  1290. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECEIVE_RUN", true );
  1291. loggerPIO.I( "[Vehicle] - 4 Receive Run On" );
  1292. Thread.Sleep( 1000 );//상대 IO 기다린다 생각.
  1293. loggerPIO.E( "[Port] - 4 Ready On" );
  1294. //Conveyor Start
  1295. loggerPIO.I( "[Vehicle] - Conveyor Run" );
  1296. this.OnConveyorStart?.Invoke( true );
  1297. Thread.Sleep( 10000 );//Conveyor 구동
  1298. this.OnCarrierDetected?.Invoke( true );
  1299. PIOClear();
  1300. Thread.Sleep( 1000 );
  1301. this.OnConveyorStop?.Invoke( true );
  1302. Thread.Sleep( 1000 );
  1303. this.OnLoadComplete?.Invoke();
  1304. #else
  1305. loggerPIO.I( $"Start Load PIO - [{targetName}]" );
  1306. this.PIOSensorOn();
  1307. LockUtils.Wait( 500 );
  1308. int result = 0;
  1309. var pioTimeout = Convert.ToInt32( this.refObjects.Sqlite.ConfigDal.GetById( ConstString.PIOTimeOut ).Value );
  1310. result = this.refObjects.Clamp.Unlock_Sync();
  1311. if ( result != 0 )
  1312. {
  1313. this.OccurVehicleAlarm( result );
  1314. return result;
  1315. }
  1316. if ( this.refObjects.Conveyor.IsInverterError() )
  1317. return 16;
  1318. if ( this.refObjects.Conveyor.IsDetectedCenter() )
  1319. {
  1320. this.OnFailReport?.Invoke( eFailCode.Load_VehicleHasCarrier );
  1321. return 0;
  1322. }
  1323. if ( !this.refObjects.IO.WaitChangeInputIO( true, 40 * ConstUtils.ONE_SECOND, "IN_LIFTER_POSITION_DETECT" ) )
  1324. {
  1325. loggerPIO.E( "[Port] - Lift Position Check Error" );
  1326. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.LoadPIOInterlockTimeout );
  1327. //this.OnFailReport?.Invoke( eFailCode.LoadPIOInterlockTimeout );
  1328. return 0; //14
  1329. }
  1330. //if ( !this.refObjects.Conveyor.IsLifterPositinCheck() )
  1331. //{
  1332. // loggerPIO.E( "[Port] - Lift Position Check Error" );
  1333. // this.OnFailReport?.Invoke( eFailCode.LoadPIOInterlockTimeout );
  1334. // return 0; //14
  1335. //}
  1336. //Todo: Sensor Setting 이 후 주석 풀기.
  1337. //if ( !this.IsLifterDuplication() )
  1338. //{
  1339. // this.OnFailReport?.Invoke( eFailCode.Load_PortHasNotCarrier );
  1340. // return 0;
  1341. //}
  1342. PIOClear();
  1343. this.OnPIOStart?.Invoke( true );
  1344. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECEIVABLE", true );
  1345. loggerPIO.I( "[Vehicle] - 4 Receivable" );
  1346. if ( !this.refObjects.IO.WaitChangeInputIO( true, 20 * ConstUtils.ONE_SECOND, "IN_PIO_SENDABLE" ) )
  1347. {
  1348. PIOClear();
  1349. loggerPIO.E( "[Port] - 4 Ready Time Out" );
  1350. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.LoadPIOInterlockTimeout );
  1351. //this.OnFailReport?.Invoke( eFailCode.LoadPIOInterlockTimeout );
  1352. return 0;
  1353. }
  1354. loggerPIO.E( "[Port] - 4 Ready On" );
  1355. //this.conveyor.SetConveyorSpeed( true );
  1356. this.refObjects.Conveyor.OnOffConveyor( true, true );
  1357. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECEIVE_RUN", true, 1000 ); //1Sec 이후 On
  1358. loggerPIO.I( "[Vehicle] - Conveyor Run" );
  1359. this.OnConveyorStart?.Invoke( true );
  1360. if ( !this.refObjects.IO.WaitChangeInputIO( true, pioTimeout, "IN_PIO_SEND_RUN" ) )
  1361. {
  1362. this.refObjects.Conveyor.OnOffConveyor( false, true );
  1363. PIOClear();
  1364. loggerPIO.E( "[Port] - 5 Sending Run Time Out" );
  1365. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.LoadPIOInterlockTimeout );
  1366. //this.OnFailReport?.Invoke( eFailCode.LoadPIOInterlockTimeout );
  1367. return 0;
  1368. }
  1369. loggerPIO.I( "[Port] - 5 Sending Run On" );
  1370. bool isStartDetected = false;
  1371. var sTime = SwUtils.CurrentTimeMillis;
  1372. while ( true )
  1373. {
  1374. LockUtils.Wait( 10 );
  1375. if ( SwUtils.Gt( sTime, 20 * ConstUtils.ONE_SECOND ) )
  1376. {
  1377. PIOClear();
  1378. this.refObjects.Conveyor.OnOffConveyor( false, true );
  1379. loggerPIO.E( "[Vehicle] Conveyor Wait Time Out" );
  1380. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.LoadPIOInterlockTimeout );
  1381. //this.OnFailReport?.Invoke( eFailCode.LoadPIOInterlockTimeout );
  1382. if ( this.refObjects.Conveyor.IsDetectedLoadStart() ) // 감지가 시작 되었으면 이동중 Error 로 판단 설비를 정지 상태로
  1383. return 10; //Conveyor Moving Timeout
  1384. else
  1385. return 0;
  1386. }
  1387. if ( this.refObjects.Conveyor.IsDetectedLoadStart() && !isStartDetected )
  1388. isStartDetected = true;
  1389. if ( !this.refObjects.Conveyor.IsDetectedLoadStart() && isStartDetected ) { }
  1390. //this.conveyor.SetConveyorSpeed( false );
  1391. if ( this.refObjects.Conveyor.IsDetectedLoadStop() ) break;
  1392. if ( this.refObjects.Conveyor.IsPIOInterLockOn() )
  1393. {
  1394. PIOClear();
  1395. this.refObjects.Conveyor.OnOffConveyor( false ); //Stop
  1396. loggerPIO.E( "[Port] PIO InterLock On " );
  1397. return 19; //
  1398. }
  1399. }
  1400. if ( this.refObjects.Conveyor.IsDetectedCenter() )
  1401. this.OnCarrierDetected?.Invoke( true );
  1402. this.refObjects.Conveyor.OnOffConveyor( false ); //Stop
  1403. PIOClear();
  1404. this.OnConveyorStop?.Invoke( true );
  1405. loggerPIO.I( "[Vehicle] Conveyor Stop" );
  1406. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", true );
  1407. loggerPIO.I( "[Vehicle] Receive Complete On" );
  1408. if ( !this.refObjects.IO.WaitChangeInputIO( true, pioTimeout, "IN_PIO_SEND_COMPLITE" ) )
  1409. {
  1410. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", false );
  1411. loggerPIO.E( "[Port] IN_PIO_SEND_COMPLITE On Time Out" );
  1412. }
  1413. loggerPIO.I( "[Port] Send Complete On" );
  1414. this.refObjects.IO.WriteOutputIO( "OUT_PIO_RECIVE_COMPLITE", false, 1000 );
  1415. loggerPIO.I( $"End Load PIO - [{targetName}]" );
  1416. result = this.refObjects.Clamp.Lock_Sync();
  1417. if ( result != 0 )
  1418. {
  1419. this.OccurVehicleAlarm( result );
  1420. return result;
  1421. }
  1422. #endif
  1423. return 0;
  1424. }
  1425. public int PIOAndUnload( string targetName )
  1426. {
  1427. #if SIMULATION
  1428. PIOClear();
  1429. loggerPIO.I( $"Start Unload PIO - [{targetName}]" );
  1430. this.OnPIOStart?.Invoke( false );
  1431. Thread.Sleep( 1000 );
  1432. this.refObjects.IO.WriteOutputIO( "OUT_PIO_READY", true );
  1433. loggerPIO.I( "[Vehicle] - 1 Ready On" );
  1434. Thread.Sleep( 1000 );
  1435. this.OnConveyorStart?.Invoke( false );
  1436. Thread.Sleep( 10000 );
  1437. this.refObjects.Conveyor.OnOffConveyor( false ); //Stop
  1438. this.OnConveyorStop?.Invoke( false );
  1439. PIOClear();
  1440. Thread.Sleep( 1000 );
  1441. this.OnUnloadComplete?.Invoke();
  1442. #else
  1443. loggerPIO.E( $"Start Unload PIO -[{targetName}]" );
  1444. this.PIOSensorOn();
  1445. LockUtils.Wait( 500 );
  1446. int result = 0;
  1447. var pioTimeout = Convert.ToInt32( this.refObjects.Sqlite.ConfigDal.GetById( ConstString.PIOTimeOut ).Value );
  1448. if ( this.refObjects.Conveyor.IsInverterError() )
  1449. return 16;
  1450. //if ( this.refObjects.Conveyor.IsLifterDuplication() )
  1451. //{
  1452. // this.OnFailReport?.Invoke( eFailCode.Unload_PortHasCarrier );
  1453. // return 0;
  1454. //}
  1455. if ( !this.refObjects.Conveyor.IsDetectedCenter() )
  1456. {
  1457. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.Unload_VehicleHasNotCarrier );
  1458. //this.OnFailReport?.Invoke( eFailCode.Unload_VehicleHasNotCarrier );
  1459. return 0;
  1460. }
  1461. if ( !this.refObjects.IO.WaitChangeInputIO( true, 40 * ConstUtils.ONE_SECOND, "IN_LIFTER_POSITION_DETECT" ) )
  1462. {
  1463. loggerPIO.E( "[Port] - Lift Position Check Error" );
  1464. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.UnlaodPIOInterlockTimeout );
  1465. //this.OnFailReport?.Invoke( eFailCode.UnlaodPIOInterlockTimeout );
  1466. return 0;
  1467. }
  1468. //if ( !this.refObjects.Conveyor.IsLifterPositinCheck() )
  1469. //{
  1470. // loggerPIO.E( "[Port] - Lift Position Check Error" );
  1471. // this.OnFailReport?.Invoke( eFailCode.UnlaodPIOInterlockTimeout ); //Unloading Fail Code 를 Time Out 으로 하자. 정의 된 코드 없음.
  1472. // return 0; //13 -> Alarm Code 보고 없음. 경알람 상태 이므로 한번 보고 후 정상 동작
  1473. //}
  1474. PIOClear();
  1475. this.OnPIOStart?.Invoke( false );
  1476. if ( !this.refObjects.IO.WaitChangeInputIO( true, 20 * ConstUtils.ONE_SECOND, "IN_PIO_READY" ) )
  1477. {
  1478. loggerPIO.E( "[Port] - 1 Ready not On" );
  1479. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.UnlaodPIOInterlockTimeout );
  1480. //this.OnFailReport?.Invoke( eFailCode.UnlaodPIOInterlockTimeout );
  1481. return 0;
  1482. }
  1483. this.refObjects.IO.WriteOutputIO( "OUT_PIO_READY", true );
  1484. loggerPIO.I( "[Vehicle] - 1 Ready On" );
  1485. if ( !this.refObjects.IO.WaitChangeInputIO( true, 10 * ConstUtils.ONE_SECOND, "IN_PIO_RECEIVE_RUN" ) )
  1486. {
  1487. PIOClear();
  1488. loggerPIO.E( "[Port] - 2 Receive CV Run Timeout" );
  1489. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.UnlaodPIOInterlockTimeout );
  1490. //this.OnFailReport?.Invoke( eFailCode.UnlaodPIOInterlockTimeout );
  1491. return 0;
  1492. }
  1493. loggerPIO.E( "[Port] - 2 Receive CV Run On" );
  1494. result = this.refObjects.Clamp.Unlock_Sync();
  1495. if ( result != 0 )
  1496. {
  1497. this.OccurVehicleAlarm( result );
  1498. return result;
  1499. }
  1500. this.refObjects.IO.WriteOutputIO( "OUT_PIO_SENDING_RUN", true );
  1501. loggerPIO.I( "[Vehicle] - 2 Send Run On" );
  1502. //this.conveyor.SetConveyorSpeed( true );
  1503. this.refObjects.Conveyor.OnOffConveyor( true );
  1504. this.OnConveyorStart?.Invoke( false );
  1505. var sTime = SwUtils.CurrentTimeMillis;
  1506. while ( true )
  1507. {
  1508. if ( SwUtils.Gt( sTime, 20 * ConstUtils.ONE_SECOND ) )
  1509. {
  1510. PIOClear();
  1511. this.refObjects.Conveyor.OnOffConveyor( false, true );
  1512. loggerPIO.E( "[Port] Conveyor Wait Time Out" );
  1513. TimerUtils.Once( 1000, this.OnFailReport, eFailCode.UnlaodPIOInterlockTimeout );
  1514. //this.OnFailReport?.Invoke( eFailCode.UnlaodPIOInterlockTimeout );
  1515. if ( this.refObjects.Conveyor.IsDetectedLoadStart() || this.refObjects.Conveyor.IsDetectedCenter() ) //중간에 걸려 있다고 생각해서 알람 처리.
  1516. return 12; //Conveyor Moving Timeout
  1517. else
  1518. {
  1519. if ( this.refObjects.Conveyor.IsDetectedCenter() ) //Time Out 후 아직 Tray 가 있으면 다시 Clamp Lock.
  1520. {
  1521. result = this.refObjects.Clamp.Unlock_Sync();
  1522. if ( result != 0 )
  1523. {
  1524. this.OccurVehicleAlarm( result );
  1525. return result;
  1526. }
  1527. }
  1528. else
  1529. return 0;
  1530. }
  1531. }
  1532. if ( !this.refObjects.Conveyor.IsDetectedLoadStart() && !this.refObjects.Conveyor.IsDetectedCenter() )
  1533. {
  1534. if ( this.refObjects.IO.IsOn( "IN_PIO_RECEIVE_COMPLITE" ) )
  1535. {
  1536. loggerPIO.I( "[Port] - 3 Receive Complete On" );
  1537. break;
  1538. }
  1539. }
  1540. }
  1541. if ( !this.refObjects.Conveyor.IsDetectedCenter() )
  1542. this.OnCarrierDetected?.Invoke( false );
  1543. this.refObjects.Conveyor.OnOffConveyor( false ); //Stop
  1544. this.OnConveyorStop?.Invoke( false );
  1545. PIOClear();
  1546. this.refObjects.IO.WriteOutputIO( "OUT_PIO_SEND_COMPLITE", true );
  1547. Thread.Sleep( 1000 );
  1548. this.refObjects.IO.WriteOutputIO( "OUT_PIO_SEND_COMPLITE", false );
  1549. loggerPIO.I( "[Vehicle] - 3 Send Complete OnOff" );
  1550. #endif
  1551. loggerPIO.I( $"End Unload PIO - [{targetName}]" );
  1552. return 0;
  1553. }
  1554. void PIOClear()
  1555. {
  1556. string[] pio = { "OUT_PIO_READY", "OUT_PIO_SENDING_RUN", "OUT_PIO_SEND_COMPLITE", "OUT_PIO_RECEIVABLE", "OUT_PIO_RECEIVE_RUN", "OUT_PIO_RECIVE_COMPLITE", "OUT_PIO_INTERLOCK" };
  1557. pio.FwEach( x => { this.refObjects.IO.OutputOff( x ); } );
  1558. }
  1559. #endregion
  1560. #endregion
  1561. #region Help Method
  1562. Task taskHostConnection = null;
  1563. /// <summary>
  1564. /// Move 이후 OCS 연결을 확인 후 Disconnected 상태이면 5분 상태 확인 후 Alarm 발생.
  1565. /// </summary>
  1566. void CheckOCSConnectionState()
  1567. {
  1568. if ( this.taskHostConnection != null )
  1569. return;
  1570. if ( refObjects.HostManager.IsConnected )
  1571. return;
  1572. this.taskHostConnection = new Task( () =>
  1573. {
  1574. long sTime = SwUtils.CurrentTimeMillis;
  1575. while ( !refObjects.HostManager.IsConnected )
  1576. {
  1577. LockUtils.Wait( 100 );
  1578. if ( SwUtils.Gt( sTime, 30 * ConstUtils.ONE_SECOND ) )
  1579. {
  1580. OccurVehicleAlarm( 43 );
  1581. break;
  1582. }
  1583. }
  1584. } );
  1585. this.taskHostConnection = null;
  1586. }
  1587. void BatteryChargeStateLED( double percent )
  1588. {
  1589. if ( percent > 60 )
  1590. {
  1591. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_00", true );
  1592. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_01", true );
  1593. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_02", true );
  1594. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_03", true );
  1595. }
  1596. else if ( percent > 45 )
  1597. {
  1598. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_00", true );
  1599. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_01", true );
  1600. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_02", true );
  1601. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_03", false );
  1602. }
  1603. else if ( percent > 30 )
  1604. {
  1605. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_00", true );
  1606. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_01", true );
  1607. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_02", false );
  1608. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_03", false );
  1609. }
  1610. else
  1611. {
  1612. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_00", true );
  1613. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_01", false );
  1614. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_02", false );
  1615. this.refObjects.IO.WriteOutputIO( "OUT_BATTERY_LED_03", false );
  1616. }
  1617. }
  1618. /// <summary>
  1619. /// 현재 Point 가 변경될때 장애물 감지 센서의 패턴을 변경한다.
  1620. /// </summary>
  1621. /// <param name="v"></param>
  1622. private void ObstaclePatternChange( int v )
  1623. {
  1624. if ( !RouteManager.Instance.Segments.Any( s => s.ID == v ) )
  1625. {
  1626. logger.E( "Current Tag Not Exist RouteManager Point List" );
  1627. return;
  1628. }
  1629. //Todo: 현재 Segment ID 를 가져 와서 변경하는 방식으로 변경 필요.
  1630. var obstacle = RouteManager.Instance.Obstacles.Where( o => o.segmentID == v ).Single();
  1631. this.ChgObstacleDetectPattern( obstacle.fieldset );
  1632. logger.D( $"[Obstacle Pattern Chg] - {obstacle.fieldset}" );
  1633. }
  1634. /// <summary>
  1635. /// 현재 좌표 값이 등록된 Route 에 맞는 위치인지 확인한다.
  1636. /// 판단 기준은 Route 에 Tolerance 범위를 사용.
  1637. /// </summary>
  1638. /// <param name="route"></param>
  1639. /// <param name="currentPosition"></param>
  1640. /// <returns></returns>
  1641. bool CorrectPosition( Route route, double currentPosition )
  1642. {
  1643. var rScale = route.ScaleValue;
  1644. var rTolerance = route.ScaleTolerance;
  1645. var result = currentPosition - rScale;
  1646. if ( rTolerance < Math.Abs( result ) )
  1647. return false;
  1648. return true;
  1649. }
  1650. /// <summary>
  1651. /// if no is zero, Laser Off
  1652. /// bit Off, On, On, On,On Area1
  1653. /// </summary>
  1654. /// <param name="no"> 0 == Off Laser</param>
  1655. /// <returns></returns>
  1656. public bool ChgObstacleDetectPattern( int no )
  1657. {
  1658. var bitArray = BitUtils.ChgBitArray( no );
  1659. int bitIndex = 0;
  1660. this.obstacleBitList.ForEach( b =>
  1661. {
  1662. if ( bitArray[bitIndex] )
  1663. this.refObjects.IO.OutputOff( b );
  1664. else
  1665. this.refObjects.IO.OutputOn( b );
  1666. bitIndex++;
  1667. } );
  1668. ObstaclePattern = no;
  1669. return true;
  1670. }
  1671. public int GetObstacleDetectPattern()
  1672. {
  1673. int bitIndex = 0;
  1674. BitArray bitArray = new BitArray( this.obstacleBitList.Count );
  1675. this.obstacleBitList.ForEach( b =>
  1676. {
  1677. if ( this.refObjects.IO.IsOn( b, false ) )
  1678. bitArray.Set( bitIndex, false );
  1679. else
  1680. bitArray.Set( bitIndex, true );
  1681. bitIndex++;
  1682. } );
  1683. return BitUtils.ChgInt32( bitArray );
  1684. }
  1685. /// <summary>
  1686. /// Vehicle 이동 및 동작 중 Alarm 발생 시 처리
  1687. /// </summary>
  1688. /// <param name="alarmID"></param>
  1689. public void OccurVehicleAlarm( int alarmID )
  1690. {
  1691. var alarm = refObjects.Alarms.Where( x => x.AlarmId == alarmID ).FirstOrDefault();
  1692. if ( alarm != null )
  1693. {
  1694. if ( alarm.Level == eAlarmLevel.Warn )
  1695. {
  1696. HisAlarm hisAlarm = new HisAlarm();
  1697. hisAlarm.AlarmId = alarmID;
  1698. hisAlarm.Text = alarm.Name + " - " + alarm.Text;
  1699. hisAlarm.Solution = alarm.Solution;
  1700. var clone = ObjectCopyUtils.DeepClone<Alarm>( alarm );
  1701. this.refObjects.Sqlite.HisAlarmDAL.Insert( hisAlarm );
  1702. return;
  1703. }
  1704. }
  1705. this.MachineMode = eMachineMode.LocalMode;
  1706. this.VehicleStateProperty = eVehicleState.Abnormal;
  1707. this.ConveyorOff();
  1708. this.refObjects.AutoManager.ProcessAlarm( alarmID );
  1709. }
  1710. public void SetObstaclePattern( ObstacleControlEventArgs.eControlKind state, int value )
  1711. {
  1712. if ( state == ObstacleControlEventArgs.eControlKind.DRIVE )
  1713. {
  1714. this.ObstacleDrive = value;
  1715. ChgObstacleDetectPattern( this.ObstacleDrive );
  1716. }
  1717. else if ( state == ObstacleControlEventArgs.eControlKind.CURVE )
  1718. {
  1719. this.ObstacleCurve = value;
  1720. ChgObstacleDetectPattern( this.ObstacleCurve );
  1721. }
  1722. else
  1723. return;
  1724. }
  1725. public eSteeringState GetESteeringState() => this.refObjects.Steering.GetSteeringState();
  1726. #endregion
  1727. #region Event Subscribe
  1728. private void BMUManager_OnDisconnect( string obj )
  1729. {
  1730. this.BatteryIsConnect = false;
  1731. this.OccurVehicleAlarm( 32 );
  1732. }
  1733. private void BMUManager_OnConnect( string obj )
  1734. {
  1735. this.BatteryIsConnect = true;
  1736. //ReqCurrentPos();
  1737. }
  1738. private void BMUManager_OnFirstColtd( List<ReceivedData> obj )
  1739. {
  1740. }
  1741. private void BMUManager_OnChangedReceivedData( Serial.DataModel.ReceivedData obj )
  1742. {
  1743. var kind = CastTo<eDataKind>.From<Enum>( obj.DataKind );
  1744. switch ( kind )
  1745. {
  1746. case eDataKind.Voltage:
  1747. this.BatteryVoltage = (double)obj.Value;
  1748. break;
  1749. case eDataKind.Current:
  1750. this.BatteryCurrent = (double)obj.Value;
  1751. if ( BatteryCurrent > 3 )
  1752. this.BatteryChargeState = true;
  1753. else
  1754. this.BatteryChargeState = false;
  1755. break;
  1756. case eDataKind.BatteryState:
  1757. this.BatteryState = (double)obj.Value;
  1758. break;
  1759. case eDataKind.ChargeCompleteTime:
  1760. this.BatteryChargeTime = (double)obj.Value;
  1761. break;
  1762. case eDataKind.DisChargeCompleteTime:
  1763. this.BatteryDisChargeTime = (double)obj.Value;
  1764. break;
  1765. case eDataKind.SOC:
  1766. this.BatteryStateOfCharge = (double)obj.Value;
  1767. break;
  1768. case eDataKind.SOH:
  1769. this.BatteryStateOfHealth = (double)obj.Value;
  1770. break;
  1771. case eDataKind.ResidualCapacity:
  1772. this.BatteryCapacity = (double)obj.Value;
  1773. break;
  1774. case eDataKind.ResidualEnergy:
  1775. this.BatteryEnergy = (double)obj.Value;
  1776. break;
  1777. case eDataKind.Temperature:
  1778. this.BatteryTemperature = (double)obj.Value;
  1779. break;
  1780. default:
  1781. break;
  1782. }
  1783. }
  1784. private void AutoManager_OnOperationModeChanged( eOperatationMode obj )
  1785. {
  1786. this.refObjects.Drive.SetDriveOperationMode( obj );
  1787. }
  1788. private void ZmqManager_PropertyChanged( object sender, System.ComponentModel.PropertyChangedEventArgs e )
  1789. {
  1790. var property = sender.GetType().GetProperty( e.PropertyName );
  1791. var newValue = property.GetValue( sender, null );
  1792. switch ( e.PropertyName )
  1793. {
  1794. case "SegmentID":
  1795. {
  1796. var v = CastTo<int>.From<object>( newValue );
  1797. this.ObstaclePatternChange( v );
  1798. }
  1799. break;
  1800. case "RequestSteering":
  1801. {
  1802. var v = CastTo<eSteeringState>.From<object>( newValue );
  1803. switch ( v )
  1804. {
  1805. case eSteeringState.None:
  1806. break;
  1807. case eSteeringState.Left:
  1808. this.refObjects.Steering.ControlSteering( true );
  1809. break;
  1810. case eSteeringState.Right:
  1811. this.refObjects.Steering.ControlSteering();
  1812. break;
  1813. default:
  1814. break;
  1815. }
  1816. logger.D( $"[Request Steering] - {v}" );
  1817. }
  1818. break;
  1819. case "CurrentPointNo":
  1820. {
  1821. var v = CastTo<int>.From<object>( newValue );
  1822. logger.D( $"{this.CurrentTag} -> {v}" );
  1823. this.CurrentTag = v;
  1824. }
  1825. break;
  1826. case "RearDriveState":
  1827. {
  1828. var v = CastTo<DriveState>.From<object>( newValue );
  1829. this.RearDriveState = v;
  1830. }
  1831. break;
  1832. case "FrontLoadFactor":
  1833. {
  1834. var v = CastTo<double>.From<object>( newValue );
  1835. this.FrontLoadFactor = v;
  1836. this.FrontTorque = Math.Truncate( ( ( v * 1.9 ) / 1000 ) * 100 ) / 100;
  1837. }
  1838. break;
  1839. case "FrontRPM":
  1840. {
  1841. var v = CastTo<double>.From<object>( newValue );
  1842. this.FrontRpm = v;
  1843. var ll = ( ( ( ( v / 60 ) * ( 2 * Math.PI ) ) * 0.06 ) / 10 );
  1844. this.FrontSpeed = Math.Truncate( ll * 100 ) / 100;
  1845. }
  1846. break;
  1847. case "RearLoadFactor":
  1848. {
  1849. var v = CastTo<double>.From<object>( newValue );
  1850. this.RearLoadFactor = v;
  1851. this.RearTorque = Math.Truncate( ( ( v * 1.9 ) / 1000 ) * 100 ) / 100;
  1852. }
  1853. break;
  1854. case "RearRPM":
  1855. {
  1856. var v = CastTo<double>.From<object>( newValue );
  1857. this.RearRpm = v;
  1858. var ll = ( ( ( ( v / 60 ) * ( 2 * Math.PI ) ) * 0.06 ) / 10 );
  1859. this.RearSpeed = Math.Truncate( ll * 100 ) / 100;
  1860. }
  1861. break;
  1862. case "AutoReadyState":
  1863. {
  1864. var v = CastTo<eVehicleAutoReadyState>.From<object>(newValue);
  1865. this.AutoReadyState = v;
  1866. }
  1867. break;
  1868. case "LinearSpeed":
  1869. {
  1870. this.LinearSpeed = CastTo<double>.From<object>(newValue);
  1871. }
  1872. break;
  1873. case "CurveSpeed":
  1874. {
  1875. this.CurveSpeed = CastTo<double>.From<object>(newValue);
  1876. }
  1877. break;
  1878. case "JogSPeed":
  1879. {
  1880. this.JogSPeed = CastTo<double>.From<object>(newValue);
  1881. }
  1882. break;
  1883. case "AccelSpeed":
  1884. {
  1885. this.AccelSpeed = CastTo<double>.From<object>(newValue);
  1886. }
  1887. break;
  1888. case "DecelSpeed":
  1889. {
  1890. this.DecelSpeed = CastTo<double>.From<object>(newValue);
  1891. }
  1892. break;
  1893. case "CreepSpeed":
  1894. {
  1895. this.CreepSpeed = CastTo<double>.From<object>(newValue);
  1896. }
  1897. break;
  1898. case "CreepDistance":
  1899. {
  1900. this.CreepDistance = CastTo<double>.From<object>(newValue);
  1901. }
  1902. break;
  1903. default:
  1904. break;
  1905. }
  1906. }
  1907. private void Motion_PropertyChanged( object sender, System.ComponentModel.PropertyChangedEventArgs e )
  1908. {
  1909. var property = sender.GetType().GetProperty( e.PropertyName );
  1910. var newValue = property.GetValue( sender, null );
  1911. switch ( e.PropertyName )
  1912. {
  1913. case "CurrentPos":
  1914. {
  1915. var v = CastTo<double>.From<object>( newValue );
  1916. this.CurrentPosition = v;
  1917. }
  1918. break;
  1919. //case "CurrentTag":
  1920. // {
  1921. // var v = CastTo<int>.From<object>( newValue );
  1922. // logger.D( $"{this.CurrentTag} -> {v}" );
  1923. // this.CurrentTag = v;
  1924. // }
  1925. // break;
  1926. case "CurrentSpeed":
  1927. {
  1928. var v = CastTo<double>.From<object>( newValue );
  1929. this.CurrentSpeed = v;
  1930. }
  1931. break;
  1932. case "CurrentTorque":
  1933. {
  1934. var v = CastTo<double>.From<object>( newValue );
  1935. this.CurrentTorque = v;
  1936. }
  1937. break;
  1938. case "ReqSteeringState":
  1939. //{
  1940. // var v = CastTo<eSteeringState>.From<object>( newValue );
  1941. // switch ( v )
  1942. // {
  1943. // case eSteeringState.None:
  1944. // break;
  1945. // case eSteeringState.Left:
  1946. // this.refObjects.Steering.ControlSteering( true );
  1947. // break;
  1948. // case eSteeringState.Right:
  1949. // this.refObjects.Steering.ControlSteering();
  1950. // break;
  1951. // default:
  1952. // break;
  1953. // }
  1954. //}
  1955. break;
  1956. case "DriveServoState":
  1957. {
  1958. var v = CastTo<eDriveServoState>.From<object>( newValue );
  1959. if ( v == eDriveServoState.ServoOn )
  1960. this.refObjects.IO.OutputOn( "OUT_DRIVE_BRAKE_OFF" );
  1961. else
  1962. this.refObjects.IO.OutputOff( "OUT_DRIVE_BRAKE_OFF" );
  1963. }
  1964. break;
  1965. case "FrontDriveState":
  1966. {
  1967. var v = CastTo<DriveState>.From<object>( newValue );
  1968. this.FrontDriveState = v;
  1969. }
  1970. break;
  1971. case "RearDriveState":
  1972. {
  1973. var v = CastTo<DriveState>.From<object>( newValue );
  1974. this.RearDriveState = v;
  1975. }
  1976. break;
  1977. default:
  1978. break;
  1979. }
  1980. }
  1981. private void Steering_PropertyChanged( object sender, System.ComponentModel.PropertyChangedEventArgs e )
  1982. {
  1983. var property = sender.GetType().GetProperty( e.PropertyName );
  1984. var newValue = property.GetValue( sender, null );
  1985. //Todo: 나중에 Test 하자
  1986. //var ownPropperty = this.GetType().GetProperty(e.PropertyName);
  1987. if ( e.PropertyName.Equals( "SteeringState" ) )
  1988. {
  1989. var v = CastTo<eSteeringState>.From<object>( newValue );
  1990. this.SteeringState = v;
  1991. logger.D( $"steering - {v}" );
  1992. }
  1993. }
  1994. private void Clamp_PropertyChanged( object sender, System.ComponentModel.PropertyChangedEventArgs e )
  1995. {
  1996. var property = sender.GetType().GetProperty( e.PropertyName );
  1997. var newValue = property.GetValue( sender, null );
  1998. if ( e.PropertyName.Equals( "ClampState" ) )
  1999. {
  2000. var v = CastTo<eClampState>.From<object>( newValue );
  2001. this.ClampState = v;
  2002. }
  2003. }
  2004. private void IO_OnChangedIO( BitBlock bit )
  2005. {
  2006. switch ( bit.Tag )
  2007. {
  2008. case "IN_CV_DETECT_01":
  2009. this.IsContain = bit.IsBitOn;
  2010. this.refObjects.ZmqManager.Publish( "Contain", this.IsContain.ToString() );
  2011. break;
  2012. case "IN_MC_ON":
  2013. if ( bit.IsBitOn )
  2014. {
  2015. if ( !this.refObjects.IO.IsOn( "IN_EMS_SW" ) && this.refObjects.IO.IsOn( "IN_CP_ON_SAFETY" ) && this.refObjects.IO.IsOn( "IN_CP_ON_24V" ) )
  2016. this.VehicleStateProperty = eVehicleState.Idle;
  2017. }
  2018. else
  2019. {
  2020. if ( this.ObstacleStateProperty == eObstacleState.Abnormal )
  2021. this.OccurVehicleAlarm( 42 );
  2022. else
  2023. this.OccurVehicleAlarm( 29 );
  2024. }
  2025. break;
  2026. case "IN_EMS_SW":
  2027. if ( bit.IsBitOn )
  2028. this.OccurVehicleAlarm( 28 );
  2029. break;
  2030. case "IN_CP_ON_SAFETY":
  2031. if ( !bit.IsBitOn )
  2032. this.OccurVehicleAlarm( 31 );
  2033. break;
  2034. case "IN_CP_ON_24V":
  2035. if ( !bit.IsBitOn )
  2036. this.OccurVehicleAlarm( 30 );
  2037. break;
  2038. case "IN_OBSTRUCTION_DETECT_ERROR":
  2039. case "IN_OBSTRUCTION_DETECT_SAFETY":
  2040. case "IN_OBSTRUCTION_DETECT_STOP":
  2041. case "IN_OBSTRUCTION_DETECT_SLOW":
  2042. CheckObstacle();
  2043. break;
  2044. case "IN_BUMPER_DETECT":
  2045. if ( bit.IsBitOn )
  2046. this.refObjects.ZmqManager.SetSafetyBumper();
  2047. break;
  2048. default:
  2049. break;
  2050. }
  2051. }
  2052. private void Steering_OnSteeringError( object sender, int e )
  2053. {
  2054. if ( e != 0 )
  2055. {
  2056. logger.E( $"[Steering] - Control Error {e}" );
  2057. this.OccurVehicleAlarm( e );
  2058. }
  2059. else
  2060. {
  2061. var msg = new DriveControlEventArgs()
  2062. {
  2063. EventDir = DriveControlEventArgs.eEventDir.ToFront,
  2064. ControlKind = DriveControlEventArgs.eControlKind.Steering,
  2065. Result = FluentResults.Results.Ok<DriveControlEventArgs.eMoveDir>( DriveControlEventArgs.eMoveDir.LEFT ),
  2066. };
  2067. this.eventAggregator.GetEvent<DriveControlPubSubEvent>().Publish( msg );
  2068. }
  2069. }
  2070. #endregion
  2071. }
  2072. }