I am currently working on a robot hand controlled wirelessly by flex sensors attached on a glove. I am using XBee Series 1 modules for communication. The other parts include:
Arduino UNO (x2)
Flex sensors (x21)
Sub Micro Servos (x15)
Standard torque servos (x3)
High torque servos (x3)
Adafruit 16 Channel servo shield (x2) (stacked)
Sparkfun Xbee Shield (x2)
Mux Shield II by Mayhew Labs (x1)
5V 10A Power Supply (x2) (one for each servo shield containing 10 & 11 servos each)
I have checked online but have found projects and solutions for robotic hand where each finger is actuated by one servo and hence, they are directly connected to the arduino. I am using individual servos for each joint and hence, my finger-to-shoulder robot arm contains 21 servos, 15 in the fingers itself. I am having trouble in controlling the servos as upto 5 can be controlled without much delay in transmission and actuation when connected directly to the board. But when i connect the same 5 motors using the servo shield, there is a considerable amount of delay and after working for about a minute or so, it suddenly stop responding just to work again few minutes later.
These are the codes I am using currently:
Flex sensors (transmission side):
Code: Select all
#include <MuxShield.h>
#define sfmin 680 //ShortFlex MIN
#define sfmax 830 //ShortFlex MAX
#define lfmin 485 //LongFlex MIN
#define lfmax 600 //LongFlex MAX
MuxShield muxShield;
void setup()
{
// put your setup code here, to run once:
muxShield.setMode(1, ANALOG_IN);
// muxShield.setMode(2, ANALOG_IN);
Serial.begin(9600);
}
int IO1AnalogVals[10];
int IO1servoposition[10];
//int IO2AnalogVals[16];
//int IO2servoposition[16];
void loop()
{
for (int i = 0; i < 5; i++) //Analog read on all 5 inputs on IO1
{
IO1AnalogVals[i] = muxShield.analogReadMS(1, i);
IO1servoposition[i] = map(IO1AnalogVals[i], sfmin, sfmax, 0, 180);
IO1servoposition[i] = constrain(IO1servoposition[i], 0, 180);
}
/*for (int j = 6; j < 10; j++)
{
IO1AnalogVals[j] = muxShield.analogReadMS(1, j);
IO1servoposition[j] = map(IO1AnalogVals[j], lfmin, lfmax, 0, 180);
IO1servoposition[j] = constrain(IO1servoposition[j], 0, 180);
}*/
Serial.write("<"); // This character represent the beginning of the package of the five values
for (int k = 0; k < 5; k++)
Serial.write(IO1servoposition[k]);
//for (int l = 0; l < 16; l++)
//Serial.write(IO2servoposition[l]);
delay(80);
}
Code: Select all
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
//Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);
#define SERVOMIN 175 // this is the 'minimum' pulse length count for sub micro servo (out of 4096)
#define SERVOMAX 595 // this is the 'maximum' pulse length count for sub micro servo (out of 4096)
byte startPackage;
double pulselen[5];
int angservo[5];
void setup()
{
Serial.begin(9600);
pwm.begin();
// pwm1.begin();
pwm.setPWMFreq(60);
//pwm1.setPWMFreq(120);
delay(300);
}
void loop()
{
if (Serial.available())
{
startPackage = Serial.read(); // The first value will be "<", the other are assigned to the finger
for (int i = 0; i < 5; i++)
angservo[i] = Serial.read(); //Read all values from 5 sensors
if (startPackage == '<') // Verifying that the first value is "<"
{
for (int j = 0; j < 5; j++)
pulselen[j] = map(angservo[j], 0, 180, SERVOMIN, SERVOMAX); //convert all values into pulse
for (int k = 0; k < 5; k++) //send pulse to 5 motors on first board
{
pwm.setPWM(k, 0, pulselen[k]);
}
}
}
delay (80);
}