Hello everyone,
We are working on a project that is Exoskeleton hand using EMG sensors, so the Exoskeleton hand has only one servo which is connected to a shaft and that shaft transfer the torque to the gear onto the shaft for each finger in order to fully close and open the fingers simultaneously with the rotation of the servo once the values read from the EMG sensor values goes above or below threshold.
Now the problem we are facing is that we want to precisely control the rotation of the servo, that the initial position of the servo motor needs to be 135 degrees, and it does a full rotation in clockwise direction to close the hand and then goes back to the initial position.
The code which we have developed is that we made modifications to the SWEEP test code to fit our application but the issue is that servo motor moves way to back and rotates more than the specified angles and it doesn't rotate completely or you can say apply enough force to close the hand.
Here is the code that we are using any help will be appreciated
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 135; // variable to store the servo position
int sensorPin = A0; // define the sensor pin 'Analog Pin 3'
#define sensorThreshold 220 // define the threshold of the value from the sensor
void setup() {
Serial.begin(115200); // starting serial communication to define threshold by reading values from sensor
myservo.attach(3); // attaches the servo on pin 9 to the servo object
}
void loop() {
int sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if(sensorValue< sensorThreshold){
for (pos = 135; pos <= 180; pos += 1) { // goes from 135 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
// waits 15ms for the servo to reach the position
}
else if(sensorValue >sensorThreshold)
for (pos =180; pos>= 135; pos -= 1) { // goes from 180 degrees to 135 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
}