-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
from_shcom.cpp
813 lines (659 loc) · 19.7 KB
/
from_shcom.cpp
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
// The contents of this file are mostly taken from src/emc/usr_intf/shcom.cc in the LinuxCNC source,
// and reduced so that only the relevant parts are included without bringing in too many other dependencies.
#include "linuxcnc/emc.hh"
#include "linuxcnc/emc_nml.hh"
#include "linuxcnc/timer.hh"
#include "nml_oi.hh"
#include <unistd.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "inifile.hh"
#include "from_shcom.h"
static int num_joints = EMCMOT_MAX_JOINTS;
double emcTimeout;
EMC_UPDATE_TYPE emcUpdateType;
EMC_WAIT_TYPE emcWaitType = EMC_WAIT_DONE;
EMC_STAT *emcStatus;
RCS_CMD_CHANNEL *emcCommandBuffer;
RCS_STAT_CHANNEL *emcStatusBuffer;
NML *emcErrorBuffer;
char error_string[NML_ERROR_LEN];
char operator_text_string[NML_TEXT_LEN];
char operator_display_string[NML_DISPLAY_LEN];
int emcCommandSerialNumber;
int programStartLine = 0;
//const char *nmlfile = "/usr/share/linuxcnc/linuxcnc.nml";
char emc_macrosPath[LINELEN];
char emc_openFile[LINELEN];
int iniLoad(const char *filename)
{
strncpy(emc_macrosPath, ".", LINELEN);
strncpy(emc_openFile, "", LINELEN);
IniFile inifile;
const char *tmpstring;
//char displayString[LINELEN] = "";
//int t;
//int i;
// open it
if (inifile.Open(filename) == false) {
return -1;
}
// if (NULL != (inistring = inifile.Find("DEBUG", "EMC"))) {
// // copy to global
// if (1 != sscanf(inistring, "%i", &emc_debug)) {
// emc_debug = 0;
// }
// } else {
// // not found, use default
// emc_debug = 0;
// }
if (NULL != (tmpstring = inifile.Find("NML_FILE", "EMC"))) {
// copy to global
strncpy(emc_nmlfile, tmpstring, LINELEN);
} else {
// not found, use default
}
if (NULL != (tmpstring = inifile.Find("SUBROUTINE_PATH", "RS274NGC"))) {
// copy to global
strncpy(emc_macrosPath, tmpstring, LINELEN);
} else {
// not found, use default
}
if (NULL != (tmpstring = inifile.Find("OPEN_FILE", "DISPLAY"))) {
// copy to global
strncpy(emc_openFile, tmpstring, LINELEN);
} else {
// not found, use default
}
// for (t = 0; t < EMCMOT_MAX_JOINTS; t++) {
// jogPol[t] = 1; // set to default
// snprintf(displayString, sizeof(displayString), "JOINT_%d", t);
// if (NULL != (inistring =
// inifile.Find("JOGGING_POLARITY", displayString)) &&
// 1 == sscanf(inistring, "%d", &i) && i == 0) {
// // it read as 0, so override default
// jogPol[t] = 0;
// }
// }
// if (NULL != (inistring = inifile.Find("LINEAR_UNITS", "DISPLAY"))) {
// if (!strcmp(inistring, "AUTO")) {
// linearUnitConversion = LINEAR_UNITS_AUTO;
// } else if (!strcmp(inistring, "INCH")) {
// linearUnitConversion = LINEAR_UNITS_INCH;
// } else if (!strcmp(inistring, "MM")) {
// linearUnitConversion = LINEAR_UNITS_MM;
// } else if (!strcmp(inistring, "CM")) {
// linearUnitConversion = LINEAR_UNITS_CM;
// }
// } else {
// // not found, leave default alone
// }
// if (NULL != (inistring = inifile.Find("ANGULAR_UNITS", "DISPLAY"))) {
// if (!strcmp(inistring, "AUTO")) {
// angularUnitConversion = ANGULAR_UNITS_AUTO;
// } else if (!strcmp(inistring, "DEG")) {
// angularUnitConversion = ANGULAR_UNITS_DEG;
// } else if (!strcmp(inistring, "RAD")) {
// angularUnitConversion = ANGULAR_UNITS_RAD;
// } else if (!strcmp(inistring, "GRAD")) {
// angularUnitConversion = ANGULAR_UNITS_GRAD;
// }
// } else {
// // not found, leave default alone
// }
// close it
inifile.Close();
return 0;
}
int emcTaskNmlGet()
{
int retval = 0;
// try to connect to EMC cmd
if (emcCommandBuffer == 0) {
emcCommandBuffer =
new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", emc_nmlfile);
if (!emcCommandBuffer->valid()) {
delete emcCommandBuffer;
emcCommandBuffer = 0;
retval = -1;
}
}
// try to connect to EMC status
if (emcStatusBuffer == 0) {
emcStatusBuffer =
new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", emc_nmlfile);
if (!emcStatusBuffer->valid()
|| EMC_STAT_TYPE != emcStatusBuffer->peek()) {
delete emcStatusBuffer;
emcStatusBuffer = 0;
emcStatus = 0;
retval = -1;
} else {
emcStatus = (EMC_STAT *) emcStatusBuffer->get_address();
}
}
return retval;
}
int emcErrorNmlGet()
{
int retval = 0;
if (emcErrorBuffer == 0) {
emcErrorBuffer =
new NML(nmlErrorFormat, "emcError", "xemc", emc_nmlfile);
if (!emcErrorBuffer->valid()) {
delete emcErrorBuffer;
emcErrorBuffer = 0;
retval = -1;
}
}
return retval;
}
int tryNml(double retry_time, double retry_interval)
{
double end;
int good;
// if ((emc_debug & EMC_DEBUG_NML) == 0) {
// set_rcs_print_destination(RCS_PRINT_TO_NULL); // inhibit diag
// // messages
// }
end = retry_time;
good = 0;
do {
if (0 == emcTaskNmlGet()) {
good = 1;
break;
}
esleep(retry_interval);
end -= retry_interval;
} while (end > 0.0);
// if ((emc_debug & EMC_DEBUG_NML) == 0) {
// set_rcs_print_destination(RCS_PRINT_TO_STDOUT); // inhibit diag
// // messages
// }
if (!good) {
return -1;
}
// if ((emc_debug & EMC_DEBUG_NML) == 0) {
// set_rcs_print_destination(RCS_PRINT_TO_NULL); // inhibit diag
// // messages
// }
end = retry_time;
good = 0;
do {
if (0 == emcErrorNmlGet()) {
good = 1;
break;
}
esleep(retry_interval);
end -= retry_interval;
} while (end > 0.0);
// if ((emc_debug & EMC_DEBUG_NML) == 0) {
// set_rcs_print_destination(RCS_PRINT_TO_STDOUT); // inhibit diag
// // messages
// }
if (!good) {
return -1;
}
return 0;
}
int updateStatus()
{
NMLTYPE type;
if (0 == emcStatus || 0 == emcStatusBuffer
|| !emcStatusBuffer->valid()) {
return -1;
}
switch (type = emcStatusBuffer->peek()) {
case -1:
// error on CMS channel
return -1;
break;
case 0: // no new data
case EMC_STAT_TYPE: // new data
// new data
break;
default:
return -1;
break;
}
return 0;
}
/*
updateError() updates "errors," which are true errors and also
operator display and text messages.
*/
int updateError()
{
NMLTYPE type;
if (0 == emcErrorBuffer || !emcErrorBuffer->valid()) {
return -1;
}
type = emcErrorBuffer->read();
//printf("------------ error type %d\n", type);
switch (type) {
case -1:
// error reading channel
return -1;
break;
case 0:
// nothing new
break;
case EMC_OPERATOR_ERROR_TYPE:
strncpy(error_string,
((EMC_OPERATOR_ERROR *) (emcErrorBuffer->get_address()))->
error, LINELEN - 1);
error_string[NML_ERROR_LEN - 1] = 0;
break;
case EMC_OPERATOR_TEXT_TYPE:
strncpy(operator_text_string,
((EMC_OPERATOR_TEXT *) (emcErrorBuffer->get_address()))->
text, LINELEN - 1);
operator_text_string[NML_TEXT_LEN - 1] = 0;
break;
case EMC_OPERATOR_DISPLAY_TYPE:
strncpy(operator_display_string,
((EMC_OPERATOR_DISPLAY *) (emcErrorBuffer->
get_address()))->display,
LINELEN - 1);
operator_display_string[NML_DISPLAY_LEN - 1] = 0;
break;
case NML_ERROR_TYPE:
strncpy(error_string,
((NML_ERROR *) (emcErrorBuffer->get_address()))->error,
NML_ERROR_LEN - 1);
error_string[NML_ERROR_LEN - 1] = 0;
break;
case NML_TEXT_TYPE:
strncpy(operator_text_string,
((NML_TEXT *) (emcErrorBuffer->get_address()))->text,
NML_TEXT_LEN - 1);
operator_text_string[NML_TEXT_LEN - 1] = 0;
break;
case NML_DISPLAY_TYPE:
strncpy(operator_display_string,
((NML_DISPLAY *) (emcErrorBuffer->get_address()))->display,
NML_DISPLAY_LEN - 1);
operator_display_string[NML_DISPLAY_LEN - 1] = 0;
break;
default:
// if not recognized, set the error string
snprintf(error_string, sizeof(error_string), "unrecognized error %d", type);
return -1;
break;
}
return type;
}
#define EMC_COMMAND_DELAY 0.01 // how long to sleep between checks
// returns
// 0 = not finished
// 1 = finished ok
// -1 = finished with error
int emcCommandPollDone()
{
//printf("emcCommandWaitDone\n");
updateStatus();
int serial_diff = emcStatus->echo_serial_number - emcCommandSerialNumber;
//printf("%d %d \n", emcCommandSerialNumber, emcStatus->echo_serial_number); fflush(stdout);
if (serial_diff < 0) {
//printf("0\n"); fflush(stdout);
return 0;
}
if (serial_diff > 0) {
return 1;
}
if (emcStatus->status == RCS_DONE) {
return 1;
}
if (emcStatus->status == RCS_ERROR) {
//printf("1\n"); fflush(stdout);
return -1;
}
//printf("2\n"); fflush(stdout);
return 0;
}
int emcCommandWaitDone()
{
//printf("emcCommandWaitDone\n");
double end;
for (end = 0.0; emcTimeout <= 0.0 || end < emcTimeout; end += EMC_COMMAND_DELAY) {
updateStatus();
int serial_diff = emcStatus->echo_serial_number - emcCommandSerialNumber;
if (serial_diff < 0) {
continue;
}
if (serial_diff > 0) {
return 0;
}
if (emcStatus->status == RCS_DONE) {
return 0;
}
if (emcStatus->status == RCS_ERROR) {
return -1;
}
esleep(EMC_COMMAND_DELAY);
}
return -1;
}
int emcCommandWaitReceived()
{
//printf("emcCommandWaitReceived\n");
double end;
for (end = 0.0; emcTimeout <= 0.0 || end < emcTimeout; end += EMC_COMMAND_DELAY) {
updateStatus();
int serial_diff = emcStatus->echo_serial_number - emcCommandSerialNumber;
if (serial_diff >= 0) {
return 0;
}
esleep(EMC_COMMAND_DELAY);
}
return -1;
}
int emcCommandSend(RCS_CMD_MSG & cmd)
{
// write command
if (emcCommandBuffer->write(&cmd)) {
return -1;
}
emcCommandSerialNumber = cmd.serial_number;
return 0;
}
int sendAbort()
{
EMC_TASK_ABORT task_abort_msg;
emcCommandSend(task_abort_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendEstop()
{
EMC_TASK_SET_STATE state_msg;
state_msg.state = EMC_TASK_STATE_ESTOP;
emcCommandSend(state_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendEstopReset()
{
EMC_TASK_SET_STATE state_msg;
state_msg.state = EMC_TASK_STATE_ESTOP_RESET;
emcCommandSend(state_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendMachineOn()
{
EMC_TASK_SET_STATE state_msg;
state_msg.state = EMC_TASK_STATE_ON;
emcCommandSend(state_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendMachineOff()
{
EMC_TASK_SET_STATE state_msg;
state_msg.state = EMC_TASK_STATE_OFF;
emcCommandSend(state_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendManual()
{
EMC_TASK_SET_MODE mode_msg;
mode_msg.mode = EMC_TASK_MODE_MANUAL;
emcCommandSend(mode_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendAuto()
{
EMC_TASK_SET_MODE mode_msg;
mode_msg.mode = EMC_TASK_MODE_AUTO;
emcCommandSend(mode_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendMdi()
{
EMC_TASK_SET_MODE mode_msg;
mode_msg.mode = EMC_TASK_MODE_MDI;
emcCommandSend(mode_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendSetTeleopEnable(int enable)
{
EMC_TRAJ_SET_TELEOP_ENABLE emc_set_teleop_enable_msg;
emc_set_teleop_enable_msg.enable = enable;
emcCommandSend(emc_set_teleop_enable_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendHome(int joint)
{
EMC_JOINT_HOME emc_joint_home_msg;
emc_joint_home_msg.joint = joint;
emcCommandSend(emc_joint_home_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendTrajSetAcceleration(double accel)
{
EMC_TRAJ_SET_ACCELERATION emc_traj_set_accel;
printf("accel = %f\n", accel);
emc_traj_set_accel.acceleration = accel;
emcCommandSend(emc_traj_set_accel);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendTrajSetMaxAcceleration(double accel)
{
EMC_TRAJ_SET_MAX_ACCELERATION emc_traj_set_max_accel;
printf("accel = %f\n", accel);
emc_traj_set_max_accel.acceleration = accel;
emcCommandSend(emc_traj_set_max_accel);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendMdiCmd(const char *mdi)
{
EMC_TASK_PLAN_EXECUTE emc_task_plan_execute_msg;
strncpy(emc_task_plan_execute_msg.command, mdi, LINELEN-1);
emcCommandSend(emc_task_plan_execute_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
static char lastProgramFile[LINELEN] = "";
int sendProgramOpen(const char *program)
{
EMC_TASK_PLAN_OPEN emc_task_plan_open_msg;
// save this to run again
strncpy(lastProgramFile, program, LINELEN-1);
strncpy(emc_task_plan_open_msg.file, program, LINELEN-1);
emcCommandSend(emc_task_plan_open_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendProgramRun(int line)
{
EMC_TASK_PLAN_RUN emc_task_plan_run_msg;
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
// first reopen program if it's not open
if (0 == emcStatus->task.file[0]) {
// send a request to open last one
sendProgramOpen(lastProgramFile);
}
// save the start line, to compare against active line later
programStartLine = line;
emc_task_plan_run_msg.line = line;
emcCommandSend(emc_task_plan_run_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendProgramPause()
{
EMC_TASK_PLAN_PAUSE emc_task_plan_pause_msg;
emcCommandSend(emc_task_plan_pause_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendProgramResume()
{
EMC_TASK_PLAN_RESUME emc_task_plan_resume_msg;
emcCommandSend(emc_task_plan_resume_msg);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}
int sendJogStop(int ja, int jjogmode)
{
EMC_JOG_STOP emc_jog_stop_msg;
if ( ( (jjogmode == JOGJOINT)
&& (emcStatus->motion.traj.mode == EMC_TRAJ_MODE_TELEOP) )
|| ( (jjogmode == JOGTELEOP )
&& (emcStatus->motion.traj.mode != EMC_TRAJ_MODE_TELEOP) )
) {
return -1;
}
if ( jjogmode && (ja < 0 || ja >= num_joints)) {
fprintf(stderr,"shcom.cc: unexpected_1 %d\n",ja); return -1;
}
if ( !jjogmode && (ja < 0)) {
fprintf(stderr,"shcom.cc: unexpected_2 %d\n",ja); return -1;
}
emc_jog_stop_msg.jjogmode = jjogmode;
emc_jog_stop_msg.joint_or_axis = ja;
emcCommandSend(emc_jog_stop_msg);
return 0;
}
int sendJogCont(int ja, int jjogmode, double speed)
{
EMC_JOG_CONT emc_jog_cont_msg;
if (emcStatus->task.state != EMC_TASK_STATE_ON) { return -1; }
if ( ( (jjogmode == JOGJOINT)
&& (emcStatus->motion.traj.mode == EMC_TRAJ_MODE_TELEOP) )
|| ( (jjogmode == JOGTELEOP )
&& (emcStatus->motion.traj.mode != EMC_TRAJ_MODE_TELEOP) )
) {
return -1;
}
if ( jjogmode && (ja < 0 || ja >= num_joints)) {
fprintf(stderr,"shcom.cc: unexpected_3 %d\n",ja); return -1;
}
if ( !jjogmode && (ja < 0)) {
fprintf(stderr,"shcom.cc: unexpected_4 %d\n",ja); return -1;
}
emc_jog_cont_msg.jjogmode = jjogmode;
emc_jog_cont_msg.joint_or_axis = ja;
emc_jog_cont_msg.vel = speed / 60.0;
emcCommandSend(emc_jog_cont_msg);
return 0;
}
int sendJogIncr(int ja, int jjogmode, double speed, double incr)
{
EMC_JOG_INCR emc_jog_incr_msg;
if (emcStatus->task.state != EMC_TASK_STATE_ON) { return -1; }
if ( ( (jjogmode == JOGJOINT)
&& ( emcStatus->motion.traj.mode == EMC_TRAJ_MODE_TELEOP) )
|| ( (jjogmode == JOGTELEOP )
&& ( emcStatus->motion.traj.mode != EMC_TRAJ_MODE_TELEOP) )
) {
return -1;
}
if ( jjogmode && (ja < 0 || ja >= num_joints)) {
fprintf(stderr,"shcom.cc: unexpected_5 %d\n",ja); return -1;
}
if ( !jjogmode && (ja < 0)) {
fprintf(stderr,"shcom.cc: unexpected_6 %d\n",ja); return -1;
}
emc_jog_incr_msg.jjogmode = jjogmode;
emc_jog_incr_msg.joint_or_axis = ja;
emc_jog_incr_msg.vel = speed / 60.0;
emc_jog_incr_msg.incr = incr;
emcCommandSend(emc_jog_incr_msg);
return 0;
}
int sendSetDout(unsigned char index, unsigned char value)
{
EMC_MOTION_SET_DOUT emc_motion_set_dout;
emc_motion_set_dout.index = index;
emc_motion_set_dout.start = value;
emc_motion_set_dout.end = value;
emc_motion_set_dout.now = 1;
emcCommandSend(emc_motion_set_dout);
if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
} else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
}
return 0;
}