领胜LDS 键盘AOI检测项目
wells
2020-07-12 5bf1b91009a182188d6d2245aa71653801eea60b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
using Bro.Common.Helper;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Bro.Common.Helper.EnumHelper;
 
namespace Bro.Common.Model
{
    /// <summary>
    /// 轴配置
    /// </summary>
    public class AxisSetting : IComplexDisplay
    {
        [Category("轴配置")]
        [DisplayName("轴号索引")]
        [Description("AxisIndex:轴号索引")]
        public int AxisIndex { get; set; }
 
        [Category("轴配置")]
        [DisplayName("轴名称")]
        [Description("AxisName:轴名称")]
        public string AxisName { get; set; }
 
        [Category("轴配置")]
        [DisplayName("轴是否启用")]
        [Description("IsAxisEnabled:轴是否启用")]
        public bool IsAxisEnabled { get; set; } = false;
 
        [Category("换算配置")]
        [DisplayName("脉冲数换算比例")]
        [Description("脉冲数和其他计量单位的换算比例,例如设置为1000,表示1000个脉冲等于1uint")]
        public int AxisRatio { get; set; } = 1;
 
        //[Category("速度配置")]
        //[DisplayName("默认速度参数")]
        //[Description("VelocityPara:默认速度参数")]
        //[TypeConverter(typeof(ComplexObjectConvert))]
        //[Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        //public VelocityPara VelocityPara { get; set; } = new VelocityPara();
 
        //[Category("回原点设置")]
        //[DisplayName("回原点模式")]
        //[Description("HomeMode:回原点模式。0:一般模式 1:极限限位模式 2:外部触发模式")]
        //public int HomeMode { get; set; } = 0;
 
        //[Category("回原点设置")]
        //[DisplayName("回原点方向")]
        //[Description("IsHomePositive:回原点方向。 true:正方向开始  false:负方向开始")]
        //public bool IsHomePositive { get; set; } = true;
 
        //[Category("回原点设置")]
        //[DisplayName("是否自动回原点")]
        //[Description("IsAutoGoHome:是否自动回原点。 true:是  false:否")]
        //public bool IsAutoGoHome { get; set; } = false;
 
        //[Category("超时设置")]
        //[DisplayName("回原点超时")]
        //[Description("TimeOutHome:回原点超时,单位毫秒")]
        //public int TimeOutHome { get; set; } = 30000;
 
        //[Category("超时设置")]
        //[DisplayName("运动超时")]
        //[Description("TimeOutMove:运动超时,单位毫秒")]
        //public int TimeOutMove { get; set; } = 10000;
 
        //[Category("开闭环设置")]
        //[DisplayName("是否使用Cmmd回馈")]
        //[Description("IsUseCmmdPosition:是否使用Cmmd回馈")]
        //public bool IsUseCmmdPosition { get; set; } = false;
 
        //[Category("开闭环设置")]
        //[DisplayName("是否使用板卡反馈停止信号")]
        //[Description("IsUseMDNStopSignal:是否使用板卡反馈停止信号")]
        //public bool IsUseMDNStopSignal { get; set; } = false;
 
        //[Category("开闭环设置")]
        //[DisplayName("是否启用报警")]
        //[Description("IsUseWarning:是否启用报警")]
        //public bool IsUseWarning { get; set; } = false;
 
        [Category("暂停配置")]
        [DisplayName("是否启用立即暂停")]
        [Description("IsImmediatePause:是否启用立即暂停")]
        public bool IsImmediatePause { get; set; } = false;
 
        //[Category("暂停配置")]
        //[DisplayName("轴位置处于区间内时适用的暂停操作")]
        //[Description("ImmediatePauseSections:当轴位置处于区间内时适用的暂停操作")]
        //[TypeConverter(typeof(CollectionCountConvert))]
        //[Editor(typeof(ComplexCollectionEditor<Section>), typeof(UITypeEditor))]
        //public List<Section> ImmediatePauseSections { get; set; } = new List<Section>();
 
        public string GetDisplayText()
        {
            return AxisIndex + "-" + AxisName + "-" + (IsAxisEnabled ? "启用" : "禁用");
        }
    }
 
    /// <summary>
    /// 位置对象
    /// </summary>
    public class Section : IComplexDisplay
    {
        [Category("暂停区间")]
        [DisplayName("起始位置")]
        [Description("StartPosition:起始位置")]
        public int StartPosition { get; set; }
 
        [Category("暂停区间")]
        [DisplayName("结束位置")]
        [Description("EndPosition:结束位置")]
        public int EndPosition { get; set; }
 
        public string GetDisplayText()
        {
            return $"{StartPosition}--{EndPosition}";
        }
    }
 
    /// <summary>
    /// 速度参数对象
    /// </summary>
    public class VelocityPara
    {
        [Category("速度配置")]
        [DisplayName("速度")]
        [Description("Velocity:速度,为0时表示不修改当前设置")]
        public double Velocity { get; set; } = 0;
 
        [Category("速度配置")]
        [DisplayName("加速度")]
        [Description("Acc:加速度,为0时表示不修改当前设置")]
        public double Acc { get; set; } = 0;
 
        [Category("速度配置")]
        [DisplayName("减速度")]
        [Description("减速度,为0时表示不修改当前设置")]
        public double Dec { get; set; } = 0;
    }
 
    /// <summary>
    /// 回原点参数对象
    /// </summary>
    public class GoHomePara
    {
        [Category("回原点参数")]
        [DisplayName("回原点方式")]
        [Description("HomeMode:回原点方式 (HOME_MODE_LIMIT = 10; HOME_MODE_LIMIT_HOME = 11; HOME_MODE_LIMIT_INDEX = 12; HOME_MODE_LIMIT_HOME_INDEX = 13;HOME_MODE_HOME = 20;HOME_MODE_HOME_INDEX = 22;HOME_MODE_INDEX = 30;")]
        public short HomeMode { get; set; } = 11;
 
        [Category("回原点参数")]
        [DisplayName("回原点方向")]
        [Description("HomeDir:1 正向,-1 负向")]
        public short HomeDir { get; set; } = 1;
 
        [Category("回原点参数")]
        [DisplayName("边缘")]
        [Description("edge:边缘")]
        public short Edge { get; set; } = 0;
 
        [Category("回原点参数")]
        [DisplayName("回原点最低速度")]
        [Description("LowVelocity:速度,为0时表示不修改当前设置")]
        public double LowVelocity { get; set; } = 50;
 
 
        [Category("回原点参数")]
        [DisplayName("回原点最高速度")]
        [Description("HighVelocity:速度,为0时表示不修改当前设置")]
        public double HighVelocity { get; set; } = 50;
 
        //[Category("回原点参数")]
        //[DisplayName("搜索距离")]
        //[Description("SearchHomeDistance:搜索距离")]
        //public int SearchHomeDistance { get; set; } = 9999999;
 
        [Category("回原点参数")]
        [DisplayName("偏移距离")]
        [Description("HomeOffset:偏移距离")]
        public int HomeOffset { get; set; } = 0;
 
        [Category("回原点参数")]
        [DisplayName("跳过步长")]
        [Description("EscapeStep:跳过步长")]
        public int EscapeStep { get; set; } = 1000;
 
    }
 
    /// <summary>
    /// 板卡运动状态对象
    /// </summary>
    public class AxisMovingStatus : IComplexDisplay
    {
        /// <summary>
        /// 轴索引
        /// </summary>
        public int AxisIndex { get; set; }
 
        /// <summary>
        /// 轴名称
        /// </summary>
        public string AxisName { get; set; }
 
        /// <summary>
        /// 当前位置
        /// </summary>
        public int CurPosition { get; set; }
 
        /// <summary>
        /// 目的地
        /// </summary>
        public int Destination { get; set; }
 
        /// <summary>
        /// 当前速度参数
        /// </summary>
        public double CurVelocity { get; set; }
 
        /// <summary>
        /// 规划速度参数
        /// </summary>
        public double PrfVelocity { get; set; }
 
        /// <summary>
        /// 轴状态
        /// </summary>
        public int AxisStatus { get; set; }
 
        public string GetDisplayText()
        {
            return $"轴{AxisIndex}:{AxisName}-当前状态:{AxisStatus}-当前位置:{CurPosition}-规划位置:{Destination}";
        }
    }
 
    /// <summary>
    /// 运动对象
    /// </summary>
    public class MovingOption : IComplexDisplay
    {
        [Category("运动配置")]
        [DisplayName("运动轴索引")]
        [Description("AxisIndex:运动轴索引")]
        [TypeConverter(typeof(AxisIndexConvert))]
        public string AxisIndexStr { get; set; } = "1";
 
        [Browsable(false)]
        [JsonIgnore]
        public int AxisIndex
        {
            get => int.Parse(AxisIndexStr);
            set => AxisIndexStr = value.ToString();
        }
 
        //private int axisIndex = 0;
        //[Category("运动配置")]
        //[DisplayName("运动轴索引")]
        //[Description("AxisIndex:运动轴索引")]
        //[TypeConverter(typeof(AxisIndexConvert))]
        //public int AxisIndex { get; set; }
        //{
        //    get => axisIndex;
        //    set
        //    {
        //        if (axisIndex != value)
        //        {
        //            axisIndex = value;
        //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AxisIndex"));
        //        }
        //        axisIndex = value;
        //    }
        //}
 
        //private MotionMode moveMode = MotionMode.Normal;
        [Category("运动配置")]
        [DisplayName("运动模式")]
        [Description("MoveMode:运动模式")]
        public MotionMode MoveMode { get; set; } = MotionMode.Normal;
        //{
        //    get => moveMode;
        //    set
        //    {
        //        if (moveMode != value)
        //        {
        //            moveMode = value;
        //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MoveMode"));
        //        }
 
        //        moveMode = value;
        //    }
        //}
 
        //private bool isAbsolute = true;
        [Category("运动配置")]
        [DisplayName("是否绝对运动")]
        [Description("IsAbsolute:是否绝对运动")]
        public bool IsAbsolute { get; set; } = true;
        //{
        //    get => isAbsolute;
        //    set
        //    {
        //        if (isAbsolute != value)
        //        {
        //            isAbsolute = value;
        //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsAbsolute"));
        //        }
 
        //        isAbsolute = value;
        //    }
        //}
 
        //private int destination = 0;
        [Category("运动配置")]
        [DisplayName("目的地")]
        [Description("Destination:目的地")]
        public int Destination { get; set; }
        //{
        //    get => destination;
        //    set
        //    {
        //        if (destination != value)
        //        {
        //            destination = value;
        //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Destination"));
        //        }
 
        //        destination = value;
        //    }
        //}
 
        //private VelocityPara velocityPara = new VelocityPara();
        [Category("运动配置")]
        [DisplayName("速度参数")]
        [Description("VelocityPara:速度参数")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public VelocityPara VelocityPara { get; set; } = new VelocityPara();
        //{
        //    get => velocityPara;
        //    set
        //    {
        //        velocityPara = value;
        //        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("VelocityPara"));
        //    }
        //}
 
        //private GoHomePara goHomePara = new GoHomePara();
        [Category("运动配置")]
        [DisplayName("回原点参数")]
        [Description("GoHomePara:速度参数")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public GoHomePara GoHomePara { get; set; } = new GoHomePara();
        //{
        //    get => goHomePara;
        //    set
        //    {
        //        goHomePara = value;
        //        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GoHomePara"));
        //    }
        //}
 
        [Category("板卡运动配置")]
        [Description("超时设置,单位:ms")]
        [DisplayName("运动超时")]
        public int MovingTimeout { get; set; } = 0;
 
        internal List<AxisSetting> _axisSettingList = new List<AxisSetting>();
 
        public void SetAxisSetting(List<AxisSetting> settings)
        {
            if (settings != null)
                _axisSettingList = settings;
        }
 
        public string GetDisplayText()
        {
            string axisName = AxisIndexStr;
            var axisSet = _axisSettingList.FirstOrDefault(a => a.AxisIndex == AxisIndex);
            if (axisSet != null)
            {
                axisName += ("-" + axisSet.AxisName);
            }
            return axisName + "," + MoveMode.ToString() + "," + (IsAbsolute ? "Abs" : "Rel") + "," + Destination;
        }
        //public event PropertyChangedEventHandler PropertyChanged;
    }
 
    public class AxisIndexConvert : ComboBoxItemTypeConvert
    {
        public override Hashtable GetConvertHash(ITypeDescriptorContext context)
        {
            Hashtable table = new Hashtable();
            if (context.Instance is MovingOption op)
            {
                op._axisSettingList.ForEach(a =>
                {
                    table[a.AxisIndex.ToString()] = a.AxisName;
                });
            }
 
            return table;
        }
 
        //public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        //{
        //    bool flag = base.CanConvertFrom(context, sourceType);
        //    return flag;
        //}
 
        //public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        //{
        //    return base.CanConvertTo(context, destinationType);
        //}
 
        //public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object v)
        //{
        //    //if (string.IsNullOrWhiteSpace(v.ToString()))
        //    //{
        //    //    return 0;
        //    //}
 
        //    return base.ConvertFrom(context, culture, Convert.ToInt32(v));
        //}
 
        //public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object v, Type destinationType)
        //{
        //    return base.ConvertTo(context, culture, v, destinationType);
        //}
    }
 
    //public class AxisIndexConvert : TypeConverter
    //{
    //    Dictionary<int, string> _indexNameDict = new Dictionary<int, string>();
 
    //    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    //    {
    //        return true;
    //    }
 
    //    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    //    {
    //        MovingOption mo = context.Instance as MovingOption;
 
    //        _indexNameDict = mo._axisSettingList.ToDictionary(a => a.AxisIndex, a => a.AxisIndex + "-" + a.AxisName);
 
    //        return new StandardValuesCollection(_indexNameDict.Keys);
    //    }
 
    //    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    //    {
    //        if (sourceType == typeof(string))
    //        {
    //            return true;
    //        }
    //        return base.CanConvertFrom(context, sourceType);
    //    }
 
    //    public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v)
    //    {
    //        if (v is string)
    //        {
    //            foreach (var indexName in _indexNameDict)
    //            {
    //                if (indexName.Value == v.ToString())
    //                {
    //                    return indexName.Key;
    //                }
    //            }
    //            return Convert.ToInt32(v);
    //        }
    //        return base.ConvertFrom(context, culture, v);
    //    }
 
    //    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v, Type destinationType)
    //    {
    //        if (destinationType == typeof(string))
    //        {
    //            if (_indexNameDict.ContainsKey(Convert.ToInt32(v)))
    //            {
    //                return _indexNameDict[Convert.ToInt32(v)];
    //            }
    //        }
    //        return base.ConvertTo(context, culture, v, destinationType);
    //    }
 
    //    public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
    //    {
    //        return false;
    //    }
    //}
 
    public class AxisConflictSet : IComplexDisplay
    {
        [Category("1.轴冲突条件")]
        [Description("轴冲突条件,满足全部条件时轴运动需要检查冲突")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<AxisLimit>), typeof(UITypeEditor))]
        public List<AxisLimit> AxisOptions { get; set; } = new List<AxisLimit>();
 
        [Category("1.轴冲突条件")]
        [Description("IO冲突条件,满足全部条件时轴运动需要检查冲突")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<IOLimit>), typeof(UITypeEditor))]
        public List<IOLimit> IOOptions { get; set; } = new List<IOLimit>();
 
        [Category("2.轴冲突限制")]
        [Description("轴冲突限制,轴运动允许区间")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<AxisLimit>), typeof(UITypeEditor))]
        public List<AxisLimit> AxisLimits { get; set; } = new List<AxisLimit>();
 
        [Category("2.轴冲突限制")]
        [Description("IO允许条件,允许输出的IO")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<IOLimit>), typeof(UITypeEditor))]
        public List<IOLimit> IOOutputs { get; set; } = new List<IOLimit>();
 
        [Category("3.轴冲突启用")]
        [Description("true:启用轴冲突限制 false:不启用轴冲突限制")]
        public bool IsEnabled { get; set; } = true;
 
        public string GetDisplayText()
        {
            string optionStr = "Options:" + String.Join(";", AxisOptions.Select(a => a.GetDisplayText()));
            string limitStr = "Limits:" + String.Join(";", AxisLimits.Select(a => a.GetDisplayText()));
 
            return optionStr + "|" + limitStr;
        }
    }
 
    public class AxisLimit : IComplexDisplay
    {
        [Category("1.轴号")]
        [Description("1.轴号")]
        public int AxisIndex { get; set; }
 
        [Category("2.轴最小限制")]
        [Description("2.轴最小限制")]
        public int LimitMin { get; set; }
 
        [Category("3.轴最大限制")]
        [Description("3.轴最大限制")]
        public int LimitMax { get; set; }
 
        private int currentPosition = 0;
        [Browsable(false)]
        [JsonIgnore]
        public int CurrentPosition
        {
            get => currentPosition;
            set
            {
                if (currentPosition != value)
                {
                    if (value >= LimitMin && value <= LimitMax)
                    {
                        IsInLimit = true;
                    }
                    else
                    {
                        IsInLimit = false;
                    }
                }
 
                currentPosition = value;
            }
        }
 
        [Browsable(false)]
        [JsonIgnore]
        public bool IsInLimit { get; set; }
 
        public string GetDisplayText()
        {
            return String.Format("Index:{0},{1}->{2}", AxisIndex, LimitMin, LimitMax);
        }
    }
 
    public class IOLimit : IComplexDisplay
    {
        [Category("1.IO限制")]
        [Description("IO索引")]
        public int IOIndex { get; set; }
 
        [Category("1.IO限制")]
        [Description("IO限制值。输入判断时该值作为启用判断值,输出判断时该值作为允许输出值")]
        public bool IOSignal { get; set; }
 
        public string GetDisplayText()
        {
            return IOIndex + "--" + IOSignal.ToString();
        }
    }
 
    public class AxisMovingStay
    {
        public int Position { get; set; }
 
        public int Velocity { get; set; }
 
        public AutoResetEvent MoveHandle { get; set; } = new AutoResetEvent(false);
 
        public AutoResetEvent MoveSendHandle { get; set; } = new AutoResetEvent(false);
    }
}