Feb 07, 2018
Gerardo Ramos
The last time I wrote a post for this project, I didn't post the codes that I was using for the arm and glove. The codes that I last used were the codes I used to control the hand without the servo shield from Adafruit. This can help you save you little bit of money by not having to buy that shield
Also, this codes seems to be much easier to understand and to calibrate the ranges for the flex sensors.
So the code for the glove is as follows:
// This will be the code for the glove. I got parts from two different existting glove codes.
// One from Garbry295 on Instuctables and the other from dschurman from
// instructables as well.
int flexpinky = A0;
int flexring = A1;
int flexmiddle = A2;
int flexindex = A3;
int flexthumb = A4;
void setup()
{
Serial.begin(9600);
pinMode(flexpinky, INPUT);
pinMode(flexring, INPUT);
pinMode(flexmiddle, INPUT);
pinMode(flexindex, INPUT);
pinMode(flexthumb, INPUT);
}
void loop()
{
// Defines analog input variables
int flex1 = analogRead(flexpinky);
int flex2 = analogRead(flexring);
int flex3 = analogRead(flexmiddle);
int flex4 = analogRead(flexindex);
int flex5 = analogRead(flexthumb);
//Serial.println("<"); // You can this section to calibrate your angle outputs by first
//Serial.println(flex1); // checking what are the minimum and maximum readings of the flex
//Serial.println(flex2); // sensors when you are closing and opening your hands.
//Serial.println(flex3); // Once you have calibrated the sensor readings, you can comment
//Serial.println(flex4); // these lines out.
//Serial.println(flex5);
// Defines "pos" variables as being proportional to the flex inputs.
// The ranges for each sensor is different. You will need to find out the max and min
// of each sensor by uncommneting the section right before these comments.
int pos1 = map(flex1,600,830,0,180);
pos1 = constrain(pos1,0,180);
int pos2 = map(flex2,730,860,0,180);
pos2 = constrain(pos2,0,180);
int pos3 = map(flex3,730,860,0,180);
pos3 = constrain(pos3,10,180);
int pos4 = map(flex4,640,840,0,180);
pos4 = constrain(pos4,0,180);
int pos5 = map(flex5,720,810,0,180);
pos5 = constrain(pos5,0,180);
Serial.write("<"); // This is what is being sent from the glove's XBee module.
Serial.write(pos1);
Serial.write(pos2);
Serial.write(pos3);
Serial.write(pos4);
Serial.write(pos5);
//Serial.println("<");
//Serial.println(pos1);
//Serial.println(pos2);
//Serial.println(pos3);
//Serial.println(pos4);
//Serial.println(pos5);
delay(50);
}
Just make sure you choose the correct board under tools and that you have the XBee disconnected from the LilyPad.This code was comprised from parts from Gabry295 and from dschurman from Instructables.com. Their work can be seen at the following links:
http://www.instructables.com/id/Wireless-Controlled-Robotic-Hand/
http://www.instructables.com/id/DIY-Robotic-Hand-Controlled-by-a-Glove-and-Arduino/
The final code used was the code for the hand itself. Again, this code was comprised from using different pars and methods from Gabry295 and dschurman. The last code is as follows:
// This code is made by combining different parts of two existing codes
// One from Gabry295 and the other from dschurman on Instructables.com
#include <Servo.h> // Includes the servo library
Servo pinky, ring, middle, index, thumb;
int servoPin1 = 5;
int servoPin2 = 6;
int servoPin3 =11;
int servoPin4 = 10;
int servoPin5 = 3;
int angpinky = 0;
int angring = 0;
int angmiddle = 0;
int angindex = 0;
int angthumb = 0;
byte startPackage; // Variable that will contain the character of start package
void setup()
{
Serial.begin(9600);
// Attach the servos to their respective pins
pinky.attach(servoPin1);
ring.attach(servoPin2);
middle.attach(servoPin3);
index.attach(servoPin4);
thumb.attach(servoPin5);
// Set each servo pin to output
pinMode(servoPin1, OUTPUT);
pinMode(servoPin2,OUTPUT);
pinMode(servoPin3, OUTPUT);
pinMode(servoPin4, OUTPUT);
pinMode(servoPin5, OUTPUT);
}
void loop()
{
if(Serial.available()) {
startPackage = Serial.read();
angpinky = Serial.read();
angring = Serial.read();
angmiddle = Serial.read();
angindex = Serial.read();
angthumb = Serial.read();
if(startPackage == '<'){
pinky.write(angpinky);
ring.write(angring);
middle.write(angmiddle);
index.write(angindex);
thumb.write(angthumb);
}
}
delay(50);
}
Just make sure you have the XBee disconnected here too as well to upload the code. So to calibrate the range for the flex sensors on the glove, you would uncomment the section that is commented out. Once this is uncommented, you would need to also comment out the section where the data is being sent to the XBee. Once this is done, you can see the readings of the flex sensor in the serial monitor.
Here you will see the maximum and the minimum readings for each individual flex sensor. You will use these maximum and minimum readings when it comes to remapping the flex sensor readings to 0 and 180 for the degrees of the servos.
Once you have chosen your max and min ranges for each indiviudal flex sensor. You will then recomment those lines that you have uncommented to find the max and min. To make sure your chose maximum and minimum readings are translating well to 0 and 180, you can uncomment the last section in the Glove code. Once these are uncommented, you will be able to see the degree position the servos will be receiving. You will see this in the serial monitor and will see it change as you close and open the glove.
Once everything is working order, you can comment out the last section. Just make sure the section right before isn't commented out. This is the data that will be sent from the Glove.
The only changes that I have done with the 3D printed hand here at Boca Bearings were the servos and the strings used for the servos. I swapped out the smaller sg90 micro servos to TowerPro MG 996R. The reason for this was that the MG996R servos have higher torque that would then translate to a stronger grip. The only downside to this new setup was the response time was significantly delayed. It could be because of the current required to move these servos. But the specs of the MG996R servos, specifically the operating speed, was lower than that of the micro servos.
The other change were the strings. The previous I have used were of nylon type material. These type of strings would stretch over time. So I later opted to used braided fish line. This fishing line is much stronger than the first type of string that I used.
The hand was also displayed at the MakerFaire in Orlando, FL at the Orlando Science Center.
I hope that the code above can help anyone that is trying to do this project. This last code still has one issue: for some reason the thumb periodically jump. I still haven't figured out what is the cause of this maybe but maybe someone can figure it out.