Skip to content

Commit 8b1b582

Browse files
committed
realse all fingers at same time
1 parent dc51f6a commit 8b1b582

File tree

4 files changed

+124
-46
lines changed

4 files changed

+124
-46
lines changed

Bluetooth-Arduino-Prosthetic-Control.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void setup() {
6767

6868
handServos.setupServos();
6969

70-
BLEDevice::init("Brunel Hand");
70+
BLEDevice::init("Brunel Hand Right");
7171
BLEServer *pServer = BLEDevice::createServer();
7272
pServer->setCallbacks(new OnConnectCallback());
7373

@@ -162,7 +162,7 @@ void updateCounter() {
162162
if (buttonState == LOW) {
163163
holdTime = millis() - startPressed;
164164
if (holdTime >= 1100) {
165-
handServos.moveServos2("0,180,180,180");
165+
handServos.openFingers();
166166
}
167167
} else {
168168
idleTime = millis() - endPressed;

HandServo.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "Arduino.h"
2+
#include "HandServo.h"
3+
4+
HandServo::HandServo(int interval)
5+
{
6+
updateInterval = interval;
7+
increment = 1;
8+
}
9+
10+
void HandServo::setupServo(int pin) {
11+
servo.attach(pin);
12+
}
13+
14+
void HandServo::moveServo() {
15+
if((millis() - lastUpdate) > updateInterval) // time to update
16+
{
17+
lastUpdate = millis();
18+
pos += increment;
19+
servo.write(pos);
20+
21+
if ((pos >= 180) || (pos <= 0)) // end of sweep
22+
{
23+
// reverse direction
24+
increment = -increment;
25+
}
26+
}
27+
28+
// if((millis() - lastUpdate) > updateInterval) {
29+
// lastUpdate = millis();
30+
// Serial.println("move");
31+
// if (lastPos > newPos) {
32+
// for (int i = lastPos; i > newPos; i--) {
33+
// servo.write(i);
34+
// lastPos = servo.read();
35+
// delay(15);
36+
// }
37+
// } else if (lastPos < newPos) {
38+
// for (int i = lastPos; i < newPos; i++) {
39+
// servo.write(i);
40+
// lastPos = servo.read();
41+
// delay(15);
42+
// }
43+
// }
44+
// }
45+
}
46+
47+
void HandServo::calibrate() {
48+
int pos = lastPos;
49+
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
50+
// in steps of 1 degree
51+
servo.write(pos);
52+
delay(15); // waits 15ms for the servo to reach the position
53+
}
54+
lastPos = servo.read();
55+
}

HandServo.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef HandServo_h
2+
#define HandServo_h
3+
4+
#include "Arduino.h"
5+
#include <ESP32Servo.h>
6+
7+
class HandServo
8+
{
9+
public:
10+
HandServo(int);
11+
Servo servo;
12+
void setupServo(int pin);
13+
void moveServo();
14+
void calibrate();
15+
int updateInterval; // interval between updates
16+
int increment = 1; // increment to move for each interval
17+
18+
private:
19+
int pin;
20+
unsigned long lastUpdate; // last update of position
21+
int pos; // current servo position
22+
int interval;
23+
int lastPos = 0;
24+
};
25+
26+
#endif

HandServos.cpp

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -70,50 +70,6 @@ void HandServos::openThumb() {
7070
lastPosT = servoT.read();
7171
}
7272

73-
void HandServos::openFingers() {
74-
if (lastPosI < 180) {
75-
for (int i = lastPosI; i <= 180; i += 1) {
76-
// in steps of 1 degree
77-
Serial.println(i);
78-
servoI.write(i);
79-
lastPosI = i;
80-
Serial.println(i);
81-
delay(15);
82-
}
83-
} else {
84-
lastPosI = 0;
85-
}
86-
87-
if (lastPosM < 180) {
88-
for (int i = lastPosM; i <= 180; i += 1) {
89-
// in steps of 1 degree
90-
Serial.println(i);
91-
servoM.write(i);
92-
lastPosM = i;
93-
Serial.println(i);
94-
delay(15);
95-
}
96-
} else {
97-
lastPosM = 0;
98-
}
99-
100-
if (lastPosR < 180) {
101-
for (int i = lastPosR; i <= 180; i += 1) {
102-
// in steps of 1 degree
103-
Serial.println(i);
104-
servoR.write(i);
105-
lastPosR = i;
106-
Serial.println(i);
107-
delay(15);
108-
}
109-
} else {
110-
lastPosR = 0;
111-
}
112-
lastPosI = servoI.read();
113-
lastPosM = servoM.read();
114-
lastPosR = servoR.read();
115-
}
116-
11773
void HandServos::calibrate() {
11874
int pos = startPosI;
11975
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
@@ -273,3 +229,44 @@ void HandServos::moveServos2(String input) {
273229
}
274230
}
275231
}
232+
233+
void HandServos::openFingers() {
234+
Serial.println("opening");
235+
int angleT = servoT.read();
236+
int angleI = servoI.read();
237+
int angleM = servoM.read();
238+
int angleR = servoR.read();
239+
240+
int angleStep = 10;
241+
242+
angleT = angleT - angleStep;
243+
angleI = angleI + angleStep;
244+
angleM = angleM + angleStep;
245+
angleR = angleR + angleStep;
246+
247+
if (angleT <= 0) {
248+
angleT = 0;
249+
}
250+
251+
if (angleI >= 180) {
252+
angleI = 180;
253+
}
254+
255+
if (angleM >= 180) {
256+
angleM = 180;
257+
}
258+
259+
if (angleR >= 180) {
260+
angleR = 180;
261+
}
262+
263+
servoT.write(angleT); // move the servo to desired angle
264+
servoI.write(angleI); // move the servo to desired angle
265+
servoM.write(angleM); // move the servo to desired angle
266+
servoR.write(angleR); // move the servo to desired angle
267+
268+
lastPosT = servoT.read();
269+
lastPosI = servoI.read();
270+
lastPosM = servoM.read();
271+
lastPosR = servoR.read();
272+
}

0 commit comments

Comments
 (0)