-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtaskintf.cc
More file actions
2183 lines (1802 loc) · 57.6 KB
/
Copy pathtaskintf.cc
File metadata and controls
2183 lines (1802 loc) · 57.6 KB
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
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************************
* Description: taskintf.cc
* Interface functions for motion.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
********************************************************************/
#include <cmath>
#include <float.h> // DBL_MAX
#include <string.h> // memcpy() strncpy()
#include <unistd.h> // unlink()
#include "motion/usrmotintf.h" // usrmotInit(), usrmotReadEmcmotStatus(),
// etc.
#include "motion/motion.h" // emcmot_command_t,STATUS, etc.
#include "motion/homing.h"
#include "nml_intf/emc.hh"
#include "nml_intf/emccfg.h" // EMC_INIFILE
#include "nml_intf/emcglb.h" // EMC_INIFILE
#include "nml_intf/emc_nml.hh"
#include "libnml/rcs/rcs_print.hh"
#include "libnml/os_intf/timer.hh"
#include <inifile.hh>
#include "ini/iniaxis.hh"
#include "ini/inijoint.hh"
#include "ini/inispindle.hh"
#include "ini/initraj.hh"
#include "ini/inihal.hh"
using namespace linuxcnc;
value_inihal_data old_inihal_data;
/* define this to catch isnan errors, for rtlinux FPU register
problem testing */
#define ISNAN_TRAP
#ifdef ISNAN_TRAP
#define CATCH_NAN(cond) do { \
if (cond) { \
printf("isnan error in %s()\n", __FUNCTION__); \
return -1; \
} \
} while(0)
#else
#define CATCH_NAN(cond) do {} while(0)
#endif
// MOTION INTERFACE
/*! \todo FIXME - this decl was originally much later in the file, moved
here temporarily for debugging */
static emcmot_status_t emcmotStatus;
/*
Implementation notes:
Initing: the emcmot interface needs to be inited once, but nml_traj_init()
and nml_servo_init() can be called in any order. Similarly, the emcmot
interface needs to be exited once, but nml_traj_exit() and nml_servo_exit()
can be called in any order. They can also be called multiple times. Flags
are used to signify if initing has been done, or if the final exit has
been called.
*/
static struct TrajConfig_t TrajConfig;
static struct JointConfig_t JointConfig[EMCMOT_MAX_JOINTS];
static struct AxisConfig_t AxisConfig[EMCMOT_MAX_AXIS];
static struct SpindleConfig_t SpindleConfig[EMCMOT_MAX_SPINDLES];
static emcmot_command_t emcmotCommand;
// local status data, not provided by emcmot
static int localMotionCommandType = 0;
static int localMotionEchoSerialNumber = 0;
// axes and joints are numbered 0..NUM-1
/*
In emcmot, we need to set the cycle time for traj, and the interpolation
rate, in any order, but both need to be done.
*/
/*! functions involving joints */
int emcJointSetType(int joint, unsigned char jointType)
{
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
JointConfig[joint].Type = jointType;
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %d)\n", __FUNCTION__, joint, jointType);
}
return 0;
}
int emcJointSetUnits(int joint, double units)
{
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
JointConfig[joint].Units = units;
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f)\n", __FUNCTION__, joint, units);
}
return 0;
}
int emcJointSetBacklash(int joint, double backlash)
{
#ifdef ISNAN_TRAP
if (std::isnan(backlash)) {
printf("std::isnan error in emcJointSetBacklash()\n");
return -1;
}
#endif
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_SET_JOINT_BACKLASH;
emcmotCommand.joint = joint;
emcmotCommand.backlash = backlash;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, joint, backlash, retval);
}
return retval;
}
int emcJointSetMinPositionLimit(int joint, double limit)
{
#ifdef ISNAN_TRAP
if (std::isnan(limit)) {
printf("isnan error in emcJointSetMinPosition()\n");
return -1;
}
#endif
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
JointConfig[joint].MinLimit = limit;
emcmotCommand.command = EMCMOT_SET_JOINT_POSITION_LIMITS;
emcmotCommand.joint = joint;
emcmotCommand.minLimit = JointConfig[joint].MinLimit;
emcmotCommand.maxLimit = JointConfig[joint].MaxLimit;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4g) returned %d\n", __FUNCTION__, joint, limit, retval);
}
return retval;
}
int emcJointSetMaxPositionLimit(int joint, double limit)
{
#ifdef ISNAN_TRAP
if (std::isnan(limit)) {
printf("std::isnan error in emcJointSetMaxPosition()\n");
return -1;
}
#endif
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
JointConfig[joint].MaxLimit = limit;
emcmotCommand.command = EMCMOT_SET_JOINT_POSITION_LIMITS;
emcmotCommand.joint = joint;
emcmotCommand.minLimit = JointConfig[joint].MinLimit;
emcmotCommand.maxLimit = JointConfig[joint].MaxLimit;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4g) returned %d\n", __FUNCTION__, joint, limit, retval);
}
return retval;
}
int emcJointSetMotorOffset(int joint, double offset)
{
#ifdef ISNAN_TRAP
if (std::isnan(offset)) {
printf("isnan error in emcJointSetMotorOffset()\n");
return -1;
}
#endif
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_SET_JOINT_MOTOR_OFFSET;
emcmotCommand.joint = joint;
emcmotCommand.motor_offset = offset;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, joint, offset, retval);
}
return retval;
}
int emcJointSetFerror(int joint, double ferror)
{
#ifdef ISNAN_TRAP
if (std::isnan(ferror)) {
printf("isnan error in emcJointSetFerror()\n");
return -1;
}
#endif
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_SET_JOINT_MAX_FERROR;
emcmotCommand.joint = joint;
emcmotCommand.maxFerror = ferror;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, joint, ferror, retval);
}
return retval;
}
int emcJointSetMinFerror(int joint, double ferror)
{
#ifdef ISNAN_TRAP
if (std::isnan(ferror)) {
printf("isnan error in emcJointSetMinFerror()\n");
return -1;
}
#endif
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_SET_JOINT_MIN_FERROR;
emcmotCommand.joint = joint;
emcmotCommand.minFerror = ferror;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, joint, ferror, retval);
}
return retval;
}
int emcJointSetHomingParams(int joint, double home, double offset, double home_final_vel,
double search_vel, double latch_vel,
int use_index, int encoder_does_not_reset,
int ignore_limits, int is_shared,
int sequence,int volatile_home, int locking_indexer, int absolute_encoder,
int home_dogbone)
{
#ifdef ISNAN_TRAP
if (std::isnan(home) || std::isnan(offset) || std::isnan(home_final_vel) ||
std::isnan(search_vel) || std::isnan(latch_vel)) {
printf("isnan error in emcJointSetHomingParams()\n");
return -1;
}
#endif
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_SET_JOINT_HOMING_PARAMS;
emcmotCommand.joint = joint;
emcmotCommand.home = home;
emcmotCommand.offset = offset;
emcmotCommand.home_final_vel = home_final_vel;
emcmotCommand.search_vel = search_vel;
emcmotCommand.latch_vel = latch_vel;
emcmotCommand.flags = 0;
emcmotCommand.home_sequence = sequence;
emcmotCommand.volatile_home = volatile_home;
emcmotCommand.home_dogbone = home_dogbone;
if (use_index) {
emcmotCommand.flags |= HOME_USE_INDEX;
}
if (encoder_does_not_reset) {
emcmotCommand.flags |= HOME_INDEX_NO_ENCODER_RESET;
}
if (ignore_limits) {
emcmotCommand.flags |= HOME_IGNORE_LIMITS;
}
if (is_shared) {
emcmotCommand.flags |= HOME_IS_SHARED;
}
if (locking_indexer) {
emcmotCommand.flags |= HOME_UNLOCK_FIRST;
}
if (absolute_encoder) {
switch (absolute_encoder) {
case 0: break;
case 1: emcmotCommand.flags |= HOME_ABSOLUTE_ENCODER;
emcmotCommand.flags |= HOME_NO_REHOME;
break;
case 2: emcmotCommand.flags |= HOME_ABSOLUTE_ENCODER;
emcmotCommand.flags |= HOME_NO_REHOME;
emcmotCommand.flags |= HOME_NO_FINAL_MOVE;
break;
default: fprintf(stderr,
"Unknown option for absolute_encoder <%d>",absolute_encoder);
break;
}
}
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f, %.4f, %.4f, %.4f, %.4f, %d, %d, %d, %d, %d, %d) returned %d\n",
__FUNCTION__, joint, home, offset, home_final_vel, search_vel, latch_vel,
use_index, ignore_limits, is_shared, sequence, volatile_home, home_dogbone, retval);
}
return retval;
}
int emcJointUpdateHomingParams(int joint, double home, double offset, int sequence)
{
CATCH_NAN(std::isnan(home) || std::isnan(offset) );
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_UPDATE_JOINT_HOMING_PARAMS;
emcmotCommand.joint = joint;
emcmotCommand.home = home;
emcmotCommand.offset = offset;
emcmotCommand.home_sequence = sequence;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f, %.4f) returned %d\n",
__FUNCTION__, joint, home, offset,retval);
}
return retval;
}
int emcJointSetMaxVelocity(int joint, double vel)
{
CATCH_NAN(std::isnan(vel));
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
if (vel < 0.0) {
vel = 0.0;
}
JointConfig[joint].MaxVel = vel;
emcmotCommand.command = EMCMOT_SET_JOINT_VEL_LIMIT;
emcmotCommand.joint = joint;
emcmotCommand.vel = vel;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, joint, vel, retval);
}
return retval;
}
int emcJointSetMaxAcceleration(int joint, double acc)
{
CATCH_NAN(std::isnan(acc));
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
if (acc < 0.0) {
acc = 0.0;
}
JointConfig[joint].MaxAccel = acc;
//FIXME-AJ: need functions for setting the AXIS_MAX_ACCEL (either from the INI, or from kins..)
emcmotCommand.command = EMCMOT_SET_JOINT_ACC_LIMIT;
emcmotCommand.joint = joint;
emcmotCommand.acc = acc;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4g) returned %d\n", __FUNCTION__, joint, acc, retval);
}
return retval;
}
int emcJointSetMaxJerk(int joint, double jerk)
{
CATCH_NAN(isnan(jerk));
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
if (jerk < 0.0) {
jerk = 0.0;
}
JointConfig[joint].MaxJerk = jerk;
emcmotCommand.command = EMCMOT_SET_JOINT_JERK_LIMIT;
emcmotCommand.joint = joint;
emcmotCommand.jerk = jerk;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, joint, jerk, retval);
}
return retval;
}
/*! functions involving cartesian Axes (X,Y,Z,A,B,C,U,V,W) */
int emcAxisSetMinPositionLimit(int axis, double limit)
{
CATCH_NAN(std::isnan(limit));
if (axis < 0 || axis >= EMCMOT_MAX_AXIS || !(TrajConfig.AxisMask & (1 << axis))) {
return 0;
}
AxisConfig[axis].MinLimit = limit;
emcmotCommand.command = EMCMOT_SET_AXIS_POSITION_LIMITS;
emcmotCommand.axis = axis;
emcmotCommand.minLimit = AxisConfig[axis].MinLimit;
emcmotCommand.maxLimit = AxisConfig[axis].MaxLimit;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, axis, limit, retval);
}
return retval;
}
int emcAxisSetMaxPositionLimit(int axis, double limit)
{
CATCH_NAN(std::isnan(limit));
if (axis < 0 || axis >= EMCMOT_MAX_AXIS || !(TrajConfig.AxisMask & (1 << axis))) {
return 0;
}
AxisConfig[axis].MaxLimit = limit;
emcmotCommand.command = EMCMOT_SET_AXIS_POSITION_LIMITS;
emcmotCommand.axis = axis;
emcmotCommand.minLimit = AxisConfig[axis].MinLimit;
emcmotCommand.maxLimit = AxisConfig[axis].MaxLimit;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, axis, limit, retval);
}
return retval;
}
int emcAxisSetMaxVelocity(int axis, double vel,double ext_offset_vel)
{
CATCH_NAN(std::isnan(vel));
if (axis < 0 || axis >= EMCMOT_MAX_AXIS || !(TrajConfig.AxisMask & (1 << axis))) {
return 0;
}
if (vel < 0.0) {
vel = 0.0;
}
AxisConfig[axis].MaxVel = vel;
emcmotCommand.command = EMCMOT_SET_AXIS_VEL_LIMIT;
emcmotCommand.axis = axis;
emcmotCommand.vel = vel;
emcmotCommand.ext_offset_vel = ext_offset_vel;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, axis, vel, retval);
}
return retval;
}
int emcAxisSetMaxAcceleration(int axis, double acc,double ext_offset_acc)
{
CATCH_NAN(std::isnan(acc));
if (axis < 0 || axis >= EMCMOT_MAX_AXIS || !(TrajConfig.AxisMask & (1 << axis))) {
return 0;
}
if (acc < 0.0) {
acc = 0.0;
}
AxisConfig[axis].MaxAccel = acc;
emcmotCommand.command = EMCMOT_SET_AXIS_ACC_LIMIT;
emcmotCommand.axis = axis;
emcmotCommand.acc = acc;
emcmotCommand.ext_offset_acc = ext_offset_acc;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f) returned %d\n", __FUNCTION__, axis, acc, retval);
}
return retval;
}
int emcAxisSetMaxJerk(int axis, double jerk)
{
if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {
return 0;
}
if (jerk < 0.0) {
jerk = 0.0;
}
if(jerk > 0) AxisConfig[axis].haveMaxJerk = 1;
AxisConfig[axis].MaxJerk = jerk;
emcmotCommand.command = EMCMOT_SET_AXIS_JERK_LIMIT;
emcmotCommand.axis = axis;
emcmotCommand.jerk = jerk;
return usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %.4f)\n", __FUNCTION__, axis, jerk);
}
return 0;
}
int emcAxisSetLockingJoint(int axis, int joint)
{
if (axis < 0 || axis >= EMCMOT_MAX_AXIS || !(TrajConfig.AxisMask & (1 << axis))) {
return 0;
}
if (joint < 0) {
joint = -1;
}
emcmotCommand.command = EMCMOT_SET_AXIS_LOCKING_JOINT;
emcmotCommand.axis = axis;
emcmotCommand.joint = joint;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d, %d) returned %d\n", __FUNCTION__, axis, joint, retval);
}
return retval;
}
double emcAxisGetMaxVelocity(int axis)
{
if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {
return 0;
}
return AxisConfig[axis].MaxVel;
}
double emcAxisGetMaxAcceleration(int axis)
{
if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {
return 0;
}
return AxisConfig[axis].MaxAccel;
}
int emcAxisHasMaxJerk(int axis)
{
if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {
return 0;
}
return AxisConfig[axis].haveMaxJerk;
}
double emcAxisGetMaxJerk(int axis)
{
if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {
return 0;
}
return AxisConfig[axis].MaxJerk;
}
int emcAxisUpdate(EMC_AXIS_STAT stat[], int axis_mask)
{
int axis_num;
emcmot_axis_status_t *axis;
for (axis_num = 0; axis_num < EMCMOT_MAX_AXIS; axis_num++) {
if(!(axis_mask & (1 << axis_num))) continue;
axis = &(emcmotStatus.axis_status[axis_num]);
stat[axis_num].velocity = axis->teleop_vel_cmd;
stat[axis_num].minPositionLimit = axis->min_pos_limit;
stat[axis_num].maxPositionLimit = axis->max_pos_limit;
}
return 0;
}
/* This function checks to see if any joint or the traj has
been inited already. At startup, if none have been inited,
usrmotIniLoad and usrmotInit must be called first. At
shutdown, after all have been halted, the usrmotExit must
be called.
*/
static int JointOrTrajInited(void)
{
int joint, spindle;
for (joint = 0; joint < EMCMOT_MAX_JOINTS; joint++) {
if (JointConfig[joint].Inited) {
return 1;
}
}
for (spindle = 0; spindle < EMCMOT_MAX_SPINDLES; spindle++) {
if (SpindleConfig[spindle].Inited) {
return 1;
}
}
if (TrajConfig.Inited) {
return 1;
}
return 0;
}
int emcJointInit(int joint)
{
int retval = 0;
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
// init emcmot interface
if (!JointOrTrajInited()) {
usrmotIniLoad(emc_inifile);
if (0 != usrmotInit("emc2_task")) {
return -1;
}
}
JointConfig[joint].Inited = 1;
if (0 != iniJoint(joint, emc_inifile)) {
retval = -1;
}
return retval;
}
int emcAxisInit(int axis)
{
int retval = 0;
if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {
return 0;
}
// init emcmot interface
if (!JointOrTrajInited()) {
usrmotIniLoad(emc_inifile);
if (0 != usrmotInit("emc2_task")) {
return -1;
}
}
AxisConfig[axis].Inited = 1;
AxisConfig[axis].haveMaxJerk = 0;
if (0 != iniAxis(axis, emc_inifile)) {
retval = -1;
}
return retval;
}
int emcSpindleInit(int spindle)
{
int retval = 0;
if (spindle < 0 || spindle >= EMCMOT_MAX_SPINDLES) {
return 0;
}
// init emcmot interface
if (!JointOrTrajInited()) {
usrmotIniLoad(emc_inifile);
if (0 != usrmotInit("emc2_task")) {
return -1;
}
}
SpindleConfig[spindle].Inited = 1;
if (0 != iniSpindle(spindle, emc_inifile)) {
retval = -1;
}
return retval;
}
int emcJointHalt(int joint)
{
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
/*! \todo FIXME-- refs global emcStatus; should make EMC_JOINT_STAT an arg here */
JointConfig[joint].Inited = 0;
if (!JointOrTrajInited()) {
usrmotExit(); // ours is final exit
}
return 0;
}
int emcJogAbort(int joint)
{
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_JOG_ABORT;
emcmotCommand.joint = joint;
emcmotCommand.axis = -1; //NA
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJointActivate(int joint)
{
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_JOINT_ACTIVATE;
emcmotCommand.joint = joint;
int retval = usrmotWriteEmcmotCommand(&emcmotCommand);
if (emc_debug & EMC_DEBUG_CONFIG) {
rcs_print("%s(%d) returned %d\n", __FUNCTION__, joint, retval);
}
return retval;
}
int emcJointDeactivate(int joint)
{
if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_JOINT_DEACTIVATE;
emcmotCommand.joint = joint;
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJointOverrideLimits(int joint)
{
// can have joint < 0, for resuming normal limit checking
if (joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_OVERRIDE_LIMITS;
emcmotCommand.joint = joint;
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJointHome(int joint)
{
if (joint < -1 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_JOINT_HOME;
emcmotCommand.joint = joint;
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJointUnhome(int joint)
{
if (joint < -2 || joint >= EMCMOT_MAX_JOINTS) {
return 0;
}
emcmotCommand.command = EMCMOT_JOINT_UNHOME;
emcmotCommand.joint = joint;
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJogCont(int nr, double vel, int jjogmode)
{
if (jjogmode) {
if (nr < 0 || nr >= EMCMOT_MAX_JOINTS) { return 0; }
if (vel > JointConfig[nr].MaxVel) {
vel = JointConfig[nr].MaxVel;
} else if (vel < -JointConfig[nr].MaxVel) {
vel = -JointConfig[nr].MaxVel;
}
emcmotCommand.joint = nr;
emcmotCommand.axis = -1; //NA
} else {
if (nr < 0 || nr >= EMCMOT_MAX_AXIS) { return 0; }
if (vel > AxisConfig[nr].MaxVel) {
vel = AxisConfig[nr].MaxVel;
} else if (vel < -AxisConfig[nr].MaxVel) {
vel = -AxisConfig[nr].MaxVel;
}
emcmotCommand.joint = -1; //NA
emcmotCommand.axis = nr;
}
emcmotCommand.command = EMCMOT_JOG_CONT;
emcmotCommand.vel = vel;
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJogIncr(int nr, double incr, double vel, int jjogmode)
{
if (jjogmode) {
if (nr < 0 || nr >= EMCMOT_MAX_JOINTS) { return 0; }
if (vel > JointConfig[nr].MaxVel) {
vel = JointConfig[nr].MaxVel;
} else if (vel < -JointConfig[nr].MaxVel) {
vel = -JointConfig[nr].MaxVel;
}
emcmotCommand.joint = nr;
emcmotCommand.axis = -1; //NA
} else {
if (nr < 0 || nr >= EMCMOT_MAX_AXIS) { return 0; }
if (vel > AxisConfig[nr].MaxVel) {
vel = AxisConfig[nr].MaxVel;
} else if (vel < -AxisConfig[nr].MaxVel) {
vel = -AxisConfig[nr].MaxVel;
}
emcmotCommand.joint = -1; //NA
emcmotCommand.axis = nr;
}
emcmotCommand.command = EMCMOT_JOG_INCR;
emcmotCommand.vel = vel;
emcmotCommand.offset = incr;
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJogAbs(int nr, double pos, double vel, int jjogmode)
{
if (jjogmode) {
if (nr < 0 || nr >= EMCMOT_MAX_JOINTS) { return 0; }
if (vel > JointConfig[nr].MaxVel) {
vel = JointConfig[nr].MaxVel;
} else if (vel < -JointConfig[nr].MaxVel) {
vel = -JointConfig[nr].MaxVel;
}
emcmotCommand.joint = nr;
emcmotCommand.axis = -1; //NA
} else {
if (nr < 0 || nr >= EMCMOT_MAX_AXIS) { return 0; }
if (vel > AxisConfig[nr].MaxVel) {
vel = AxisConfig[nr].MaxVel;
} else if (vel < -AxisConfig[nr].MaxVel) {
vel = -AxisConfig[nr].MaxVel;
}
emcmotCommand.joint = -1; //NA
emcmotCommand.axis = nr;
}
emcmotCommand.command = EMCMOT_JOG_ABS;
emcmotCommand.vel = vel;
emcmotCommand.offset = pos;
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJogStop(int nr, int jjogmode)
{
if (jjogmode) {
if (nr < 0 || nr >= EMCMOT_MAX_JOINTS) { return 0; }
emcmotCommand.joint = nr;
emcmotCommand.axis = -1; //NA
} else {
if (nr < 0 || nr >= EMCMOT_MAX_AXIS) { return 0; }
emcmotCommand.joint = -1; //NA
emcmotCommand.axis = nr;
}
emcmotCommand.command = EMCMOT_JOG_ABORT;
return usrmotWriteEmcmotCommand(&emcmotCommand);
}
int emcJointLoadComp(int joint, const char *file, int type)
{
return usrmotLoadComp(joint, file, type);
}
static emcmot_config_t emcmotConfig;
int get_emcmot_internal_info = 0; // debug usage
/*
these globals are set in emcMotionUpdate(), then referenced in
emcJointUpdate(), emcTrajUpdate() to save calls to usrmotReadEmcmotStatus
*/
static emcmot_internal_t emcmotInternal;
static char errorString[EMCMOT_ERROR_LEN];
static int new_config = 0;
/*! \todo FIXME - debugging - uncomment the following line to log changes in
JOINT_FLAG */
// #define WATCH_FLAGS 1
int emcJointUpdate(EMC_JOINT_STAT stat[], int numJoints)
{
/*! \todo FIXME - this function accesses data that has been
moved. Once I know what it is used for I'll fix it */
int joint_num;
emcmot_joint_status_t *joint;
#ifdef WATCH_FLAGS
static int old_joint_flag[8];
#endif
// check for valid range
if (numJoints <= 0 || numJoints > EMCMOT_MAX_JOINTS) {
return -1;
}
for (joint_num = 0; joint_num < numJoints; joint_num++) {
/* point to joint data */
joint = &(emcmotStatus.joint_status[joint_num]);
stat[joint_num].jointType = JointConfig[joint_num].Type;
stat[joint_num].units = JointConfig[joint_num].Units;
if (new_config) {
stat[joint_num].backlash = joint->backlash;
stat[joint_num].minPositionLimit = joint->min_pos_limit;
stat[joint_num].maxPositionLimit = joint->max_pos_limit;
stat[joint_num].minFerror = joint->min_ferror;
stat[joint_num].maxFerror = joint->max_ferror;
/*! \todo FIXME - should all homing config params be included here? */
// stat[joint_num].homeOffset = joint->home_offset;
}
stat[joint_num].output = joint->pos_cmd;
stat[joint_num].input = joint->pos_fb;
stat[joint_num].velocity = joint->vel_cmd;
stat[joint_num].ferrorCurrent = joint->ferror;
stat[joint_num].ferrorHighMark = joint->ferror_high_mark;
stat[joint_num].homing = joint->homing;
stat[joint_num].homed = joint->homed;
stat[joint_num].fault = (joint->flag & EMCMOT_JOINT_FAULT_BIT ? 1 : 0);
stat[joint_num].enabled = (joint->flag & EMCMOT_JOINT_ENABLE_BIT ? 1 : 0);
stat[joint_num].inpos = (joint->flag & EMCMOT_JOINT_INPOS_BIT ? 1 : 0);
/* FIXME - soft limits are now applied to the command, and should never
happen */
stat[joint_num].minSoftLimit = 0;
stat[joint_num].maxSoftLimit = 0;
stat[joint_num].minHardLimit =
(joint->flag & EMCMOT_JOINT_MIN_HARD_LIMIT_BIT ? 1 : 0);
stat[joint_num].maxHardLimit =
(joint->flag & EMCMOT_JOINT_MAX_HARD_LIMIT_BIT ? 1 : 0);
stat[joint_num].overrideLimits = !!(emcmotStatus.overrideLimitMask); // one
// for
// all
#ifdef WATCH_FLAGS
if (old_joint_flag[joint_num] != joint->flag) {
printf("joint %d flag: %04X -> %04X\n", joint_num,