-
Notifications
You must be signed in to change notification settings - Fork 5
/
X_Limb_Hand_Control.ino
490 lines (382 loc) · 13.5 KB
/
X_Limb_Hand_Control.ino
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
/* This code is developed for control of six DC motors using the custom designed PCB (Arduino Mega compatible) */
/* In the designed X-Limb hand only 5 motors are used for individual actuation of five fingers of the hand. */
#define STATUS_LED 53
//motors
#define ENABLE 38 // enable/disbale all motors
#define MOTOR_A 1
#define MOTOR_B 2
#define MOTOR_C 3
#define MOTOR_D 4
#define MOTOR_E 5
#define MOTOR_F 6
// Motor A Control
#define POTA A3 // Potentiometer A
#define FBA A0 // Current feedback for the motor A
#define PWMA 7 // Speed control A
#define D2A 11 // enbale(HIGH)/disbale(LOW) for motor A
#define DIRA 12 // Directions for motor A
// Motor B Control
#define POTB A2 // Potentiometer B
#define FBB A1 // Current feedback for the motor B
#define PWMB 4 // Speed control B
#define D2B 8 // enbale(HIGH)/disbale(LOW) for motor B
#define DIRB 9 // Directions for motor B
// Motor C Control
#define POTC A7 // Potentiometer C
#define FBC A13 // Current feedback for the motor C
#define PWMC 5 // Speed control C
#define D2C 39 // enbale(HIGH)/disbale(LOW) for motor C
#define DIRC 29 // Directions for motor C
// Motor D Control
#define POTD A8 // Potentiometer D
#define FBD A14 // Current feedback for the motor D
#define PWMD 2 // Speed control D
#define D2D 25 // enbale(HIGH)/disbale(LOW) for motor D
#define DIRD 26 // Directions for motor D
// Motor E Control
#define POTE A10 // Potentiometer E
#define FBE A12 // Current feedback for the motor E
#define PWME 3 // Speed control E
#define D2E 37 // enbale(HIGH)/disbale(LOW) for motor E
#define DIRE 36 // Directions for motor E
// Motor F Control
#define POTF A9 // Potentiometer F
#define FBF A11 // Current feedback for the motor F
#define PWMF 6 // Speed control F
#define D2F 19 // enbale(HIGH)/disbale(LOW) for motor F
#define DIRF 18 // Directions for motor F
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(STATUS_LED, OUTPUT);
pinMode(ENABLE, OUTPUT);
digitalWrite(ENABLE, LOW); // Disable all motors
pinMode(D2C, OUTPUT);
pinMode(DIRC, OUTPUT);
pinMode(FBC, INPUT);
pinMode(PWMC, OUTPUT); // setPwmFrequency2560(PWMC, 1);
// Enables
pinMode(D2A, OUTPUT);
pinMode(D2B, OUTPUT);
pinMode(D2C, OUTPUT);
pinMode(D2D, OUTPUT);
pinMode(D2E, OUTPUT);
pinMode(D2F, OUTPUT);
// Enables value
digitalWrite(D2A, HIGH);
digitalWrite(D2B, HIGH);
digitalWrite(D2C, HIGH);
digitalWrite(D2D, HIGH);
digitalWrite(D2E, HIGH);
digitalWrite(D2F, HIGH);
// Directions
pinMode(DIRA, OUTPUT);
pinMode(DIRB, OUTPUT);
pinMode(DIRC, OUTPUT);
pinMode(DIRD, OUTPUT);
pinMode(DIRE, OUTPUT);
pinMode(DIRF, OUTPUT);
// Directions value
digitalWrite(DIRA, HIGH);
digitalWrite(DIRB, LOW);
digitalWrite(DIRC, LOW);
digitalWrite(DIRD, HIGH);
digitalWrite(DIRE, HIGH);
digitalWrite(DIRF, LOW);
// PWM
pinMode(PWMA, OUTPUT); // setPwmFrequency2560(PWMC, 1);
pinMode(PWMB, OUTPUT); // setPwmFrequency2560(PWMC, 1);
pinMode(PWMC, OUTPUT); // setPwmFrequency2560(PWMC, 1);
pinMode(PWMD, OUTPUT); // setPwmFrequency2560(PWMC, 1);
pinMode(PWME, OUTPUT); // setPwmFrequency2560(PWMC, 1);
pinMode(PWMF, OUTPUT); // setPwmFrequency2560(PWMC, 1);
// PWM value
analogWrite(PWMA, 0);
analogWrite(PWMB, 0);
analogWrite(PWMC, 0);
analogWrite(PWMD, 0);
analogWrite(PWME, 0);
analogWrite(PWMF, 0);
// Current feedback
pinMode(FBA, INPUT);
pinMode(FBB, INPUT);
pinMode(FBC, INPUT);
pinMode(FBD, INPUT);
pinMode(FBE, INPUT);
pinMode(FBF, INPUT);
// Position feedback
pinMode(POTA, INPUT);
pinMode(POTB, INPUT);
pinMode(POTC, INPUT);
pinMode(POTD, INPUT);
pinMode(POTE, INPUT);
pinMode(POTF, INPUT);
digitalWrite(ENABLE, HIGH);
}
unsigned int CommandCloseOpen; // Closing/Opening the hand
unsigned int CommandGraspType; // Switching to the desired grip
// Variables for potentiometer values
unsigned int PotA;
unsigned int PotB;
unsigned int PotC;
unsigned int PotD;
unsigned int PotE;
unsigned int PotF;
// Variables for motor current values
unsigned int CurrentA;
unsigned int CurrentB;
unsigned int CurrentC;
unsigned int CurrentD;
unsigned int CurrentE;
unsigned int CurrentF;
// Variables for motors opening and closing speed
unsigned int speedA_Close=90; unsigned int speedA_Open=80;
unsigned int speedB_Close=100; unsigned int speedB_Open=90;
unsigned int speedC_Close=50; unsigned int speedC_Open=40;
unsigned int speedD_Close=0; unsigned int speedD_Open=0;
unsigned int speedE_Close=90; unsigned int speedE_Open=80;
unsigned int speedF_Close=100; unsigned int speedF_Open=90;
// Zero motor speeds
//unsigned int speedA_Close=0; unsigned int speedA_Open=0;
//unsigned int speedB_Close=100; unsigned int speedB_Open=90;
//unsigned int speedC_Close=0; unsigned int speedC_Open=0;
//unsigned int speedD_Close=0; unsigned int speedD_Open=0;
//unsigned int speedE_Close=100; unsigned int speedE_Open=90;
//unsigned int speedF_Close=0; unsigned int speedF_Open=0;
// Grasp type
unsigned int Type=1;
void loop() {
// Reading potentimeter values
PotA = analogRead(A3); Serial.print(" PotA: "); Serial.println(PotA);
PotB = analogRead(A2); Serial.print(" PotB: "); Serial.println(PotB);
PotC = analogRead(A7); Serial.print(" PotC: "); Serial.println(PotC);
// PotD = analogRead(A8); Serial.print(" PotD: "); Serial.println(PotD);
PotE = analogRead(A10); Serial.print(" PotE: "); Serial.println(PotE);
PotF = analogRead(A11); Serial.print("PotF: "); Serial.println(PotF);
// Reading current values
// CurrentA=analogRead(A0); Serial.print("CurrentA: "); Serial.println(CurrentA);
// CurrentB=analogRead(A1); Serial.print("CurrentB: "); Serial.println(CurrentB);
// CurrentC=analogRead(A13); Serial.print("CurrentC: "); Serial.println(CurrentC);
// CurrentD=analogRead(A14); Serial.print("CurrentD: "); Serial.println(CurrentD);
// CurrentE=analogRead(A12); Serial.print("CurrentE: "); Serial.println(CurrentE);
// CurrentF=analogRead(A11); Serial.print("CurrentF: "); Serial.println(CurrentF);
CommandCloseOpen = analogRead(A4);
CommandGraspType = analogRead(A5);
Serial.print("CommandCloseOpen: "); Serial.print(CommandCloseOpen);
Serial.print(" CommandGraspType: "); Serial.print(CommandGraspType);
if (CommandGraspType<100){
delay(600);
Type=Type+1;
if (Type>3){
Type=3;
}
}
if (CommandGraspType>1000){
delay(600);
Type=Type-1;
if (Type<1){
Type=1;
}
}
Serial.print(" GraspType: "); Serial.print(Type);
//Type=3;
//************* Pinch Grasp ****************//
if (Type==1) {
PotA = analogRead(A3); PotB = analogRead(A2); PotC = analogRead(A7); PotE = analogRead(A10); PotF = analogRead(A11);
// Close Fingers
if (CommandCloseOpen<100){
// Thumb
if (PotE<750){
digitalWrite(DIRE, HIGH);
analogWrite(PWME, map(speedE_Close, 0, 100, 0, 255));}
else{
analogWrite(PWME, map(0, 0, 100, 0, 255));}
// Index
if (PotA<800){
if (PotE>650){
digitalWrite(DIRA, HIGH);
analogWrite(PWMA, map(speedA_Close, 0, 100, 0, 255));}}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));}
}
else if(CommandCloseOpen>1000){
// Thumb
if (PotE>250){
if (POTA<200){
digitalWrite(DIRE, LOW);
analogWrite(PWME, map(speedE_Open, 0, 100, 0, 255));}}
else{
analogWrite(PWME, map(0, 0, 100, 0, 255));}
// Index
if (PotA>100){
digitalWrite(DIRA, LOW);
analogWrite(PWMA, map(speedA_Open, 0, 100, 0, 255));}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));}
}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));
analogWrite(PWMB, map(0, 0, 100, 0, 255));
analogWrite(PWMC, map(0, 0, 100, 0, 255));
analogWrite(PWMD, map(0, 0, 100, 0, 255));
analogWrite(PWME, map(0, 0, 100, 0, 255));
analogWrite(PWMF, map(0, 0, 100, 0, 255));}
}
//************* Tripod Grasp ****************//
if (Type==2) {
PotA = analogRead(A3); PotB = analogRead(A2); PotC = analogRead(A7); PotE = analogRead(A10); PotF = analogRead(A11);
// Close Fingers
if (CommandCloseOpen<100){
// Thumb
if (PotE<800){
digitalWrite(DIRE, HIGH);
analogWrite(PWME, map(speedE_Close, 0, 100, 0, 255));}
else{
analogWrite(PWME, map(0, 0, 100, 0, 255));}
// Index
if (PotA<980){
if (PotE>600){
digitalWrite(DIRA, HIGH);
analogWrite(PWMA, map(speedA_Close, 0, 100, 0, 255));}}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));}
// Middle
if (PotB>500){
if (PotE>600){
digitalWrite(DIRB, LOW);
analogWrite(PWMB, map(speedB_Close, 0, 100, 0, 255));}}
else{
analogWrite(PWMB, map(0, 0, 100, 0, 255));}
// Ring
if (PotF>400){
digitalWrite(DIRF, LOW);
analogWrite(PWMF, map(speedF_Close, 0, 100, 0, 255));}
else{
analogWrite(PWMF, map(0, 0, 100, 0, 255));}
// Little
if (PotC>200){
digitalWrite(DIRC, LOW);
analogWrite(PWMC, map(speedC_Close, 0, 100, 0, 255));}
else{
analogWrite(PWMC, map(0, 0, 100, 0, 255));}
}
else if(CommandCloseOpen>1000){
// Thumb
if (PotE>100){
if (POTA<200){
digitalWrite(DIRE, LOW);
analogWrite(PWME, map(speedE_Open, 0, 100, 0, 255));}}
else{
analogWrite(PWME, map(0, 0, 100, 0, 255));}
// Index
if (PotA>150){
digitalWrite(DIRA, LOW);
analogWrite(PWMA, map(speedA_Open, 0, 100, 0, 255));}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));}
// Middle
if (PotB<960){
digitalWrite(DIRB, HIGH);
analogWrite(PWMB, map(speedB_Open, 0, 100, 0, 255));}
else{
analogWrite(PWMB, map(0, 0, 100, 0, 255));}
// Ring
if (PotF<980){
if (POTA<200){
digitalWrite(DIRF, HIGH);
analogWrite(PWMF, map(speedF_Open, 0, 100, 0, 255));}}
else{
analogWrite(PWMF, map(0, 0, 100, 0, 255));}
// Little
if (PotC<790){
if (POTA<200){
digitalWrite(DIRC, HIGH);
analogWrite(PWMC, map(speedC_Open, 0, 100, 0, 255));}}
else{
analogWrite(PWMC, map(0, 0, 100, 0, 255));}
}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));
analogWrite(PWMB, map(0, 0, 100, 0, 255));
analogWrite(PWMC, map(0, 0, 100, 0, 255));
analogWrite(PWMD, map(0, 0, 100, 0, 255));
analogWrite(PWME, map(0, 0, 100, 0, 255));
analogWrite(PWMF, map(0, 0, 100, 0, 255));}
}
//************* Power Grasp ****************//
if (Type==3) {
PotA = analogRead(A3); PotB = analogRead(A2); PotC = analogRead(A7); PotE = analogRead(A10); PotF = analogRead(A11);
// Close Fingers
if (CommandCloseOpen<100){
// Thumb
if (PotE<750){
digitalWrite(DIRE, HIGH);
analogWrite(PWME, map(speedE_Close, 0, 100, 0, 255));}
else{
analogWrite(PWME, map(0, 0, 100, 0, 255));}
// Index
if (PotA<800){
digitalWrite(DIRA, HIGH);
analogWrite(PWMA, map(speedA_Close, 0, 100, 0, 255));}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));}
// Little
if (PotC>200){
digitalWrite(DIRC, LOW);
analogWrite(PWMC, map(speedC_Close, 0, 100, 0, 255));}
else{
analogWrite(PWMC, map(0, 0, 100, 0, 255));}
// Middle
if (PotB>100){
digitalWrite(DIRB, LOW);
analogWrite(PWMB, map(speedB_Close, 0, 100, 0, 255));}
else{
analogWrite(PWMB, map(0, 0, 100, 0, 255));}
// Ring
if (PotF>300){
digitalWrite(DIRF, LOW);
analogWrite(PWMF, map(speedF_Close, 0, 100, 0, 255));}
else{
analogWrite(PWMF, map(0, 0, 100, 0, 255));}
}
else if(CommandCloseOpen>1000){
// Thumb
if (PotE>250){
digitalWrite(DIRE, LOW);
analogWrite(PWME, map(speedE_Open, 0, 100, 0, 255));}
else{
analogWrite(PWME, map(0, 0, 100, 0, 255));}
// Index
if (PotA>150){
digitalWrite(DIRA, LOW);
analogWrite(PWMA, map(speedA_Open, 0, 100, 0, 255));}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));}
// Little
if (PotC<790){
digitalWrite(DIRC, HIGH);
analogWrite(PWMC, map(speedC_Open, 0, 100, 0, 255));}
else{
analogWrite(PWMC, map(0, 0, 100, 0, 255));}
// Middle
if (PotB<960){
digitalWrite(DIRB, HIGH);
analogWrite(PWMB, map(speedB_Open, 0, 100, 0, 255));}
else{
analogWrite(PWMB, map(0, 0, 100, 0, 255));}
// Ring
if (PotF<980){
digitalWrite(DIRF, HIGH);
analogWrite(PWMF, map(speedF_Open, 0, 100, 0, 255));}
else{
analogWrite(PWMF, map(0, 0, 100, 0, 255));}
}
else{
analogWrite(PWMA, map(0, 0, 100, 0, 255));
analogWrite(PWMB, map(0, 0, 100, 0, 255));
analogWrite(PWMC, map(0, 0, 100, 0, 255));
analogWrite(PWMD, map(0, 0, 100, 0, 255));
analogWrite(PWME, map(0, 0, 100, 0, 255));
analogWrite(PWMF, map(0, 0, 100, 0, 255));}
}
} // void loop