Hi folks ive been having a problem trying to add grip control using a force sensor to a mechanical claw project that i have going. Ive got code written that can do this fine in movement simulations in loops, or when controlling the claw through the serial interface using the keyboard.
But now im using a glove with flex sensors sewn into to it, to control the claw over an xbee connection. So when i move my fingers or wrist the mechanical claw will move too. Now with this real time control, the code ive been using for grip control isnt working. This is what ive been using
sending
int Finger1 = 0;
int Finger2 = 1;
int Finger3 = 2;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int FingerV1 = analogRead(Finger1);
int FingerV2 = analogRead(Finger2);
int FingerV3 = analogRead(Finger3);
if (FingerV1 < 385) FingerV1 = 385;
else if (FingerV1 > 550) FingerV1 =550;
if (FingerV2 < 425) FingerV2 = 425;
else if (FingerV2 > 485) FingerV2 = 485;
if (FingerV3 < 370) FingerV3 = 370;
else if (FingerV3 > 490) FingerV3 = 490;
byte servoVal1 = map(FingerV1,550, 385, 0, 180);//twist
byte servoVal2 = map(FingerV2,485, 425, 0, 180);//bend
byte servoVal3 = map(FingerV3,370, 490, 0, 180);//grab
Serial.print(".");
Serial.print(servoVal1, DEC);
Serial.print(",");
Serial.print(servoVal2, DEC);
Serial.print(",");
Serial.print(servoVal3, DEC);
Serial.print(",");
}
and receiving
#include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;
int pressurePin =A1;
// how much serial data we expect before a terminator
const unsigned int MAX_INPUT = 100;
const char TERMINATOR = '/';
const char STARTER = '.';
void setup ()
{
Serial.begin(9600);
myservo1.attach(8); //twist
myservo2.attach(9); //bend
myservo3.attach(10); //grab
} // end of setup
int twist, bend, grab;
// here to process incoming serial data after a terminator received
void process_data (char * data)
{
// convert strings into numbers:
middle = atoi (strtok (data, ","));
thumb = atoi (strtok (NULL, ","));
ring = atoi (strtok (NULL, ","));
pointer = atoi (strtok (NULL, ","));
rotation = atoi (strtok (NULL, ","));
myservo1.write(twist);
myservo2.write(bend);
myservo3.write(grab);
if (analogRead(pressurePin) > 450)// heres the grip control
myservo3.detach();
if (analogRead(grab) >170) // and here's where im getting the problems
{
myservo3.attach(10);
myservo3.write(grab);
}
} // end of process_data
void loop()
{
static char input_line [MAX_INPUT];
static unsigned int input_pos = 0;
if (Serial.available () > 0)
{
char inByte = Serial.read ();
switch (inByte)
{
case TERMINATOR: // end of text
input_line [input_pos] = 0; // terminating null byte
// terminator reached! process input_line here ...
process_data (input_line);
// reset buffer for next time
input_pos = 0;
break;
case STARTER:
// reset buffer
input_pos = 0;
break;
default:
// keep adding if not full ... allow for terminating null byte
if (input_pos < (MAX_INPUT - 1))
input_line [input_pos++] = inByte;
break;
} // end of switch
} // end of incoming data
} // end of loop
The idea is that the flex sensors will read the position of my fingers and wrist and send that data over xbee radio to the other arduino, and the mechanical claw will mirror the movements
When i clench my hand the gripper will close on an object, the pressure sensor will cut off the power to the servo when the grip becomes tight enough and the claw will be left holding the object. Then when i unclench my hand to full extension with the flex sensors will read this and send a command to the arduino to give power back to the claw and the claw will drop the object.
The problem is that im relying on data from the flex sensors to trigger power back to the gripper servo. And the data is never constant. I tried printing to the serial monitor the values the claw arduino is receiving over xbee, from the flex sensor, and it just gave a value of 423 descending to around 200 in about 10seconds.
i dont think this method can work with this application, but if anyone has any suggestions I'm all ears.
also if anyone has any other ways of using an fsr for grip control I'd love to hear it