천호석
2022-06-17 4de9ea98e13449174aa2cd09c8351fc0e978f44a
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
using MMCE_Test;
using System;
 
namespace SHARP_CLAS_UI
{
    public class Axis : Slave
    {
        #region Enum
        #endregion
 
        #region Property
        /// <summary>
        /// Axis Status 값
        /// </summary>
        public uint AxisStatus;
 
        /// <summary>
        /// Axis State 중 하나로 축의 Error상태로 모션 동작이 불가능한 상태
        /// </summary>
        public bool ErrorStop { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcErrorStop) > 0); } }
 
        /// <summary>
        /// Axis State 중 하나로 축의 Amp Off 상태로 모션 동작이 불가능한 상태
        /// </summary>
        public bool Disabled { get {return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcDisabled) > 0); } }
 
        /// <summary>
        /// Axis State 중 하나로 MC_Stop에 의해 감속정지 중 또는 감속정지는 완료 되었지만 MC_Stop의 Execute가 유지되어 있는 상태로 모션 동작이 불가능한 상태
        /// </summary>
        public bool Stopping { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcStopping) > 0); } }
 
        /// <summary>
        /// Axis State 중 하나로 축의 Amp On 상태로 모션 동작이 가능한 준비 상태
        /// </summary>
        public bool StandStill { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcStandStill) > 0); } }
 
        /// <summary>
        /// Axis State 중 하나로 MC_MoveAbsoulte, MC_MoveRelative, MC_Halt 등에 의해 단축 모션 중인 상태
        /// </summary>
        public bool DiscreteMotion { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcDiscreteMotion) > 0); } }
 
        /// <summary>
        /// Axis State 중 하나로 MC_MoveVelocity에 의해 지속적인 모션 중인 상태
        /// </summary>
        public bool ContinuousMotion { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcContinuousMotion) > 0); } }
 
        /// <summary>
        /// Axis State 중 하나로 MC_GearIn 또는 GroupMotion에 의한 모션 상태
        /// </summary>
        public bool SynchroMotion { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcSynchroMotion) > 0); } }
 
        /// <summary>
        /// Axis State 중 하나로 축이 MC_Home에 의해 원점복귀 중인 상태
        /// </summary>
        public bool Homing { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcHoming) > 0); } }
 
        /// <summary>
        /// Software Position Positive Limit Value를 벗어나면 On으로 변경
        /// </summary>
        public bool Reserved_as_8 { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcReserved_as_8) > 0); } }
 
        /// <summary>
        /// Software Position Negative Limit Value를 벗어나면 On으로 변경
        /// </summary>
        public bool Reserved_as_9 { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcReserved_as_9) > 0); } }
 
        /// <summary>
        /// 모션이 등속동작 중인 상태
        /// </summary>
        public bool ConstantVelocity { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcConstantVelocity) > 0); } }
 
        /// <summary>
        /// 모션이 가속동작 중인 상태
        /// </summary>
        public bool Accelerating { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcAccelerating) > 0); } }
 
        /// <summary>
        /// 모션이 감속동작 중인 상태
        /// </summary>
        public bool Decelerating { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcDecelerating) > 0); } }
 
        /// <summary>
        /// 모션이 정방향으로 동작 중인 상태(모션이 정지 중일 때 Default로 동작)
        /// </summary>
        public bool DirectionPositive { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcDirectionPositive) > 0); } }
 
        /// <summary>
        /// 모션이 역방향으로 동작 중인 상태
        /// </summary>
        public bool DirectionNegative { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcDirectionNegative) > 0); } }
 
        /// <summary>
        /// Negative Hardware Limit Switch의 상태 0: OFF, 1: ON
        /// </summary>
        public bool LimitSwitchNeg { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcLimitSwitchNeg) > 0); } }
 
        /// <summary>
        /// Positive Hardware Limit Switch의 상태0: OFF, 1: ON
        /// </summary>
        public bool LimitSwitchPos { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcLimitSwitchPos) > 0); } }
 
        /// <summary>
        /// Home Switch의 상태 0: OFF, 1: ON
        /// </summary>
        public bool HomeAbsSwitch { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcHomeAbsSwitch) > 0); } }
 
        /// <summary>
        /// Positive Hardware Limit Switch가Active 되었을 때 On으로 변경(해당 Switch가 Off되었다고 해서 Off가 해제 되는 것은 아님)
        /// </summary>
        public bool LimitSwitchPosEvent { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcLimitSwitchPosEvent) > 0); } }
 
        /// <summary>
        /// Negative Hardware Limit Switch가Active 되었을 때 On으로 변경(해당 Switch가 Off되었다고 해서 Off가 되는 것은 아님)
        /// </summary>
        public bool LimitSwitchNegEvent { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcLimitSwitchNegEvent) > 0); } }
 
        /// <summary>
        /// 해당 축에 링크된 Slave Drive가 Fault상태(Slave Statusword bit 3)
        /// </summary>
        public bool DriveFault { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcDriveFault) > 0); } }
 
        /// <summary>
        /// 해당 축에 설정된 SensorStop에 의해 모션이 정지된 상태
        /// </summary>
        public bool SensorStop { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcSensorStop) > 0); } }
 
        /// <summary>
        /// AmpOn이 가능한 상태
        /// </summary>
        public bool ReadyForPowerOn { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcReadyForPowerOn) > 0); } }
 
        /// <summary>
        /// AmpOn이 정상적으로 완료된 상태
        /// </summary>
        public bool PowerOn { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcPowerOn) > 0); } }
 
        /// <summary>
        /// MC_Home에 의해 원점복귀가 완료된 상태
        /// </summary>
        public bool IsHomed { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcIsHomed) > 0); } }
 
        /// <summary>
        /// 모션 동작에는 문제가 없지만 축의 Warning상태
        /// </summary>
        public bool AxisWarning { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcAxisWarning) > 0); } }
 
        /// <summary>
        /// 모션 동작이 완료된 Inposition 상태
        /// </summary>
        public bool MotionComplete { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcMotionComplete) > 0); } }
 
        /// <summary>
        /// MC_GearIn에 의해 Gearing 동작 중인 상태
        /// </summary>
        public bool Gearing { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcGearing) > 0); } }
 
        /// <summary>
        /// 해당 축이 그룹에 속한 상태이며 해당 그룹이 Enable인 상태
        /// </summary>
        public bool GroupMotion { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcGroupMotion) > 0); } }
 
        /// <summary>
        /// 해당 축의 Buffer 1000개가 모두 사용된 상태
        /// </summary>
        public bool BufferFull { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcBufferFull) > 0); } }
 
        /// <summary>
        /// Reserved for Future Use
        /// </summary>
        public bool Reserved_as_30 { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcReserved_as_30) > 0); } }
 
        /// <summary>
        /// 해당 축에 링크된 Slave Drive의 Sensor data의 버그상태
        /// </summary>
        public bool Reserved_as_31 { get { return ((AxisStatus & (uint)NMCSDKLib.MC_AXISSTATUS.mcReserved_as_31) > 0); } }
 
 
        public ushort ErrorID { get; private set; }
 
 
        public ushort ErrorInfo0 { get; private set; }
 
 
        public ushort ErrorInfo1 { get; private set; }
 
        /// <summary>
        /// Current Position
        /// </summary>
        public double Position { get; private set; }
        
        /// <summary>
        /// Current Velocity
        /// </summary>
        public double Velocity { get; private set; }
 
        private bool Auto_Mode
        {
            get
            {
                return Board_Control.IO_manager.Get_Input(InputData.Safety_Mode_SW_Auto);
            }
        }
        #endregion
 
        #region Field
        private Sharp_Board_Control Board_Control;
 
        public Func<bool, bool> Check_Jog_Interlock;
        public Func<bool> Check_Move_Interlock;
        public Func<bool> Check_Home_Interlock;
 
        private double teach_velocity = 30;
        #endregion
 
        #region Construct
        public Axis(Sharp_Board_Control Board_Control, ushort Board_Id, ushort Device_Id)
            : base(Board_Id, Device_Id)
        {
            this.Board_Control = Board_Control;
        }
        #endregion
 
        #region Function
        /// <summary>
        /// Get Axis Status
        /// </summary>
        /// <returns></returns>
        public bool Get_Axis_Status()
        {
            try
            {
                uint uData = 0;
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_ReadAxisStatus(Board_Id, Device_Id, ref uData);
                
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    AxisStatus = uData;
                    return true;
                }
                else
                {
                    AxisStatus = 0;
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Axis Amp On
        /// </summary>
        /// <returns></returns>
        public bool Amp_On()
        {
            try
            {
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_Power(Board_Id, Device_Id, true);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Axis Amp Off
        /// </summary>
        /// <returns></returns>
        public bool Amp_Off()
        {
            try
            {
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_Power(Board_Id, Device_Id, false);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Axis MC Error Reset
        /// </summary>
        /// <returns></returns>
        public bool MC_Error_Reset()
        {
            try
            {
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_Reset(Board_Id, Device_Id);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Zog Move Negative
        /// </summary>
        /// <param name="Velocity">velocity</param>
        /// <param name="Accel">accelator</param>
        /// <param name="Decel">deccelator</param>
        /// <param name="Jerk">jerk</param>
        /// <returns></returns>
        public bool Negative_Zog(double Velocity)
        {
            try
            {
                if (Check_Jog_Interlock != null && Check_Jog_Interlock(false))
                {
                    return false;
                }
 
                if (Velocity <= 0)
                {
                    Interlock_Manager.Add_Interlock_Msg($"{((MotorAxis)Device_Id).ToString()} can't minus jog", $"{((MotorAxis)Device_Id).ToString()}'s velocity is under 0");
                    return false;
                }
 
                if(!Auto_Mode)
                {
                    if(Velocity > teach_velocity)
                    {
                        Velocity = teach_velocity;
                    }
                }
 
                NMCSDKLib.MC_STATUS mc;
                double Accel = Velocity * 10;
                double Decel = Velocity * 10;
                double Jerk = Velocity * 100;
 
                mc = NMCSDKLib.MC_MoveVelocity(Board_Id, Device_Id, Velocity, Accel, Decel, Jerk, NMCSDKLib.MC_DIRECTION.mcNegativeDirection, NMCSDKLib.MC_BUFFER_MODE.mcAborting);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Zog Move Positive
        /// </summary>
        /// <param name="Velocity">velocity</param>
        /// <param name="Accel">accelator</param>
        /// <param name="Decel">deccelator</param>
        /// <param name="Jerk">jerk</param>
        /// <returns></returns>
        public bool Positive_Zog(double Velocity)
        {
            try
            {
                if(Check_Jog_Interlock != null && Check_Jog_Interlock(true))
                {
                    return false;
                }
 
                if(Velocity <= 0)
                {
                    Interlock_Manager.Add_Interlock_Msg($"{((MotorAxis)Device_Id).ToString()} can't plus jog", $"{((MotorAxis)Device_Id).ToString()}'s velocity is under 0");
                    return false;
                }
 
                if (!Auto_Mode)
                {
                    if (Velocity > teach_velocity)
                    {
                        Velocity = teach_velocity;
                    }
                }
 
                NMCSDKLib.MC_STATUS mc;
 
                double Accel = Velocity * 10;
                double Decel = Velocity * 10;
                double Jerk = Velocity * 100;
 
                mc = NMCSDKLib.MC_MoveVelocity(Board_Id, Device_Id, Velocity, Accel, Decel, Jerk, NMCSDKLib.MC_DIRECTION.mcPositiveDirection, NMCSDKLib.MC_BUFFER_MODE.mcAborting);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Home
        /// </summary>
        /// <returns></returns>
        public bool Home()
        {
            try
            {
                if(Check_Home_Interlock !=null && Check_Home_Interlock())
                {
                    return false;
                }
 
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_Home(Board_Id, Device_Id, 0, NMCSDKLib.MC_BUFFER_MODE.mcAborting);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Axis Move Stop
        /// </summary>
        /// <param name="Decel">deccelator</param>
        /// <param name="Jerk">jerk</param>
        /// <returns></returns>
        public bool Move_Stop(double Velocity = 300)
        {
            try
            { 
                if (Velocity <= 0)
                {
                    Velocity = 300;
                }
 
                NMCSDKLib.MC_STATUS mc;
                
                double Decel = Velocity * 10;
                double Jerk = Velocity * 100;
 
                mc = NMCSDKLib.MC_Halt(Board_Id, Device_Id, Decel, Jerk, NMCSDKLib.MC_BUFFER_MODE.mcAborting);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    return false;
                    //throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Move absololute
        /// </summary>
        /// <param name="Position">positiion</param>
        /// <param name="Velocity">velocity</param>
        /// <param name="Accel">accelator</param>
        /// <param name="Decel">deccelator</param>
        /// <param name="Jerk">jerk</param>
        /// <returns></returns>
        public bool Move_Absolute_Pos(double Position, double Velocity)
        {
            try
            {
                if (Check_Move_Interlock != null && Check_Move_Interlock())
                {
                    return false;
                }
 
                if (Velocity <= 0)
                {
                    Interlock_Manager.Add_Interlock_Msg($"{((MotorAxis)Device_Id).ToString()} can't absolute move", $"{((MotorAxis)Device_Id).ToString()}'s velocity is under 0");
                    return false;
                }
 
                if (!Auto_Mode)
                {
                    if (Velocity > teach_velocity)
                    {
                        Velocity = teach_velocity;
                    }
                }
 
                NMCSDKLib.MC_STATUS mc;
 
                double Accel = Velocity * 10;
                double Decel = Velocity * 10;
                double Jerk = Velocity * 100;
 
                mc = NMCSDKLib.MC_MoveAbsolute(Board_Id, Device_Id, Position, Velocity, Accel, Decel, Jerk, NMCSDKLib.MC_DIRECTION.mcPositiveDirection, NMCSDKLib.MC_BUFFER_MODE.mcAborting);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Move Relative
        /// </summary>
        /// <param name="Distance">distance</param>
        /// <param name="Velocity">velocity</param>
        /// <param name="Accel">accelator</param>
        /// <param name="Decel">deccelator</param>
        /// <param name="Jerk">jerk</param>
        /// <returns></returns>
        public bool Move_Relative_Pos(double Distance, double Velocity)
        {
            try
            {
                if (Check_Move_Interlock != null && Check_Move_Interlock())
                {
                    return false;
                }
 
                if (Velocity <= 0)
                {
                    Interlock_Manager.Add_Interlock_Msg($"{((MotorAxis)Device_Id).ToString()} can't relative move", $"{((MotorAxis)Device_Id).ToString()}'s velocity is under 0");
                    return false;
                }
 
                if (!Auto_Mode)
                {
                    if (Velocity > teach_velocity)
                    {
                        Velocity = teach_velocity;
                    }
                }
                double Accel = Velocity * 10;
                double Decel = Velocity * 10;
                double Jerk = Velocity * 100;
 
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_MoveRelative(Board_Id, Device_Id, Distance, Velocity, Accel, Decel, Jerk, NMCSDKLib.MC_BUFFER_MODE.mcAborting);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Get actual position
        /// </summary>
        /// <param name="position">position</param>
        /// <returns></returns>
        public bool Get_Actual_Position()
        {
            try
            {
                double dData = 0;
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_ReadCommandedPosition(Board_Id, Device_Id, ref dData);
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    Position = double.Parse(dData.ToString("F3"));
                    return true;
                }
                else
                {
                    Position = 0;
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Get actual velocity
        /// </summary>
        /// <param name="Velocity">velocity</param>
        /// <returns></returns>
        public bool Get_Actual_Velocity()
        {
            try
            {
                double dData = 0;
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_ReadCommandedVelocity(Board_Id, Device_Id, ref dData);
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    Velocity = double.Parse(dData.ToString("F3"));
                    return true;
                }
                else
                {
                    Velocity = 0;
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        public bool Position_Clear()
        {
            try
            {
                NMCSDKLib.MC_STATUS mc;
                mc = NMCSDKLib.MC_SetPosition(Board_Id, Device_Id, 0, false, NMCSDKLib.MC_EXECUTION_MODE.mcImmediately);
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    return true;
                }
                else
                {
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        /// <summary>
        /// Get Error Info
        /// </summary>
        /// <returns></returns>
        public bool ErrorInfo()
        {
            try
            {
                NMCSDKLib.MC_STATUS mc;
                ushort usErrorId = 0;
                ushort usErrorInfo0 = 0;
                ushort usErrorInfo1 = 0;
 
                mc = NMCSDKLib.MC_ReadAxisError(Board_Id, Device_Id, ref usErrorId, ref usErrorInfo0, ref usErrorInfo1);
 
                if (mc == NMCSDKLib.MC_STATUS.MC_OK)
                {
                    ErrorID = usErrorId;
                    ErrorInfo0 = usErrorInfo0;
                    ErrorInfo1 = usErrorInfo1;
                    return true;
                }
                else
                {
                    ErrorID = 0;
                    ErrorInfo0 = 0;
                    ErrorInfo1 = 0;
                    throw new Exception($"Board_Id : {Board_Id}, Device_Id : {Device_Id}, " + mc.ToString());
                }
            }
            catch (Exception ex)
            {
                //WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
                return false;
            }
        }
 
        public bool Is_Inposition(double position, double offset)
        {
            if (position - offset <= this.Position && this.Position <= position + offset)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
    }
}