PlcPointParamsViewModel.cs 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  1. using Cognex.VisionPro;
  2. using MahApps.Metro.Controls;
  3. using MaterialDesignThemes.Wpf;
  4. using MathNet.Numerics.LinearAlgebra;
  5. using NPOI.SS.Formula.Functions;
  6. using OpenCvSharp.Flann;
  7. using Prism.Commands;
  8. using Prism.Events;
  9. using Prism.Ioc;
  10. using Prism.Mvvm;
  11. using Prism.Regions;
  12. using Prism.Services.Dialogs;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Collections.ObjectModel;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. using System.Windows;
  21. using TeamAAS_VP.Controls;
  22. using TeamAAS_VP.Core;
  23. using TeamAAS_VP.Core.PLCs;
  24. using TeamAAS_VP.Core.Robots;
  25. using TeamAAS_VP.DxfModule;
  26. using TeamAAS_VP.Enums;
  27. using TeamAAS_VP.Events;
  28. using TeamAAS_VP.Interfaces;
  29. using TeamAAS_VP.Models;
  30. using TeamAAS_VP.Models.PLC;
  31. using TeamAAS_VP.Models.Robot;
  32. using TeamAAS_VP.Resources.Languages;
  33. using TeamAAS_VP.Services;
  34. using TeamAAS_VP.Views.Product;
  35. using static TeamAAS_VP.ViewModels.Product.AutoCorrectLockPointViewModel;
  36. namespace TeamAAS_VP.ViewModels.Product
  37. {
  38. public class PlcPointParamsViewModel : BindableBase, IConfirmNavigationRequest
  39. {
  40. IRegionManager _regionManager;
  41. IEventAggregator _eventAggregator;
  42. IContainerProvider _container;
  43. IDialogService _dialogService;
  44. IConfigService _configService;
  45. IRobotService _robotService;
  46. ISystemDatabaseService _systemDatabaseService;
  47. IRemoteCommandService _remoteCommandService;
  48. ICalibrationService _calibrationService;
  49. ICameraService _cameraService;
  50. IProductService _productService;
  51. #region 属性
  52. private ObservableCollection<AxisExtended> _AdditionalAxisList;
  53. public ObservableCollection<AxisExtended> AdditionalAxisList
  54. {
  55. get { return _AdditionalAxisList; }
  56. set { SetProperty(ref _AdditionalAxisList, value); }
  57. }
  58. private ProductModel _SelectProduct;
  59. /// <summary>
  60. /// 选中的产品
  61. /// </summary>
  62. public ProductModel SelectProduct
  63. {
  64. get { return _SelectProduct; }
  65. set { SetProperty(ref _SelectProduct, value); }
  66. }
  67. private PlcPoint _SelectedPoint;
  68. public PlcPoint SelectedPoint
  69. {
  70. get { return _SelectedPoint; }
  71. set { SetProperty(ref _SelectedPoint, value); }
  72. }
  73. private PlcPoint _selectedPointInDataGrid;
  74. public PlcPoint SelectedPointInDataGrid
  75. {
  76. get { return _selectedPointInDataGrid; }
  77. set
  78. {
  79. if (SetProperty(ref _selectedPointInDataGrid, value))
  80. {
  81. SelectedPointInComboBox = value;
  82. // update command availability
  83. _MovePointUpCommand?.RaiseCanExecuteChanged();
  84. _MovePointDownCommand?.RaiseCanExecuteChanged();
  85. // 更新依赖可执行状态的命令
  86. _TechPointCommand?.RaiseCanExecuteChanged();
  87. _ExecuteMotion?.RaiseCanExecuteChanged();
  88. }
  89. // 可以同步到 SelectPoint 属性
  90. SelectedPoint = value;
  91. }
  92. }
  93. private PlcPoint _selectedPointInComboBox;
  94. public PlcPoint SelectedPointInComboBox
  95. {
  96. get { return _selectedPointInComboBox; }
  97. set
  98. {
  99. if (SetProperty(ref _selectedPointInComboBox, value))
  100. {
  101. SelectedPointInDataGrid = value;
  102. }
  103. // 可以同步到 SelectPoint 属性
  104. SelectedPoint = value;
  105. }
  106. }
  107. private ObservableCollection<PlcPoint> _Points = new ObservableCollection<PlcPoint>();
  108. /// <summary>
  109. /// 点位集合
  110. /// </summary>
  111. public ObservableCollection<PlcPoint> Points
  112. {
  113. get { return _Points; }
  114. set { SetProperty(ref _Points, value); }
  115. }
  116. private MotionCommand _SelectMotionCommand;
  117. /// <summary>
  118. /// 选中的运动指令
  119. /// </summary>
  120. public MotionCommand SelectMotionCommand
  121. {
  122. get { return _SelectMotionCommand; }
  123. set { SetProperty(ref _SelectMotionCommand, value); }
  124. }
  125. public Management management { get; set; }
  126. private XYZU_Robot _Robot;
  127. public XYZU_Robot Robot
  128. {
  129. get { return _Robot; }
  130. set
  131. {
  132. SetProperty(ref _Robot, value);
  133. }
  134. }
  135. private int _SelectedIndex;
  136. public int SelectedIndex
  137. {
  138. get { return _SelectedIndex; }
  139. set { SetProperty(ref _SelectedIndex, value); }
  140. }
  141. private double _Distance = 1;
  142. public double Distance
  143. {
  144. get { return _Distance; }
  145. set
  146. {
  147. SetProperty(ref _Distance, value);
  148. try
  149. {
  150. if (Robot == null)
  151. {
  152. return;
  153. }
  154. _configService.UpdateRobotStepDistance(Robot.Id, value);
  155. }
  156. catch (Exception)
  157. {
  158. }
  159. }
  160. }
  161. private ObservableCollection<ProcedureModel> _ProcedureModels;
  162. /// <summary>
  163. /// 流程集合
  164. /// </summary>
  165. public ObservableCollection<ProcedureModel> ProcedureModels
  166. {
  167. get { return _ProcedureModels; }
  168. set { SetProperty(ref _ProcedureModels, value); }
  169. }
  170. private ProcedureModel _SelectProcedure;
  171. /// <summary>
  172. /// 选中的流程
  173. /// </summary>
  174. public ProcedureModel SelectProcedure
  175. {
  176. get { return _SelectProcedure; }
  177. set
  178. {
  179. SetProperty(ref _SelectProcedure, value);
  180. }
  181. }
  182. private bool _IsGrap;
  183. public bool IsGrap
  184. {
  185. get { return _IsGrap; }
  186. set { SetProperty(ref _IsGrap, value); }
  187. }
  188. private ObservableCollection<CameraInfo> _CameraList;
  189. public ObservableCollection<CameraInfo> CameraList
  190. {
  191. get { return _CameraList; }
  192. set { SetProperty(ref _CameraList, value); }
  193. }
  194. private CameraInfo _SelectedCamera;
  195. public CameraInfo SelectedCamera
  196. {
  197. get { return _SelectedCamera; }
  198. set
  199. {
  200. SetProperty(ref _SelectedCamera, value);
  201. if (value != null)
  202. {
  203. if (Camera != null)
  204. {
  205. if (Camera.IsGrabbing)
  206. {
  207. Camera.StopGrabbing();
  208. }
  209. Camera.ImageCallbackEvent -= Camera_ImageCallbackEvent;
  210. }
  211. Camera = _cameraService.GetCamera(value.Id);
  212. Camera.ImageCallbackEvent += Camera_ImageCallbackEvent;
  213. }
  214. }
  215. }
  216. private ICamera _Camera;
  217. public ICamera Camera
  218. {
  219. get { return _Camera; }
  220. set { SetProperty(ref _Camera, value); }
  221. }
  222. private ICogImage _Image;
  223. public ICogImage Image
  224. {
  225. get { return _Image; }
  226. set { SetProperty(ref _Image, value); }
  227. }
  228. private string _Message;
  229. public string Message
  230. {
  231. get { return _Message; }
  232. set { SetProperty(ref _Message, value); }
  233. }
  234. private bool _IsLeftDrawerOpen;
  235. public bool IsLeftDrawerOpen
  236. {
  237. get { return _IsLeftDrawerOpen; }
  238. set
  239. {
  240. SetProperty(ref _IsLeftDrawerOpen, value);
  241. if (!value)
  242. {
  243. if (IsGrap)
  244. {
  245. ExecuteStopGrabbingCommand();
  246. }
  247. }
  248. }
  249. }
  250. private int _Inhal = 1;
  251. public int Inhal
  252. {
  253. get { return _Inhal; }
  254. set { SetProperty(ref _Inhal, value); }
  255. }
  256. private PlcPoint _PickP1 = new PlcPoint();
  257. public PlcPoint PickP1
  258. {
  259. get { return _PickP1; }
  260. set { SetProperty(ref _PickP1, value); }
  261. }
  262. private PlcPoint _PickP2 = new PlcPoint();
  263. public PlcPoint PickP2
  264. {
  265. get { return _PickP2; }
  266. set { SetProperty(ref _PickP2, value); }
  267. }
  268. private int _ColumnNum = 18;
  269. public int ColumnNum
  270. {
  271. get { return _ColumnNum; }
  272. set { SetProperty(ref _ColumnNum, value); }
  273. }
  274. #endregion
  275. #region 命令
  276. private DelegateCommand _NextCommand;
  277. public DelegateCommand NextCommand =>
  278. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  279. private DelegateCommand _BackCommand;
  280. public DelegateCommand BackCommand =>
  281. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  282. private DelegateCommand _LoadedCommand;
  283. public DelegateCommand LoadedCommand =>
  284. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  285. private DelegateCommand<object> _ExecuteMotion;
  286. public DelegateCommand<object> ExecuteMotion =>
  287. _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecutePointCommand).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
  288. private DelegateCommand<object> _JogCommand;
  289. public DelegateCommand<object> JogCommand =>
  290. _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  291. private DelegateCommand _TechPointCommand;
  292. public DelegateCommand TechPointCommand =>
  293. _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecutePointCommand).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
  294. private DelegateCommand<string> _MotorCommand;
  295. public DelegateCommand<string> MotorCommand =>
  296. _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  297. private DelegateCommand _ResetCommand;
  298. public DelegateCommand ResetCommand =>
  299. _ResetCommand ?? (_ResetCommand = new DelegateCommand(ExecuteResetCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  300. private DelegateCommand _sFreeCommand;
  301. public DelegateCommand sFreeCommand =>
  302. _sFreeCommand ?? (_sFreeCommand = new DelegateCommand(ExecutesFreeCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  303. private DelegateCommand _SLockCommand;
  304. public DelegateCommand SLockCommand =>
  305. _SLockCommand ?? (_SLockCommand = new DelegateCommand(ExecuteSLockCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  306. private DelegateCommand _SelectionChangedCommand;
  307. public DelegateCommand SelectionChangedCommand =>
  308. _SelectionChangedCommand ?? (_SelectionChangedCommand = new DelegateCommand(ExecuteSelectionChangedCommand));
  309. private DelegateCommand _AddPointCommand;
  310. public DelegateCommand AddPointCommand =>
  311. _AddPointCommand ?? (_AddPointCommand = new DelegateCommand(ExecuteAddPointCommand));
  312. private DelegateCommand _DeletePointCommand;
  313. public DelegateCommand DeletePointCommand =>
  314. _DeletePointCommand ?? (_DeletePointCommand = new DelegateCommand(ExecuteDeletePointCommand, CanExecuteDeletePointCommand).ObservesProperty(() => SelectedPointInDataGrid));
  315. private DelegateCommand _MovePointUpCommand;
  316. public DelegateCommand MovePointUpCommand => _MovePointUpCommand ?? (_MovePointUpCommand = new DelegateCommand(ExecuteMovePointUpCommand, CanMovePointUp));
  317. private DelegateCommand _MovePointDownCommand;
  318. public DelegateCommand MovePointDownCommand => _MovePointDownCommand ?? (_MovePointDownCommand = new DelegateCommand(ExecuteMovePointDownCommand, CanMovePointDown));
  319. private DelegateCommand _ImportCadPointCommand;
  320. public DelegateCommand ImportCadPointCommand =>
  321. _ImportCadPointCommand ?? (_ImportCadPointCommand = new DelegateCommand(ExecuteImportCadPointCommand));
  322. private DelegateCommand _StartGrabbingCommand;
  323. public DelegateCommand StartGrabbingCommand =>
  324. _StartGrabbingCommand ?? (_StartGrabbingCommand = new DelegateCommand(ExecuteStartGrabbingCommand, CanExecuteStartGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(() => SelectedCamera));
  325. private DelegateCommand _StopGrabbingCommand;
  326. public DelegateCommand StopGrabbingCommand =>
  327. _StopGrabbingCommand ?? (_StopGrabbingCommand = new DelegateCommand(ExecuteStopGrabbingCommand, CanExecuteStopGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(() => SelectedCamera));
  328. private DelegateCommand _GoPickCommand;
  329. public DelegateCommand GoPickCommand =>
  330. _GoPickCommand ?? (_GoPickCommand = new DelegateCommand(ExecuteGoPickCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
  331. private DelegateCommand _GoRepositionCommand;
  332. public DelegateCommand GoRepositionCommand =>
  333. _GoRepositionCommand ?? (_GoRepositionCommand = new DelegateCommand(ExecuteGoRepositionCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
  334. private DelegateCommand _TakeProductPhotoCommand;
  335. public DelegateCommand TakeProductPhotoCommand =>
  336. _TakeProductPhotoCommand ?? (_TakeProductPhotoCommand = new DelegateCommand(ExecuteTakeProductPhotoCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
  337. private DelegateCommand _TakeProductCommand;
  338. public DelegateCommand TakeProductCommand =>
  339. _TakeProductCommand ?? (_TakeProductCommand = new DelegateCommand(ExecuteTakeProductCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
  340. //附加轴,轴点动+命令
  341. private DelegateCommand<object> _AdditionalAxisJogPlusCommand;
  342. public DelegateCommand<object> AdditionalAxisJogPlusCommand =>
  343. _AdditionalAxisJogPlusCommand ?? (_AdditionalAxisJogPlusCommand = new DelegateCommand<object>(ExecuteAdditionalAxisJogPlusCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  344. //附加轴,轴点动-命令
  345. private DelegateCommand<object> _AdditionalAxisJogMinusCommand;
  346. public DelegateCommand<object> AdditionalAxisJogMinusCommand =>
  347. _AdditionalAxisJogMinusCommand ?? (_AdditionalAxisJogMinusCommand = new DelegateCommand<object>(ExecuteAdditionalAxisJogMinusCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  348. private DelegateCommand<object> _AdditionalAxisMotorOnCommand;
  349. public DelegateCommand<object> AdditionalAxisMotorOnCommand =>
  350. _AdditionalAxisMotorOnCommand ?? (_AdditionalAxisMotorOnCommand = new DelegateCommand<object>(ExecuteAdditionalAxisMotorOnCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  351. private DelegateCommand<object> _AdditionalAxisMotorOffCommand;
  352. public DelegateCommand<object> AdditionalAxisMotorOffCommand =>
  353. _AdditionalAxisMotorOffCommand ?? (_AdditionalAxisMotorOffCommand = new DelegateCommand<object>(ExecuteAdditionalAxisMotorOffCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
  354. private DelegateCommand<string> _PickTechCommand;
  355. public DelegateCommand<string> PickTechCommand =>
  356. _PickTechCommand ?? (_PickTechCommand = new DelegateCommand<string>(ExecutePickTechCommand));
  357. private DelegateCommand<string> _PickMoveCommand;
  358. public DelegateCommand<string> PickMoveCommand =>
  359. _PickMoveCommand ?? (_PickMoveCommand = new DelegateCommand<string>(ExecutePickMoveCommand));
  360. private DelegateCommand _CalPickPosCommand;
  361. public DelegateCommand CalPickPosCommand =>
  362. _CalPickPosCommand ?? (_CalPickPosCommand = new DelegateCommand(ExecuteCalPickPosCommand));
  363. #endregion
  364. #region 事件
  365. #endregion
  366. public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  367. IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService, IRemoteCommandService remoteCommandService,
  368. ICalibrationService calibrationService, ICameraService cameraService, IProductService productService)
  369. {
  370. _regionManager = regionManager;
  371. _eventAggregator = ea;
  372. _container = container;
  373. _dialogService = dialogService;
  374. _configService = configService;
  375. _systemDatabaseService = systemDatabaseService;
  376. //订阅权限登录事件
  377. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  378. management = _container.Resolve<Management>();
  379. _robotService = robotService;
  380. _remoteCommandService = remoteCommandService;
  381. _calibrationService = calibrationService;
  382. _cameraService = cameraService;
  383. _productService = productService;
  384. }
  385. #region 方法
  386. /// <summary>
  387. /// 下一步
  388. /// </summary>
  389. void ExecuteNextCommand()
  390. {
  391. NavigationParameters param = new NavigationParameters();
  392. param.Add("SelectProduct", SelectProduct);
  393. _regionManager.RequestNavigate("ProductRegionContext", "ProductParams", param);
  394. }
  395. /// <summary>
  396. /// 上一步
  397. /// </summary>
  398. void ExecuteBackCommand()
  399. {
  400. NavigationParameters param = new NavigationParameters();
  401. param.Add("SelectProduct", SelectProduct);
  402. param.Add("SelectedProcedure", null);
  403. _regionManager.RequestNavigate("ProductRegionContext", "ProcessBasics", param);
  404. }
  405. /// <summary>
  406. /// 点动
  407. /// </summary>
  408. /// <param name="obj"></param>
  409. private async void ExecuteJogCommand(object obj)
  410. {
  411. if (Robot == null || !Robot.IsConnected) return;
  412. try
  413. {
  414. var items = ((string)obj).Split(':');
  415. //如果移动距离大于10mm,则提示用户确认
  416. double distance = double.Parse(items[1]);
  417. if (Math.Abs(distance) >= 10)
  418. {
  419. if (MessageBox.Show($"确认要点动距离 {distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  420. {
  421. return;
  422. }
  423. }
  424. Robot.Timeout = 6000000;
  425. switch (items[0])
  426. {
  427. case "X+":
  428. await Robot.JogAsync("X", distance);
  429. break;
  430. case "X-":
  431. await Robot.JogAsync("X", -distance);
  432. break;
  433. case "Y+":
  434. await Robot.JogAsync("Y", distance);
  435. break;
  436. case "Y-":
  437. await Robot.JogAsync("Y", -distance);
  438. break;
  439. case "Z+":
  440. await Robot.JogAsync("Z", distance);
  441. break;
  442. case "Z-":
  443. await Robot.JogAsync("Z", -distance);
  444. break;
  445. case "U+":
  446. await Robot.JogAsync("U", distance);
  447. break;
  448. case "U-":
  449. await Robot.JogAsync("U", -distance);
  450. break;
  451. case "V+":
  452. await Robot.JogAsync("V", distance);
  453. break;
  454. case "V-":
  455. await Robot.JogAsync("V", -distance);
  456. break;
  457. case "W+":
  458. await Robot.JogAsync("W", distance);
  459. break;
  460. case "W-":
  461. await Robot.JogAsync("W", -distance);
  462. break;
  463. default:
  464. break;
  465. }
  466. Robot.Timeout = 5000;
  467. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  468. }
  469. catch (Exception ex)
  470. {
  471. LogHelper.WriteLogError("机器人点位-机器人点动时出错", ex);
  472. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  473. }
  474. }
  475. /// <summary>
  476. /// 执行运动
  477. /// </summary>
  478. /// <param name="obj"></param>
  479. async void ExecuteExecuteMotion(object parameter)
  480. {
  481. if (parameter == null)
  482. {
  483. return;
  484. }
  485. if (SelectedPoint == null)
  486. {
  487. return;
  488. }
  489. var values = (object[])parameter;
  490. var point = new RPoint()
  491. {
  492. X = SelectedPoint.X_Position,
  493. Y = SelectedPoint.Y_Position,
  494. Z = SelectedPoint.Z_Position_Start,
  495. U = SelectedPoint.U_Position,
  496. V = SelectedPoint.R_Position,
  497. };
  498. MotionCommand motionCmd = (MotionCommand)values[1];
  499. if (Robot == null || !Robot.IsConnected) return;
  500. try
  501. {
  502. //确认要执行该点位的该运动指令吗
  503. if (MessageBox.Show($"确认要执行点位 {SelectedPoint.Number} 的 {motionCmd} 指令吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  504. {
  505. return;
  506. }
  507. if (SelectedIndex == 1)
  508. {
  509. var curpos = await Robot.GetRobotPosAsync();
  510. var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
  511. curpos.Z = 0;
  512. await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, PickP1.Z_Position_Stop);
  513. curpos.X = SelectedPoint.X_Position;
  514. curpos.Y = SelectedPoint.Y_Position;
  515. curpos.Z = SelectedPoint.Z_Position_Start;
  516. curpos.U = SelectedPoint.U_Position;
  517. await Robot.CalibMotionAsync(curpos, 0);
  518. }
  519. else
  520. {
  521. //Robot.Timeout = 6000000;
  522. switch (motionCmd)
  523. {
  524. case MotionCommand.Go:
  525. await Robot.GoAsync(point);
  526. break;
  527. case MotionCommand.Jump:
  528. await Robot.JumpAsync(point, 0);
  529. break;
  530. case MotionCommand.Move:
  531. await Robot.MoveAsync(point);
  532. break;
  533. }
  534. }
  535. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  536. }
  537. catch (Exception ex)
  538. {
  539. LogHelper.WriteLogError("机器人点位-执行点位时出错", ex);
  540. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  541. }
  542. }
  543. /// <summary>
  544. /// 示教点位
  545. /// </summary>
  546. /// <param name="point"></param>
  547. async void ExecuteTechPointCommand()
  548. {
  549. if (Robot == null || !Robot.IsConnected) return;
  550. if (SelectedPoint == null) return;
  551. try
  552. {
  553. //如果当前的选项卡处于锁付点位,则提示用户当前模式不允许进行示教
  554. if (SelectedIndex == 4)
  555. {
  556. //如果local为空,则必须先通过相机定位产品,否则无法示教锁付点位
  557. if (toolCoord == null)
  558. {
  559. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "当前模式不允许直接示教贴敷点位,请先通过相机定位产品和定位辅料!", Duration = 1 });
  560. return;
  561. }
  562. //弹窗用户是否确认要示教该点位
  563. if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  564. {
  565. return;
  566. }
  567. var curpos1 = await Robot.GetRobotPosAsync();
  568. //将当前点位转换为产品Local坐标系下的点位
  569. SelectedPoint.X_Position = (float)curpos1.X;
  570. SelectedPoint.Y_Position = (float)curpos1.Y;
  571. SelectedPoint.Z_Position_Start = curpos1.Z;
  572. SelectedPoint.U_Position = curpos1.U;
  573. SelectedPoint.R_Position = curpos1.V;
  574. SelectProduct.FixedUpCameraTempletAngle = _FixedUpCameraTempletAngle;
  575. SelectProduct.MoveDownCamerTempletAngle = _MoveCameraTempletAngle;
  576. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  577. return;
  578. }
  579. else if (SelectedIndex == 1)
  580. {
  581. //弹窗用户是否确认要示教该点位
  582. if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  583. {
  584. return;
  585. }
  586. var curpos = await Robot.GetRobotPosAsync();
  587. var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
  588. SelectedPoint.X_Position = curpos.X;
  589. SelectedPoint.Y_Position = curpos.Y;
  590. SelectedPoint.Z_Position_Start = curpos.Z;
  591. SelectedPoint.U_Position = curpos.U;
  592. SelectedPoint.R_Position = curpos.V;
  593. SelectedPoint.Z_Position_Stop = addpos;
  594. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  595. }
  596. else
  597. {
  598. //弹窗用户是否确认要示教该点位
  599. if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  600. {
  601. return;
  602. }
  603. var curpos = await Robot.GetRobotPosAsync();
  604. SelectedPoint.X_Position = curpos.X;
  605. SelectedPoint.Y_Position = curpos.Y;
  606. SelectedPoint.Z_Position_Start = curpos.Z;
  607. SelectedPoint.U_Position = curpos.U;
  608. SelectedPoint.R_Position = curpos.V;
  609. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  610. }
  611. }
  612. catch (Exception ex)
  613. {
  614. LogHelper.WriteLogError("机器人点位-示教点位时出错", ex);
  615. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  616. }
  617. }
  618. void ExecuteLoadedCommand()
  619. {
  620. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  621. {
  622. IsAllowEdit = false;
  623. }
  624. else
  625. {
  626. IsAllowEdit = true;
  627. }
  628. }
  629. /// <summary>
  630. /// 电机
  631. /// </summary>
  632. /// <param name="obj"></param>
  633. private async void ExecuteMotorCommand(string obj)
  634. {
  635. if (Robot == null || !Robot.IsConnected) return;
  636. try
  637. {
  638. await Robot.MotorAsync(Convert.ToBoolean(obj));
  639. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  640. }
  641. catch (Exception ex)
  642. {
  643. LogHelper.WriteLogError("机器人点击操作时出错!", ex);
  644. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  645. }
  646. }
  647. /// <summary>
  648. /// 重置
  649. /// </summary>
  650. private async void ExecuteResetCommand()
  651. {
  652. if (Robot == null || !Robot.IsConnected) return;
  653. try
  654. {
  655. await Robot.ResetAsync();
  656. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  657. }
  658. catch (Exception ex)
  659. {
  660. LogHelper.WriteLogError("重置机器人时出错!", ex);
  661. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  662. }
  663. }
  664. /// <summary>
  665. /// 锁定刹车
  666. /// </summary>
  667. private async void ExecuteSLockCommand()
  668. {
  669. if (Robot == null || !Robot.IsConnected) return;
  670. try
  671. {
  672. await Robot.SLockAsync();
  673. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  674. }
  675. catch (Exception ex)
  676. {
  677. LogHelper.WriteLogError("机器人锁定刹车时出错!", ex);
  678. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  679. }
  680. }
  681. /// <summary>
  682. /// 释放刹车
  683. /// </summary>
  684. private async void ExecutesFreeCommand()
  685. {
  686. if (Robot == null || !Robot.IsConnected) return;
  687. try
  688. {
  689. await Robot.SFreeAsync();
  690. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  691. }
  692. catch (Exception ex)
  693. {
  694. LogHelper.WriteLogError("机器人释放刹车时出错!", ex);
  695. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  696. }
  697. }
  698. private bool CanExecute
  699. {
  700. get
  701. {
  702. // 命令可执行仅当机器人可执行且已选择点位
  703. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  704. {
  705. return true;
  706. }
  707. return false;
  708. }
  709. }
  710. //是否可以示教或者执行点位
  711. private bool CanExecutePointCommand
  712. {
  713. get
  714. {
  715. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  716. {
  717. return SelectedPointInDataGrid != null;
  718. }
  719. return false;
  720. }
  721. }
  722. /// <summary>
  723. /// 点位表切换时
  724. /// </summary>
  725. void ExecuteSelectionChangedCommand()
  726. {
  727. switch (SelectedIndex)
  728. {
  729. case 0:
  730. Points = SelectProduct.PickCameraPoints;
  731. break;
  732. case 1:
  733. Points = SelectProduct.PickPoints;
  734. break;
  735. case 2:
  736. Points = SelectProduct.SecPosCameraPoints;
  737. break;
  738. case 3:
  739. Points = SelectProduct.ScrewCameraPoints;
  740. break;
  741. case 4:
  742. Points = SelectProduct.ScrewPoints;
  743. break;
  744. case 5:
  745. Points = SelectProduct.CheckCameraPoints;
  746. break;
  747. default:
  748. break;
  749. }
  750. }
  751. /// <summary>
  752. /// 增加点位
  753. /// </summary>
  754. void ExecuteAddPointCommand()
  755. {
  756. //添加点位
  757. Points.Add(new PlcPoint()
  758. {
  759. Number = Points.Count + 1,
  760. X_Velocity = 100,
  761. Y_Velocity = 100,
  762. Z_Velocity_Start = 100,
  763. Z_Velocity_Stop = 100,
  764. U_Velocity = 100,
  765. R_Velocity = 100,
  766. });
  767. // update commands
  768. _MovePointUpCommand?.RaiseCanExecuteChanged();
  769. _MovePointDownCommand?.RaiseCanExecuteChanged();
  770. }
  771. /// <summary>
  772. /// 移除点位
  773. /// </summary>
  774. void ExecuteDeletePointCommand()
  775. {
  776. if (SelectedPoint == null)
  777. {
  778. return;
  779. }
  780. // 确认删除
  781. if (MessageBox.Show("确认要删除选中的点位吗?", "删除点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  782. {
  783. return;
  784. }
  785. int removedIndex = Points.IndexOf(SelectedPoint);
  786. Points.Remove(SelectedPoint);
  787. //重新编号
  788. for (int i = 0; i < Points.Count; i++)
  789. {
  790. Points[i].Number = i + 1;
  791. }
  792. // adjust selection
  793. if (Points.Count > 0)
  794. {
  795. int newIndex = Math.Min(removedIndex, Points.Count - 1);
  796. SelectedPointInDataGrid = Points[newIndex];
  797. }
  798. else
  799. {
  800. SelectedPointInDataGrid = null;
  801. }
  802. // update commands
  803. _MovePointUpCommand?.RaiseCanExecuteChanged();
  804. _MovePointDownCommand?.RaiseCanExecuteChanged();
  805. }
  806. bool CanExecuteDeletePointCommand()
  807. {
  808. return SelectedPointInDataGrid != null;
  809. }
  810. private bool CanMovePointUp()
  811. {
  812. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) > 0;
  813. }
  814. private bool CanMovePointDown()
  815. {
  816. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) >= 0 && Points.IndexOf(SelectedPointInDataGrid) < Points.Count - 1;
  817. }
  818. /// <summary>
  819. /// 向上移动点位
  820. /// </summary>
  821. void ExecuteMovePointUpCommand()
  822. {
  823. if (SelectedPointInDataGrid == null) return;
  824. // 确认移动
  825. if (MessageBox.Show("确认将选中点位上移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  826. {
  827. return;
  828. }
  829. int idx = Points.IndexOf(SelectedPointInDataGrid);
  830. if (idx <= 0) return;
  831. var item = SelectedPointInDataGrid;
  832. Points.Move(idx, idx - 1);
  833. // renumber
  834. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  835. SelectedPointInDataGrid = item;
  836. _MovePointUpCommand?.RaiseCanExecuteChanged();
  837. _MovePointDownCommand?.RaiseCanExecuteChanged();
  838. }
  839. /// <summary>
  840. /// 向下移动点位
  841. /// </summary>
  842. void ExecuteMovePointDownCommand()
  843. {
  844. if (SelectedPointInDataGrid == null) return;
  845. // 确认移动
  846. if (MessageBox.Show("确认将选中点位下移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  847. {
  848. return;
  849. }
  850. int idx = Points.IndexOf(SelectedPointInDataGrid);
  851. if (idx < 0 || idx >= Points.Count - 1) return;
  852. var item = SelectedPointInDataGrid;
  853. Points.Move(idx, idx + 1);
  854. // renumber
  855. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  856. SelectedPointInDataGrid = item;
  857. _MovePointUpCommand?.RaiseCanExecuteChanged();
  858. _MovePointDownCommand?.RaiseCanExecuteChanged();
  859. }
  860. /// <summary>
  861. /// CAD导入点位
  862. /// </summary>
  863. async void ExecuteImportCadPointCommand()
  864. {
  865. try
  866. {
  867. var view = new DxfView();
  868. //show the dialog
  869. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  870. if (result != null)
  871. {
  872. var cadPoints = view.Points;
  873. if (cadPoints != null && cadPoints.Count > 0)
  874. {
  875. //要导入的开始点编号
  876. int startNumber = view.StartIndex;
  877. //弹窗提示用户是否确认要导入从该编号开始的点位,点位数量为cadPoints.Count
  878. if (MessageBox.Show($"确认要从点位编号 {startNumber} 开始导入 {cadPoints.Count} 个点位吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  879. {
  880. return;
  881. }
  882. //导入点位
  883. for (int i = 0; i < cadPoints.Count; i++)
  884. {
  885. //如果点位编号已存在,则更新该点位,否则新增点位,只更新XY坐标
  886. var point = cadPoints[i];
  887. var existingPoint = Points.FirstOrDefault(p => p.Number == startNumber + i);
  888. if (existingPoint != null)
  889. {
  890. existingPoint.X_Position = point.X;
  891. existingPoint.Y_Position = point.Y;
  892. }
  893. else
  894. {
  895. Points.Add(new PlcPoint()
  896. {
  897. Number = startNumber + i,
  898. X_Position = point.X,
  899. Y_Position = point.Y,
  900. X_Velocity = 100,
  901. Y_Velocity = 100,
  902. Z_Velocity_Start = 100,
  903. Z_Velocity_Stop = 100,
  904. U_Velocity = 100,
  905. R_Velocity = 100,
  906. });
  907. }
  908. }
  909. //对所有的点位重新编号,确保编号连续
  910. var sortedPoints = Points.OrderBy(p => p.Number).ToList();
  911. Points.Clear();
  912. for (int i = 0; i < sortedPoints.Count; i++)
  913. {
  914. sortedPoints[i].Number = i + 1;
  915. Points.Add(sortedPoints[i]);
  916. }
  917. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  918. }
  919. }
  920. }
  921. catch (Exception ex)
  922. {
  923. LogHelper.WriteLogError("导入CAD点位时出错!", ex);
  924. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  925. }
  926. }
  927. /// <summary>
  928. /// 停止采集
  929. /// </summary>
  930. void ExecuteStopGrabbingCommand()
  931. {
  932. if (Camera != null)
  933. Camera.StopGrabbing();
  934. IsGrap = false;
  935. }
  936. bool CanExecuteStopGrabbingCommand()
  937. {
  938. return IsGrap;
  939. }
  940. /// <summary>
  941. /// 开始采集
  942. /// </summary>
  943. void ExecuteStartGrabbingCommand()
  944. {
  945. if (Camera != null)
  946. Camera.StartGrabbing();
  947. IsGrap = true;
  948. }
  949. bool CanExecuteStartGrabbingCommand()
  950. {
  951. return SelectedCamera != null && !IsGrap;
  952. }
  953. private void Camera_ImageCallbackEvent(ICogImage image, TimeSpan totaltime, string errormessage)
  954. {
  955. Image = image;
  956. App.Current.Dispatcher.Invoke(new
  957. Action(() =>
  958. {
  959. if (errormessage != null && !string.IsNullOrEmpty(errormessage))
  960. {
  961. Message = $"{Lang.耗时}:{totaltime.TotalMilliseconds.ToString("F1")} ms Error:{errormessage}";
  962. }
  963. else
  964. {
  965. Message = $"{Lang.耗时}:{totaltime.TotalMilliseconds.ToString("F1")} ms";
  966. }
  967. }));
  968. }
  969. /// <summary>
  970. /// 去取料
  971. /// </summary>
  972. async void ExecuteGoPickCommand()
  973. {
  974. try
  975. {
  976. if (SelectedPoint == null)
  977. {
  978. return;
  979. }
  980. if (Robot == null || !Robot.IsConnected)
  981. {
  982. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料!", Duration = 1 });
  983. return;
  984. }
  985. if (MessageBox.Show("确认要执行取料吗?", "去取料", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  986. {
  987. return;
  988. }
  989. var waiting = new WaitingControl();
  990. //show the dialog
  991. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  992. // 1. 控制机器人移动至拍照点位
  993. var rpoint = new RPoint()
  994. {
  995. X = SelectedPoint.X_Position,
  996. Y = SelectedPoint.Y_Position,
  997. Z = SelectedPoint.Z_Position_Start,
  998. U = SelectedPoint.U_Position,
  999. V = SelectedPoint.R_Position,
  1000. };
  1001. await Robot.CalibMotionAsync(rpoint, 0);
  1002. await Robot.CalibParameAsync(new PickInfo() { Inhal = Inhal, Blow = 1 }, 20, 20, true, 200, 200);
  1003. //打开吸真空
  1004. await Robot.CalibOutIOAsync(true);
  1005. await Task.Delay(500);
  1006. rpoint.Z = 0;
  1007. await Robot.CalibMotionAsync(rpoint, 0);
  1008. if (DialogHost.IsDialogOpen("RootDialog"))
  1009. {
  1010. DialogHost.Close("RootDialog");
  1011. }
  1012. await task;
  1013. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料完成!", Duration = 0.4 });
  1014. }
  1015. catch (Exception ex)
  1016. {
  1017. LogHelper.WriteLogError("取料时出错!", ex);
  1018. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1019. }
  1020. }
  1021. bool CanExecuteCommandGoPickCommandName()
  1022. {
  1023. return SelectedPoint != null;
  1024. }
  1025. ToolCoord toolCoord = null;
  1026. double _FixedUpCameraTempletAngle = 0;
  1027. double _MoveCameraTempletAngle = 0;
  1028. PointF _PutPoint = new PointF();
  1029. /// <summary>
  1030. /// 去二次定位
  1031. /// </summary>
  1032. async void ExecuteGoRepositionCommand()
  1033. {
  1034. try
  1035. {
  1036. if (SelectedPoint == null)
  1037. {
  1038. return;
  1039. }
  1040. if (Robot == null || !Robot.IsConnected)
  1041. {
  1042. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行二次定位!", Duration = 1 });
  1043. return;
  1044. }
  1045. if (MessageBox.Show("确认要执行下相机拍产二次定位吗?", "去下相机拍照", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1046. {
  1047. return;
  1048. }
  1049. var waiting = new WaitingControl();
  1050. //show the dialog
  1051. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1052. // 1. 控制机器人移动至拍照点位
  1053. var rpoint = new RPoint()
  1054. {
  1055. X = SelectedPoint.X_Position,
  1056. Y = SelectedPoint.Y_Position,
  1057. Z = SelectedPoint.Z_Position_Start,
  1058. U = SelectedPoint.U_Position,
  1059. V = SelectedPoint.R_Position,
  1060. };
  1061. await Robot.CalibMotionAsync(rpoint, 0);
  1062. await Task.Delay(200);
  1063. //获取固定向上相机1的流程
  1064. var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera1ProcedureId);
  1065. if (process1 == null)
  1066. {
  1067. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机1视觉流程,流程ID:{SelectProduct.FixedUpCamera1ProcedureId} 未找到!", Duration = 1 });
  1068. if (DialogHost.IsDialogOpen("RootDialog"))
  1069. {
  1070. DialogHost.Close("RootDialog");
  1071. }
  1072. await task;
  1073. return;
  1074. }
  1075. //获取固定向上相机2的流程
  1076. var process2 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera2ProcedureId);
  1077. if (process2 == null)
  1078. {
  1079. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机2视觉流程,流程ID:{SelectProduct.FixedUpCamera2ProcedureId} 未找到!", Duration = 1 });
  1080. if (DialogHost.IsDialogOpen("RootDialog"))
  1081. {
  1082. DialogHost.Close("RootDialog");
  1083. }
  1084. await task;
  1085. return;
  1086. }
  1087. // 执行视觉任务
  1088. var _cts = new CancellationTokenSource();
  1089. var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1090. var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1091. var visionResults = await Task.WhenAll(task1, task2);
  1092. if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
  1093. {
  1094. float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
  1095. float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
  1096. _FixedUpCameraTempletAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
  1097. toolCoord = new ToolCoord();
  1098. toolCoord.SetTool(toolX, toolY);
  1099. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位成功!", Duration = 0.4 });
  1100. if (DialogHost.IsDialogOpen("RootDialog"))
  1101. {
  1102. DialogHost.Close("RootDialog");
  1103. }
  1104. await task;
  1105. return;
  1106. }
  1107. else
  1108. {
  1109. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行二次定位!", Duration = 1 });
  1110. if (DialogHost.IsDialogOpen("RootDialog"))
  1111. {
  1112. DialogHost.Close("RootDialog");
  1113. }
  1114. await task;
  1115. return;
  1116. }
  1117. }
  1118. catch (Exception ex)
  1119. {
  1120. LogHelper.WriteLogError("二次定位时出错!", ex);
  1121. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1122. if (DialogHost.IsDialogOpen("RootDialog"))
  1123. {
  1124. DialogHost.Close("RootDialog");
  1125. }
  1126. }
  1127. }
  1128. /// <summary>
  1129. /// 执行产品拍照
  1130. /// </summary>
  1131. async void ExecuteTakeProductPhotoCommand()
  1132. {
  1133. try
  1134. {
  1135. if (SelectedPoint == null)
  1136. {
  1137. return;
  1138. }
  1139. if (Robot == null || !Robot.IsConnected)
  1140. {
  1141. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行产品拍照!", Duration = 1 });
  1142. return;
  1143. }
  1144. if (MessageBox.Show("确认要执行产品拍照吗?", "去产品位置拍照", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1145. {
  1146. return;
  1147. }
  1148. //如果二次定位的工具坐标为空,则提示用户先进行二次定位
  1149. if (toolCoord == null)
  1150. {
  1151. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
  1152. return;
  1153. }
  1154. var waiting = new WaitingControl();
  1155. //show the dialog
  1156. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1157. // 1. 控制机器人移动至拍照点位
  1158. var rpoint = new RPoint()
  1159. {
  1160. X = SelectedPoint.X_Position,
  1161. Y = SelectedPoint.Y_Position,
  1162. Z = SelectedPoint.Z_Position_Start,
  1163. U = SelectedPoint.U_Position,
  1164. V = SelectedPoint.R_Position,
  1165. };
  1166. await Robot.CalibMotionAsync(rpoint, 0);
  1167. await Task.Delay(200);
  1168. //获取移动向下相机1的流程
  1169. var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera1LockPhotoProcedureId);
  1170. if (process1 == null)
  1171. {
  1172. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机1视觉流程,流程ID:{SelectProduct.MoveDownCamera1LockPhotoProcedureId} 未找到!", Duration = 1 });
  1173. if (DialogHost.IsDialogOpen("RootDialog"))
  1174. {
  1175. DialogHost.Close("RootDialog");
  1176. }
  1177. await task;
  1178. return;
  1179. }
  1180. // 执行视觉任务
  1181. var _cts = new CancellationTokenSource();
  1182. var visionResult =await _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1183. if (visionResult.IsSucceed)
  1184. {
  1185. _MoveCameraTempletAngle = visionResult.U;
  1186. _PutPoint = new PointF((float)visionResult.X, (float)visionResult.Y);
  1187. if (DialogHost.IsDialogOpen("RootDialog"))
  1188. {
  1189. DialogHost.Close("RootDialog");
  1190. }
  1191. await task;
  1192. return;
  1193. }
  1194. else
  1195. {
  1196. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行产品拍照!", Duration = 1 });
  1197. if (DialogHost.IsDialogOpen("RootDialog"))
  1198. {
  1199. DialogHost.Close("RootDialog");
  1200. }
  1201. await task;
  1202. return;
  1203. }
  1204. }
  1205. catch (Exception ex)
  1206. {
  1207. LogHelper.WriteLogError("执行产品拍照时出错!", ex);
  1208. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1209. if (DialogHost.IsDialogOpen("RootDialog"))
  1210. {
  1211. DialogHost.Close("RootDialog");
  1212. }
  1213. }
  1214. }
  1215. /// <summary>
  1216. /// 执行产品贴敷
  1217. /// </summary>
  1218. async void ExecuteTakeProductCommand()
  1219. {
  1220. try
  1221. {
  1222. if (SelectedPoint == null)
  1223. {
  1224. return;
  1225. }
  1226. if (Robot == null || !Robot.IsConnected)
  1227. {
  1228. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行产品贴敷!", Duration = 1 });
  1229. return;
  1230. }
  1231. if (MessageBox.Show("确认要执行产品贴敷吗?", "去产品贴敷", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1232. {
  1233. return;
  1234. }
  1235. //如果二次定位的工具坐标为空,则提示用户先进行二次定位
  1236. if (toolCoord == null)
  1237. {
  1238. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
  1239. return;
  1240. }
  1241. if (_PutPoint.X == 0 && _PutPoint.Y == 0)
  1242. {
  1243. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "检测到未定位产品", Duration = 1 });
  1244. return;
  1245. }
  1246. var waiting = new WaitingControl();
  1247. //show the dialog
  1248. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1249. var pn = Vector<double>.Build.Dense(new double[] { _PutPoint.X, _PutPoint.Y });
  1250. //目标角度:
  1251. double angle = SelectedPoint.U_Position + (_FixedUpCameraTempletAngle - SelectProduct.FixedUpCameraTempletAngle) + (_MoveCameraTempletAngle - SelectProduct.MoveDownCamerTempletAngle);
  1252. //将_PutPoint转换为Tool0下要走的点
  1253. var p0 = toolCoord.GetTool0Coord(pn, angle);
  1254. // 1. 控制机器人移动至拍照点位
  1255. var rpoint = new RPoint()
  1256. {
  1257. X = (float)p0[0],
  1258. Y = (float)p0[1],
  1259. Z = SelectedPoint.Z_Position_Start,
  1260. U = (float)angle,
  1261. V = SelectedPoint.R_Position,
  1262. };
  1263. await Robot.CalibMotionAsync(rpoint, 0);
  1264. if (DialogHost.IsDialogOpen("RootDialog"))
  1265. {
  1266. DialogHost.Close("RootDialog");
  1267. }
  1268. await task;
  1269. return;
  1270. }
  1271. catch (Exception ex)
  1272. {
  1273. LogHelper.WriteLogError("执行产品贴敷时出错!", ex);
  1274. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1275. if (DialogHost.IsDialogOpen("RootDialog"))
  1276. {
  1277. DialogHost.Close("RootDialog");
  1278. }
  1279. }
  1280. }
  1281. /// <summary>
  1282. /// 附加轴+点动
  1283. /// </summary>
  1284. /// <param name="obj"></param>
  1285. async void ExecuteAdditionalAxisJogPlusCommand(object obj)
  1286. {
  1287. if (Robot == null || !Robot.IsConnected) return;
  1288. try
  1289. {
  1290. if (obj is AxisExtended axis)
  1291. {
  1292. //如果移动距离大于10mm,则提示用户确认
  1293. if (Math.Abs(Distance) >= 10)
  1294. {
  1295. if (MessageBox.Show($"确认要点动距离 {Distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1296. {
  1297. return;
  1298. }
  1299. }
  1300. await Robot.AdditionalAxisJogAsync(axis.Name, Distance);
  1301. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1302. }
  1303. }
  1304. catch (Exception ex)
  1305. {
  1306. LogHelper.WriteLogError("附加轴点动+时出错!", ex);
  1307. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1308. }
  1309. }
  1310. /// <summary>
  1311. /// 附加轴-点动
  1312. /// </summary>
  1313. /// <param name="obj"></param>
  1314. async void ExecuteAdditionalAxisJogMinusCommand(object obj)
  1315. {
  1316. if (Robot == null || !Robot.IsConnected) return;
  1317. try
  1318. {
  1319. if (obj is AxisExtended axis)
  1320. {
  1321. //如果移动距离大于10mm,则提示用户确认
  1322. if (Math.Abs(Distance) >= 10)
  1323. {
  1324. if (MessageBox.Show($"确认要点动距离 {Distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1325. {
  1326. return;
  1327. }
  1328. }
  1329. await Robot.AdditionalAxisJogNegAsync(axis.Name, Distance);
  1330. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1331. }
  1332. }
  1333. catch (Exception ex)
  1334. {
  1335. LogHelper.WriteLogError("附加轴点动-时出错!", ex);
  1336. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1337. }
  1338. }
  1339. /// <summary>
  1340. /// 附加轴下使能
  1341. /// </summary>
  1342. /// <param name="obj"></param>
  1343. async void ExecuteAdditionalAxisMotorOffCommand(object obj)
  1344. {
  1345. if (Robot == null || !Robot.IsConnected) return;
  1346. try
  1347. {
  1348. if (obj is AxisExtended axis)
  1349. {
  1350. await Robot.AdditionalAxisMotorAsync(axis.Name, false);
  1351. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1352. }
  1353. }
  1354. catch (Exception ex)
  1355. {
  1356. LogHelper.WriteLogError("附加轴上使能时出错!", ex);
  1357. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1358. }
  1359. }
  1360. /// <summary>
  1361. /// 附加轴上使能
  1362. /// </summary>
  1363. /// <param name="obj"></param>
  1364. async void ExecuteAdditionalAxisMotorOnCommand(object obj)
  1365. {
  1366. if (Robot == null || !Robot.IsConnected) return;
  1367. try
  1368. {
  1369. if (obj is AxisExtended axis)
  1370. {
  1371. await Robot.AdditionalAxisMotorAsync(axis.Name, true);
  1372. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1373. }
  1374. }
  1375. catch (Exception ex)
  1376. {
  1377. LogHelper.WriteLogError("附加轴下使能时出错!", ex);
  1378. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1379. }
  1380. }
  1381. /// <summary>
  1382. /// 移动取料托盘点
  1383. /// </summary>
  1384. async void ExecutePickMoveCommand(string parameter)
  1385. {
  1386. if (Robot == null || !Robot.IsConnected) return;
  1387. try
  1388. {
  1389. //弹窗用户是否确认要示教该点位
  1390. if (MessageBox.Show($"确认要移动取料点位 {parameter} 吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1391. {
  1392. return;
  1393. }
  1394. int index = int.Parse(parameter);
  1395. var curpos = await Robot.GetRobotPosAsync();
  1396. var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
  1397. if (index == 1)
  1398. {
  1399. curpos.Z = 0;
  1400. await Robot.CalibMotionAsync(curpos, 0);
  1401. await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, PickP1.Z_Position_Stop);
  1402. curpos.X = PickP1.X_Position;
  1403. curpos.Y = PickP1.Y_Position;
  1404. curpos.Z = PickP1.Z_Position_Start;
  1405. curpos.U = PickP1.U_Position;
  1406. await Robot.CalibMotionAsync(curpos, 0);
  1407. }
  1408. else if (index == 2)
  1409. {
  1410. curpos.Z = 0;
  1411. await Robot.CalibMotionAsync(curpos, 0);
  1412. await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, PickP2.Z_Position_Stop);
  1413. curpos.X = PickP2.X_Position;
  1414. curpos.Y = PickP2.Y_Position;
  1415. curpos.Z = PickP2.Z_Position_Start;
  1416. curpos.U = PickP2.U_Position;
  1417. await Robot.CalibMotionAsync(curpos, 0);
  1418. }
  1419. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1420. }
  1421. catch (Exception ex)
  1422. {
  1423. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1424. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1425. }
  1426. }
  1427. /// <summary>
  1428. /// 示教取料托盘点
  1429. /// </summary>
  1430. /// <param name="parameter"></param>
  1431. async void ExecutePickTechCommand(string parameter)
  1432. {
  1433. if (Robot == null || !Robot.IsConnected) return;
  1434. try
  1435. {
  1436. //弹窗用户是否确认要示教该点位
  1437. if (MessageBox.Show($"确认要示教取料点位 {parameter} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1438. {
  1439. return;
  1440. }
  1441. int index = int.Parse(parameter);
  1442. var curpos = await Robot.GetRobotPosAsync();
  1443. var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
  1444. if (index == 1)
  1445. {
  1446. PickP1.X_Position = curpos.X;
  1447. PickP1.Y_Position = curpos.Y;
  1448. PickP1.Z_Position_Start = curpos.Z;
  1449. PickP1.U_Position = curpos.U;
  1450. PickP1.Z_Position_Stop = addpos;
  1451. }
  1452. else if (index == 2)
  1453. {
  1454. PickP2.X_Position = curpos.X;
  1455. PickP2.Y_Position = curpos.Y;
  1456. PickP2.Z_Position_Start = curpos.Z;
  1457. PickP2.U_Position = curpos.U;
  1458. PickP2.Z_Position_Stop = addpos;
  1459. }
  1460. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1461. }
  1462. catch (Exception ex)
  1463. {
  1464. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1465. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1466. }
  1467. }
  1468. /// <summary>
  1469. /// 计算所有托盘点
  1470. /// </summary>
  1471. void ExecuteCalPickPosCommand()
  1472. {
  1473. try
  1474. {
  1475. if (ColumnNum < 1)
  1476. {
  1477. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"请设置托盘列数!", Duration = 1 });
  1478. return;
  1479. }
  1480. //弹窗用户是否确认要示教该点位
  1481. if (MessageBox.Show($"确认要计算托盘 吗?", "计算托盘", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1482. {
  1483. return;
  1484. }
  1485. //托盘间隔
  1486. double invt = (PickP2.Z_Position_Stop - PickP1.Z_Position_Stop) / (ColumnNum - 1);
  1487. for (int i = 0; i < ColumnNum; i++)
  1488. {
  1489. if (Points.Count - 1 <= i)
  1490. {
  1491. Points[i].Number = i + 1;
  1492. Points[i].X_Position = PickP1.X_Position;
  1493. Points[i].X_Velocity = 100;
  1494. Points[i].Y_Position = PickP1.Y_Position;
  1495. Points[i].Y_Velocity = 100;
  1496. Points[i].Z_Position_Start = PickP1.Z_Position_Start;
  1497. Points[i].Z_Velocity_Start = 100;
  1498. Points[i].U_Position = PickP1.U_Position;
  1499. Points[i].U_Velocity = 100;
  1500. Points[i].Z_Position_Stop = (float)(PickP1.Z_Position_Stop + i * invt);
  1501. Points[i].Z_Velocity_Stop = 100;
  1502. }
  1503. else
  1504. {
  1505. Points.Add(new PlcPoint()
  1506. {
  1507. Number= i + 1,
  1508. X_Position = PickP1.X_Position,
  1509. X_Velocity = 100,
  1510. Y_Position = PickP1.Y_Position,
  1511. Y_Velocity = 100,
  1512. Z_Position_Start = PickP1.Z_Position_Start,
  1513. Z_Velocity_Start = 100,
  1514. U_Position = PickP1.U_Position,
  1515. U_Velocity = 100,
  1516. Z_Position_Stop = (float)(PickP1.Z_Position_Stop + i * invt),
  1517. Z_Velocity_Stop = 100
  1518. });
  1519. }
  1520. }
  1521. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1522. }
  1523. catch (Exception ex)
  1524. {
  1525. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1526. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1527. }
  1528. }
  1529. #endregion
  1530. #region 继承
  1531. /// <summary>
  1532. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  1533. /// </summary>
  1534. /// <param name="navigationContext"></param>
  1535. /// <param name="continuationCallback"></param>
  1536. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  1537. {
  1538. continuationCallback(true);
  1539. }
  1540. /// <summary>
  1541. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  1542. /// </summary>
  1543. /// <param name="navigationContext"></param>
  1544. /// <exception cref="NotImplementedException"></exception>
  1545. public async void OnNavigatedTo(NavigationContext navigationContext)
  1546. {
  1547. try
  1548. {
  1549. toolCoord = null;
  1550. _PutPoint = new PointF();
  1551. SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
  1552. SelectedIndex = 0;
  1553. Points = SelectProduct.PickCameraPoints;
  1554. if (Robot == null)
  1555. {
  1556. Robot = _robotService.GetRobotByNumber(1) as XYZU_Robot;
  1557. }
  1558. if (Robot != null && Robot.IsConnected)
  1559. {
  1560. this.Distance = _configService.GetRobotStepDistance(Robot.Id);
  1561. Robot.EnterDebugMode = true;
  1562. AdditionalAxisList = Robot.AdditionalAxisList;
  1563. }
  1564. else if (Robot != null)
  1565. {
  1566. Robot.EnterDebugMode = true;
  1567. }
  1568. ProcedureModels = new ObservableCollection<ProcedureModel>();
  1569. foreach (var item in SelectProduct.CameraProcedures)
  1570. {
  1571. foreach (var item1 in item.ProcedureModels)
  1572. {
  1573. ProcedureModels.Add(item1);
  1574. }
  1575. }
  1576. CameraList = new ObservableCollection<CameraInfo>(_configService.GetAllCameras());
  1577. if (SelectProduct.PickPoints!=null && SelectProduct.PickPoints.Count>0)
  1578. {
  1579. PickP1 = SelectProduct.PickPoints.FirstOrDefault().Clone();
  1580. PickP2 = SelectProduct.PickPoints.LastOrDefault().Clone();
  1581. ColumnNum = SelectProduct.PickPoints.Count;
  1582. }
  1583. }
  1584. catch (Exception ex)
  1585. {
  1586. LogHelper.WriteLogError("机器人点位界面进入时出错!", ex);
  1587. }
  1588. }
  1589. /// <summary>
  1590. /// 是否允许导航到此视图模型。
  1591. /// </summary>
  1592. /// <param name="navigationContext"></param>
  1593. /// <returns></returns>
  1594. public bool IsNavigationTarget(NavigationContext navigationContext)
  1595. {
  1596. return true;
  1597. }
  1598. /// <summary>
  1599. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1600. /// </summary>
  1601. /// <param name="navigationContext"></param>
  1602. public void OnNavigatedFrom(NavigationContext navigationContext)
  1603. {
  1604. //if (Robot != null)
  1605. //{
  1606. // Robot.EnterDebugMode = false;
  1607. //}
  1608. try
  1609. {
  1610. IsGrap = false;
  1611. if (Camera != null)
  1612. {
  1613. if (Camera.IsGrabbing)
  1614. {
  1615. Camera.StopGrabbing();
  1616. }
  1617. Camera.ImageCallbackEvent -= Camera_ImageCallbackEvent;
  1618. Camera = null;
  1619. }
  1620. SelectedCamera = null;
  1621. IsLeftDrawerOpen = false;
  1622. }
  1623. catch (Exception)
  1624. {
  1625. }
  1626. }
  1627. #endregion
  1628. private bool _IsAllowEdit = false;
  1629. public bool IsAllowEdit
  1630. {
  1631. get { return _IsAllowEdit; }
  1632. set { SetProperty(ref _IsAllowEdit, value); }
  1633. }
  1634. private void LoginChange(Models.User user)
  1635. {
  1636. if (user.userPart == Enums.UserPart.Operator)
  1637. {
  1638. IsAllowEdit = false;
  1639. }
  1640. else
  1641. {
  1642. IsAllowEdit = true;
  1643. }
  1644. }
  1645. }
  1646. }