PlcPointParamsViewModel.cs 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859
  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. private DelegateCommand _DynamicTestAnalyzerCommand;
  364. public DelegateCommand DynamicTestAnalyzerCommand =>
  365. _DynamicTestAnalyzerCommand ?? (_DynamicTestAnalyzerCommand = new DelegateCommand(ExecuteDynamicTestAnalyzerCommand));
  366. #endregion
  367. #region 事件
  368. #endregion
  369. public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  370. IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService, IRemoteCommandService remoteCommandService,
  371. ICalibrationService calibrationService, ICameraService cameraService, IProductService productService)
  372. {
  373. _regionManager = regionManager;
  374. _eventAggregator = ea;
  375. _container = container;
  376. _dialogService = dialogService;
  377. _configService = configService;
  378. _systemDatabaseService = systemDatabaseService;
  379. //订阅权限登录事件
  380. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  381. management = _container.Resolve<Management>();
  382. _robotService = robotService;
  383. _remoteCommandService = remoteCommandService;
  384. _calibrationService = calibrationService;
  385. _cameraService = cameraService;
  386. _productService = productService;
  387. }
  388. #region 方法
  389. /// <summary>
  390. /// 下一步
  391. /// </summary>
  392. void ExecuteNextCommand()
  393. {
  394. NavigationParameters param = new NavigationParameters();
  395. param.Add("SelectProduct", SelectProduct);
  396. _regionManager.RequestNavigate("ProductRegionContext", "ProductParams", param);
  397. }
  398. /// <summary>
  399. /// 上一步
  400. /// </summary>
  401. void ExecuteBackCommand()
  402. {
  403. NavigationParameters param = new NavigationParameters();
  404. param.Add("SelectProduct", SelectProduct);
  405. param.Add("SelectedProcedure", null);
  406. _regionManager.RequestNavigate("ProductRegionContext", "ProcessBasics", param);
  407. }
  408. /// <summary>
  409. /// 点动
  410. /// </summary>
  411. /// <param name="obj"></param>
  412. private async void ExecuteJogCommand(object obj)
  413. {
  414. if (Robot == null || !Robot.IsConnected) return;
  415. try
  416. {
  417. var items = ((string)obj).Split(':');
  418. //如果移动距离大于10mm,则提示用户确认
  419. double distance = double.Parse(items[1]);
  420. if (Math.Abs(distance) >= 10)
  421. {
  422. if (MessageBox.Show($"确认要点动距离 {distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  423. {
  424. return;
  425. }
  426. }
  427. Robot.Timeout = 6000000;
  428. switch (items[0])
  429. {
  430. case "X+":
  431. await Robot.JogAsync("X", distance);
  432. break;
  433. case "X-":
  434. await Robot.JogAsync("X", -distance);
  435. break;
  436. case "Y+":
  437. await Robot.JogAsync("Y", distance);
  438. break;
  439. case "Y-":
  440. await Robot.JogAsync("Y", -distance);
  441. break;
  442. case "Z+":
  443. await Robot.JogAsync("Z", distance);
  444. break;
  445. case "Z-":
  446. await Robot.JogAsync("Z", -distance);
  447. break;
  448. case "U+":
  449. await Robot.JogAsync("U", distance);
  450. break;
  451. case "U-":
  452. await Robot.JogAsync("U", -distance);
  453. break;
  454. case "V+":
  455. await Robot.JogAsync("V", distance);
  456. break;
  457. case "V-":
  458. await Robot.JogAsync("V", -distance);
  459. break;
  460. case "W+":
  461. await Robot.JogAsync("W", distance);
  462. break;
  463. case "W-":
  464. await Robot.JogAsync("W", -distance);
  465. break;
  466. default:
  467. break;
  468. }
  469. Robot.Timeout = 5000;
  470. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  471. }
  472. catch (Exception ex)
  473. {
  474. LogHelper.WriteLogError("机器人点位-机器人点动时出错", ex);
  475. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  476. }
  477. }
  478. /// <summary>
  479. /// 执行运动
  480. /// </summary>
  481. /// <param name="obj"></param>
  482. async void ExecuteExecuteMotion(object parameter)
  483. {
  484. if (parameter == null)
  485. {
  486. return;
  487. }
  488. if (SelectedPoint == null)
  489. {
  490. return;
  491. }
  492. var values = (object[])parameter;
  493. var point = new RPoint()
  494. {
  495. X = SelectedPoint.X_Position,
  496. Y = SelectedPoint.Y_Position,
  497. Z = SelectedPoint.Z_Position_Start,
  498. U = SelectedPoint.U_Position,
  499. V = SelectedPoint.R_Position,
  500. };
  501. MotionCommand motionCmd = (MotionCommand)values[1];
  502. if (Robot == null || !Robot.IsConnected) return;
  503. try
  504. {
  505. //确认要执行该点位的该运动指令吗
  506. if (MessageBox.Show($"确认要执行点位 {SelectedPoint.Number} 的 {motionCmd} 指令吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  507. {
  508. return;
  509. }
  510. //Robot.Timeout = 6000000;
  511. switch (motionCmd)
  512. {
  513. case MotionCommand.Go:
  514. await Robot.GoAsync(point);
  515. break;
  516. case MotionCommand.Jump:
  517. await Robot.JumpAsync(point, 0);
  518. break;
  519. case MotionCommand.Move:
  520. await Robot.MoveAsync(point);
  521. break;
  522. }
  523. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  524. }
  525. catch (Exception ex)
  526. {
  527. LogHelper.WriteLogError("机器人点位-执行点位时出错", ex);
  528. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  529. }
  530. }
  531. /// <summary>
  532. /// 示教点位
  533. /// </summary>
  534. /// <param name="point"></param>
  535. async void ExecuteTechPointCommand()
  536. {
  537. if (Robot == null || !Robot.IsConnected) return;
  538. if (SelectedPoint == null) return;
  539. try
  540. {
  541. //如果当前的选项卡处于锁付点位,则提示用户当前模式不允许进行示教
  542. if (SelectedIndex == 4)
  543. {
  544. //如果local为空,则必须先通过相机定位产品,否则无法示教锁付点位
  545. if (toolCoord == null)
  546. {
  547. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "当前模式不允许直接示教贴敷点位,请先通过相机定位产品和定位辅料!", Duration = 1 });
  548. return;
  549. }
  550. //弹窗用户是否确认要示教该点位
  551. if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  552. {
  553. return;
  554. }
  555. double upCameraU = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)_PutPoints[0].X, (float)_PutPoints[0].Y), new PointF((float)_PutPoints[1].X, (float)_PutPoints[1].Y));
  556. var curpos1 = await Robot.GetRobotPosAsync();
  557. //将当前点位转换为产品Local坐标系下的点位
  558. SelectedPoint.X_Position = (float)curpos1.X;
  559. SelectedPoint.Y_Position = (float)curpos1.Y;
  560. SelectedPoint.Z_Position_Start = curpos1.Z;
  561. SelectedPoint.U_Position = curpos1.U;
  562. SelectedPoint.R_Position = curpos1.V;
  563. SelectProduct.FixedUpCameraTempletAngle = _FixedUpCameraTempletAngle;
  564. SelectProduct.MoveDownCamerTempletAngle = upCameraU;
  565. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  566. return;
  567. }
  568. else
  569. {
  570. //弹窗用户是否确认要示教该点位
  571. if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  572. {
  573. return;
  574. }
  575. var curpos = await Robot.GetRobotPosAsync();
  576. SelectedPoint.X_Position = curpos.X;
  577. SelectedPoint.Y_Position = curpos.Y;
  578. SelectedPoint.Z_Position_Start = curpos.Z;
  579. SelectedPoint.U_Position = curpos.U;
  580. SelectedPoint.R_Position = curpos.V;
  581. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  582. }
  583. }
  584. catch (Exception ex)
  585. {
  586. LogHelper.WriteLogError("机器人点位-示教点位时出错", ex);
  587. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  588. }
  589. }
  590. void ExecuteLoadedCommand()
  591. {
  592. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  593. {
  594. IsAllowEdit = false;
  595. }
  596. else
  597. {
  598. IsAllowEdit = true;
  599. }
  600. }
  601. /// <summary>
  602. /// 电机
  603. /// </summary>
  604. /// <param name="obj"></param>
  605. private async void ExecuteMotorCommand(string obj)
  606. {
  607. if (Robot == null || !Robot.IsConnected) return;
  608. try
  609. {
  610. await Robot.MotorAsync(Convert.ToBoolean(obj));
  611. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  612. }
  613. catch (Exception ex)
  614. {
  615. LogHelper.WriteLogError("机器人点击操作时出错!", ex);
  616. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  617. }
  618. }
  619. /// <summary>
  620. /// 重置
  621. /// </summary>
  622. private async void ExecuteResetCommand()
  623. {
  624. if (Robot == null || !Robot.IsConnected) return;
  625. try
  626. {
  627. await Robot.ResetAsync();
  628. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  629. }
  630. catch (Exception ex)
  631. {
  632. LogHelper.WriteLogError("重置机器人时出错!", ex);
  633. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  634. }
  635. }
  636. /// <summary>
  637. /// 锁定刹车
  638. /// </summary>
  639. private async void ExecuteSLockCommand()
  640. {
  641. if (Robot == null || !Robot.IsConnected) return;
  642. try
  643. {
  644. await Robot.SLockAsync();
  645. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  646. }
  647. catch (Exception ex)
  648. {
  649. LogHelper.WriteLogError("机器人锁定刹车时出错!", ex);
  650. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  651. }
  652. }
  653. /// <summary>
  654. /// 释放刹车
  655. /// </summary>
  656. private async void ExecutesFreeCommand()
  657. {
  658. if (Robot == null || !Robot.IsConnected) return;
  659. try
  660. {
  661. await Robot.SFreeAsync();
  662. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  663. }
  664. catch (Exception ex)
  665. {
  666. LogHelper.WriteLogError("机器人释放刹车时出错!", ex);
  667. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  668. }
  669. }
  670. private bool CanExecute
  671. {
  672. get
  673. {
  674. // 命令可执行仅当机器人可执行且已选择点位
  675. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  676. {
  677. return true;
  678. }
  679. return false;
  680. }
  681. }
  682. //是否可以示教或者执行点位
  683. private bool CanExecutePointCommand
  684. {
  685. get
  686. {
  687. if (Robot != null && Robot.IsConnected && Robot.CanExecute)
  688. {
  689. return SelectedPointInDataGrid != null;
  690. }
  691. return false;
  692. }
  693. }
  694. /// <summary>
  695. /// 点位表切换时
  696. /// </summary>
  697. void ExecuteSelectionChangedCommand()
  698. {
  699. switch (SelectedIndex)
  700. {
  701. case 0:
  702. Points = SelectProduct.PickCameraPoints;
  703. break;
  704. case 1:
  705. Points = SelectProduct.PickPoints;
  706. break;
  707. case 2:
  708. Points = SelectProduct.SecPosCameraPoints;
  709. break;
  710. case 3:
  711. Points = SelectProduct.ScrewCameraPoints;
  712. break;
  713. case 4:
  714. Points = SelectProduct.ScrewPoints;
  715. break;
  716. case 5:
  717. Points = SelectProduct.CheckCameraPoints;
  718. break;
  719. default:
  720. break;
  721. }
  722. }
  723. /// <summary>
  724. /// 增加点位
  725. /// </summary>
  726. void ExecuteAddPointCommand()
  727. {
  728. //添加点位
  729. Points.Add(new PlcPoint()
  730. {
  731. Number = Points.Count + 1,
  732. X_Velocity = 100,
  733. Y_Velocity = 100,
  734. Z_Velocity_Start = 100,
  735. Z_Velocity_Stop = 100,
  736. U_Velocity = 100,
  737. R_Velocity = 100,
  738. });
  739. // update commands
  740. _MovePointUpCommand?.RaiseCanExecuteChanged();
  741. _MovePointDownCommand?.RaiseCanExecuteChanged();
  742. }
  743. /// <summary>
  744. /// 移除点位
  745. /// </summary>
  746. void ExecuteDeletePointCommand()
  747. {
  748. if (SelectedPoint == null)
  749. {
  750. return;
  751. }
  752. // 确认删除
  753. if (MessageBox.Show("确认要删除选中的点位吗?", "删除点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  754. {
  755. return;
  756. }
  757. int removedIndex = Points.IndexOf(SelectedPoint);
  758. Points.Remove(SelectedPoint);
  759. //重新编号
  760. for (int i = 0; i < Points.Count; i++)
  761. {
  762. Points[i].Number = i + 1;
  763. }
  764. // adjust selection
  765. if (Points.Count > 0)
  766. {
  767. int newIndex = Math.Min(removedIndex, Points.Count - 1);
  768. SelectedPointInDataGrid = Points[newIndex];
  769. }
  770. else
  771. {
  772. SelectedPointInDataGrid = null;
  773. }
  774. // update commands
  775. _MovePointUpCommand?.RaiseCanExecuteChanged();
  776. _MovePointDownCommand?.RaiseCanExecuteChanged();
  777. }
  778. bool CanExecuteDeletePointCommand()
  779. {
  780. return SelectedPointInDataGrid != null;
  781. }
  782. private bool CanMovePointUp()
  783. {
  784. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) > 0;
  785. }
  786. private bool CanMovePointDown()
  787. {
  788. return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) >= 0 && Points.IndexOf(SelectedPointInDataGrid) < Points.Count - 1;
  789. }
  790. /// <summary>
  791. /// 向上移动点位
  792. /// </summary>
  793. void ExecuteMovePointUpCommand()
  794. {
  795. if (SelectedPointInDataGrid == null) return;
  796. // 确认移动
  797. if (MessageBox.Show("确认将选中点位上移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  798. {
  799. return;
  800. }
  801. int idx = Points.IndexOf(SelectedPointInDataGrid);
  802. if (idx <= 0) return;
  803. var item = SelectedPointInDataGrid;
  804. Points.Move(idx, idx - 1);
  805. // renumber
  806. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  807. SelectedPointInDataGrid = item;
  808. _MovePointUpCommand?.RaiseCanExecuteChanged();
  809. _MovePointDownCommand?.RaiseCanExecuteChanged();
  810. }
  811. /// <summary>
  812. /// 向下移动点位
  813. /// </summary>
  814. void ExecuteMovePointDownCommand()
  815. {
  816. if (SelectedPointInDataGrid == null) return;
  817. // 确认移动
  818. if (MessageBox.Show("确认将选中点位下移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  819. {
  820. return;
  821. }
  822. int idx = Points.IndexOf(SelectedPointInDataGrid);
  823. if (idx < 0 || idx >= Points.Count - 1) return;
  824. var item = SelectedPointInDataGrid;
  825. Points.Move(idx, idx + 1);
  826. // renumber
  827. for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
  828. SelectedPointInDataGrid = item;
  829. _MovePointUpCommand?.RaiseCanExecuteChanged();
  830. _MovePointDownCommand?.RaiseCanExecuteChanged();
  831. }
  832. /// <summary>
  833. /// CAD导入点位
  834. /// </summary>
  835. async void ExecuteImportCadPointCommand()
  836. {
  837. try
  838. {
  839. var view = new DxfView();
  840. //show the dialog
  841. var result = await DialogHost.Show(view, "RootDialog", null, null, null);
  842. if (result != null)
  843. {
  844. var cadPoints = view.Points;
  845. if (cadPoints != null && cadPoints.Count > 0)
  846. {
  847. //要导入的开始点编号
  848. int startNumber = view.StartIndex;
  849. //弹窗提示用户是否确认要导入从该编号开始的点位,点位数量为cadPoints.Count
  850. if (MessageBox.Show($"确认要从点位编号 {startNumber} 开始导入 {cadPoints.Count} 个点位吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  851. {
  852. return;
  853. }
  854. //导入点位
  855. for (int i = 0; i < cadPoints.Count; i++)
  856. {
  857. //如果点位编号已存在,则更新该点位,否则新增点位,只更新XY坐标
  858. var point = cadPoints[i];
  859. var existingPoint = Points.FirstOrDefault(p => p.Number == startNumber + i);
  860. if (existingPoint != null)
  861. {
  862. existingPoint.X_Position = point.X;
  863. existingPoint.Y_Position = point.Y;
  864. }
  865. else
  866. {
  867. Points.Add(new PlcPoint()
  868. {
  869. Number = startNumber + i,
  870. X_Position = point.X,
  871. Y_Position = point.Y,
  872. X_Velocity = 100,
  873. Y_Velocity = 100,
  874. Z_Velocity_Start = 100,
  875. Z_Velocity_Stop = 100,
  876. U_Velocity = 100,
  877. R_Velocity = 100,
  878. });
  879. }
  880. }
  881. //对所有的点位重新编号,确保编号连续
  882. var sortedPoints = Points.OrderBy(p => p.Number).ToList();
  883. Points.Clear();
  884. for (int i = 0; i < sortedPoints.Count; i++)
  885. {
  886. sortedPoints[i].Number = i + 1;
  887. Points.Add(sortedPoints[i]);
  888. }
  889. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  890. }
  891. }
  892. }
  893. catch (Exception ex)
  894. {
  895. LogHelper.WriteLogError("导入CAD点位时出错!", ex);
  896. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  897. }
  898. }
  899. /// <summary>
  900. /// 停止采集
  901. /// </summary>
  902. void ExecuteStopGrabbingCommand()
  903. {
  904. if (Camera != null)
  905. Camera.StopGrabbing();
  906. IsGrap = false;
  907. }
  908. bool CanExecuteStopGrabbingCommand()
  909. {
  910. return IsGrap;
  911. }
  912. /// <summary>
  913. /// 开始采集
  914. /// </summary>
  915. void ExecuteStartGrabbingCommand()
  916. {
  917. if (Camera != null)
  918. Camera.StartGrabbing();
  919. IsGrap = true;
  920. }
  921. bool CanExecuteStartGrabbingCommand()
  922. {
  923. return SelectedCamera != null && !IsGrap;
  924. }
  925. private void Camera_ImageCallbackEvent(ICogImage image, TimeSpan totaltime, string errormessage)
  926. {
  927. Image = image;
  928. App.Current.Dispatcher.Invoke(new
  929. Action(() =>
  930. {
  931. if (errormessage != null && !string.IsNullOrEmpty(errormessage))
  932. {
  933. Message = $"{Lang.耗时}:{totaltime.TotalMilliseconds.ToString("F1")} ms Error:{errormessage}";
  934. }
  935. else
  936. {
  937. Message = $"{Lang.耗时}:{totaltime.TotalMilliseconds.ToString("F1")} ms";
  938. }
  939. }));
  940. }
  941. /// <summary>
  942. /// 去取料
  943. /// </summary>
  944. async void ExecuteGoPickCommand()
  945. {
  946. try
  947. {
  948. if (SelectedPoint == null)
  949. {
  950. return;
  951. }
  952. if (Robot == null || !Robot.IsConnected)
  953. {
  954. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料!", Duration = 1 });
  955. return;
  956. }
  957. if (MessageBox.Show("确认要执行取料吗?", "去取料", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  958. {
  959. return;
  960. }
  961. var waiting = new WaitingControl();
  962. //show the dialog
  963. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  964. // 1. 控制机器人移动至拍照点位
  965. var rpoint = new RPoint()
  966. {
  967. X = SelectedPoint.X_Position,
  968. Y = SelectedPoint.Y_Position,
  969. Z = SelectedPoint.Z_Position_Start,
  970. U = SelectedPoint.U_Position,
  971. V = SelectedPoint.R_Position,
  972. };
  973. await Robot.CalibMotionAsync(rpoint, 0);
  974. await Robot.CalibParameAsync(new PickInfo() { Inhal = Inhal, Blow = 1 }, 20, 20, true, 200, 200);
  975. //打开吸真空
  976. await Robot.CalibOutIOAsync(true);
  977. await Task.Delay(500);
  978. rpoint.Z = 0;
  979. await Robot.CalibMotionAsync(rpoint, 0);
  980. if (DialogHost.IsDialogOpen("RootDialog"))
  981. {
  982. DialogHost.Close("RootDialog");
  983. }
  984. await task;
  985. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料完成!", Duration = 0.4 });
  986. }
  987. catch (Exception ex)
  988. {
  989. LogHelper.WriteLogError("取料时出错!", ex);
  990. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  991. }
  992. }
  993. bool CanExecuteCommandGoPickCommandName()
  994. {
  995. return SelectedPoint != null;
  996. }
  997. ToolCoord toolCoord = null;
  998. double _FixedUpCameraTempletAngle = 0;
  999. OpenCvSharp.Point3f[] _PutPoints = new OpenCvSharp.Point3f[2];
  1000. /// <summary>
  1001. /// 去二次定位
  1002. /// </summary>
  1003. async void ExecuteGoRepositionCommand()
  1004. {
  1005. try
  1006. {
  1007. if (SelectedPoint == null)
  1008. {
  1009. return;
  1010. }
  1011. if (Robot == null || !Robot.IsConnected)
  1012. {
  1013. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行二次定位!", Duration = 1 });
  1014. return;
  1015. }
  1016. if (MessageBox.Show("确认要执行下相机拍产二次定位吗?", "去下相机拍照", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1017. {
  1018. return;
  1019. }
  1020. var waiting = new WaitingControl();
  1021. //show the dialog
  1022. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1023. // 1. 控制机器人移动至拍照点位
  1024. var rpoint = new RPoint()
  1025. {
  1026. X = SelectedPoint.X_Position,
  1027. Y = SelectedPoint.Y_Position,
  1028. Z = SelectedPoint.Z_Position_Start,
  1029. U = SelectedPoint.U_Position,
  1030. V = SelectedPoint.R_Position,
  1031. };
  1032. await Robot.CalibMotionAsync(rpoint, 0);
  1033. await Task.Delay(200);
  1034. //获取固定向上相机1的流程
  1035. var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera1ProcedureId);
  1036. if (process1 == null)
  1037. {
  1038. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机1视觉流程,流程ID:{SelectProduct.FixedUpCamera1ProcedureId} 未找到!", Duration = 1 });
  1039. if (DialogHost.IsDialogOpen("RootDialog"))
  1040. {
  1041. DialogHost.Close("RootDialog");
  1042. }
  1043. await task;
  1044. return;
  1045. }
  1046. //获取固定向上相机2的流程
  1047. var process2 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera2ProcedureId);
  1048. if (process2 == null)
  1049. {
  1050. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机2视觉流程,流程ID:{SelectProduct.FixedUpCamera2ProcedureId} 未找到!", Duration = 1 });
  1051. if (DialogHost.IsDialogOpen("RootDialog"))
  1052. {
  1053. DialogHost.Close("RootDialog");
  1054. }
  1055. await task;
  1056. return;
  1057. }
  1058. // 执行视觉任务
  1059. var _cts = new CancellationTokenSource();
  1060. var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1061. var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1062. var visionResults = await Task.WhenAll(task1, task2);
  1063. if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
  1064. {
  1065. float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
  1066. float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
  1067. _FixedUpCameraTempletAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
  1068. toolCoord = new ToolCoord();
  1069. toolCoord.SetTool(toolX, toolY);
  1070. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位成功!", Duration = 0.4 });
  1071. if (DialogHost.IsDialogOpen("RootDialog"))
  1072. {
  1073. DialogHost.Close("RootDialog");
  1074. }
  1075. await task;
  1076. return;
  1077. }
  1078. else
  1079. {
  1080. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行二次定位!", Duration = 1 });
  1081. if (DialogHost.IsDialogOpen("RootDialog"))
  1082. {
  1083. DialogHost.Close("RootDialog");
  1084. }
  1085. await task;
  1086. return;
  1087. }
  1088. }
  1089. catch (Exception ex)
  1090. {
  1091. LogHelper.WriteLogError("二次定位时出错!", ex);
  1092. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1093. if (DialogHost.IsDialogOpen("RootDialog"))
  1094. {
  1095. DialogHost.Close("RootDialog");
  1096. }
  1097. }
  1098. }
  1099. /// <summary>
  1100. /// 执行产品拍照
  1101. /// </summary>
  1102. async void ExecuteTakeProductPhotoCommand()
  1103. {
  1104. try
  1105. {
  1106. if (SelectedPoint == null)
  1107. {
  1108. return;
  1109. }
  1110. if (Robot == null || !Robot.IsConnected)
  1111. {
  1112. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行产品拍照!", Duration = 1 });
  1113. return;
  1114. }
  1115. if (MessageBox.Show("确认要执行产品拍照吗?", "去产品位置拍照", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1116. {
  1117. return;
  1118. }
  1119. //如果二次定位的工具坐标为空,则提示用户先进行二次定位
  1120. if (toolCoord == null)
  1121. {
  1122. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
  1123. return;
  1124. }
  1125. var waiting = new WaitingControl();
  1126. //show the dialog
  1127. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1128. // 1. 控制机器人移动至拍照点位
  1129. var rpoint = new RPoint()
  1130. {
  1131. X = Points[0].X_Position,
  1132. Y = Points[0].Y_Position,
  1133. Z = Points[0].Z_Position_Start,
  1134. U = Points[0].U_Position,
  1135. V = Points[0].R_Position,
  1136. };
  1137. await Robot.CalibMotionAsync(rpoint, 0);
  1138. await Task.Delay(200);
  1139. //获取移动向下相机1的流程
  1140. var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera1LockPhotoProcedureId);
  1141. if (process1 == null)
  1142. {
  1143. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机1视觉流程,流程ID:{SelectProduct.MoveDownCamera1LockPhotoProcedureId} 未找到!", Duration = 1 });
  1144. if (DialogHost.IsDialogOpen("RootDialog"))
  1145. {
  1146. DialogHost.Close("RootDialog");
  1147. }
  1148. await task;
  1149. return;
  1150. }
  1151. // 执行视觉任务
  1152. var _cts = new CancellationTokenSource();
  1153. var visionResult =await _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1154. if (visionResult.IsSucceed)
  1155. {
  1156. _PutPoints[0] = new OpenCvSharp.Point3f((float)visionResult.X, (float)visionResult.Y, (float)visionResult.U);
  1157. }
  1158. else
  1159. {
  1160. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行产品拍照!", Duration = 1 });
  1161. if (DialogHost.IsDialogOpen("RootDialog"))
  1162. {
  1163. DialogHost.Close("RootDialog");
  1164. }
  1165. await task;
  1166. return;
  1167. }
  1168. // 2. 控制机器人移动至拍照点位
  1169. rpoint = new RPoint()
  1170. {
  1171. X = Points[1].X_Position,
  1172. Y = Points[1].Y_Position,
  1173. Z = Points[1].Z_Position_Start,
  1174. U = Points[1].U_Position,
  1175. V = Points[1].R_Position,
  1176. };
  1177. await Robot.CalibMotionAsync(rpoint, 0);
  1178. await Task.Delay(200);
  1179. //获取移动向下相机1的流程
  1180. var process2= _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera2LockPhotoProcedureId);
  1181. if (process2 == null)
  1182. {
  1183. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机2视觉流程,流程ID:{SelectProduct.MoveDownCamera2LockPhotoProcedureId} 未找到!", Duration = 1 });
  1184. if (DialogHost.IsDialogOpen("RootDialog"))
  1185. {
  1186. DialogHost.Close("RootDialog");
  1187. }
  1188. await task;
  1189. return;
  1190. }
  1191. // 执行视觉任务
  1192. _cts = new CancellationTokenSource();
  1193. visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
  1194. if (visionResult.IsSucceed)
  1195. {
  1196. _PutPoints[1] = new OpenCvSharp.Point3f((float)visionResult.X, (float)visionResult.Y, (float)visionResult.U);
  1197. if (DialogHost.IsDialogOpen("RootDialog"))
  1198. {
  1199. DialogHost.Close("RootDialog");
  1200. }
  1201. await task;
  1202. return;
  1203. }
  1204. else
  1205. {
  1206. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行产品拍照!", Duration = 1 });
  1207. if (DialogHost.IsDialogOpen("RootDialog"))
  1208. {
  1209. DialogHost.Close("RootDialog");
  1210. }
  1211. await task;
  1212. return;
  1213. }
  1214. }
  1215. catch (Exception ex)
  1216. {
  1217. LogHelper.WriteLogError("执行产品拍照时出错!", ex);
  1218. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1219. if (DialogHost.IsDialogOpen("RootDialog"))
  1220. {
  1221. DialogHost.Close("RootDialog");
  1222. }
  1223. }
  1224. }
  1225. /// <summary>
  1226. /// 执行产品贴敷
  1227. /// </summary>
  1228. async void ExecuteTakeProductCommand()
  1229. {
  1230. try
  1231. {
  1232. if (SelectedPoint == null)
  1233. {
  1234. return;
  1235. }
  1236. if (Robot == null || !Robot.IsConnected)
  1237. {
  1238. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行产品贴敷!", Duration = 1 });
  1239. return;
  1240. }
  1241. if (MessageBox.Show("确认要执行产品贴敷吗?", "去产品贴敷", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1242. {
  1243. return;
  1244. }
  1245. //如果二次定位的工具坐标为空,则提示用户先进行二次定位
  1246. if (toolCoord == null)
  1247. {
  1248. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
  1249. return;
  1250. }
  1251. if (_PutPoints[0].X == 0 && _PutPoints[0].Y == 0 && _PutPoints[1].X == 0 && _PutPoints[1].Y == 0)
  1252. {
  1253. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "检测到未定位产品", Duration = 1 });
  1254. return;
  1255. }
  1256. var waiting = new WaitingControl();
  1257. //show the dialog
  1258. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  1259. double upCameraX = (_PutPoints[0].X + _PutPoints[1].X) / 2;
  1260. double upCameraY = (_PutPoints[0].Y + _PutPoints[1].Y) / 2;
  1261. double upCameraU = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)_PutPoints[0].X, (float)_PutPoints[0].Y), new PointF((float)_PutPoints[1].X, (float)_PutPoints[1].Y));
  1262. var pn = Vector<double>.Build.Dense(new double[] { upCameraX, upCameraY });
  1263. //目标角度:
  1264. double angle = SelectedPoint.U_Position + (_FixedUpCameraTempletAngle - SelectProduct.FixedUpCameraTempletAngle) + (upCameraU - SelectProduct.MoveDownCamerTempletAngle);
  1265. //将_PutPoint转换为Tool0下要走的点
  1266. var p0 = toolCoord.GetTool0Coord(pn, angle);
  1267. // 1. 控制机器人移动至拍照点位
  1268. var rpoint = new RPoint()
  1269. {
  1270. X = (float)p0[0],
  1271. Y = (float)p0[1],
  1272. Z = SelectedPoint.Z_Position_Start,
  1273. U = (float)angle,
  1274. V = SelectedPoint.R_Position,
  1275. };
  1276. await Robot.CalibMotionAsync(rpoint, 0);
  1277. if (DialogHost.IsDialogOpen("RootDialog"))
  1278. {
  1279. DialogHost.Close("RootDialog");
  1280. }
  1281. await task;
  1282. return;
  1283. }
  1284. catch (Exception ex)
  1285. {
  1286. LogHelper.WriteLogError("执行产品贴敷时出错!", ex);
  1287. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1288. if (DialogHost.IsDialogOpen("RootDialog"))
  1289. {
  1290. DialogHost.Close("RootDialog");
  1291. }
  1292. }
  1293. }
  1294. /// <summary>
  1295. /// 附加轴+点动
  1296. /// </summary>
  1297. /// <param name="obj"></param>
  1298. async void ExecuteAdditionalAxisJogPlusCommand(object obj)
  1299. {
  1300. if (Robot == null || !Robot.IsConnected) return;
  1301. try
  1302. {
  1303. if (obj is AxisExtended axis)
  1304. {
  1305. //如果移动距离大于10mm,则提示用户确认
  1306. if (Math.Abs(Distance) >= 10)
  1307. {
  1308. if (MessageBox.Show($"确认要点动距离 {Distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1309. {
  1310. return;
  1311. }
  1312. }
  1313. await Robot.AdditionalAxisJogAsync(axis.Name, Distance);
  1314. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1315. }
  1316. }
  1317. catch (Exception ex)
  1318. {
  1319. LogHelper.WriteLogError("附加轴点动+时出错!", ex);
  1320. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1321. }
  1322. }
  1323. /// <summary>
  1324. /// 附加轴-点动
  1325. /// </summary>
  1326. /// <param name="obj"></param>
  1327. async void ExecuteAdditionalAxisJogMinusCommand(object obj)
  1328. {
  1329. if (Robot == null || !Robot.IsConnected) return;
  1330. try
  1331. {
  1332. if (obj is AxisExtended axis)
  1333. {
  1334. //如果移动距离大于10mm,则提示用户确认
  1335. if (Math.Abs(Distance) >= 10)
  1336. {
  1337. if (MessageBox.Show($"确认要点动距离 {Distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1338. {
  1339. return;
  1340. }
  1341. }
  1342. await Robot.AdditionalAxisJogNegAsync(axis.Name, Distance);
  1343. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1344. }
  1345. }
  1346. catch (Exception ex)
  1347. {
  1348. LogHelper.WriteLogError("附加轴点动-时出错!", ex);
  1349. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1350. }
  1351. }
  1352. /// <summary>
  1353. /// 附加轴下使能
  1354. /// </summary>
  1355. /// <param name="obj"></param>
  1356. async void ExecuteAdditionalAxisMotorOffCommand(object obj)
  1357. {
  1358. if (Robot == null || !Robot.IsConnected) return;
  1359. try
  1360. {
  1361. if (obj is AxisExtended axis)
  1362. {
  1363. await Robot.AdditionalAxisMotorAsync(axis.Name, false);
  1364. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1365. }
  1366. }
  1367. catch (Exception ex)
  1368. {
  1369. LogHelper.WriteLogError("附加轴上使能时出错!", ex);
  1370. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1371. }
  1372. }
  1373. /// <summary>
  1374. /// 附加轴上使能
  1375. /// </summary>
  1376. /// <param name="obj"></param>
  1377. async void ExecuteAdditionalAxisMotorOnCommand(object obj)
  1378. {
  1379. if (Robot == null || !Robot.IsConnected) return;
  1380. try
  1381. {
  1382. if (obj is AxisExtended axis)
  1383. {
  1384. await Robot.AdditionalAxisMotorAsync(axis.Name, true);
  1385. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1386. }
  1387. }
  1388. catch (Exception ex)
  1389. {
  1390. LogHelper.WriteLogError("附加轴下使能时出错!", ex);
  1391. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1392. }
  1393. }
  1394. /// <summary>
  1395. /// 移动取料托盘点
  1396. /// </summary>
  1397. async void ExecutePickMoveCommand(string parameter)
  1398. {
  1399. if (Robot == null || !Robot.IsConnected) return;
  1400. try
  1401. {
  1402. //弹窗用户是否确认要示教该点位
  1403. if (MessageBox.Show($"确认要移动取料点位 {parameter} 吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1404. {
  1405. return;
  1406. }
  1407. int index = int.Parse(parameter);
  1408. var curpos = await Robot.GetRobotPosAsync();
  1409. var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
  1410. if (index == 1)
  1411. {
  1412. curpos.Z = 0;
  1413. await Robot.CalibMotionAsync(curpos, 0);
  1414. await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, PickP1.Z_Position_Stop);
  1415. curpos.X = PickP1.X_Position;
  1416. curpos.Y = PickP1.Y_Position;
  1417. curpos.Z = PickP1.Z_Position_Start;
  1418. curpos.U = PickP1.U_Position;
  1419. await Robot.CalibMotionAsync(curpos, 0);
  1420. }
  1421. else if (index == 2)
  1422. {
  1423. curpos.Z = 0;
  1424. await Robot.CalibMotionAsync(curpos, 0);
  1425. await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, PickP2.Z_Position_Stop);
  1426. curpos.X = PickP2.X_Position;
  1427. curpos.Y = PickP2.Y_Position;
  1428. curpos.Z = PickP2.Z_Position_Start;
  1429. curpos.U = PickP2.U_Position;
  1430. await Robot.CalibMotionAsync(curpos, 0);
  1431. }
  1432. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1433. }
  1434. catch (Exception ex)
  1435. {
  1436. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1437. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1438. }
  1439. }
  1440. /// <summary>
  1441. /// 示教取料托盘点
  1442. /// </summary>
  1443. /// <param name="parameter"></param>
  1444. async void ExecutePickTechCommand(string parameter)
  1445. {
  1446. if (Robot == null || !Robot.IsConnected) return;
  1447. try
  1448. {
  1449. //弹窗用户是否确认要示教该点位
  1450. if (MessageBox.Show($"确认要示教取料点位 {parameter} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1451. {
  1452. return;
  1453. }
  1454. int index = int.Parse(parameter);
  1455. var curpos = await Robot.GetRobotPosAsync();
  1456. var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
  1457. if (index == 1)
  1458. {
  1459. PickP1.X_Position = curpos.X;
  1460. PickP1.Y_Position = curpos.Y;
  1461. PickP1.Z_Position_Start = curpos.Z;
  1462. PickP1.U_Position = curpos.U;
  1463. PickP1.Z_Position_Stop = addpos;
  1464. }
  1465. else if (index == 2)
  1466. {
  1467. PickP2.X_Position = curpos.X;
  1468. PickP2.Y_Position = curpos.Y;
  1469. PickP2.Z_Position_Start = curpos.Z;
  1470. PickP2.U_Position = curpos.U;
  1471. PickP2.Z_Position_Stop = addpos;
  1472. }
  1473. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1474. }
  1475. catch (Exception ex)
  1476. {
  1477. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1478. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1479. }
  1480. }
  1481. /// <summary>
  1482. /// 计算所有托盘点
  1483. /// </summary>
  1484. void ExecuteCalPickPosCommand()
  1485. {
  1486. try
  1487. {
  1488. if (ColumnNum < 1)
  1489. {
  1490. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"请设置托盘列数!", Duration = 1 });
  1491. return;
  1492. }
  1493. //弹窗用户是否确认要示教该点位
  1494. if (MessageBox.Show($"确认要计算托盘 吗?", "计算托盘", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
  1495. {
  1496. return;
  1497. }
  1498. //托盘间隔
  1499. double invt = (PickP2.Z_Position_Stop - PickP1.Z_Position_Stop) / (ColumnNum - 1);
  1500. for (int i = 0; i < ColumnNum; i++)
  1501. {
  1502. if (Points.Count - 1 <= i)
  1503. {
  1504. Points[i].Number = i + 1;
  1505. Points[i].X_Position = PickP1.X_Position;
  1506. Points[i].X_Velocity = 100;
  1507. Points[i].Y_Position = PickP1.Y_Position;
  1508. Points[i].Y_Velocity = 100;
  1509. Points[i].Z_Position_Start = PickP1.Z_Position_Start;
  1510. Points[i].Z_Velocity_Start = 100;
  1511. Points[i].U_Position = PickP1.U_Position;
  1512. Points[i].U_Velocity = 100;
  1513. Points[i].Z_Position_Stop = (float)(PickP1.Z_Position_Stop + i * invt);
  1514. Points[i].Z_Velocity_Stop = 100;
  1515. }
  1516. else
  1517. {
  1518. Points.Add(new PlcPoint()
  1519. {
  1520. Number= i + 1,
  1521. X_Position = PickP1.X_Position,
  1522. X_Velocity = 100,
  1523. Y_Position = PickP1.Y_Position,
  1524. Y_Velocity = 100,
  1525. Z_Position_Start = PickP1.Z_Position_Start,
  1526. Z_Velocity_Start = 100,
  1527. U_Position = PickP1.U_Position,
  1528. U_Velocity = 100,
  1529. Z_Position_Stop = (float)(PickP1.Z_Position_Stop + i * invt),
  1530. Z_Velocity_Stop = 100
  1531. });
  1532. }
  1533. }
  1534. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
  1535. }
  1536. catch (Exception ex)
  1537. {
  1538. LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
  1539. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
  1540. }
  1541. }
  1542. /// <summary>
  1543. /// 动态测试分析仪
  1544. /// </summary>
  1545. void ExecuteDynamicTestAnalyzerCommand()
  1546. {
  1547. try
  1548. {
  1549. IDialogParameters parameters = new DialogParameters();
  1550. parameters.Add("SelectProduct", SelectProduct);
  1551. parameters.Add("Robot", Robot);
  1552. _dialogService.Show("VisionDynamicAccuracyAnalyzer", parameters, rst =>
  1553. {
  1554. //对话框关闭之后的回调函数,可以在这解析结果。
  1555. ButtonResult result1 = rst.Result;
  1556. if (result1 == ButtonResult.OK)
  1557. {
  1558. //var param = rst.Parameters.GetValue<RobotTool>("Tool");
  1559. //var param1 = rst.Parameters.GetValue<Matrix<double>>("RobotCameraRotationMatrix");
  1560. //var param2 = rst.Parameters.GetValue<double>("Angle");
  1561. _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
  1562. }
  1563. });
  1564. }
  1565. catch (Exception ex)
  1566. {
  1567. LogHelper.WriteLogError("执行动态测试分析仪命令时出错", ex);
  1568. MessageBox.Show(ex.Message);
  1569. }
  1570. }
  1571. #endregion
  1572. #region 继承
  1573. /// <summary>
  1574. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  1575. /// </summary>
  1576. /// <param name="navigationContext"></param>
  1577. /// <param name="continuationCallback"></param>
  1578. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  1579. {
  1580. continuationCallback(true);
  1581. }
  1582. /// <summary>
  1583. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  1584. /// </summary>
  1585. /// <param name="navigationContext"></param>
  1586. /// <exception cref="NotImplementedException"></exception>
  1587. public async void OnNavigatedTo(NavigationContext navigationContext)
  1588. {
  1589. try
  1590. {
  1591. toolCoord = null;
  1592. SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
  1593. SelectedIndex = 0;
  1594. Points = SelectProduct.PickCameraPoints;
  1595. if (Robot == null)
  1596. {
  1597. Robot = _robotService.GetRobotByNumber(1) as XYZU_Robot;
  1598. }
  1599. if (Robot != null && Robot.IsConnected)
  1600. {
  1601. this.Distance = _configService.GetRobotStepDistance(Robot.Id);
  1602. Robot.EnterDebugMode = true;
  1603. AdditionalAxisList = Robot.AdditionalAxisList;
  1604. }
  1605. else if (Robot != null)
  1606. {
  1607. Robot.EnterDebugMode = true;
  1608. }
  1609. ProcedureModels = new ObservableCollection<ProcedureModel>();
  1610. foreach (var item in SelectProduct.CameraProcedures)
  1611. {
  1612. foreach (var item1 in item.ProcedureModels)
  1613. {
  1614. ProcedureModels.Add(item1);
  1615. }
  1616. }
  1617. CameraList = new ObservableCollection<CameraInfo>(_configService.GetAllCameras());
  1618. if (SelectProduct.PickPoints!=null && SelectProduct.PickPoints.Count>0)
  1619. {
  1620. PickP1 = SelectProduct.PickPoints.FirstOrDefault().Clone();
  1621. PickP2 = SelectProduct.PickPoints.LastOrDefault().Clone();
  1622. ColumnNum = SelectProduct.PickPoints.Count;
  1623. }
  1624. }
  1625. catch (Exception ex)
  1626. {
  1627. LogHelper.WriteLogError("机器人点位界面进入时出错!", ex);
  1628. }
  1629. }
  1630. /// <summary>
  1631. /// 是否允许导航到此视图模型。
  1632. /// </summary>
  1633. /// <param name="navigationContext"></param>
  1634. /// <returns></returns>
  1635. public bool IsNavigationTarget(NavigationContext navigationContext)
  1636. {
  1637. return true;
  1638. }
  1639. /// <summary>
  1640. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  1641. /// </summary>
  1642. /// <param name="navigationContext"></param>
  1643. public void OnNavigatedFrom(NavigationContext navigationContext)
  1644. {
  1645. //if (Robot != null)
  1646. //{
  1647. // Robot.EnterDebugMode = false;
  1648. //}
  1649. try
  1650. {
  1651. IsGrap = false;
  1652. if (Camera != null)
  1653. {
  1654. if (Camera.IsGrabbing)
  1655. {
  1656. Camera.StopGrabbing();
  1657. }
  1658. Camera.ImageCallbackEvent -= Camera_ImageCallbackEvent;
  1659. Camera = null;
  1660. }
  1661. SelectedCamera = null;
  1662. IsLeftDrawerOpen = false;
  1663. }
  1664. catch (Exception)
  1665. {
  1666. }
  1667. }
  1668. #endregion
  1669. private bool _IsAllowEdit = false;
  1670. public bool IsAllowEdit
  1671. {
  1672. get { return _IsAllowEdit; }
  1673. set { SetProperty(ref _IsAllowEdit, value); }
  1674. }
  1675. private void LoginChange(Models.User user)
  1676. {
  1677. if (user.userPart == Enums.UserPart.Operator)
  1678. {
  1679. IsAllowEdit = false;
  1680. }
  1681. else
  1682. {
  1683. IsAllowEdit = true;
  1684. }
  1685. }
  1686. }
  1687. }