ProcedureModel.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. using Cognex.VisionPro.ToolBlock;
  2. using Newtonsoft.Json;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using TeamAAS_VP.Enums;
  12. using TeamAAS_VP.Models.Feeder;
  13. using TeamAAS_VP.Models.Lights;
  14. using TeamAAS_VP.Models.Product;
  15. namespace TeamAAS_VP.Models
  16. {
  17. /// <summary>
  18. /// 流程模型
  19. /// </summary>
  20. [JsonObject(MemberSerialization.OptOut)]
  21. public class ProcedureModel : BindableBase
  22. {
  23. public Guid Id { get; set; }
  24. /// <summary>
  25. /// 流程名称
  26. /// </summary>
  27. public string Name { get; set; }
  28. public string CameraName { get; set; }
  29. private int _CameraNo;
  30. /// <summary>
  31. /// 相机编号
  32. /// </summary>
  33. public int CameraNo
  34. {
  35. get { return _CameraNo; }
  36. set { SetProperty(ref _CameraNo, value); }
  37. }
  38. /// <summary>
  39. /// 视觉图像处理模式
  40. /// </summary>
  41. public VisionModel VisionModel { get; set; }
  42. /// <summary>
  43. /// 触发相机命令
  44. /// </summary>
  45. public string TriggerCommand { get; set; }
  46. /// <summary>
  47. /// 机器人
  48. /// </summary>
  49. public Guid RobotId { get; set; }
  50. /// <summary>
  51. /// Feeder
  52. /// </summary>
  53. public Guid FeederId { get; set; }
  54. /// <summary>
  55. /// Camera
  56. /// </summary>
  57. public Guid CameraId { get; set; }
  58. /// <summary>
  59. /// 校准
  60. /// </summary>
  61. public Guid CalibrationId { get; set; }
  62. private ObservableCollection<ProcedureOutput> _ProcedureOutputs;
  63. /// <summary>
  64. /// 主页图像显示窗口的ID
  65. /// </summary>
  66. public Guid DisplayId { get; set; }
  67. /// <summary>
  68. /// 主页图像显示窗口的名称
  69. /// </summary>
  70. public string DisplayName { get; set; }
  71. /// <summary>
  72. /// 视觉流程输出集合
  73. /// </summary>
  74. public ObservableCollection<ProcedureOutput> ProcedureOutputs
  75. {
  76. get { return _ProcedureOutputs; }
  77. set { SetProperty(ref _ProcedureOutputs,value); }
  78. }
  79. private string _OutputSeparator = ";";
  80. /// <summary>
  81. /// 视觉流程输出项之间的分割符
  82. /// </summary>
  83. public string OutputSeparator
  84. {
  85. get { return _OutputSeparator; }
  86. set { SetProperty(ref _OutputSeparator, value); }
  87. }
  88. private FeederWorks _FeederWorks;
  89. /// <summary>
  90. /// Feeder振动集合
  91. /// </summary>
  92. public FeederWorks FeederWorks
  93. {
  94. get { return _FeederWorks; }
  95. set { SetProperty(ref _FeederWorks,value); }
  96. }
  97. private FeederStockWorks _FeederStockWorks;
  98. /// <summary>
  99. /// Feeder料仓振动集合
  100. /// </summary>
  101. public FeederStockWorks FeederStockWorks
  102. {
  103. get { return _FeederStockWorks; }
  104. set { SetProperty(ref _FeederStockWorks, value); }
  105. }
  106. private double _MinArea;
  107. /// <summary>
  108. /// Blob最小面积
  109. /// </summary>
  110. public double MinArea
  111. {
  112. get { return _MinArea; }
  113. set { SetProperty(ref _MinArea, value); }
  114. }
  115. private int _LightValue;
  116. /// <summary>
  117. /// 亮度
  118. /// </summary>
  119. public int LightValue
  120. {
  121. get { return _LightValue; }
  122. set { SetProperty(ref _LightValue, value); }
  123. }
  124. private float _ExposureTime;
  125. /// <summary>
  126. /// 相机曝光时间
  127. /// </summary>
  128. public float ExposureTime
  129. {
  130. get { return _ExposureTime; }
  131. set { SetProperty(ref _ExposureTime, value);}
  132. }
  133. private float _ExposureTime2;
  134. /// <summary>
  135. /// 相机曝光2时间
  136. /// </summary>
  137. public float ExposureTime2
  138. {
  139. get { return _ExposureTime2; }
  140. set { SetProperty(ref _ExposureTime2, value); }
  141. }
  142. private float _Gain;
  143. /// <summary>
  144. /// 相机增益
  145. /// </summary>
  146. public float Gain
  147. {
  148. get { return _Gain; }
  149. set { SetProperty(ref _Gain, value); }
  150. }
  151. private float _Gain2;
  152. /// <summary>
  153. /// 相机增益2
  154. /// </summary>
  155. public float Gain2
  156. {
  157. get { return _Gain2; }
  158. set { SetProperty(ref _Gain2, value); }
  159. }
  160. private int _Photo1Light1;
  161. /// <summary>
  162. /// 第一次拍照光源1亮度
  163. /// </summary>
  164. public int Photo1Light1
  165. {
  166. get { return _Photo1Light1; }
  167. set { SetProperty(ref _Photo1Light1, value); }
  168. }
  169. private int _Photo1Light2;
  170. /// <summary>
  171. /// 第一次拍照光源2亮度
  172. /// </summary>
  173. public int Photo1Light2
  174. {
  175. get { return _Photo1Light2; }
  176. set { SetProperty(ref _Photo1Light2, value); }
  177. }
  178. private int _Photo1Light3;
  179. /// <summary>
  180. /// 第一次拍照光源3亮度
  181. /// </summary>
  182. public int Photo1Light3
  183. {
  184. get { return _Photo1Light3; }
  185. set { SetProperty(ref _Photo1Light3, value); }
  186. }
  187. private int _Photo1Light4;
  188. /// <summary>
  189. /// 第一次拍照光源4亮度
  190. /// </summary>
  191. public int Photo1Light4
  192. {
  193. get { return _Photo1Light4; }
  194. set { SetProperty(ref _Photo1Light4, value); }
  195. }
  196. private int _Photo1Light5;
  197. /// <summary>
  198. /// 第一次拍照光源5亮度
  199. /// </summary>
  200. public int Photo1Light5
  201. {
  202. get { return _Photo1Light5; }
  203. set { SetProperty(ref _Photo1Light5, value); }
  204. }
  205. private int _Photo1Light6;
  206. /// <summary>
  207. /// 第一次拍照光源6亮度
  208. /// </summary>
  209. public int Photo1Light6
  210. {
  211. get { return _Photo1Light6; }
  212. set { SetProperty(ref _Photo1Light6, value); }
  213. }
  214. private int _Photo1Light7;
  215. /// <summary>
  216. /// 第一次拍照光源7亮度
  217. /// </summary>
  218. public int Photo1Light7
  219. {
  220. get { return _Photo1Light7; }
  221. set { SetProperty(ref _Photo1Light7, value); }
  222. }
  223. private int _Photo2Light1;
  224. /// <summary>
  225. /// 第二次拍照光源1亮度
  226. /// </summary>
  227. public int Photo2Light1
  228. {
  229. get { return _Photo2Light1; }
  230. set { SetProperty(ref _Photo2Light1, value); }
  231. }
  232. private int _Photo2Light2;
  233. /// <summary>
  234. /// 第二次拍照光源2亮度
  235. /// </summary>
  236. public int Photo2Light2
  237. {
  238. get { return _Photo2Light2; }
  239. set { SetProperty(ref _Photo2Light2, value); }
  240. }
  241. private int _Photo2Light3;
  242. /// <summary>
  243. /// 第二次拍照光源3亮度
  244. /// </summary>
  245. public int Photo2Light3
  246. {
  247. get { return _Photo2Light3; }
  248. set { SetProperty(ref _Photo2Light3, value); }
  249. }
  250. private int _Photo2Light4;
  251. /// <summary>
  252. /// 第二次拍照光源4亮度
  253. /// </summary>
  254. public int Photo2Light4
  255. {
  256. get { return _Photo2Light4; }
  257. set { SetProperty(ref _Photo2Light4, value); }
  258. }
  259. private int _Photo2Light5;
  260. /// <summary>
  261. /// 第二次拍照光源5亮度
  262. /// </summary>
  263. public int Photo2Light5
  264. {
  265. get { return _Photo2Light5; }
  266. set { SetProperty(ref _Photo2Light5, value); }
  267. }
  268. private int _Photo2Light6;
  269. /// <summary>
  270. /// 第二次拍照光源6亮度
  271. /// </summary>
  272. public int Photo2Light6
  273. {
  274. get { return _Photo2Light6; }
  275. set { SetProperty(ref _Photo2Light6, value); }
  276. }
  277. private int _Photo2Light7;
  278. /// <summary>
  279. /// 第二次拍照光源7亮度
  280. /// </summary>
  281. public int Photo2Light7
  282. {
  283. get { return _Photo2Light7; }
  284. set { SetProperty(ref _Photo2Light7, value); }
  285. }
  286. private int _PhotoCount;
  287. /// <summary>
  288. /// 拍照次数
  289. /// </summary>
  290. public int PhotoCount
  291. {
  292. get { return _PhotoCount; }
  293. set { SetProperty(ref _PhotoCount, value); }
  294. }
  295. private CogToolBlock _ToolBlock;
  296. /// <summary>
  297. /// 工具组
  298. /// </summary>
  299. [JsonIgnore]
  300. public CogToolBlock ToolBlock
  301. {
  302. get { return _ToolBlock; }
  303. set { SetProperty(ref _ToolBlock,value); }
  304. }
  305. private ObservableCollection<ToolInfo> _ToolInfo = new ObservableCollection<ToolInfo>();
  306. /// <summary>
  307. /// 工具末端的补偿
  308. /// </summary>
  309. public ObservableCollection<ToolInfo> ToolInfo
  310. {
  311. get { return _ToolInfo; }
  312. set { SetProperty(ref _ToolInfo, value); }
  313. }
  314. private int _WaitPhoto;
  315. /// <summary>
  316. /// 延时拍照时长(ms)
  317. /// </summary>
  318. public int WaitPhoto
  319. {
  320. get { return _WaitPhoto; }
  321. set { SetProperty(ref _WaitPhoto, value); }
  322. }
  323. private int _WaitFeederStop;
  324. /// <summary>
  325. /// 等待震动盘静止时长(ms)
  326. /// </summary>
  327. public int WaitFeederStop
  328. {
  329. get { return _WaitFeederStop; }
  330. set { SetProperty(ref _WaitFeederStop, value); }
  331. }
  332. private VibrationModel _VibrationModel;
  333. /// <summary>
  334. /// 振动模式
  335. /// </summary>
  336. public VibrationModel VibrationModel
  337. {
  338. get { return _VibrationModel; }
  339. set { SetProperty(ref _VibrationModel, value); }
  340. }
  341. private int _FeederFailLimit;
  342. /// <summary>
  343. /// 拍照失败Feeder振动最大次数
  344. /// </summary>
  345. public int FeederFailLimit
  346. {
  347. get { return _FeederFailLimit; }
  348. set { SetProperty(ref _FeederFailLimit, value); }
  349. }
  350. private OutputPointMode _OutputPointMode;
  351. /// <summary>
  352. /// 点位发送的模式
  353. /// </summary>
  354. public OutputPointMode OutputPointMode
  355. {
  356. get { return _OutputPointMode; }
  357. set { SetProperty(ref _OutputPointMode, value); }
  358. }
  359. private int _OutputPointCountMax=100;
  360. /// <summary>
  361. /// 每次发送给机器人的点数最大值
  362. /// </summary>
  363. public int OutputPointCountMax
  364. {
  365. get { return _OutputPointCountMax; }
  366. set { SetProperty(ref _OutputPointCountMax, value); }
  367. }
  368. private bool _IsExcludeNearPoint;
  369. /// <summary>
  370. /// 是否剔除本次识别到的物料与上一次识别到的物料位置过近的点
  371. /// </summary>
  372. public bool IsExcludeNearPoint
  373. {
  374. get { return _IsExcludeNearPoint; }
  375. set { SetProperty(ref _IsExcludeNearPoint, value); }
  376. }
  377. private double _ExcludeNearPointThreshol=1;
  378. /// <summary>
  379. /// 物料位置过近阈值
  380. /// </summary>
  381. public double ExcludeNearPointThreshol
  382. {
  383. get { return _ExcludeNearPointThreshol; }
  384. set { SetProperty(ref _ExcludeNearPointThreshol, value); }
  385. }
  386. private bool _IsSaveImage;
  387. /// <summary>
  388. /// 保存图像
  389. /// </summary>
  390. public bool IsSaveImage
  391. {
  392. get { return _IsSaveImage; }
  393. set { SetProperty(ref _IsSaveImage, value); }
  394. }
  395. private ProcedureSaveImageModel _SaveImageModel;
  396. /// <summary>
  397. /// 存图模式
  398. /// </summary>
  399. public ProcedureSaveImageModel SaveImageModel
  400. {
  401. get { return _SaveImageModel; }
  402. set { SetProperty(ref _SaveImageModel, value); }
  403. }
  404. private ProcedureSaveImagePathModel _SaveImagePathModel;
  405. /// <summary>
  406. /// 存图路径模式
  407. /// </summary>
  408. public ProcedureSaveImagePathModel SaveImagePathModel
  409. {
  410. get { return _SaveImagePathModel; }
  411. set { SetProperty(ref _SaveImagePathModel, value); }
  412. }
  413. private string _SavePath;
  414. /// <summary>
  415. /// 存图路径
  416. /// </summary>
  417. public string SavePath
  418. {
  419. get { return _SavePath; }
  420. set { SetProperty(ref _SavePath, value); }
  421. }
  422. //用户定义的图片文件名格式,例如:{ProductSN}_Daisy_KB Screw _01 _{CameraName}-Locate_{ShotCount}_WhiteRingLight_{Result}_{DateTime:yyyy-MM-dd_HH-mm-ss}.png
  423. private string _ImageFileNameFormat;
  424. /// <summary>
  425. /// 用户定义的图片文件名格式,例如:{ProductSN}_Daisy_KB Screw _01 _{CameraName}-Locate_{ShotCount}_WhiteRingLight_{Result}_{DateTime:yyyy-MM-dd_HH-mm-ss}.png
  426. /// </summary>
  427. public string ImageFileNameFormat
  428. {
  429. get { return _ImageFileNameFormat; }
  430. set { SetProperty(ref _ImageFileNameFormat, value); }
  431. }
  432. private bool _IsCompress;
  433. /// <summary>
  434. /// 是否压缩图片
  435. /// </summary>
  436. public bool IsCompress
  437. {
  438. get { return _IsCompress; }
  439. set { SetProperty(ref _IsCompress, value); }
  440. }
  441. private FeederFrequencyModel _FeederFindFrequency;
  442. /// <summary>
  443. /// Feeder自动寻频配置
  444. /// </summary>
  445. public FeederFrequencyModel FeederFindFrequency
  446. {
  447. get { return _FeederFindFrequency; }
  448. set { SetProperty(ref _FeederFindFrequency, value); }
  449. }
  450. private ObservableCollection<ProcedureUserDefineParam> _UserDefineParameters;
  451. /// <summary>
  452. /// 用户自定义参数
  453. /// </summary>
  454. public ObservableCollection<ProcedureUserDefineParam> UserDefineParameters
  455. {
  456. get { return _UserDefineParameters; }
  457. set { SetProperty(ref _UserDefineParameters, value); }
  458. }
  459. private bool _IsControlLightChannels;
  460. /// <summary>
  461. /// 是否控制光源通道亮灭
  462. /// </summary>
  463. public bool IsControlLightChannels
  464. {
  465. get { return _IsControlLightChannels; }
  466. set { SetProperty(ref _IsControlLightChannels, value); }
  467. }
  468. private ObservableCollection<ChannelConfig> _LightChannels;
  469. /// <summary>
  470. /// 光源通道配置集合。每个流程可配置多个光源通道及其默认亮度。
  471. /// </summary>
  472. public ObservableCollection<ChannelConfig> LightChannels
  473. {
  474. get { return _LightChannels; }
  475. set { SetProperty(ref _LightChannels, value); }
  476. }
  477. #region 运行时的一些临时记忆
  478. /// <summary>
  479. /// 最后一次的Blob面积值
  480. /// </summary>
  481. [JsonIgnore]
  482. public double LastBlobArea { get; set; } = 0;
  483. /// <summary>
  484. /// 最后一次运行的点数据
  485. /// </summary>
  486. [JsonIgnore]
  487. public List<double[]> LastRunPoints { get; set; } = new List<double[]>();
  488. #endregion
  489. public ProcedureModel()
  490. {
  491. Id = Guid.NewGuid();
  492. ProcedureOutputs = new ObservableCollection<ProcedureOutput>();
  493. ToolInfo= new ObservableCollection<ToolInfo>();
  494. FeederFindFrequency= new FeederFrequencyModel();
  495. UserDefineParameters= new ObservableCollection<ProcedureUserDefineParam>();
  496. FeederWorks = new FeederWorks();
  497. FeederStockWorks= new FeederStockWorks();
  498. LightChannels = new ObservableCollection<ChannelConfig>();
  499. }
  500. public ProcedureModel(string name, string cameraName, Guid cameraId,int camerano)
  501. {
  502. Id = Guid.NewGuid();
  503. Name = name;
  504. CameraName = cameraName;
  505. CameraNo = camerano;
  506. CameraId = cameraId;
  507. ProcedureOutputs = new ObservableCollection<ProcedureOutput>();
  508. ToolInfo = new ObservableCollection<ToolInfo>();
  509. FeederFindFrequency = new FeederFrequencyModel();
  510. UserDefineParameters = new ObservableCollection<ProcedureUserDefineParam>();
  511. FeederWorks = new FeederWorks();
  512. FeederStockWorks = new FeederStockWorks();
  513. LightChannels = new ObservableCollection<ChannelConfig>();
  514. }
  515. public ProcedureModel Clone()
  516. {
  517. return new ProcedureModel
  518. {
  519. Id = this.Id,
  520. Name = this.Name,
  521. CameraName=this.CameraName,
  522. CameraNo=this.CameraNo,
  523. VisionModel = this.VisionModel,
  524. TriggerCommand=this.TriggerCommand,
  525. RobotId = this.RobotId,
  526. FeederId = this.FeederId,
  527. CameraId = this.CameraId,
  528. CalibrationId = this.CalibrationId,
  529. DisplayId = this.DisplayId,
  530. DisplayName = this.DisplayName,
  531. ProcedureOutputs = new ObservableCollection<ProcedureOutput>(this.ProcedureOutputs.Select(po => po.Copy())),
  532. FeederWorks = this.FeederWorks?.Copy(),
  533. FeederStockWorks = this.FeederStockWorks?.Copy(),
  534. MinArea = this.MinArea,
  535. LightValue = this.LightValue,
  536. ExposureTime = this.ExposureTime,
  537. Gain = this.Gain,
  538. // ToolBlock不克隆
  539. ToolInfo = new ObservableCollection<ToolInfo>(this.ToolInfo.Select(ti => ti.Copy())),
  540. WaitPhoto = this.WaitPhoto,
  541. WaitFeederStop = this.WaitFeederStop,
  542. VibrationModel = this.VibrationModel,
  543. FeederFailLimit = this.FeederFailLimit,
  544. OutputPointCountMax = this.OutputPointCountMax,
  545. IsSaveImage = this.IsSaveImage,
  546. SaveImageModel = this.SaveImageModel,
  547. SaveImagePathModel = this.SaveImagePathModel,
  548. SavePath = this.SavePath,
  549. ImageFileNameFormat = this.ImageFileNameFormat,
  550. IsCompress = this.IsCompress,
  551. FeederFindFrequency = this.FeederFindFrequency?.Copy(),
  552. IsExcludeNearPoint=this.IsExcludeNearPoint,
  553. ExcludeNearPointThreshol = this.ExcludeNearPointThreshol,
  554. OutputPointMode=this.OutputPointMode,
  555. OutputSeparator=this.OutputSeparator,
  556. UserDefineParameters = new ObservableCollection<ProcedureUserDefineParam>(this.UserDefineParameters.Select(udp => udp.Copy())),
  557. LightChannels = this.LightChannels == null ? new ObservableCollection<ChannelConfig>() : new ObservableCollection<ChannelConfig>(this.LightChannels.Select(ch => new ChannelConfig
  558. {
  559. Name = ch.Name,
  560. Description = ch.Description,
  561. LocalIndex = ch.LocalIndex,
  562. GlobalIndex = ch.GlobalIndex,
  563. DefaultBrightness = ch.DefaultBrightness
  564. })),
  565. };
  566. }
  567. }
  568. }