| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182 |
- using Cognex.VisionPro;
- using MahApps.Metro.Controls;
- using MaterialDesignThemes.Wpf;
- using MathNet.Numerics.LinearAlgebra;
- using NPOI.SS.Formula.Functions;
- using OpenCvSharp.Flann;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Ioc;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Drawing;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using TeamAAS_VP.Controls;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Core.PLCs;
- using TeamAAS_VP.Core.Robots;
- using TeamAAS_VP.DxfModule;
- using TeamAAS_VP.Enums;
- using TeamAAS_VP.Events;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- using TeamAAS_VP.Models.PLC;
- using TeamAAS_VP.Models.Robot;
- using TeamAAS_VP.Resources.Languages;
- using TeamAAS_VP.Services;
- using TeamAAS_VP.Views.Product;
- using static TeamAAS_VP.ViewModels.Product.AutoCorrectLockPointViewModel;
- namespace TeamAAS_VP.ViewModels.Product
- {
- public class PlcPointParamsViewModel : BindableBase, IConfirmNavigationRequest
- {
- IRegionManager _regionManager;
- IEventAggregator _eventAggregator;
- IContainerProvider _container;
- IDialogService _dialogService;
- IConfigService _configService;
- IRobotService _robotService;
- ISystemDatabaseService _systemDatabaseService;
- IRemoteCommandService _remoteCommandService;
- ICalibrationService _calibrationService;
- ICameraService _cameraService;
- IProductService _productService;
- #region 属性
- private ObservableCollection<AxisExtended> _AdditionalAxisList;
- public ObservableCollection<AxisExtended> AdditionalAxisList
- {
- get { return _AdditionalAxisList; }
- set { SetProperty(ref _AdditionalAxisList, value); }
- }
- private ProductModel _SelectProduct;
- /// <summary>
- /// 选中的产品
- /// </summary>
- public ProductModel SelectProduct
- {
- get { return _SelectProduct; }
- set { SetProperty(ref _SelectProduct, value); }
- }
- private PlcPoint _SelectedPoint;
- public PlcPoint SelectedPoint
- {
- get { return _SelectedPoint; }
- set { SetProperty(ref _SelectedPoint, value); }
- }
- private PlcPoint _selectedPointInDataGrid;
- public PlcPoint SelectedPointInDataGrid
- {
- get { return _selectedPointInDataGrid; }
- set
- {
- if (SetProperty(ref _selectedPointInDataGrid, value))
- {
- SelectedPointInComboBox = value;
- // update command availability
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- // 更新依赖可执行状态的命令
- _TechPointCommand?.RaiseCanExecuteChanged();
- _ExecuteMotion?.RaiseCanExecuteChanged();
- }
- // 可以同步到 SelectPoint 属性
- SelectedPoint = value;
- }
- }
- private PlcPoint _selectedPointInComboBox;
- public PlcPoint SelectedPointInComboBox
- {
- get { return _selectedPointInComboBox; }
- set
- {
- if (SetProperty(ref _selectedPointInComboBox, value))
- {
- SelectedPointInDataGrid = value;
- }
- // 可以同步到 SelectPoint 属性
- SelectedPoint = value;
- }
- }
- private ObservableCollection<PlcPoint> _Points = new ObservableCollection<PlcPoint>();
- /// <summary>
- /// 点位集合
- /// </summary>
- public ObservableCollection<PlcPoint> Points
- {
- get { return _Points; }
- set { SetProperty(ref _Points, value); }
- }
- private MotionCommand _SelectMotionCommand;
- /// <summary>
- /// 选中的运动指令
- /// </summary>
- public MotionCommand SelectMotionCommand
- {
- get { return _SelectMotionCommand; }
- set { SetProperty(ref _SelectMotionCommand, value); }
- }
- public Management management { get; set; }
- private XYZU_Robot _Robot;
- public XYZU_Robot Robot
- {
- get { return _Robot; }
- set
- {
- SetProperty(ref _Robot, value);
- }
- }
- private int _SelectedIndex;
- public int SelectedIndex
- {
- get { return _SelectedIndex; }
- set { SetProperty(ref _SelectedIndex, value); }
- }
- private double _Distance = 1;
- public double Distance
- {
- get { return _Distance; }
- set
- {
- SetProperty(ref _Distance, value);
- try
- {
- if (Robot == null)
- {
- return;
- }
- _configService.UpdateRobotStepDistance(Robot.Id, value);
- }
- catch (Exception)
- {
- }
- }
- }
- private ObservableCollection<ProcedureModel> _ProcedureModels;
- /// <summary>
- /// 流程集合
- /// </summary>
- public ObservableCollection<ProcedureModel> ProcedureModels
- {
- get { return _ProcedureModels; }
- set { SetProperty(ref _ProcedureModels, value); }
- }
- private ProcedureModel _SelectProcedure;
- /// <summary>
- /// 选中的流程
- /// </summary>
- public ProcedureModel SelectProcedure
- {
- get { return _SelectProcedure; }
- set
- {
- SetProperty(ref _SelectProcedure, value);
- }
- }
- private bool _IsGrap;
- public bool IsGrap
- {
- get { return _IsGrap; }
- set { SetProperty(ref _IsGrap, value); }
- }
- private ObservableCollection<CameraInfo> _CameraList;
- public ObservableCollection<CameraInfo> CameraList
- {
- get { return _CameraList; }
- set { SetProperty(ref _CameraList, value); }
- }
- private CameraInfo _SelectedCamera;
- public CameraInfo SelectedCamera
- {
- get { return _SelectedCamera; }
- set
- {
- SetProperty(ref _SelectedCamera, value);
- if (value != null)
- {
- if (Camera != null)
- {
- if (Camera.IsGrabbing)
- {
- Camera.StopGrabbing();
- }
- Camera.ImageCallbackEvent -= Camera_ImageCallbackEvent;
- }
- Camera = _cameraService.GetCamera(value.Id);
- Camera.ImageCallbackEvent += Camera_ImageCallbackEvent;
- }
- }
- }
- private ICamera _Camera;
- public ICamera Camera
- {
- get { return _Camera; }
- set { SetProperty(ref _Camera, value); }
- }
- private ICogImage _Image;
- public ICogImage Image
- {
- get { return _Image; }
- set { SetProperty(ref _Image, value); }
- }
- private string _Message;
- public string Message
- {
- get { return _Message; }
- set { SetProperty(ref _Message, value); }
- }
- private bool _IsLeftDrawerOpen;
- public bool IsLeftDrawerOpen
- {
- get { return _IsLeftDrawerOpen; }
- set
- {
- SetProperty(ref _IsLeftDrawerOpen, value);
- if (!value)
- {
- if (IsGrap)
- {
- ExecuteStopGrabbingCommand();
- }
- }
- }
- }
- private int _Inhal = 1;
- /// <summary>
- /// 吸真空编号
- /// </summary>
- public int Inhal
- {
- get { return _Inhal; }
- set { SetProperty(ref _Inhal, value); }
- }
- private PalletEx _Pallet1;
- /// <summary>
- /// 托盘1
- /// </summary>
- public PalletEx Pallet1
- {
- get { return _Pallet1; }
- set { SetProperty(ref _Pallet1, value); }
- }
- private PalletEx _Pallet2;
- /// <summary>
- /// 托盘2
- /// </summary>
- public PalletEx Pallet2
- {
- get { return _Pallet2; }
- set { SetProperty(ref _Pallet2, value); }
- }
- #endregion
- #region 命令
- private DelegateCommand _NextCommand;
- public DelegateCommand NextCommand =>
- _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
- private DelegateCommand _BackCommand;
- public DelegateCommand BackCommand =>
- _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
- private DelegateCommand _LoadedCommand;
- public DelegateCommand LoadedCommand =>
- _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
- private DelegateCommand<object> _ExecuteMotion;
- public DelegateCommand<object> ExecuteMotion =>
- _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecutePointCommand).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
- private DelegateCommand<object> _JogCommand;
- public DelegateCommand<object> JogCommand =>
- _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _TechPointCommand;
- public DelegateCommand TechPointCommand =>
- _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecutePointCommand).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
- private DelegateCommand<string> _MotorCommand;
- public DelegateCommand<string> MotorCommand =>
- _MotorCommand ?? (_MotorCommand = new DelegateCommand<string>(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _ResetCommand;
- public DelegateCommand ResetCommand =>
- _ResetCommand ?? (_ResetCommand = new DelegateCommand(ExecuteResetCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _sFreeCommand;
- public DelegateCommand sFreeCommand =>
- _sFreeCommand ?? (_sFreeCommand = new DelegateCommand(ExecutesFreeCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _SLockCommand;
- public DelegateCommand SLockCommand =>
- _SLockCommand ?? (_SLockCommand = new DelegateCommand(ExecuteSLockCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand _SelectionChangedCommand;
- public DelegateCommand SelectionChangedCommand =>
- _SelectionChangedCommand ?? (_SelectionChangedCommand = new DelegateCommand(ExecuteSelectionChangedCommand));
- private DelegateCommand _AddPointCommand;
- public DelegateCommand AddPointCommand =>
- _AddPointCommand ?? (_AddPointCommand = new DelegateCommand(ExecuteAddPointCommand));
- private DelegateCommand _DeletePointCommand;
- public DelegateCommand DeletePointCommand =>
- _DeletePointCommand ?? (_DeletePointCommand = new DelegateCommand(ExecuteDeletePointCommand, CanExecuteDeletePointCommand).ObservesProperty(() => SelectedPointInDataGrid));
- private DelegateCommand _MovePointUpCommand;
- public DelegateCommand MovePointUpCommand => _MovePointUpCommand ?? (_MovePointUpCommand = new DelegateCommand(ExecuteMovePointUpCommand, CanMovePointUp));
- private DelegateCommand _MovePointDownCommand;
- public DelegateCommand MovePointDownCommand => _MovePointDownCommand ?? (_MovePointDownCommand = new DelegateCommand(ExecuteMovePointDownCommand, CanMovePointDown));
- private DelegateCommand _ImportCadPointCommand;
- public DelegateCommand ImportCadPointCommand =>
- _ImportCadPointCommand ?? (_ImportCadPointCommand = new DelegateCommand(ExecuteImportCadPointCommand));
- private DelegateCommand _StartGrabbingCommand;
- public DelegateCommand StartGrabbingCommand =>
- _StartGrabbingCommand ?? (_StartGrabbingCommand = new DelegateCommand(ExecuteStartGrabbingCommand, CanExecuteStartGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(() => SelectedCamera));
- private DelegateCommand _StopGrabbingCommand;
- public DelegateCommand StopGrabbingCommand =>
- _StopGrabbingCommand ?? (_StopGrabbingCommand = new DelegateCommand(ExecuteStopGrabbingCommand, CanExecuteStopGrabbingCommand).ObservesProperty(() => IsGrap).ObservesProperty(() => SelectedCamera));
- private DelegateCommand _GoPickCommand;
- public DelegateCommand GoPickCommand =>
- _GoPickCommand ?? (_GoPickCommand = new DelegateCommand(ExecuteGoPickCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
- private DelegateCommand _GoRepositionCommand;
- public DelegateCommand GoRepositionCommand =>
- _GoRepositionCommand ?? (_GoRepositionCommand = new DelegateCommand(ExecuteGoRepositionCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
- private DelegateCommand _TakeProductPhotoCommand;
- public DelegateCommand TakeProductPhotoCommand =>
- _TakeProductPhotoCommand ?? (_TakeProductPhotoCommand = new DelegateCommand(ExecuteTakeProductPhotoCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
- private DelegateCommand _TakeProductCommand;
- public DelegateCommand TakeProductCommand =>
- _TakeProductCommand ?? (_TakeProductCommand = new DelegateCommand(ExecuteTakeProductCommand, CanExecuteCommandGoPickCommandName).ObservesProperty(() => SelectedPoint));
- //附加轴,轴点动+命令
- private DelegateCommand<object> _AdditionalAxisJogPlusCommand;
- public DelegateCommand<object> AdditionalAxisJogPlusCommand =>
- _AdditionalAxisJogPlusCommand ?? (_AdditionalAxisJogPlusCommand = new DelegateCommand<object>(ExecuteAdditionalAxisJogPlusCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- //附加轴,轴点动-命令
- private DelegateCommand<object> _AdditionalAxisJogMinusCommand;
- public DelegateCommand<object> AdditionalAxisJogMinusCommand =>
- _AdditionalAxisJogMinusCommand ?? (_AdditionalAxisJogMinusCommand = new DelegateCommand<object>(ExecuteAdditionalAxisJogMinusCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand<object> _AdditionalAxisMotorOnCommand;
- public DelegateCommand<object> AdditionalAxisMotorOnCommand =>
- _AdditionalAxisMotorOnCommand ?? (_AdditionalAxisMotorOnCommand = new DelegateCommand<object>(ExecuteAdditionalAxisMotorOnCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand<object> _AdditionalAxisMotorOffCommand;
- public DelegateCommand<object> AdditionalAxisMotorOffCommand =>
- _AdditionalAxisMotorOffCommand ?? (_AdditionalAxisMotorOffCommand = new DelegateCommand<object>(ExecuteAdditionalAxisMotorOffCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
- private DelegateCommand<string> _PickTechCommand;
- public DelegateCommand<string> PickTechCommand =>
- _PickTechCommand ?? (_PickTechCommand = new DelegateCommand<string>(ExecutePickTechCommand));
- private DelegateCommand<string> _PickMoveCommand;
- public DelegateCommand<string> PickMoveCommand =>
- _PickMoveCommand ?? (_PickMoveCommand = new DelegateCommand<string>(ExecutePickMoveCommand));
- private DelegateCommand<string> _CalPickPosCommand;
- public DelegateCommand<string> CalPickPosCommand =>
- _CalPickPosCommand ?? (_CalPickPosCommand = new DelegateCommand<string>(ExecuteCalPickPosCommand));
- private DelegateCommand _DynamicTestAnalyzerCommand;
- public DelegateCommand DynamicTestAnalyzerCommand =>
- _DynamicTestAnalyzerCommand ?? (_DynamicTestAnalyzerCommand = new DelegateCommand(ExecuteDynamicTestAnalyzerCommand));
- private DelegateCommand _SetOffsetCommand;
- public DelegateCommand SetOffsetCommand =>
- _SetOffsetCommand ?? (_SetOffsetCommand = new DelegateCommand(ExecuteSetOffsetCommand));
- #endregion
- #region 事件
- #endregion
- public PlcPointParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
- IConfigService configService, IRobotService robotService, ISystemDatabaseService systemDatabaseService, IRemoteCommandService remoteCommandService,
- ICalibrationService calibrationService, ICameraService cameraService, IProductService productService)
- {
- _regionManager = regionManager;
- _eventAggregator = ea;
- _container = container;
- _dialogService = dialogService;
- _configService = configService;
- _systemDatabaseService = systemDatabaseService;
- //订阅权限登录事件
- _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
- management = _container.Resolve<Management>();
- _robotService = robotService;
- _remoteCommandService = remoteCommandService;
- _calibrationService = calibrationService;
- _cameraService = cameraService;
- _productService = productService;
- }
- #region 方法
- /// <summary>
- /// 下一步
- /// </summary>
- void ExecuteNextCommand()
- {
- NavigationParameters param = new NavigationParameters();
- param.Add("SelectProduct", SelectProduct);
- _regionManager.RequestNavigate("ProductRegionContext", "ProductParams", param);
- }
- /// <summary>
- /// 上一步
- /// </summary>
- void ExecuteBackCommand()
- {
- NavigationParameters param = new NavigationParameters();
- param.Add("SelectProduct", SelectProduct);
- param.Add("SelectedProcedure", null);
- _regionManager.RequestNavigate("ProductRegionContext", "ProcessBasics", param);
- }
- /// <summary>
- /// 点动
- /// </summary>
- /// <param name="obj"></param>
- private async void ExecuteJogCommand(object obj)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- var items = ((string)obj).Split(':');
- //如果移动距离大于10mm,则提示用户确认
- double distance = double.Parse(items[1]);
- if (Math.Abs(distance) >= 10)
- {
- if (MessageBox.Show($"确认要点动距离 {distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- }
- Robot.Timeout = 6000000;
- switch (items[0])
- {
- case "X+":
- await Robot.JogAsync("X", distance);
- break;
- case "X-":
- await Robot.JogAsync("X", -distance);
- break;
- case "Y+":
- await Robot.JogAsync("Y", distance);
- break;
- case "Y-":
- await Robot.JogAsync("Y", -distance);
- break;
- case "Z+":
- await Robot.JogAsync("Z", distance);
- break;
- case "Z-":
- await Robot.JogAsync("Z", -distance);
- break;
- case "U+":
- await Robot.JogAsync("U", distance);
- break;
- case "U-":
- await Robot.JogAsync("U", -distance);
- break;
- case "V+":
- await Robot.JogAsync("V", distance);
- break;
- case "V-":
- await Robot.JogAsync("V", -distance);
- break;
- case "W+":
- await Robot.JogAsync("W", distance);
- break;
- case "W-":
- await Robot.JogAsync("W", -distance);
- break;
- default:
- break;
- }
- Robot.Timeout = 5000;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点位-机器人点动时出错", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 执行运动
- /// </summary>
- /// <param name="obj"></param>
- async void ExecuteExecuteMotion(object parameter)
- {
- if (parameter == null)
- {
- return;
- }
- if (SelectedPoint == null)
- {
- return;
- }
- var values = (object[])parameter;
- var point = new RPoint()
- {
- X = SelectedPoint.X_Position,
- Y = SelectedPoint.Y_Position,
- Z = SelectedPoint.Z_Position_Start,
- U = SelectedPoint.U_Position,
- V = SelectedPoint.R_Position,
- };
- MotionCommand motionCmd = (MotionCommand)values[1];
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- //确认要执行该点位的该运动指令吗
- if (MessageBox.Show($"确认要执行点位 {SelectedPoint.Number} 的 {motionCmd} 指令吗?", "执行点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- if (SelectedIndex == 6)
- {
- await Robot.WaitCameraMoveFinishedAsync(point.Number, point);
- }
- else if (SelectedIndex == 8)
- {
- //弹窗用户是否确认要示教该点位
- if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[1].Name, SelectedPoint.Z_Position_Start);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- return;
- }
- else if (SelectedIndex == 1)
- {
- var curpos = await Robot.GetRobotPosAsync();
- //var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
- curpos.Z = 0;
- await Robot.CalibMotionAsync(curpos, 0);
- await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, SelectedPoint.Z_Position_Stop);
- curpos.X = SelectedPoint.X_Position;
- curpos.Y = SelectedPoint.Y_Position;
- curpos.Z = SelectedPoint.Z_Position_Start;
- curpos.U = SelectedPoint.U_Position;
- await Robot.CalibMotionAsync(curpos, 0);
- }
- else
- {
- //Robot.Timeout = 6000000;
- switch (motionCmd)
- {
- case MotionCommand.Go:
- await Robot.GoAsync(point);
- break;
- case MotionCommand.Jump:
- await Robot.JumpAsync(point, null);
- break;
- case MotionCommand.Move:
- await Robot.MoveAsync(point);
- break;
- }
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点位-执行点位时出错", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 示教点位
- /// </summary>
- /// <param name="point"></param>
- async void ExecuteTechPointCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- if (SelectedPoint == null) return;
- try
- {
- //如果当前的选项卡处于锁付点位,则提示用户当前模式不允许进行示教
- if (SelectedIndex == 4)
- {
- ////如果local为空,则必须先通过相机定位产品,否则无法示教锁付点位
- //if (toolCoord == null)
- //{
- // _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "当前模式不允许直接示教贴敷点位,请先通过相机定位产品和定位辅料!", Duration = 1 });
- // return;
- //}
- //弹窗用户是否确认要示教该点位
- if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- double upCameraU = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)_PutPoints[0].X, (float)_PutPoints[0].Y), new PointF((float)_PutPoints[1].X, (float)_PutPoints[1].Y));
- var curpos1 = await Robot.GetRobotPosAsync();
- //var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[1].Name);
- //将当前点位转换为产品Local坐标系下的点位
- SelectedPoint.X_Position = (float)curpos1.X;
- SelectedPoint.Y_Position = (float)curpos1.Y;
- SelectedPoint.Z_Position_Start = curpos1.Z;
- SelectedPoint.U_Position = curpos1.U;
- SelectedPoint.R_Position = curpos1.V;
- //SelectedPoint.Z_Position_Stop = addpos;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- return;
- }
- else if (SelectedIndex == 1)
- {
- //弹窗用户是否确认要示教该点位
- if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- var curpos1 = await Robot.GetRobotPosAsync();
- var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
- //将当前点位转换为产品Local坐标系下的点位
- SelectedPoint.X_Position = (float)curpos1.X;
- SelectedPoint.Y_Position = (float)curpos1.Y;
- SelectedPoint.Z_Position_Start = curpos1.Z;
- SelectedPoint.Z_Position_Stop = addpos;
- SelectedPoint.U_Position = curpos1.U;
- SelectedPoint.R_Position = curpos1.V;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- return;
- }
- else if (SelectedIndex == 6)
- {
- //弹窗用户是否确认要示教该点位
- if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- var curpos1 = await Robot.GetCameraPosAsync(SelectedPoint.Number);
- //将当前点位转换为产品Local坐标系下的点位
- SelectedPoint.X_Position = (float)curpos1.X;
- SelectedPoint.Y_Position = (float)curpos1.Y;
- SelectedPoint.Z_Position_Start = curpos1.Z;
- SelectedPoint.U_Position = curpos1.U;
- SelectedPoint.R_Position = curpos1.V;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- return;
- }
- else if (SelectedIndex == 8)
- {
- //弹窗用户是否确认要示教该点位
- if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[1].Name);
- SelectedPoint.Z_Position_Start = addpos;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- return;
- }
- else
- {
- //弹窗用户是否确认要示教该点位
- if (MessageBox.Show($"确认要示教点位 {SelectedPoint.Number} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- var curpos = await Robot.GetRobotPosAsync();
- SelectedPoint.X_Position = curpos.X;
- SelectedPoint.Y_Position = curpos.Y;
- SelectedPoint.Z_Position_Start = curpos.Z;
- SelectedPoint.U_Position = curpos.U;
- SelectedPoint.R_Position = curpos.V;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点位-示教点位时出错", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- void ExecuteLoadedCommand()
- {
- if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- }
- /// <summary>
- /// 电机
- /// </summary>
- /// <param name="obj"></param>
- private async void ExecuteMotorCommand(string obj)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- await Robot.MotorAsync(Convert.ToBoolean(obj));
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点击操作时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 重置
- /// </summary>
- private async void ExecuteResetCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- await Robot.ResetAsync();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("重置机器人时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 锁定刹车
- /// </summary>
- private async void ExecuteSLockCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- await Robot.SLockAsync();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人锁定刹车时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 释放刹车
- /// </summary>
- private async void ExecutesFreeCommand()
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- await Robot.SFreeAsync();
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人释放刹车时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- private bool CanExecute
- {
- get
- {
- // 命令可执行仅当机器人可执行且已选择点位
- if (Robot != null && Robot.IsConnected && Robot.CanExecute)
- {
- return true;
- }
- return false;
- }
- }
- //是否可以示教或者执行点位
- private bool CanExecutePointCommand
- {
- get
- {
- if (Robot != null && Robot.IsConnected && Robot.CanExecute)
- {
- return SelectedPointInDataGrid != null;
- }
- return false;
- }
- }
- /// <summary>
- /// 点位表切换时
- /// </summary>
- void ExecuteSelectionChangedCommand()
- {
- switch (SelectedIndex)
- {
- case 0:
- Points = SelectProduct.PickCameraPoints;
- break;
- case 1:
- Points = SelectProduct.PickPoints;
- break;
- case 2:
- Points = SelectProduct.SecPosCameraPoints;
- break;
- case 3:
- Points = SelectProduct.ScrewCameraPoints;
- break;
- case 4:
- Points = SelectProduct.ScrewPoints;
- break;
- case 5:
- Points = SelectProduct.CheckCameraPoints;
- break;
- case 6:
- Points = SelectProduct.IndependentCamerPoints;
- break;
- case 7:
- Points = SelectProduct.RemovePoints;
- break;
- case 8:
- Points = SelectProduct.PressurePlacePoints;
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 增加点位
- /// </summary>
- void ExecuteAddPointCommand()
- {
- //添加点位
- Points.Add(new PlcPoint()
- {
- Number = Points.Count + 1,
- X_Velocity = 100,
- Y_Velocity = 100,
- Z_Velocity_Start = 100,
- Z_Velocity_Stop = 100,
- U_Velocity = 100,
- R_Velocity = 100,
- });
- // update commands
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- }
- /// <summary>
- /// 移除点位
- /// </summary>
- void ExecuteDeletePointCommand()
- {
- if (SelectedPoint == null)
- {
- return;
- }
- // 确认删除
- if (MessageBox.Show("确认要删除选中的点位吗?", "删除点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- int removedIndex = Points.IndexOf(SelectedPoint);
- Points.Remove(SelectedPoint);
- //重新编号
- for (int i = 0; i < Points.Count; i++)
- {
- Points[i].Number = i + 1;
- }
- // adjust selection
- if (Points.Count > 0)
- {
- int newIndex = Math.Min(removedIndex, Points.Count - 1);
- SelectedPointInDataGrid = Points[newIndex];
- }
- else
- {
- SelectedPointInDataGrid = null;
- }
- // update commands
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- }
- bool CanExecuteDeletePointCommand()
- {
- return SelectedPointInDataGrid != null;
- }
- private bool CanMovePointUp()
- {
- return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) > 0;
- }
- private bool CanMovePointDown()
- {
- return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) >= 0 && Points.IndexOf(SelectedPointInDataGrid) < Points.Count - 1;
- }
- /// <summary>
- /// 向上移动点位
- /// </summary>
- void ExecuteMovePointUpCommand()
- {
- if (SelectedPointInDataGrid == null) return;
- // 确认移动
- if (MessageBox.Show("确认将选中点位上移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- int idx = Points.IndexOf(SelectedPointInDataGrid);
- if (idx <= 0) return;
- var item = SelectedPointInDataGrid;
- Points.Move(idx, idx - 1);
- // renumber
- for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
- SelectedPointInDataGrid = item;
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- }
- /// <summary>
- /// 向下移动点位
- /// </summary>
- void ExecuteMovePointDownCommand()
- {
- if (SelectedPointInDataGrid == null) return;
- // 确认移动
- if (MessageBox.Show("确认将选中点位下移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- int idx = Points.IndexOf(SelectedPointInDataGrid);
- if (idx < 0 || idx >= Points.Count - 1) return;
- var item = SelectedPointInDataGrid;
- Points.Move(idx, idx + 1);
- // renumber
- for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
- SelectedPointInDataGrid = item;
- _MovePointUpCommand?.RaiseCanExecuteChanged();
- _MovePointDownCommand?.RaiseCanExecuteChanged();
- }
- /// <summary>
- /// CAD导入点位
- /// </summary>
- async void ExecuteImportCadPointCommand()
- {
- try
- {
- var view = new DxfView();
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null)
- {
- var cadPoints = view.Points;
- if (cadPoints != null && cadPoints.Count > 0)
- {
- //要导入的开始点编号
- int startNumber = view.StartIndex;
- //弹窗提示用户是否确认要导入从该编号开始的点位,点位数量为cadPoints.Count
- if (MessageBox.Show($"确认要从点位编号 {startNumber} 开始导入 {cadPoints.Count} 个点位吗?", "导入点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- //导入点位
- for (int i = 0; i < cadPoints.Count; i++)
- {
- //如果点位编号已存在,则更新该点位,否则新增点位,只更新XY坐标
- var point = cadPoints[i];
- var existingPoint = Points.FirstOrDefault(p => p.Number == startNumber + i);
- if (existingPoint != null)
- {
- existingPoint.X_Position = point.X;
- existingPoint.Y_Position = point.Y;
- }
- else
- {
- Points.Add(new PlcPoint()
- {
- Number = startNumber + i,
- X_Position = point.X,
- Y_Position = point.Y,
- X_Velocity = 100,
- Y_Velocity = 100,
- Z_Velocity_Start = 100,
- Z_Velocity_Stop = 100,
- U_Velocity = 100,
- R_Velocity = 100,
- });
- }
- }
- //对所有的点位重新编号,确保编号连续
- var sortedPoints = Points.OrderBy(p => p.Number).ToList();
- Points.Clear();
- for (int i = 0; i < sortedPoints.Count; i++)
- {
- sortedPoints[i].Number = i + 1;
- Points.Add(sortedPoints[i]);
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("导入CAD点位时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 设置偏移
- /// </summary>
- void ExecuteSetOffsetCommand()
- {
- if (SelectedIndex < 0) return;
- IDialogParameters parameters1 = new DialogParameters();
- if (SelectedIndex == 0)
- {
- parameters1.Add("Title", "取料拍照点位-补偿值设置");
- }
- else if (SelectedIndex == 1)
- {
- parameters1.Add("Title", "取料点位-补偿值设置");
- }
- else if (SelectedIndex == 2)
- {
- parameters1.Add("Title", "下相机二次定位点位-补偿值设置");
- }
- else if (SelectedIndex == 3)
- {
- parameters1.Add("Title", "锁附拍照点位-补偿值设置");
- }
- else if (SelectedIndex == 4)
- {
- parameters1.Add("Title", "锁附点位-补偿值设置");
- }
- else if (SelectedIndex == 5)
- {
- parameters1.Add("Title", "复检点位-补偿值设置");
- }
- else
- {
- parameters1.Add("Title", "点位-补偿值设置");
- }
- List<PlcPoint> _points = new List<PlcPoint>();
- foreach (var item in Points)
- {
- _points.Add(item.Clone());
- }
- parameters1.Add("Points", _points.ToArray());
- _dialogService.ShowDialog("PlcPointOffserParams", parameters1, rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- var param = rst.Parameters.GetValue<PlcPoint[]>("Points");
- //更新点位
- for (int i = 0; i < Points.Count; i++)
- {
- Points[i].X_Offset = param[i].X_Offset;
- Points[i].Y_Offset = param[i].Y_Offset;
- Points[i].Z_Start_Offset = param[i].Z_Start_Offset;
- Points[i].Z_Stop_Offset = param[i].Z_Stop_Offset;
- Points[i].U_Offset = param[i].U_Offset;
- Points[i].R_Offset = param[i].R_Offset;
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}", Duration = 1 });
- }
- });
- }
- /// <summary>
- /// 停止采集
- /// </summary>
- void ExecuteStopGrabbingCommand()
- {
- if (Camera != null)
- Camera.StopGrabbing();
- IsGrap = false;
- }
- bool CanExecuteStopGrabbingCommand()
- {
- return IsGrap;
- }
- /// <summary>
- /// 开始采集
- /// </summary>
- void ExecuteStartGrabbingCommand()
- {
- if (Camera != null)
- Camera.StartGrabbing();
- IsGrap = true;
- }
- bool CanExecuteStartGrabbingCommand()
- {
- return SelectedCamera != null && !IsGrap;
- }
- private void Camera_ImageCallbackEvent(ICogImage image, TimeSpan totaltime, string errormessage)
- {
- Image = image;
- App.Current.Dispatcher.Invoke(new
- Action(() =>
- {
- if (errormessage != null && !string.IsNullOrEmpty(errormessage))
- {
- Message = $"{Lang.耗时}:{totaltime.TotalMilliseconds.ToString("F1")} ms Error:{errormessage}";
- }
- else
- {
- Message = $"{Lang.耗时}:{totaltime.TotalMilliseconds.ToString("F1")} ms";
- }
- }));
- }
- /// <summary>
- /// 去取料
- /// </summary>
- async void ExecuteGoPickCommand()
- {
- try
- {
- if (SelectedPoint == null)
- {
- return;
- }
- if (Robot == null || !Robot.IsConnected)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行取料!", Duration = 1 });
- return;
- }
- if (MessageBox.Show("确认要执行取料吗?", "去取料", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- var waiting = new WaitingControl();
- //show the dialog
- var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
- // 1. 控制机器人移动至拍照点位
- var rpoint = new RPoint()
- {
- X = SelectedPoint.X_Position,
- Y = SelectedPoint.Y_Position,
- Z = SelectedPoint.Z_Position_Start,
- U = SelectedPoint.U_Position,
- V = SelectedPoint.R_Position,
- };
- await Robot.CalibMotionAsync(rpoint, null);
- await Robot.CalibParameAsync(new PickInfo() { Inhal = Inhal, Blow = 1 }, 20, 20, true, 200, 200);
- //打开吸真空
- await Robot.CalibOutIOAsync(true);
- await Task.Delay(500);
- rpoint.Z = 0;
- await Robot.CalibMotionAsync(rpoint, null);
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "取料完成!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("取料时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- bool CanExecuteCommandGoPickCommandName()
- {
- return SelectedPoint != null;
- }
- ToolCoord toolCoord = null;
- double _FixedUpCameraTempletAngle = 0;
- OpenCvSharp.Point3f[] _PutPoints = new OpenCvSharp.Point3f[2];
- /// <summary>
- /// 去二次定位
- /// </summary>
- async void ExecuteGoRepositionCommand()
- {
- try
- {
- if (SelectedPoint == null)
- {
- return;
- }
- if (Robot == null || !Robot.IsConnected)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行二次定位!", Duration = 1 });
- return;
- }
- if (MessageBox.Show("确认要执行下相机拍产二次定位吗?", "去下相机拍照", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- var waiting = new WaitingControl();
- //show the dialog
- var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
- // 1. 控制机器人移动至拍照点位
- var rpoint = new RPoint()
- {
- X = SelectedPoint.X_Position,
- Y = SelectedPoint.Y_Position,
- Z = SelectedPoint.Z_Position_Start,
- U = SelectedPoint.U_Position,
- V = SelectedPoint.R_Position,
- };
- await Robot.CalibMotionAsync(rpoint, null);
- await Task.Delay(200);
- //获取固定向上相机1的流程
- var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera1ProcedureId);
- if (process1 == null)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机1视觉流程,流程ID:{SelectProduct.FixedUpCamera1ProcedureId} 未找到!", Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- //获取固定向上相机2的流程
- var process2 = _productService.GetCurrentProductProcedureModelById(SelectProduct.FixedUpCamera2ProcedureId);
- if (process2 == null)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"固定向上相机2视觉流程,流程ID:{SelectProduct.FixedUpCamera2ProcedureId} 未找到!", Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- // 执行视觉任务
- var _cts = new CancellationTokenSource();
- var task1 = _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
- var task2 = _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
- var visionResults = await Task.WhenAll(task1, task2);
- if (visionResults[0].IsSucceed && visionResults[1].IsSucceed)
- {
- float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
- float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
- _FixedUpCameraTempletAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
- toolCoord = new ToolCoord();
- toolCoord.SetTool(toolX, toolY);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位成功!", Duration = 0.4 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- else
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行二次定位!", Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("二次定位时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- }
- }
- /// <summary>
- /// 执行产品拍照
- /// </summary>
- async void ExecuteTakeProductPhotoCommand()
- {
- try
- {
- if (SelectedPoint == null)
- {
- return;
- }
- if (Robot == null || !Robot.IsConnected)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行产品拍照!", Duration = 1 });
- return;
- }
- if (MessageBox.Show("确认要执行产品拍照吗?", "去产品位置拍照", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- //如果二次定位的工具坐标为空,则提示用户先进行二次定位
- if (toolCoord == null)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
- return;
- }
- var waiting = new WaitingControl();
- //show the dialog
- var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
- // 1. 控制机器人移动至拍照点位
- var rpoint = new RPoint()
- {
- X = Points[0].X_Position,
- Y = Points[0].Y_Position,
- Z = Points[0].Z_Position_Start,
- U = Points[0].U_Position,
- V = Points[0].R_Position,
- };
- await Robot.CalibMotionAsync(rpoint, null);
- await Task.Delay(200);
- //获取移动向下相机1的流程
- var process1 = _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera1LockPhotoProcedureId);
- if (process1 == null)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机1视觉流程,流程ID:{SelectProduct.MoveDownCamera1LockPhotoProcedureId} 未找到!", Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- // 执行视觉任务
- var _cts = new CancellationTokenSource();
- var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process1, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
- if (visionResult.IsSucceed)
- {
- _PutPoints[0] = new OpenCvSharp.Point3f((float)visionResult.X, (float)visionResult.Y, (float)visionResult.U);
- }
- else
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行产品拍照!", Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- // 2. 控制机器人移动至拍照点位
- rpoint = new RPoint()
- {
- X = Points[1].X_Position,
- Y = Points[1].Y_Position,
- Z = Points[1].Z_Position_Start,
- U = Points[1].U_Position,
- V = Points[1].R_Position,
- };
- await Robot.CalibMotionAsync(rpoint, null);
- await Task.Delay(200);
- //获取移动向下相机1的流程
- var process2 = _productService.GetCurrentProductProcedureModelById(SelectProduct.MoveDownCamera2LockPhotoProcedureId);
- if (process2 == null)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"移动向下相机2视觉流程,流程ID:{SelectProduct.MoveDownCamera2LockPhotoProcedureId} 未找到!", Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- // 执行视觉任务
- _cts = new CancellationTokenSource();
- visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process2, null, new double[] { rpoint.X, rpoint.Y, rpoint.U }, _cts.Token);
- if (visionResult.IsSucceed)
- {
- _PutPoints[1] = new OpenCvSharp.Point3f((float)visionResult.X, (float)visionResult.Y, (float)visionResult.U);
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- else
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "视觉定位失败,无法进行产品拍照!", Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("执行产品拍照时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- }
- }
- /// <summary>
- /// 执行产品贴敷
- /// </summary>
- async void ExecuteTakeProductCommand()
- {
- try
- {
- if (SelectedPoint == null)
- {
- return;
- }
- if (Robot == null || !Robot.IsConnected)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人未连接,无法执行产品贴敷!", Duration = 1 });
- return;
- }
- if (MessageBox.Show("确认要执行产品贴敷吗?", "去产品贴敷", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- //如果二次定位的工具坐标为空,则提示用户先进行二次定位
- if (toolCoord == null)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "二次定位的工具坐标为空,无法执行产品拍照!", Duration = 1 });
- return;
- }
- if (_PutPoints[0].X == 0 && _PutPoints[0].Y == 0 && _PutPoints[1].X == 0 && _PutPoints[1].Y == 0)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "检测到未定位产品", Duration = 1 });
- return;
- }
- var waiting = new WaitingControl();
- //show the dialog
- var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
- double upCameraX = (_PutPoints[0].X + _PutPoints[1].X) / 2;
- double upCameraY = (_PutPoints[0].Y + _PutPoints[1].Y) / 2;
- double upCameraU = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)_PutPoints[0].X, (float)_PutPoints[0].Y), new PointF((float)_PutPoints[1].X, (float)_PutPoints[1].Y));
- var pn = Vector<double>.Build.Dense(new double[] { upCameraX, upCameraY });
- //目标角度:
- double angle = SelectedPoint.U_Position + (_FixedUpCameraTempletAngle - SelectProduct.FixedUpCameraTempletAngle) + (upCameraU - SelectProduct.MoveDownCamerTempletAngle);
- //将_PutPoint转换为Tool0下要走的点
- var p0 = toolCoord.GetTool0Coord(pn, angle);
- // 1. 控制机器人移动至拍照点位
- var rpoint = new RPoint()
- {
- X = (float)p0[0],
- Y = (float)p0[1],
- Z = SelectedPoint.Z_Position_Start,
- U = (float)angle,
- V = SelectedPoint.R_Position,
- };
- await Robot.CalibMotionAsync(rpoint, null);
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- return;
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("执行产品贴敷时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- }
- }
- /// <summary>
- /// 附加轴+点动
- /// </summary>
- /// <param name="obj"></param>
- async void ExecuteAdditionalAxisJogPlusCommand(object obj)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- if (obj is AxisExtended axis)
- {
- //如果移动距离大于10mm,则提示用户确认
- if (Math.Abs(Distance) >= 10)
- {
- if (MessageBox.Show($"确认要点动距离 {Distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- }
- await Robot.AdditionalAxisJogAsync(axis.Name, Distance);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("附加轴点动+时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 附加轴-点动
- /// </summary>
- /// <param name="obj"></param>
- async void ExecuteAdditionalAxisJogMinusCommand(object obj)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- if (obj is AxisExtended axis)
- {
- //如果移动距离大于10mm,则提示用户确认
- if (Math.Abs(Distance) >= 10)
- {
- if (MessageBox.Show($"确认要点动距离 {Distance} mm 吗?", "确认点动", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- }
- await Robot.AdditionalAxisJogNegAsync(axis.Name, Distance);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("附加轴点动-时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 附加轴下使能
- /// </summary>
- /// <param name="obj"></param>
- async void ExecuteAdditionalAxisMotorOffCommand(object obj)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- if (obj is AxisExtended axis)
- {
- await Robot.AdditionalAxisMotorAsync(axis.Name, false);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("附加轴上使能时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 附加轴上使能
- /// </summary>
- /// <param name="obj"></param>
- async void ExecuteAdditionalAxisMotorOnCommand(object obj)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- if (obj is AxisExtended axis)
- {
- await Robot.AdditionalAxisMotorAsync(axis.Name, true);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("附加轴下使能时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 移动取料托盘点
- /// </summary>
- async void ExecutePickMoveCommand(string parameter)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- //弹窗用户是否确认要示教该点位
- if (MessageBox.Show($"确认要移动取料点位 {parameter} 吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- int palletIndex = int.Parse(parameter.Split('-')[0]);
- int pointIndex = int.Parse(parameter.Split('-')[1]);
- var curpos = await Robot.GetRobotPosAsync();
- var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
- PlcPoint pn = null;
- if (palletIndex == 1)
- {
- switch (pointIndex)
- {
- case 1:
- pn = Pallet1.P0.Clone();
- break;
- case 2:
- pn = Pallet1.P1.Clone();
- break;
- case 3:
- pn = Pallet1.P2.Clone();
- break;
- default:
- break;
- }
- }
- else
- {
- switch (pointIndex)
- {
- case 1:
- pn = Pallet2.P0.Clone();
- break;
- case 2:
- pn = Pallet2.P1.Clone();
- break;
- case 3:
- pn = Pallet2.P2.Clone();
- break;
- default:
- break;
- }
- }
- if (pn == null)
- {
- return;
- }
- // 1.Z轴上升到安全高度
- curpos.Z = 0;
- bool isSuccess = await Robot.CalibMotionAsync(curpos, null);
- if (!isSuccess)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人移动失败!", Duration = 1 });
- return;
- }
- // 2.附加轴移动
- isSuccess = await Robot.AdditionalAxisMoveAsync(Robot.AdditionalAxisList[0].Name, pn.Z_Position_Stop);
- if (!isSuccess)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "附加轴移动失败!", Duration = 1 });
- return;
- }
- // 3.移动XY轴到位
- curpos.X = pn.X_Position;
- curpos.Y = pn.Y_Position;
- curpos.Z = pn.Z_Position_Start;
- curpos.U = pn.U_Position;
- isSuccess = await Robot.CalibMotionAsync(curpos, null);
- if (!isSuccess)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "机器人移动失败!", Duration = 1 });
- return;
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 示教取料托盘点
- /// </summary>
- /// <param name="parameter"></param>
- async void ExecutePickTechCommand(string parameter)
- {
- if (Robot == null || !Robot.IsConnected) return;
- try
- {
- //弹窗用户是否确认要示教该点位
- if (MessageBox.Show($"确认要示教取料点位 {parameter} 吗?", "示教点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
- {
- return;
- }
- int palletIndex = int.Parse(parameter.Split('-')[0]);
- int pointIndex = int.Parse(parameter.Split('-')[1]);
- var curpos = await Robot.GetRobotPosAsync();
- var addpos = await Robot.GetAdditionalAxisCurrentPosAsync(Robot.AdditionalAxisList[0].Name);
- if (palletIndex == 1)
- {
- switch (pointIndex)
- {
- case 1:
- Pallet1.P0.X_Position = curpos.X;
- Pallet1.P0.Y_Position = curpos.Y;
- Pallet1.P0.Z_Position_Start = curpos.Z;
- Pallet1.P0.U_Position = curpos.U;
- Pallet1.P0.Z_Position_Stop = addpos;
- break;
- case 2:
- Pallet1.P1.X_Position = curpos.X;
- Pallet1.P1.Y_Position = curpos.Y;
- Pallet1.P1.Z_Position_Start = curpos.Z;
- Pallet1.P1.U_Position = curpos.U;
- Pallet1.P1.Z_Position_Stop = addpos;
- break;
- case 3:
- Pallet1.P2.X_Position = curpos.X;
- Pallet1.P2.Y_Position = curpos.Y;
- Pallet1.P2.Z_Position_Start = curpos.Z;
- Pallet1.P2.U_Position = curpos.U;
- Pallet1.P2.Z_Position_Stop = addpos;
- break;
- default:
- break;
- }
- }
- else
- {
- switch (pointIndex)
- {
- case 1:
- Pallet2.P0.X_Position = curpos.X;
- Pallet2.P0.Y_Position = curpos.Y;
- Pallet2.P0.Z_Position_Start = curpos.Z;
- Pallet2.P0.U_Position = curpos.U;
- Pallet2.P0.Z_Position_Stop = addpos;
- break;
- case 2:
- Pallet2.P1.X_Position = curpos.X;
- Pallet2.P1.Y_Position = curpos.Y;
- Pallet2.P1.Z_Position_Start = curpos.Z;
- Pallet2.P1.U_Position = curpos.U;
- Pallet2.P1.Z_Position_Stop = addpos;
- break;
- case 3:
- Pallet2.P2.X_Position = curpos.X;
- Pallet2.P2.Y_Position = curpos.Y;
- Pallet2.P2.Z_Position_Start = curpos.Z;
- Pallet2.P2.U_Position = curpos.U;
- Pallet2.P2.Z_Position_Stop = addpos;
- break;
- default:
- break;
- }
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 计算所有托盘点
- /// </summary>
- void ExecuteCalPickPosCommand(string parameter)
- {
- try
- {
- int palletIndex = int.Parse(parameter);
- if (palletIndex == 1)
- {
- PalletTool palletTool = new PalletTool(Pallet1);
- //托盘中所有的点‘
- var points = palletTool.PlcPoints;
- //将所有的点写入到取料点中,如果当前定义的取料点不存在,则新增
- for (int i = 0; i < points.Length; i++)
- {
- //如果当前的取料点数量小于等于i,则新增一个取料点
- if (SelectProduct.PickPoints.Count <= i)
- {
- SelectProduct.PickPoints.Add(new PlcPoint()
- {
- Number = i + 1,
- X_Position = points[i].X_Position,
- X_Velocity = 100,
- Y_Position = points[i].Y_Position,
- Y_Velocity = 100,
- Z_Position_Start = points[i].Z_Position_Start,
- Z_Velocity_Start = 100,
- U_Position = points[i].U_Position,
- U_Velocity = 100,
- Z_Position_Stop = points[i].Z_Position_Stop,
- Z_Velocity_Stop = 100,
- });
- }
- else
- {
- //否则更新当前的取料点
- SelectProduct.PickPoints[i].Number = i + 1;
- SelectProduct.PickPoints[i].X_Position = points[i].X_Position;
- SelectProduct.PickPoints[i].Y_Position = points[i].Y_Position;
- SelectProduct.PickPoints[i].Z_Position_Start = points[i].Z_Position_Start;
- SelectProduct.PickPoints[i].U_Position = points[i].U_Position;
- SelectProduct.PickPoints[i].Z_Position_Stop = points[i].Z_Position_Stop;
- }
- }
- }
- else
- {
- //如果当前的取料点数量小于托盘1的点数量,则提示用户先计算托盘1的点
- if (SelectProduct.PickPoints.Count < Pallet1.Row * Pallet1.Column)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "请先计算托盘1的点位!", Duration = 1 });
- return;
- }
- PalletTool palletTool = new PalletTool(Pallet2);
- //托盘中所有的点‘
- var points = palletTool.PlcPoints;
- //将所有的点写入到取料点中,如果当前定义的取料点不存在,则新增
- for (int i = 0; i < points.Length; i++)
- {
- int index = i + Pallet1.Row * Pallet1.Column;
- //如果当前的取料点数量小于等于index,则新增一个取料点
- if (SelectProduct.PickPoints.Count <= index)
- {
- SelectProduct.PickPoints.Add(new PlcPoint()
- {
- Number = index + 1,
- X_Position = points[i].X_Position,
- X_Velocity = 100,
- Y_Position = points[i].Y_Position,
- Y_Velocity = 100,
- Z_Position_Start = points[i].Z_Position_Start,
- Z_Velocity_Start = 100,
- U_Position = points[i].U_Position,
- U_Velocity = 100,
- Z_Position_Stop = points[i].Z_Position_Stop,
- Z_Velocity_Stop = 100,
- });
- }
- else
- {
- //否则更新当前的取料点
- SelectProduct.PickPoints[index].Number = index + 1;
- SelectProduct.PickPoints[index].X_Position = points[i].X_Position;
- SelectProduct.PickPoints[index].Y_Position = points[i].Y_Position;
- SelectProduct.PickPoints[index].Z_Position_Start = points[i].Z_Position_Start;
- SelectProduct.PickPoints[index].U_Position = points[i].U_Position;
- SelectProduct.PickPoints[index].Z_Position_Stop = points[i].Z_Position_Stop;
- }
- }
- }
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = $"{Lang.完成}!", Duration = 0.4 });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("示教取料托盘点时出错!", ex);
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = ex.Message, Duration = 1 });
- }
- }
- /// <summary>
- /// 动态测试分析仪
- /// </summary>
- void ExecuteDynamicTestAnalyzerCommand()
- {
- try
- {
- IDialogParameters parameters = new DialogParameters();
- parameters.Add("SelectProduct", SelectProduct);
- parameters.Add("Robot", Robot);
- _dialogService.Show("VisionDynamicAccuracyAnalyzer", parameters, rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- //var param = rst.Parameters.GetValue<RobotTool>("Tool");
- //var param1 = rst.Parameters.GetValue<Matrix<double>>("RobotCameraRotationMatrix");
- //var param2 = rst.Parameters.GetValue<double>("Angle");
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("执行动态测试分析仪命令时出错", ex);
- MessageBox.Show(ex.Message);
- }
- }
- #endregion
- #region 继承
- /// <summary>
- /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <param name="continuationCallback"></param>
- public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
- {
- continuationCallback(true);
- }
- /// <summary>
- /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <exception cref="NotImplementedException"></exception>
- public async void OnNavigatedTo(NavigationContext navigationContext)
- {
- try
- {
- toolCoord = null;
- SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
- SelectedIndex = 0;
- Points = SelectProduct.PickCameraPoints;
- if (Robot == null)
- {
- Robot = _robotService.GetRobotByNumber(1) as XYZU_Robot;
- }
- if (Robot != null && Robot.IsConnected)
- {
- this.Distance = _configService.GetRobotStepDistance(Robot.Id);
- Robot.EnterDebugMode = true;
- AdditionalAxisList = Robot.AdditionalAxisList;
- }
- else if (Robot != null)
- {
- Robot.EnterDebugMode = true;
- }
- ProcedureModels = new ObservableCollection<ProcedureModel>();
- foreach (var item in SelectProduct.CameraProcedures)
- {
- foreach (var item1 in item.ProcedureModels)
- {
- ProcedureModels.Add(item1);
- }
- }
- CameraList = new ObservableCollection<CameraInfo>(_configService.GetAllCameras());
- Pallet1 = new PalletEx() { Row = 4, Column = 2, P1 = new PlcPoint(), P0 = new PlcPoint(), P2 = new PlcPoint() };
- Pallet2 = new PalletEx() { Row = 4, Column = 2, P1 = new PlcPoint(), P0 = new PlcPoint(), P2 = new PlcPoint() };
- if (SelectProduct.PickCameraPoints == null)
- {
- SelectProduct.PickCameraPoints = new ObservableCollection<PlcPoint>();
- }
- if (SelectProduct.PickPoints == null)
- {
- SelectProduct.PickPoints = new ObservableCollection<PlcPoint>();
- }
- if (SelectProduct.SecPosCameraPoints == null)
- {
- SelectProduct.SecPosCameraPoints = new ObservableCollection<PlcPoint>();
- }
- if (SelectProduct.ScrewCameraPoints == null)
- {
- SelectProduct.ScrewCameraPoints = new ObservableCollection<PlcPoint>();
- }
- if (SelectProduct.ScrewPoints == null)
- {
- SelectProduct.ScrewPoints = new ObservableCollection<PlcPoint>();
- }
- if (SelectProduct.CheckCameraPoints == null)
- {
- SelectProduct.CheckCameraPoints = new ObservableCollection<PlcPoint>();
- }
- if (SelectProduct.IndependentCamerPoints == null)
- {
- SelectProduct.IndependentCamerPoints = new ObservableCollection<PlcPoint>();
- }
- if (SelectProduct.RemovePoints == null)
- {
- SelectProduct.RemovePoints = new ObservableCollection<PlcPoint>();
- }
- if (SelectProduct.PressurePlacePoints == null)
- {
- SelectProduct.PressurePlacePoints = new ObservableCollection<PlcPoint>();
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("机器人点位界面进入时出错!", ex);
- }
- }
- /// <summary>
- /// 是否允许导航到此视图模型。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <returns></returns>
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- /// <summary>
- /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
- /// </summary>
- /// <param name="navigationContext"></param>
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- //if (Robot != null)
- //{
- // Robot.EnterDebugMode = false;
- //}
- try
- {
- IsGrap = false;
- if (Camera != null)
- {
- if (Camera.IsGrabbing)
- {
- Camera.StopGrabbing();
- }
- Camera.ImageCallbackEvent -= Camera_ImageCallbackEvent;
- Camera = null;
- }
- SelectedCamera = null;
- IsLeftDrawerOpen = false;
- }
- catch (Exception)
- {
- }
- }
- #endregion
- private bool _IsAllowEdit = false;
- public bool IsAllowEdit
- {
- get { return _IsAllowEdit; }
- set { SetProperty(ref _IsAllowEdit, value); }
- }
- private void LoginChange(Models.User user)
- {
- if (user.userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- }
- }
- }
|