-
Notifications
You must be signed in to change notification settings - Fork 2
/
Epos4.m
969 lines (882 loc) · 33.5 KB
/
Epos4.m
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
classdef Epos4 < handle
% EPOS4 class, use this class for communication with Maxon EPOS4
% motor controller
%
% This class has the methods
%
% EPOS4 (nodeID, portNameSuffix), Constructor
%
% use it as: Motor1 = Epos4(1,0);
% for creating a new object Motor1 wich will deal with EPOS4 Node 1 and USB0.
%
% delete, Destructor:
%
% use it as: delete(Motor1);
% when you finish with EPOS4 node.
%
% ActualPosition
% return actual encoder position.
% Example:
% qc = Motor1.ActualPosition;
%
% ActualVelocity
% return actual motor velocity.
% Example:
% rpm = Motor1.ActualVelocity;
%
% ActualCurrent
% return actual current throght motor
% Example:
% i = Motor1.ActualCurrent;
%
% IsInErrorState
% return 0 if not error, or 1 if error
% Example:
% errorstate = Motor1.IsInErrorState;
%
% ClearErrorState
% clear actual error in EPOS4
% Example:
% if (Motor1.IsInErrorState)
% Motor1.ClearErrorState;
% end
%
% EnableNode
% power the motor
% Example:
% Motor1.EnableNode;
%
% DisableNode
% Unpower the motor
% Example:
% Motor1.DisableNode;
%
% SetOperationMode
% Change the operation mode for epos4
% Example:
% Motor1.SetOperationMode(OperationModes.CurrentMode);
% tip: use the tab key for the list of operation modes in class.
% >> OperationModes.<tab>
% for further help type:
% >> help Epos4.SetOperationMode
%
% GetOperationModes
% return the actual Operation Mode in Epos4
% Example
% OpMode = Motor1.GetOperationMode;
%
% SetHommingMethod
% for changing the way as the motor home
% Example
% Motor1.SetHommingMethod( HommingMethods.ActualPosition )
% for further help type:
% >> help Epos4.SetHommingMethod
%
% GetHommingMethod
% for returning the actual home method
% Example
% Motor1.GetHommingMethod
%
% DoHomming
% for performing the home procedure
% Example
% Motor1.DoHomming
%
% MotionInPosition
% for moving the motor in Position or Profile Position Mode
% Example:
% Motor1.MotionInPosition( 132000 )
% for further help type:
% >> help Epos4.MotionInPosition
%
% MotionInVelocity
% for moving the motor in Velocity or Profile Velocity Mode
% Example:
% Motor1.MotionInVelocity( 2000 )
% for further help type:
% >> help Epos4.MotionInVelocity
%
% MotionWithCurrent
% for moving the motor in Current Mode
% Example:
% Motor1.MotionWithCurrent( 2000 )
%
% Stop
% for stopping the motor
% Example:
% Motor1.Stop
%
% E. Yime, 2015
%
properties (SetAccess = immutable )
NodeID = 0;
Handle = 0;
end
properties (SetAccess = private )
OpMode = 0;
Enable = 0;
HomeMethod = 0;
end
methods
function res = Epos4(node, usbId)
% constructor
% use it as: Motor1 = Epos4(1, 0);
%
% E. Yime, 2015
%
res.NodeID = node;
res.Handle = OpenCommunication(usbId);
res.OpMode = res.GetOperationMode;
res.Enable = res.IsEnable;
res.GetHommingMethod;
end
function delete(obj)
% destructor
% use it as: delete(Motor1)
%
% E. Yime, 2015
%
obj.ClearErrorState;
obj.DisableNode;
CloseCommunication(obj.Handle);
end
function res = GetHandle(obj)
% This function is only for debugging purpose
% use it as: Motor1.GetHandle
%
% E. Yime, 2015
%
res = obj.Handle;
end
function res = IsInErrorState(obj)
% This function is for obtaining the error state in a Epos4
% node
%
% use it as:
% if (Motor1.IsInErrorState)
% Motor1.ClearErrorState
% ....
% end
%
% E. Yime, 2015
%
res = (bitand(obj.GetStatusWord, 8) == 8);
end
function res = ExplainErrors(obj)
% This function is for listing the actual errors in a Epos4
% node
%
% use it as:
% >> Motor1.ExplainErrors;
%
% E. Yime, 2015
%
Errors = {
0, 'No Error'; ...
4096, 'Generic Error'; ...
8976, 'Overcurrent Error';
12816, 'Overvoltage Error'; ...
12832, 'Undervoltage Error'; ...
16912, 'Overtemperature Error'; ...
20755, 'Logic Supply Voltage Too Low Error'; ...
20756, 'Supply Voltage Output Stage Too Low Error'; ...
24832, 'Internal Software Error'; ...
25376, 'Software Parameter Error'; ...
29472, 'Position Sensor Error'; ...
33040, 'CAN Overrun Error (Objects lost)'; ...
33041, 'CAN Overrun Error'; ...
33056, 'CAN Passive Mode Error'; ...
33072, 'CAN Life Guarding Error or Heartbeat Error'; ...
33104, 'CAN Transmit COB-ID Collision Error'; ...
33277, 'CAN Bus Off Error'; ...
33278, 'CAN Rx Queue Overflow Error'; ...
33279, 'CAN Tx Queue Overflow Error'; ...
33296, 'CAN PDO Length Error'; ...
34321, 'Following Error'; ...
65281, 'Hall Sensor Error'; ...
65282, 'Index Processing Error'; ...
68283, 'Encoder Resolution Error'; ...
65284, 'Hall Sensor not found Error'; ...
65285, 'Negative Limit Switch Error'; ...
65287, 'Positive Limit Switch Error'; ...
65288, 'Hall Angle Detection Error'; ...
65289, 'Software Position Limit Error'; ...
65290, 'Position Sensor Breach Error'; ...
65291, 'System Overloaded Error'; ...
65292, 'Interpolated Position Mode Error'; ...
65293, 'Auto Tuning Identification Error'; ...
65295, 'Gear Scaling Factor Error'; ...
65296, 'Controller Gain Error'; ...
65297, 'Main Sensor Direction Error'; ...
65298, 'Auxiliary Sensor Direction Error' };
Index = 4099;
number = GetObject(obj.Handle, obj.NodeID, Index, 0, 1);
for i = 1:number
res = GetObject(obj.Handle, obj.NodeID, Index, number, 4);
for j = 1:size( Errors, 1)
if ( res == cell2mat(Errors(j,1)) )
disp( Errors(j, 2) );
end
end
end
end
function res = ClearErrorState(obj)
% This function is for clearing the error in a node
%
% use it as:
% if (Motor1.IsInErrorState)
% Motor1.ClearErrorState
% ....
% end
%
% E. Yime, 2015
%
res = ClearErrorState(obj.Handle, obj.NodeID);
end
function res = ShowOperationMode(obj)
% This function is for detecting actual Operation Mode in
% Epos4 class
%
% use it as:
% >> Motor1.ShowOperationMode
%
% E. Yime, 2015
%
res = obj.OpMode;
end
function res = GetOperationMode(obj)
% This function is for receiving actual Operation Mode in a
% physical Epos4 Motor controller
%
% use it as:
% >> Motor1.GetOperationMode
%
% E. Yime, 2015
%
a = GetObject(obj.Handle, obj.NodeID, 24672, 0, 1);
switch a
case 6
res = OperationModes.HommingMode;
case 3
res = OperationModes.ProfileVelocityMode;
case 1
res = OperationModes.ProfilePositionMode;
case 255
res = OperationModes.PositionMode;
case 254
res = OperationModes.VelocityMode;
case 253
res = OperationModes.CurrentMode;
otherwise
res = OperationModes.UnimplementedMode;
end
end
function res = SetOperationMode(obj, mode, varargin)
% This function is for setting the actual Operation Mode in a Epos4 Motor controller
% you can use it in the following ways,
%
% >> Motor1.SetOperationMode( OperationModes.HommingMode )
%
% >> Motor1.SetOperationMode( OperationModes.ProfileVelocityMode )
%
% >> Motor1.SetOperationMode( OperationModes.ProfilePositionMode )
%
% >> Motor1.SetOperationMode( OperationModes.PositionMode )
%
% >> Motor1.SetOperationMode( OperationModes.VelocityMode )
%
% >> Motor1.SetOperationMode( OperationModes.CurrentMode )
%
% E. Yime, 2015
%
% Object to write
Index = 24672;
SubIndex = 0;
bytes = 1;
switch mode
case OperationModes.HommingMode
Values = 6;
case OperationModes.ProfileVelocityMode
Values = 3;
case OperationModes.ProfilePositionMode
Values = 1;
case OperationModes.PositionMode
Values = -1;
case OperationModes.VelocityMode
Values = -2;
case OperationModes.CurrentMode
Values = -3;
otherwise
error('invalid mode');
end
res = SetObject(obj.Handle, obj.NodeID, Index, SubIndex, Values, bytes);
obj.OpMode = mode;
end
function res = SetHommingMethod(obj, homming, varargin)
% This function if for performing a homming in a EPOS4 node
% you can use it in the following ways,
%
% >> Motor1.SetHommingMethod( HommingMethods.ActualPosition )
% The EPOS4 will set the actual position as the default zero
%
% >> Motor1.SetHommingMethod( HommingMethods.HomeSwitchNegSpeed )
% or
% >> Motor1.SetHommingMethod( HommingMethods.HomeSwitchNegSpeed, SpeedForZeroSearch, AccelerationForZeroSearch )
%
% >> Motor1.SetHommingMethod( HommingMethods.HomeSwitchNegSpeedIndex )
% or
% >> Motor1.SetHommingMethod( HommingMethods.HomeSwitchNegSpeedIndex, SpeedForZeroSearch, SpeedForIndexSearch, AccelerationForZeroSearch )
%
% >> Motor1.SetHommingMethod( HommingMethods.HomeSwitchPosSpeed )
% or
% >> Motor1.SetHommingMethod( HommingMethods.HomeSwitchPosSpeed, SpeedForZeroSearch, AccelerationForZeroSearch )
%
% >> Motor1.SetHommingMethod( HommingMethods.HomeSwitchPosSpeedIndex )
% or
% >> Motor1.SetHommingMethod( HommingMethods.HomeSwitchPosSpeedIndex, SpeedForZeroSearch, SpeedForIndexSearch, AccelerationForZeroSearch )
%
% >> Motor1.SetHommingMethod( HommingMethods.CurrentNegSpeed )
% or
% >> Motor1.SetHommingMethod( HommingMethods.CurrentNegSpeed, CurrentToZeroSearch )
%
% >> Motor1.SetHommingMethod( HommingMethods.CurrentNegSpeedIndex )
% or
% >> Motor1.SetHommingMethod( HommingMethods.CurrentNegSpeedIndex, CurrentToZeroSearch, SpeedForIndexSearch )
%
% >> Motor1.SetHommingMethod( HommingMethods.CurrentPosSpeed )
% or
% >> Motor1.SetHommingMethod( HommingMethods.CurrentPosSpeed, CurrentToZeroSearch )
%
% >> Motor1.SetHommingMethod( HommingMethods.CurrentPosSpeedIndex )
% or
% >> Motor1.SetHommingMethod( HommingMethods.CurrentPosSpeedIndex, CurrentToZeroSearch, SpeedForIndexSearch )
%
% E. Yime, 2015
%
% Initial values
Index = zeros(4);
SubIndex = zeros(4);
Bytes = zeros(4);
Values = zeros(4);
% First object
number = 1;
Index(1) = 24728;
SubIndex(1) = 0;
Bytes(1) = 1;
if (nargin > 5)
error('No more of 4 arguments allowed ')
end
switch (homming)
case HommingMethods.ActualPosition
Values(1) = 35;
if (nargin > 2)
error('No additional arguments allowed when homming to actual Position')
end
obj.HomeMethod = 1;
case HommingMethods.HomeSwitchNegSpeed
Values(1) = 27;
if (nargin > 4)
error('Only two aditional parameters allowed')
end
if (nargin > 2)
% Speed Zero
number = 2;
Index(2) = 24729;
SubIndex(2) = 1;
Values(2) = cell2mat(varargin(1));
Bytes(2) = 4;
end
if (nargin > 3)
% Accel
number = 3;
Index(3) = 24730;
SubIndex(3) = 0;
Values(3) = cell2mat(varargin(2));
Bytes(3) = 4;
end
obj.HomeMethod = 2;
case HommingMethods.HomeSwitchNegSpeedIndex
Values(1) = 11;
if (nargin > 2)
% Speed to Home
number = 2;
Index(2) = 24729;
SubIndex(2) = 1;
Values(2) = cell2mat(varargin(1));
Bytes(2) = 4;
end
if (nargin > 3)
% Speed to Index
number = 3;
Index(3) = 24729;
SubIndex(3) = 2;
Values(3) = cell2mat(varargin(2));
Bytes(3) = 4;
end
if (nargin > 4)
% Accel
number = 4;
Index(4) = 24730;
SubIndex(4) = 0;
Values(4) = cell2mat(varargin(3));
Bytes(4) = 4;
end
obj.HomeMethod = 3;
case HommingMethods.HomeSwitchPosSpeed
Values(1) = 23;
if (nargin > 4)
error('Only two aditional parameters allowed')
end
if (nargin > 2)
% Speed Zero
number = 2;
Index(2) = 24729;
SubIndex(2) = 1;
Values(2) = cell2mat(varargin(1));
Bytes(2) = 4;
end
if (nargin > 3)
% Accel
number = 3;
Index(3) = 24730;
SubIndex(3) = 0;
Values(3) = cell2mat(varargin(2));
Bytes(3) = 4;
end
obj.HomeMethod = 4;
case HommingMethods.HomeSwitchPosSpeedIndex
Values(1) = 7;
if (nargin > 2)
% Speed to Home
number = 2;
Index(2) = 24729;
SubIndex(2) = 1;
Values(2) = cell2mat(varargin(1));
Bytes(2) = 4;
end
if (nargin > 3)
% Speed to Index
number = 3;
Index(3) = 24729;
SubIndex(3) = 2;
Values(3) = cell2mat(varargin(2));
Bytes(3) = 4;
end
if (nargin > 4)
% Accel
number = 4;
Index(4) = 24730;
SubIndex(4) = 0;
Values(4) = cell2mat(varargin(3));
Bytes(4) = 4;
end
obj.HomeMethod = 5;
case HommingMethods.CurrentNegSpeed
Values(1) = -4;
if (nargin > 3)
error('Only Current Threshold allowed in Current Negative Speed')
end
if (nargin > 2)
% current threshold
number = 2;
Index(2) = 8320;
SubIndex(2) = 0;
Values(2) = cell2mat(varargin(1));
Bytes(2) = 2;
end
obj.HomeMethod = 6;
case HommingMethods.CurrentNegSpeedIndex
Values(1) = -2;
if (nargin > 4)
error('Only two additional values allowed')
end
if (nargin > 2)
% current threshold
number = 2;
Index(2) = 8320;
SubIndex(2) = 0;
Values(2) = cell2mat(varargin(1));
Bytes(2) = 2;
end
if (nargin > 3)
% Speed to Index
number = 3;
Index(3) = 24729;
SubIndex(3) = 2;
Values(3) = cell2mat(varargin(2));
Bytes(3) = 4;
end
obj.HomeMethod = 7;
case HommingMethods.CurrentPosSpeed
Values(1) = -3;
if (nargin > 3)
error('Only Current Threshold allowed in Current Positive Speed')
end
if (nargin > 2)
% current threshold
number = 2;
Index(2) = 8320;
SubIndex(2) = 0;
Values(2) = cell2mat(varargin(1));
Bytes(2) = 2;
end
obj.HomeMethod = 8;
case HommingMethods.CurrentPosSpeedIndex
Values(1) = -1;
if (nargin > 4)
error('Only two additional values allowed')
end
if (nargin > 2)
% current threshold
number = 2;
Index(2) = 8320;
SubIndex(2) = 0;
Values(2) = cell2mat(varargin(1));
Bytes(2) = 2;
end
if (nargin > 3)
% Speed to Index
number = 3;
Index(3) = 24729;
SubIndex(3) = 2;
Values(3) = cell2mat(varargin(2));
Bytes(3) = 4;
end
obj.HomeMethod = 9;
otherwise
error('Not Implemente Homming Method')
end
for i = 1:number
res = SetObject(obj.Handle, obj.NodeID, Index(i), SubIndex(i), Values(i), Bytes(i));
end
end
function res = GetHommingMethod(obj)
% This function is for getting the actual value of the homming method in a EPOS4
% controller
%
% use it as:
%
% >> Motor1.GetHommingMethod
%
% E. Yime, 2015
%
Index = 24728;
SubIndex = 0;
Size = 1;
a = GetObject(obj.Handle, obj.NodeID, Index, SubIndex, Size);
switch (a)
case 35
res = HommingMethods.ActualPosition;
obj.HomeMethod = 1;
case 27
res = HommingMethods.HomeSwitchNegSpeed;
obj.HomeMethod = 2;
case 23
res = HommingMethods.HomeSwitchPosSpeed;
obj.HomeMethod = 4;
case 11
res = HommingMethods.HomeSwitchNegSpeedIndex;
obj.HomeMethod = 3;
case 7
res = HommingMethods.HomeSwitchPosSpeedIndex;
obj.HomeMethod = 5;
case 255
res = HommingMethods.CurrentPosSpeedIndex;
obj.HomeMethod = 7;
case 254
res = HommingMethods.CurrentNegSpeedIndex;
obj.HomeMethod = 9;
case 253
res = HommingMethods.CurrentPosSpeed;
obj.HomeMethod = 6;
case 252
res = HommingMethods.CurrentNegSpeed;
obj.HomeMethod = 8;
otherwise
res = HommingMethods.NotImplemented;
obj.HomeMethod = 0;
end
end
function res = DoHomming(obj)
% This function is for Homming a motor connected to a EPOS4
% controller when the EPOS4 is in Homming
%
% use it as:
%
% >> Motor1.DoHomming
%
% E. Yime, 2015
%
if (obj.IsInErrorState)
obj.Enable = 0;
error('you can not do a Homming when the motors is in error state');
end
if ( obj.Enable == 0)
error('you can not do a Homming with a disabled motor');
end
if ( obj.OpMode ~= OperationModes.HommingMode )
error('you can not do a Homming when the motor is not in Homming Mode');
end
if (obj.HomeMethod == 0)
error('you must specify a valid Homming Method before performing a homming');
end
% change controlword to home the motor
res = FindHome(obj.Handle, obj.NodeID, obj.HomeMethod);
end
function res = IsEnable(obj)
% This function is for detecting if EPOS4 is enabled
%
% use it as:
% >> Motor1.IsEnable
%
% E. Yime, 2015
%
res = (bitand(obj.GetStatusWord, 4) == 4);
end
function res = EnableNode(obj)
% This function is for enabling a physical EPOS4 Motor Controller
%
% use it as:
% >> Motor1.EnableNode
%
% E. Yime, 2015
%
if (obj.IsInErrorState)
obj.Enable = 0;
error('you can not Enable a Motore when it is in error state');
end
obj.Enable = 1;
res = EnableNode(obj.Handle, obj.NodeID);
end
function res = DisableNode(obj)
% This function is for disabling a physical EPOS4 Motor Controller
%
% use it as:
% >> Motor1.DisableNode
%
% E. Yime, 2015
%
obj.Enable = 0;
res = DisableNode(obj.Handle, obj.NodeID);
end
function res = GetStatusWord(obj)
% This function is for getting the actual status word in a EPOS4
% object dictionary
%
% use it as:
% >> Motor1.GetStatusWord
%
% E. Yime, 2015
%
res = GetObject(obj.Handle, obj.NodeID, 24641, 0, 2);
end
function res = ExplainStatusWord(obj)
% This function is for obtaining an interpretation of the object
% status word in the object dictionary
%
% use it as:
% >> Motor1.ExplainStatusWord
%
% E. Yime, 2015
%
res = obj.GetStatusWord;
if (bitand(res,1) == 1)
disp('Node is Ready to Swith On');
end
if (bitand(res,2) == 2)
disp('Node is Swithed On');
end
if (bitand(res,4) == 4)
disp('Node is Operation Enable');
end
if (bitand(res,8) == 8)
disp('Node is Fault State');
end
if (bitand(res,16) == 16)
disp('Node is Voltage Enabled');
end
if (bitand(res,32) == 32)
disp('Node is QuickStop');
end
if (bitand(res,64) == 64)
disp('Node is Swtich On Disable');
end
if (bitand(res,128) == 128)
disp('Node is Warning State');
end
if (bitand(res,1024) == 1024)
disp('Node has reached target');
end
end
function res = ActualPosition(obj)
% This function is for obtaining the actual position of the EPOS4
% node
%
% use it as:
% >> Motor1.ActualPosition
%
% E. Yime, 2015
%
res = GetPosition(obj.Handle, obj.NodeID);
end
function res = WaitUntilDone( obj, TimeOut )
% This function will wait until the motor reachs the target
%
% use it as:
% >> Motor1.WaitUntilDone( TimeOutIn_ms );
%
% E. Yime, 2015
%
res = WaitForTargetReached( obj.Handle, obj.NodeID, TimeOut );
end
function res = MotionInPosition(obj, varargin)
% This function is for moving a motor connected to a EPOS4 controller
% when the motor is in Position or Profile Position Mode.
%
% use it as:
%
% In Position Mode or Profile Position mode
% >> Motor1.MotionInPosition( DesiredPosition )
%
% In Profile Position mode
% >> Motor1.MotionInPosition( DesiredPosition, ProfileVelocity, ProfileAcceleration, AbsoluteOrRelativePosition )
%
% E. Yime, 2015
%
if (nargin < 2 || nargin > 5)
error('you should call this function with four arguments');
end
if (obj.IsInErrorState)
obj.Enable = 0;
error('you can not move a motor when it is in error state');
end
if ( obj.Enable == 0)
error('you can not move a disabled motor');
end
if ( (obj.OpMode ~= OperationModes.PositionMode) && (obj.OpMode ~= OperationModes.ProfilePositionMode) )
error('you can not move a motor when it is not in position related mode');
end
Position = cell2mat(varargin(1));
if (nargin > 2)
velocity = cell2mat(varargin(2));
else
velocity = 8000;
end
if (nargin > 3)
acceleration = cell2mat(varargin(3));
else
acceleration = velocity/2;
end
if (nargin > 4)
Abs = cell2mat(varargin(4));
else
Abs = 0;
end
if (obj.GetOperationMode == OperationModes.PositionMode)
res = SetPosition(obj.Handle, obj.NodeID, Position);
elseif (obj.GetOperationMode == OperationModes.ProfilePositionMode)
if ( nargin > 2)
SetProfilePositionData(obj.Handle, obj.NodeID, velocity, acceleration);
end
res = MoveToPosition(obj.Handle, obj.NodeID, Position, Abs);
end
end
function res = ActualVelocity(obj)
% This function is for obtaining the actual velocity of the EPOS4
% node
%
% use it as:
% >> Motor1.ActualVelocity
%
% E. Yime, 2015
%
res = GetVelocity(obj.Handle, obj.NodeID);
end
function res = MotionInVelocity(obj, varargin)
% This function is for moving a motor connected to a EPOS4 controller
% when the motor is in Velocity or Profile Velocity Mode.
%
% use it as:
%
% In Velocity Mode or Profile Velocity mode
% >> Motor1.MotionInVelocity( DesiredVelocity )
%
% In Profile Velocity mode
% >> Motor1.MotionInPosition( DesiredVelocity, ProfileAcceleration )
%
% E. Yime, 2015
%
if (nargin < 2 || nargin > 3)
error('you should call this function with four arguments');
end
if (obj.IsInErrorState)
obj.Enable = 0;
error('you can not move a motor when it is in error state');
end
if ( obj.Enable == 0)
error('you can not move a disabled motor');
end
if ( (obj.OpMode ~= OperationModes.VelocityMode) && (obj.OpMode ~= OperationModes.ProfileVelocityMode) )
error('you can not move a motor when it is not in velocity related mode');
end
Velocity = cell2mat(varargin(1));
if (nargin > 2)
Acceleration = cell2mat(varargin(2));
else
Acceleration = 4000;
end
if (obj.GetOperationMode == OperationModes.VelocityMode)
res = SetVelocity(obj.Handle, obj.NodeID, Velocity);
elseif (obj.GetOperationMode == OperationModes.ProfileVelocityMode)
if (nargin > 2)
SetProfileVelocityData(obj.Handle, obj.NodeID, Acceleration);
end
res = MoveWithVelocity(obj.Handle, obj.NodeID, Velocity);
end
end
function res = ActualCurrent(obj)
% This function is for obtaining the actual current of the EPOS4
% node
%
% use it as:
% >> Motor1.ActualCurrent
%
% E. Yime, 2015
%
res = GetCurrent(obj.Handle, obj.NodeID);
end
function res = MotionWithCurrent(obj, current)
% This function is for moving a motor connected to a EPOS4 controller
% when the motor is in Current Mode
%
% use it as:
%
% >> Motor1.MotionWithCurrent( DesiredCurrent )
%
% E. Yime, 2015
%
if (obj.IsInErrorState)
obj.Enable = 0;
error('you can not move a motor when it is in error state');
end
if ( obj.Enable == 0)
error('you can not move a disabled motor');
end
if ( obj.OpMode ~= OperationModes.CurrentMode)
error('you can not move the motor when it is not in current mode');
end
res = SetCurrent( obj.Handle, obj.NodeID, current);
end
function res = Stop(obj)
% This function is for stopping a motor connected to a EPOS4 controller
%
% use it as:
%
% >> Motor1.Stop
%
% E. Yime, 2015
%
res = QuickStop(obj.Handle, obj.NodeID);
end
end
end