PlcPointParamsViewModel.cs 74 KB

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