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:
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.
Hello Gerado, I have uploaded your codes but they still not work,. i tried using the code from dschurman, it have worked in uno and lilypad so I think problem form the Xbee, this is my Xbee :
ReplyDeletehttps://drive.google.com/file/d/0B3X1A57Xgjozdzd1eFhpUTRKcTQ/view?usp=sharing
Is it correct vesion ?
One more thing,i use flex sensor 2,2 inch and 47k ohm, servo MG90S
Hope you will reply soon,
I'm really sorry to hear that. I can't really tell you what the problem is then. I don't know if it may have to do with your wiring or maybe it is the XBee that you are using. Your XBee is different from the one that I used and from the one that Gabry295 used. Our XBee's were SP1 XBees. Yours says MaxStream on it. So I think maybe your XBee may need some configuration. But I am not sure, I could be wrong. I'm not an expert on these types of topics. I found information on your XBee at:
ReplyDeletehttps://www.sparkfun.com/datasheets/Wireless/Zigbee/XBee-Manual.pdf
I looked over it really quick and saw a configuration section in it. The SP1 XBees don't need any configuration from what I know of. i didn't do configuration for this project on the XBees. And I think the XBee must be powered by 3.3 volts. I'm not sure if you're supplying more than that on the XBee with the LilyPad.
I've found this forum that talks about the XBee MaxStream. It may provide some information for your XBee.
http://www.microchip.com/forums/m155645.aspx
In that forum thread they mention some website that helps with MaxStream but I don't know if it can be of any help at all and the thread is from 2006.
I think your flex sensor is fine. I think it's shorter than mines but it's the one that Gabry used. You just need to figure out the maximum and minimum values of the flex sensors. And your resistors are fine. Your servos, MG90S, are also fine I think. Just make sure you provide enough voltage to them since they may draw large amounts of amps for a servo. The first servos I used were similar to yours and they would not work at all on the Arduino's 5V pin. Even if it was just one servo hooked up to it. The only way it worked was when I provided its own power source of 6V from 4 AA batteries.
I hope you figure out the problem with your project. But things like this happen all the time. There is always something that doesn't go according to plan but eventually you will figure out what the problem is. It happened to me on all the projects that I have worked on here at Boca Bearings.
When I was trying to calibrate my flex sensors using the serial monitor there where 5 values displayed, for example if the hand was I unflexed it showed
ReplyDelete<´Ž£˜´<
180
142
163
152
180
<
830
832
847
808
815
<´�¢--´<
180
141
162
151
180
<
Do I just pick the lowest which is 808 to be my min value?
The first value after < is the reading for the pinky. The second is for the ring finger, the third is for the middle finer, fourth for the index, and the fifth is for the thumb.
ReplyDeleteSo 808 is the fourth value, so it's for the index finger. I think 808 would be your max value for the index finer which would be pos4. All the other numbers in that set after the > are max values for each different flex sensor.
When you connected your xbees did you do anything or did you just turn on the glove and Arduino and it started working?
ReplyDeleteBecause I'm following exactly what you did but its not transmitting for some reason
DeleteThis comment has been removed by the author.
ReplyDeletealso whenever I turn on my power supply one servo makes a noise but the rest don't do anything and one time I saw smoke coming out. IS this a wiring problem or can it be fixed in the code
ReplyDeletehi Jared i have the same problems you mentioned, my xbees dont seem to be transmitting and recieving. and also when i turn on the power one servo makes a noise, no smoke though...
Deletehow did u fix these problems??
I just turned on the glove and the hand. The order in which they are turned on doesn't matter. Just make sure the switch on the SparkFun XBee shield is switched to UART. If not, data will not be transmitted. That's what happened to me. Another thing to check is to make sure in the final program of the glove that you are using the Serial.write commands at the end of the program and not the Serial.println command. Also, make sure you are using "<" in the first Serial.write command in the glove and that '<' is used for the if statement in the hand code. This is what marks in where the data should start to be read by the hand code.
ReplyDeleteSometimes the servos sound can happen because of the range they are programmed in, their range of angle that is obtained from the range of the flex sensor readings. Sometimes if the range of the flex sensor is small, the servo may twitch. But I am sure if that's the problem. One of my servos always twitched no matter what I did to try to fix it. I think the smoke coming out is a wiring problem. Maybe some wires that shouldn't be touching each other are making contact with each other. Just review your wiring. Hopefully this helps and hopefully you get it up and running.
Sorry for bothering you this much, but I have one last question to ask. I got new xbees and they seem to be communicating, the glove wiring is also good, each servo gets a signal from the arduino when running the sample sweep code.
ReplyDeleteBut as soon as I hook up the signal wires from the 5 servos to the Adafruit motor shield nothing happens even when giving eternal power. But if I run the sample code for the servo sweep and connect one to the digital pin 9 slot that one runs the code. Could it be a problem with the actual Adafruit motor shield or the wiring. By the way I'm using a 3 AA battery pack to power all 5, is that too little because I could replace it with a 4 AA battery pack.
Is it possible to show me exactly how you set up the wiring for the inmoov arm.
Once again sorry to be asking so many questions your probably very busy.
It's not a problem, you can ask me as much as you want and I will try to help as much as I can.
DeleteThe first main reason why it may not be working is because the codes shown here is meant to be used without the use of an Adafruit shield because I found it difficult to use the Adafruit servo shield.
Another reason why the Adafruit isn't working could be because you haven't included its library in the code. If you have included the library in the code, you have to make sure you have the library saved in a libraries folder saved in the Arudino folder. But you have to have a code that is incorporating the use of the Servo shield.
Another thing, I'm not sure which Adafruit shield you're using. There is the Adafruit motor shield https://www.adafruit.com/products/1438 which could only control 2 servos.
The other shield is the Adafruit PWM/Servo shield https://www.adafruit.com/products/1411 which can control up to 16 servos. This is the shield you would want to use out of the two. But, it requires some knowledge of how to really use it. I had some trouble using it. I could get it to work but I couldn't obtain the full 180 degrees of motion of the servos. If you want me to, I can send the codes or upload them here that used this particular shield. Then you can probably look over it and maybe try to fix it or tweak it to make it fully work.
Maybe 3 AA batteries might not be enough for the servos. I would go with the 4 AA batteries. 4 AA batteries should be enough. I used it for the small micro servos I first used and it worked perfectly. When I changed out the small servos to standard size high torque servos, TowerPro MG 996R, the movement of the servos was much slower. I think it could be probably because the high torque motors may draw more current or that is how they operate.
Yes, I can try to show you how I set up the wiring of the Inmoov arm. Just give me a day or two to create the wiring setup in a program to display it.
This comment has been removed by the author.
ReplyDeleteI would also really appreciate you showing me the wiring, thank you.
DeleteThis comment has been removed by the author.
DeleteSo I got most of it to working but the thumb keeps tewtching, like I would go up and down and when I stop it keeps replaying
ReplyDeleteYeah that's the same thing that happened to me. I tried to find a solution to it but I couldn't figure it out. I have heard that it happens because of large current draws from the servos. I've read online before that you can use a capacitor to try to fix this by providing energy when needed. I played around with it a little but I couldn't figure it out like what capacitor size to use and if capacitor type matters.
DeleteBut that's good you got it to work this far. Do you have any pictures or video of your work? I would really like to check it out. I also added a new post about the wiring and the codes I used for the Servo shield if you want to check it out.
I found this on Adafruit. It may help.
Deletehttps://learn.adafruit.com/adafruit-arduino-lesson-14-servo-motors/if-the-servo-misbehaves
So I bought some capacitor which I'm planning to test with. I am currently restringing the tendons. I will post a link to the video when thats done(probably in a couple of days).
DeleteThis comment has been removed by the author.
ReplyDeleteHere is the video: https://drive.google.com/file/d/0B11i8iMEGWZ5RWYzZUhCbDdWTFE/view?usp=sharing
ReplyDeleteThat looks pretty cool, Thanks for sharing! Glad that you got it to work now.
Deletewhat to do after finding the max and min values o each flex snsor??
ReplyDeleteOnce you find the max and min of each flex sensor, you can use those values in the map function when converting from the flex sensor readings to degrees that the servos would use. For example, in the following line of the code
Deleteint pos1 = map(flex1,600,830,0,180);
600 and 830 were the min and max values I found for the first flex sensor. Each finger will have a different range. So you need to find the min and max of each flex sensor and then use those values when converting from flex sensor readings to degrees. I hope this helped clarify things for you.
yeah i figured that out after asking that question :p.
Deletethanks for the neat explanation btw.
however it still doesnt work.
in the serial monitor i can see the flex sensor readings and i also used the min and max values to map from 0 to 180 and saw the results i the serial monitor. so the glove part is fine. however after i connected every thing it still doesnt work...i have 2 xbee s1 and two arduino xbee pro shields so i connected the tx and rx pins of the lilypad to the rx and tx pins of the xbee shield and simply mounted the other shield on top of the arduino uno. Is there a way to check if the arduino uno board is recieving signal from the lilypad??
Hi, it's been a while since I've worked on this project but I'll try my best to help you troubleshoot what the problem is. I think there is a way to see if the Arduino Uno is receiving some kind of signal from the glove.
DeleteIn the hand code, you probably replace the following lines of code
pinky.write(angpinky);
ring.write(angring);
middle.write(angmiddle);
index.write(angindex);
thumb.write(angthumb);
with some form of the command
Serial.println();
so you can see it being displayed in the serial monitor, the degree positions. But if you just leave everything unchanged from the hand code and run it, you should be able to see some random characters that will be displayed in the serial monitor. Those characters will change as you open and close the glove. Then you would know that the hand is receiving some form of signal from the glove.
I also looked online and found that the Arduino XBee shield has some sort of jumper on board that would change its settings. So that may also be a reason for no communication.
This comment has been removed by the author.
ReplyDeleteits working, but not properly. When i bend the flex sensors individually, two or three of the fingers are working properly. when i bend one of the flex sensors two servo motors are reacting together. Sometimes 3 of them rotate together...and sometimes none of them rotate...
ReplyDeletewhat do i do?
It's very difficult to pinpoint what the problem could be in your situation. It could be that maybe there isn't enough power being supplied to the servos. Make sure when you are bending one flex sensor that you are not flexing the nearby sensors. A slight movement of the nearby sensors can cause the servos to move. I hope you figure it out. Sorry I couldn't really help much.
Delete