@digipair/skill-mybuddy 0.89.0 → 0.91.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,876 @@
1
+ import { PinsSettings } from '@digipair/engine';
2
+ import mybuddy from '@marcbuils/mybuddy';
3
+
4
+ const TIMEOUT_READ_COMMANDS = 1000;
5
+
6
+ class MyBuddyService {
7
+ private async connect(params: any, context: any) {
8
+ const { MY_BUDDY = context.privates.MY_BUDDY ?? { port: '/dev/ttyACM0', baud: 115200 } } = params;
9
+ return mybuddy.connect(MY_BUDDY.port, MY_BUDDY.baud);
10
+ }
11
+
12
+ // Actions
13
+ async sendAngles(params: any, _pinsSettingsList: PinsSettings[], context: any) {
14
+ const { device, angles, speed = 50 } = params;
15
+ const connection = await this.connect(params, context);
16
+ const result = connection.write(mybuddy.sendAngles(device, angles, speed));
17
+ await new Promise((resolve) => setTimeout(resolve, 50));
18
+ connection.close();
19
+ return result;
20
+ }
21
+
22
+ async powerOn(params: any, _pinsSettingsList: PinsSettings[], context: any) {
23
+ const { device } = params;
24
+ const connection = await this.connect(params, context);
25
+ const result = connection.write(mybuddy.powerOn(device));
26
+ await new Promise((resolve) => setTimeout(resolve, 50));
27
+ connection.close();
28
+ return result;
29
+ }
30
+
31
+ async powerOff(params: any, _pinsSettingsList: PinsSettings[], context: any) {
32
+ const { device } = params;
33
+ const connection = await this.connect(params, context);
34
+ const result = connection.write(mybuddy.powerOff(device));
35
+ await new Promise((resolve) => setTimeout(resolve, 50));
36
+ connection.close();
37
+ return result;
38
+ }
39
+
40
+ async releaseAllServos(params: any, _pinsSettingsList: PinsSettings[], context: any) {
41
+ const { device } = params;
42
+ const connection = await this.connect(params, context);
43
+ const result = connection.write(mybuddy.releaseAllServos(device));
44
+ await new Promise((resolve) => setTimeout(resolve, 50));
45
+ connection.close();
46
+ return result;
47
+ }
48
+
49
+ async sendAngle(params: any, _pinsSettingsList: PinsSettings[], context: any) {
50
+ const { device, id, degree, speed = 50 } = params;
51
+ const connection = await this.connect(params, context);
52
+ const result = connection.write(mybuddy.sendAngle(device, id, degree, speed));
53
+ await new Promise((resolve) => setTimeout(resolve, 50));
54
+ connection.close();
55
+ return result;
56
+ }
57
+
58
+ async sendCoord(params: any, _pinsSettingsList: PinsSettings[], context: any) {
59
+ const { device, id, coord, speed = 50 } = params;
60
+ const connection = await this.connect(params, context);
61
+ const result = connection.write(mybuddy.sendCoord(device, id, coord, speed));
62
+ await new Promise((resolve) => setTimeout(resolve, 50));
63
+ connection.close();
64
+ return result;
65
+ }
66
+
67
+ async sendCoords(params: any, _pinsSettingsList: PinsSettings[], context: any) {
68
+ const { device, coords, speed = 50, mode = 0 } = params;
69
+ const connection = await this.connect(params, context);
70
+ const result = connection.write(mybuddy.sendCoords(device, coords, speed, mode));
71
+ await new Promise((resolve) => setTimeout(resolve, 50));
72
+ connection.close();
73
+ return result;
74
+ }
75
+
76
+ async programPause(params: any, _pinsSettingsList: PinsSettings[], context: any) {
77
+ const { device } = params;
78
+ const connection = await this.connect(params, context);
79
+ const result = connection.write(mybuddy.programPause(device));
80
+ await new Promise((resolve) => setTimeout(resolve, 50));
81
+ connection.close();
82
+ return result;
83
+ }
84
+
85
+ async programResume(params: any, _pinsSettingsList: PinsSettings[], context: any) {
86
+ const { device } = params;
87
+ const connection = await this.connect(params, context);
88
+ const result = connection.write(mybuddy.programResume(device));
89
+ await new Promise((resolve) => setTimeout(resolve, 50));
90
+ connection.close();
91
+ return result;
92
+ }
93
+
94
+ async stop(params: any, _pinsSettingsList: PinsSettings[], context: any) {
95
+ const { device } = params;
96
+ const connection = await this.connect(params, context);
97
+ const result = connection.write(mybuddy.stop(device));
98
+ await new Promise((resolve) => setTimeout(resolve, 50));
99
+ connection.close();
100
+ return result;
101
+ }
102
+
103
+ async jogAngle(params: any, _pinsSettingsList: PinsSettings[], context: any) {
104
+ const { device, joint_id, direction, speed } = params;
105
+ const connection = await this.connect(params, context);
106
+ const result = connection.write(mybuddy.jogAngle(device, joint_id, direction, speed));
107
+ await new Promise((resolve) => setTimeout(resolve, 50));
108
+ connection.close();
109
+ return result;
110
+ }
111
+
112
+ async jogCoord(params: any, _pinsSettingsList: PinsSettings[], context: any) {
113
+ const { device, coord_id, direction, speed } = params;
114
+ const connection = await this.connect(params, context);
115
+ const result = connection.write(mybuddy.jogCoord(device, coord_id, direction, speed));
116
+ await new Promise((resolve) => setTimeout(resolve, 50));
117
+ connection.close();
118
+ return result;
119
+ }
120
+
121
+ async jogStop(params: any, _pinsSettingsList: PinsSettings[], context: any) {
122
+ const { device } = params;
123
+ const connection = await this.connect(params, context);
124
+ const result = connection.write(mybuddy.jogStop(device));
125
+ await new Promise((resolve) => setTimeout(resolve, 50));
126
+ connection.close();
127
+ return result;
128
+ }
129
+
130
+ async setEncoder(params: any, _pinsSettingsList: PinsSettings[], context: any) {
131
+ const { device, joint_id, encoder } = params;
132
+ const connection = await this.connect(params, context);
133
+ const result = connection.write(mybuddy.setEncoder(device, joint_id, encoder));
134
+ await new Promise((resolve) => setTimeout(resolve, 50));
135
+ connection.close();
136
+ return result;
137
+ }
138
+
139
+ async setEncoders(params: any, _pinsSettingsList: PinsSettings[], context: any) {
140
+ const { device, encoders, speed } = params;
141
+ const connection = await this.connect(params, context);
142
+ const result = connection.write(mybuddy.setEncoders(device, encoders, speed));
143
+ await new Promise((resolve) => setTimeout(resolve, 50));
144
+ connection.close();
145
+ return result;
146
+ }
147
+
148
+ async setSpeed(params: any, _pinsSettingsList: PinsSettings[], context: any) {
149
+ const { device, speed } = params;
150
+ const connection = await this.connect(params, context);
151
+ const result = connection.write(mybuddy.setSpeed(device, speed));
152
+ await new Promise((resolve) => setTimeout(resolve, 50));
153
+ connection.close();
154
+ return result;
155
+ }
156
+
157
+ async setServoData(params: any, _pinsSettingsList: PinsSettings[], context: any) {
158
+ const { device, servo_no, data_id, value } = params;
159
+ const connection = await this.connect(params, context);
160
+ const result = connection.write(mybuddy.setServoData(device, servo_no, data_id, value));
161
+ await new Promise((resolve) => setTimeout(resolve, 50));
162
+ connection.close();
163
+ return result;
164
+ }
165
+
166
+ async setServoCalibration(params: any, _pinsSettingsList: PinsSettings[], context: any) {
167
+ const { device, servo_no } = params;
168
+ const connection = await this.connect(params, context);
169
+ const result = connection.write(mybuddy.setServoCalibration(device, servo_no));
170
+ await new Promise((resolve) => setTimeout(resolve, 50));
171
+ connection.close();
172
+ return result;
173
+ }
174
+
175
+ async releaseServo(params: any, _pinsSettingsList: PinsSettings[], context: any) {
176
+ const { device, servo_no } = params;
177
+ const connection = await this.connect(params, context);
178
+ const result = connection.write(mybuddy.releaseServo(device, servo_no));
179
+ await new Promise((resolve) => setTimeout(resolve, 50));
180
+ connection.close();
181
+ return result;
182
+ }
183
+
184
+ async focusServo(params: any, _pinsSettingsList: PinsSettings[], context: any) {
185
+ const { device, servo_no } = params;
186
+ const connection = await this.connect(params, context);
187
+ const result = connection.write(mybuddy.focusServo(device, servo_no));
188
+ await new Promise((resolve) => setTimeout(resolve, 50));
189
+ connection.close();
190
+ return result;
191
+ }
192
+
193
+ async setPinMode(params: any, _pinsSettingsList: PinsSettings[], context: any) {
194
+ const { device, pin_no, pin_mode } = params;
195
+ const connection = await this.connect(params, context);
196
+ const result = connection.write(mybuddy.setPinMode(device, pin_no, pin_mode));
197
+ await new Promise((resolve) => setTimeout(resolve, 50));
198
+ connection.close();
199
+ return result;
200
+ }
201
+
202
+ async setDigitalOutput(params: any, _pinsSettingsList: PinsSettings[], context: any) {
203
+ const { device, pin_no, pin_signal } = params;
204
+ const connection = await this.connect(params, context);
205
+ const result = connection.write(mybuddy.setDigitalOutput(device, pin_no, pin_signal));
206
+ await new Promise((resolve) => setTimeout(resolve, 50));
207
+ connection.close();
208
+ return result;
209
+ }
210
+
211
+ async setGripperState(params: any, _pinsSettingsList: PinsSettings[], context: any) {
212
+ const { device, flag, speed } = params;
213
+ const connection = await this.connect(params, context);
214
+ const result = connection.write(mybuddy.setGripperState(device, flag, speed));
215
+ await new Promise((resolve) => setTimeout(resolve, 50));
216
+ connection.close();
217
+ return result;
218
+ }
219
+
220
+ async setGripperValue(params: any, _pinsSettingsList: PinsSettings[], context: any) {
221
+ const { device, value, speed } = params;
222
+ const connection = await this.connect(params, context);
223
+ const result = connection.write(mybuddy.setGripperValue(device, value, speed));
224
+ await new Promise((resolve) => setTimeout(resolve, 50));
225
+ connection.close();
226
+ return result;
227
+ }
228
+
229
+ async setGripperIni(params: any, _pinsSettingsList: PinsSettings[], context: any) {
230
+ const connection = await this.connect(params, context);
231
+ const result = connection.write(mybuddy.setGripperIni());
232
+ await new Promise((resolve) => setTimeout(resolve, 50));
233
+ connection.close();
234
+ return result;
235
+ }
236
+
237
+ async setBasicOutput(params: any, _pinsSettingsList: PinsSettings[], context: any) {
238
+ const { device, pin_no, pin_signal } = params;
239
+ const connection = await this.connect(params, context);
240
+ const result = connection.write(mybuddy.setBasicOutput(device, pin_no, pin_signal));
241
+ await new Promise((resolve) => setTimeout(resolve, 50));
242
+ connection.close();
243
+ return result;
244
+ }
245
+
246
+ async setColor(params: any, _pinsSettingsList: PinsSettings[], context: any) {
247
+ const { device, r, g, b } = params;
248
+ const connection = await this.connect(params, context);
249
+ const result = connection.write(mybuddy.setColor(device, r, g, b));
250
+ await new Promise((resolve) => setTimeout(resolve, 50));
251
+ connection.close();
252
+ return result;
253
+ }
254
+
255
+ // Data Retrieval
256
+ async getAngles(params: any, _pinsSettingsList: PinsSettings[], context: any) {
257
+ const { device } = params;
258
+ const connection = await this.connect(params, context);
259
+
260
+ return new Promise((resolve, reject) => {
261
+ const timeoutId = setTimeout(() => {
262
+ connection.close();
263
+ reject('TIMEOUT_READ_COMMANDS');
264
+ }, TIMEOUT_READ_COMMANDS);
265
+
266
+ connection.on('data', (data: Buffer) => {
267
+ if (
268
+ data[0] === 0xfe &&
269
+ data[1] === 0xfe &&
270
+ data[2] === device &&
271
+ data[4] === parseInt(mybuddy.COMMAND.GET_ANGLES, 16)
272
+ ) {
273
+ clearTimeout(timeoutId);
274
+ const result = mybuddy.processReceived(data);
275
+ connection.close();
276
+ resolve(result);
277
+ }
278
+ });
279
+
280
+ connection.write(mybuddy.getAngles(device));
281
+ });
282
+ }
283
+
284
+ async isPowerOn(params: any, _pinsSettingsList: PinsSettings[], context: any) {
285
+ const { device } = params;
286
+ const connection = await this.connect(params, context);
287
+
288
+ return new Promise((resolve, reject) => {
289
+ const timeoutId = setTimeout(() => {
290
+ connection.close();
291
+ reject('TIMEOUT_READ_COMMANDS');
292
+ }, TIMEOUT_READ_COMMANDS);
293
+
294
+ connection.on('data', (data: Buffer) => {
295
+ if (
296
+ data[0] === 0xfe &&
297
+ data[1] === 0xfe &&
298
+ data[2] === device &&
299
+ data[4] === parseInt(mybuddy.COMMAND.IS_POWER_ON, 16)
300
+ ) {
301
+ clearTimeout(timeoutId);
302
+ const result = mybuddy.processReceived(data);
303
+ connection.close();
304
+ resolve(result);
305
+ }
306
+ });
307
+
308
+ connection.write(mybuddy.isPowerOn(device));
309
+ });
310
+ }
311
+
312
+ async isControllerConnect(params: any, _pinsSettingsList: PinsSettings[], context: any) {
313
+ const { device } = params;
314
+ const connection = await this.connect(params, context);
315
+
316
+ return new Promise((resolve, reject) => {
317
+ const timeoutId = setTimeout(() => {
318
+ connection.close();
319
+ reject('TIMEOUT_READ_COMMANDS');
320
+ }, TIMEOUT_READ_COMMANDS);
321
+
322
+ connection.on('data', (data: Buffer) => {
323
+ if (
324
+ data[0] === 0xfe &&
325
+ data[1] === 0xfe &&
326
+ data[2] === device &&
327
+ data[4] === parseInt(mybuddy.COMMAND.IS_CONTROLLER_CONNECTED, 16)
328
+ ) {
329
+ clearTimeout(timeoutId);
330
+ const result = mybuddy.processReceived(data);
331
+ connection.close();
332
+ resolve(result);
333
+ }
334
+ });
335
+
336
+ connection.write(mybuddy.isControllerConnect());
337
+ });
338
+ }
339
+
340
+ async getCoords(params: any, _pinsSettingsList: PinsSettings[], context: any) {
341
+ const { device } = params;
342
+ const connection = await this.connect(params, context);
343
+
344
+ return new Promise((resolve, reject) => {
345
+ const timeoutId = setTimeout(() => {
346
+ connection.close();
347
+ reject('TIMEOUT_READ_COMMANDS');
348
+ }, TIMEOUT_READ_COMMANDS);
349
+
350
+ connection.on('data', (data: Buffer) => {
351
+ if (
352
+ data[0] === 0xfe &&
353
+ data[1] === 0xfe &&
354
+ data[2] === device &&
355
+ data[4] === parseInt(mybuddy.COMMAND.GET_COORDS, 16)
356
+ ) {
357
+ clearTimeout(timeoutId);
358
+ const result = mybuddy.processReceived(data);
359
+ connection.close();
360
+ resolve(result);
361
+ }
362
+ });
363
+
364
+ connection.write(mybuddy.getCoords(device));
365
+ });
366
+ }
367
+
368
+ async isInPosition(params: any, _pinsSettingsList: PinsSettings[], context: any) {
369
+ const { device, data, flag } = params;
370
+ const connection = await this.connect(params, context);
371
+
372
+ return new Promise((resolve, reject) => {
373
+ const timeoutId = setTimeout(() => {
374
+ connection.close();
375
+ reject('TIMEOUT_READ_COMMANDS');
376
+ }, TIMEOUT_READ_COMMANDS);
377
+
378
+ connection.on('data', (data: Buffer) => {
379
+ if (
380
+ data[0] === 0xfe &&
381
+ data[1] === 0xfe &&
382
+ data[2] === device &&
383
+ data[4] === parseInt(mybuddy.COMMAND.IS_IN_POSITION, 16)
384
+ ) {
385
+ clearTimeout(timeoutId);
386
+ const result = mybuddy.processReceived(data);
387
+ connection.close();
388
+ resolve(result);
389
+ }
390
+ });
391
+
392
+ connection.write(mybuddy.isInPosition(device, data, flag));
393
+ });
394
+ }
395
+
396
+ async getEncoder(params: any, _pinsSettingsList: PinsSettings[], context: any) {
397
+ const { device, joint_id } = params;
398
+ const connection = await this.connect(params, context);
399
+
400
+ return new Promise((resolve, reject) => {
401
+ const timeoutId = setTimeout(() => {
402
+ connection.close();
403
+ reject('TIMEOUT_READ_COMMANDS');
404
+ }, TIMEOUT_READ_COMMANDS);
405
+
406
+ connection.on('data', (data: Buffer) => {
407
+ if (
408
+ data[0] === 0xfe &&
409
+ data[1] === 0xfe &&
410
+ data[2] === device &&
411
+ data[4] === parseInt(mybuddy.COMMAND.GET_ENCODER, 16)
412
+ ) {
413
+ clearTimeout(timeoutId);
414
+ const result = mybuddy.processReceived(data);
415
+ connection.close();
416
+ resolve(result);
417
+ }
418
+ });
419
+
420
+ connection.write(mybuddy.getEncoder(device, joint_id));
421
+ });
422
+ }
423
+
424
+ async getEncoders(params: any, _pinsSettingsList: PinsSettings[], context: any) {
425
+ const { device } = params;
426
+ const connection = await this.connect(params, context);
427
+
428
+ return new Promise((resolve, reject) => {
429
+ const timeoutId = setTimeout(() => {
430
+ connection.close();
431
+ reject('TIMEOUT_READ_COMMANDS');
432
+ }, TIMEOUT_READ_COMMANDS);
433
+
434
+ connection.on('data', (data: Buffer) => {
435
+ if (
436
+ data[0] === 0xfe &&
437
+ data[1] === 0xfe &&
438
+ data[2] === device &&
439
+ data[4] === parseInt(mybuddy.COMMAND.GET_ENCODER, 16)
440
+ ) {
441
+ clearTimeout(timeoutId);
442
+ const result = mybuddy.processReceived(data);
443
+ connection.close();
444
+ resolve(result);
445
+ }
446
+ });
447
+
448
+ connection.write(mybuddy.getEncoders(device));
449
+ });
450
+ }
451
+
452
+ async getSpeed(params: any, _pinsSettingsList: PinsSettings[], context: any) {
453
+ const { device } = params;
454
+ const connection = await this.connect(params, context);
455
+
456
+ return new Promise((resolve, reject) => {
457
+ const timeoutId = setTimeout(() => {
458
+ connection.close();
459
+ reject('TIMEOUT_READ_COMMANDS');
460
+ }, TIMEOUT_READ_COMMANDS);
461
+
462
+ connection.on('data', (data: Buffer) => {
463
+ if (
464
+ data[0] === 0xfe &&
465
+ data[1] === 0xfe &&
466
+ data[2] === device &&
467
+ data[4] === parseInt(mybuddy.COMMAND.GET_SPEED, 16)
468
+ ) {
469
+ clearTimeout(timeoutId);
470
+ const result = mybuddy.processReceived(data);
471
+ connection.close();
472
+ resolve(result);
473
+ }
474
+ });
475
+
476
+ connection.write(mybuddy.getSpeed(device));
477
+ });
478
+ }
479
+
480
+ async getJointMin(params: any, _pinsSettingsList: PinsSettings[], context: any) {
481
+ const { device, joint_id } = params;
482
+ const connection = await this.connect(params, context);
483
+
484
+ return new Promise((resolve, reject) => {
485
+ const timeoutId = setTimeout(() => {
486
+ connection.close();
487
+ reject('TIMEOUT_READ_COMMANDS');
488
+ }, TIMEOUT_READ_COMMANDS);
489
+
490
+ connection.on('data', (data: Buffer) => {
491
+ if (
492
+ data[0] === 0xfe &&
493
+ data[1] === 0xfe &&
494
+ data[2] === device &&
495
+ data[4] === parseInt(mybuddy.COMMAND.GET_JOINT_MIN_ANGLE, 16)
496
+ ) {
497
+ clearTimeout(timeoutId);
498
+ const result = mybuddy.processReceived(data);
499
+ connection.close();
500
+ resolve(result);
501
+ }
502
+ });
503
+
504
+ connection.write(mybuddy.getJointMin(device, joint_id));
505
+ });
506
+ }
507
+
508
+ async getJointMax(params: any, _pinsSettingsList: PinsSettings[], context: any) {
509
+ const { device, joint_id } = params;
510
+ const connection = await this.connect(params, context);
511
+
512
+ return new Promise((resolve, reject) => {
513
+ const timeoutId = setTimeout(() => {
514
+ connection.close();
515
+ reject('TIMEOUT_READ_COMMANDS');
516
+ }, TIMEOUT_READ_COMMANDS);
517
+
518
+ connection.on('data', (data: Buffer) => {
519
+ if (
520
+ data[0] === 0xfe &&
521
+ data[1] === 0xfe &&
522
+ data[2] === device &&
523
+ data[4] === parseInt(mybuddy.COMMAND.GET_JOINT_MAX_ANGLE, 16)
524
+ ) {
525
+ clearTimeout(timeoutId);
526
+ const result = mybuddy.processReceived(data);
527
+ connection.close();
528
+ resolve(result);
529
+ }
530
+ });
531
+
532
+ connection.write(mybuddy.getJointMax(device, joint_id));
533
+ });
534
+ }
535
+
536
+ async isServoEnable(params: any, _pinsSettingsList: PinsSettings[], context: any) {
537
+ const { device, servo_id } = params;
538
+ const connection = await this.connect(params, context);
539
+
540
+ return new Promise((resolve, reject) => {
541
+ const timeoutId = setTimeout(() => {
542
+ connection.close();
543
+ reject('TIMEOUT_READ_COMMANDS');
544
+ }, TIMEOUT_READ_COMMANDS);
545
+
546
+ connection.on('data', (data: Buffer) => {
547
+ if (
548
+ data[0] === 0xfe &&
549
+ data[1] === 0xfe &&
550
+ data[2] === device &&
551
+ data[4] === parseInt(mybuddy.COMMAND.IS_SERVO_ENABLE, 16)
552
+ ) {
553
+ clearTimeout(timeoutId);
554
+ const result = mybuddy.processReceived(data);
555
+ connection.close();
556
+ resolve(result);
557
+ }
558
+ });
559
+
560
+ connection.write(mybuddy.isServoEnable(device, servo_id));
561
+ });
562
+ }
563
+
564
+ async isAllServoEnable(params: any, _pinsSettingsList: PinsSettings[], context: any) {
565
+ const { device } = params;
566
+ const connection = await this.connect(params, context);
567
+
568
+ return new Promise((resolve, reject) => {
569
+ const timeoutId = setTimeout(() => {
570
+ connection.close();
571
+ reject('TIMEOUT_READ_COMMANDS');
572
+ }, TIMEOUT_READ_COMMANDS);
573
+
574
+ connection.on('data', (data: Buffer) => {
575
+ if (
576
+ data[0] === 0xfe &&
577
+ data[1] === 0xfe &&
578
+ data[2] === device &&
579
+ data[4] === parseInt(mybuddy.COMMAND.IS_ALL_SERVO_ENABLE, 16)
580
+ ) {
581
+ clearTimeout(timeoutId);
582
+ const result = mybuddy.processReceived(data);
583
+ connection.close();
584
+ resolve(result);
585
+ }
586
+ });
587
+
588
+ connection.write(mybuddy.isAllServoEnable(device));
589
+ });
590
+ }
591
+
592
+ async getServodata(params: any, _pinsSettingsList: PinsSettings[], context: any) {
593
+ const { device, servo_no, data_id } = params;
594
+ const connection = await this.connect(params, context);
595
+
596
+ return new Promise((resolve, reject) => {
597
+ const timeoutId = setTimeout(() => {
598
+ connection.close();
599
+ reject('TIMEOUT_READ_COMMANDS');
600
+ }, TIMEOUT_READ_COMMANDS);
601
+
602
+ connection.on('data', (data: Buffer) => {
603
+ if (
604
+ data[0] === 0xfe &&
605
+ data[1] === 0xfe &&
606
+ data[2] === device &&
607
+ data[4] === parseInt(mybuddy.COMMAND.GET_SERVO_DATA, 16)
608
+ ) {
609
+ clearTimeout(timeoutId);
610
+ const result = mybuddy.processReceived(data);
611
+ connection.close();
612
+ resolve(result);
613
+ }
614
+ });
615
+
616
+ connection.write(mybuddy.getServodata(device, servo_no, data_id));
617
+ });
618
+ }
619
+
620
+ async getDigitalInput(params: any, _pinsSettingsList: PinsSettings[], context: any) {
621
+ const { device, pin_no } = params;
622
+ const connection = await this.connect(params, context);
623
+
624
+ return new Promise((resolve, reject) => {
625
+ const timeoutId = setTimeout(() => {
626
+ connection.close();
627
+ reject('TIMEOUT_READ_COMMANDS');
628
+ }, TIMEOUT_READ_COMMANDS);
629
+
630
+ connection.on('data', (data: Buffer) => {
631
+ if (
632
+ data[0] === 0xfe &&
633
+ data[1] === 0xfe &&
634
+ data[2] === device &&
635
+ data[4] === parseInt(mybuddy.COMMAND.GET_DIGITAL_INPUT, 16)
636
+ ) {
637
+ clearTimeout(timeoutId);
638
+ const result = mybuddy.processReceived(data);
639
+ connection.close();
640
+ resolve(result);
641
+ }
642
+ });
643
+
644
+ connection.write(mybuddy.getDigitalInput(device, pin_no));
645
+ });
646
+ }
647
+
648
+ async getGripperValue(params: any, _pinsSettingsList: PinsSettings[], context: any) {
649
+ const { device } = params;
650
+ const connection = await this.connect(params, context);
651
+
652
+ return new Promise((resolve, reject) => {
653
+ const timeoutId = setTimeout(() => {
654
+ connection.close();
655
+ reject('TIMEOUT_READ_COMMANDS');
656
+ }, TIMEOUT_READ_COMMANDS);
657
+
658
+ connection.on('data', (data: Buffer) => {
659
+ if (
660
+ data[0] === 0xfe &&
661
+ data[1] === 0xfe &&
662
+ data[2] === device &&
663
+ data[4] === parseInt(mybuddy.COMMAND.GET_GRIPPER_VALUE, 16)
664
+ ) {
665
+ clearTimeout(timeoutId);
666
+ const result = mybuddy.processReceived(data);
667
+ connection.close();
668
+ resolve(result);
669
+ }
670
+ });
671
+
672
+ connection.write(mybuddy.getGripperValue(device));
673
+ });
674
+ }
675
+
676
+ async getBasicOutput(params: any, _pinsSettingsList: PinsSettings[], context: any) {
677
+ const { device, pin_no } = params;
678
+ const connection = await this.connect(params, context);
679
+
680
+ return new Promise((resolve, reject) => {
681
+ const timeoutId = setTimeout(() => {
682
+ connection.close();
683
+ reject('TIMEOUT_READ_COMMANDS');
684
+ }, TIMEOUT_READ_COMMANDS);
685
+
686
+ connection.on('data', (data: Buffer) => {
687
+ if (
688
+ data[0] === 0xfe &&
689
+ data[1] === 0xfe &&
690
+ data[2] === device &&
691
+ data[4] === parseInt(mybuddy.COMMAND.GET_BASIC_INPUT, 16)
692
+ ) {
693
+ clearTimeout(timeoutId);
694
+ const result = mybuddy.processReceived(data);
695
+ connection.close();
696
+ resolve(result);
697
+ }
698
+ });
699
+
700
+ connection.write(mybuddy.getBasicOutput(device, pin_no));
701
+ });
702
+ }
703
+
704
+ async isGripperMoving(params: any, _pinsSettingsList: PinsSettings[], context: any) {
705
+ const { device } = params;
706
+ const connection = await this.connect(params, context);
707
+
708
+ return new Promise((resolve, reject) => {
709
+ const timeoutId = setTimeout(() => {
710
+ connection.close();
711
+ reject('TIMEOUT_READ_COMMANDS');
712
+ }, TIMEOUT_READ_COMMANDS);
713
+
714
+ connection.on('data', (data: Buffer) => {
715
+ if (
716
+ data[0] === 0xfe &&
717
+ data[1] === 0xfe &&
718
+ data[2] === device &&
719
+ data[4] === parseInt(mybuddy.COMMAND.IS_GRIPPER_MOVING, 16)
720
+ ) {
721
+ clearTimeout(timeoutId);
722
+ const result = mybuddy.processReceived(data);
723
+ connection.close();
724
+ resolve(result);
725
+ }
726
+ });
727
+
728
+ connection.write(mybuddy.isGripperMoving(device));
729
+ });
730
+ }
731
+
732
+ // TOOLS
733
+ async sleep(params: any, _pinsSettingsList: PinsSettings[], context: any) {
734
+ const { time } = params;
735
+
736
+ await new Promise(resolve => setTimeout(resolve, time * 1000));
737
+
738
+ return context.previous;
739
+ }
740
+ }
741
+
742
+ export const sendAngles = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
743
+ new MyBuddyService().sendAngles(params, pinsSettingsList, context);
744
+
745
+ export const getAngles = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
746
+ new MyBuddyService().getAngles(params, pinsSettingsList, context);
747
+
748
+ // Add other export functions for actions and data retrieval methods
749
+ export const powerOn = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
750
+ new MyBuddyService().powerOn(params, pinsSettingsList, context);
751
+
752
+ export const powerOff = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
753
+ new MyBuddyService().powerOff(params, pinsSettingsList, context);
754
+
755
+ export const releaseAllServos = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
756
+ new MyBuddyService().releaseAllServos(params, pinsSettingsList, context);
757
+
758
+ export const sendAngle = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
759
+ new MyBuddyService().sendAngle(params, pinsSettingsList, context);
760
+
761
+ export const sendCoord = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
762
+ new MyBuddyService().sendCoord(params, pinsSettingsList, context);
763
+
764
+ export const sendCoords = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
765
+ new MyBuddyService().sendCoords(params, pinsSettingsList, context);
766
+
767
+ export const programPause = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
768
+ new MyBuddyService().programPause(params, pinsSettingsList, context);
769
+
770
+ export const programResume = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
771
+ new MyBuddyService().programResume(params, pinsSettingsList, context);
772
+
773
+ export const stop = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
774
+ new MyBuddyService().stop(params, pinsSettingsList, context);
775
+
776
+ export const jogAngle = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
777
+ new MyBuddyService().jogAngle(params, pinsSettingsList, context);
778
+
779
+ export const jogCoord = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
780
+ new MyBuddyService().jogCoord(params, pinsSettingsList, context);
781
+
782
+ export const jogStop = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
783
+ new MyBuddyService().jogStop(params, pinsSettingsList, context);
784
+
785
+ export const setEncoder = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
786
+ new MyBuddyService().setEncoder(params, pinsSettingsList, context);
787
+
788
+ export const setEncoders = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
789
+ new MyBuddyService().setEncoders(params, pinsSettingsList, context);
790
+
791
+ export const setSpeed = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
792
+ new MyBuddyService().setSpeed(params, pinsSettingsList, context);
793
+
794
+ export const setServoData = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
795
+ new MyBuddyService().setServoData(params, pinsSettingsList, context);
796
+
797
+ export const setServoCalibration = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
798
+ new MyBuddyService().setServoCalibration(params, pinsSettingsList, context);
799
+
800
+ export const releaseServo = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
801
+ new MyBuddyService().releaseServo(params, pinsSettingsList, context);
802
+
803
+ export const focusServo = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
804
+ new MyBuddyService().focusServo(params, pinsSettingsList, context);
805
+
806
+ export const setPinMode = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
807
+ new MyBuddyService().setPinMode(params, pinsSettingsList, context);
808
+
809
+ export const setDigitalOutput = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
810
+ new MyBuddyService().setDigitalOutput(params, pinsSettingsList, context);
811
+
812
+ export const setGripperState = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
813
+ new MyBuddyService().setGripperState(params, pinsSettingsList, context);
814
+
815
+ export const setGripperValue = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
816
+ new MyBuddyService().setGripperValue(params, pinsSettingsList, context);
817
+
818
+ export const setGripperIni = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
819
+ new MyBuddyService().setGripperIni(params, pinsSettingsList, context);
820
+
821
+ export const setBasicOutput = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
822
+ new MyBuddyService().setBasicOutput(params, pinsSettingsList, context);
823
+
824
+ export const setColor = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
825
+ new MyBuddyService().setColor(params, pinsSettingsList, context);
826
+
827
+ export const isPowerOn = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
828
+ new MyBuddyService().isPowerOn(params, pinsSettingsList, context);
829
+
830
+ export const isControllerConnect = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
831
+ new MyBuddyService().isControllerConnect(params, pinsSettingsList, context);
832
+
833
+ export const getCoords = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
834
+ new MyBuddyService().getCoords(params, pinsSettingsList, context);
835
+
836
+ export const isInPosition = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
837
+ new MyBuddyService().isInPosition(params, pinsSettingsList, context);
838
+
839
+ export const getEncoder = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
840
+ new MyBuddyService().getEncoder(params, pinsSettingsList, context);
841
+
842
+ export const getEncoders = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
843
+ new MyBuddyService().getEncoders(params, pinsSettingsList, context);
844
+
845
+ export const getSpeed = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
846
+ new MyBuddyService().getSpeed(params, pinsSettingsList, context);
847
+
848
+ export const getJointMin = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
849
+ new MyBuddyService().getJointMin(params, pinsSettingsList, context);
850
+
851
+ export const getJointMax = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
852
+ new MyBuddyService().getJointMax(params, pinsSettingsList, context);
853
+
854
+ export const isServoEnable = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
855
+ new MyBuddyService().isServoEnable(params, pinsSettingsList, context);
856
+
857
+ export const isAllServoEnable = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
858
+ new MyBuddyService().isAllServoEnable(params, pinsSettingsList, context);
859
+
860
+ export const getServodata = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
861
+ new MyBuddyService().getServodata(params, pinsSettingsList, context);
862
+
863
+ export const getDigitalInput = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
864
+ new MyBuddyService().getDigitalInput(params, pinsSettingsList, context);
865
+
866
+ export const getGripperValue = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
867
+ new MyBuddyService().getGripperValue(params, pinsSettingsList, context);
868
+
869
+ export const getBasicOutput = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
870
+ new MyBuddyService().getBasicOutput(params, pinsSettingsList, context);
871
+
872
+ export const isGripperMoving = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
873
+ new MyBuddyService().isGripperMoving(params, pinsSettingsList, context);
874
+
875
+ export const sleep = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
876
+ new MyBuddyService().sleep(params, pinsSettingsList, context);