Thursday, April 21, 2011

Final

Here's the final post. I used a 4.5V worm gear box by Tamiya as the motor to raise and lower the claw. I constructed a lightweight claw using the Antman232 design (http://www.instructables.com/id/The-Claw-1/) instead of the heavier commercial claw I initially intended to use. The claw is motored by a 5V servo. The Arduino motor shield can support up to 4 DC motors but they all are powered by the external power supply you provide. So if you use a 12V power supply, they all get 12V unless you reduce their speed. Well I had a problem because the worm drive was rated 4.5V. I reduced the set speed to 75 in order to drop the voltage down to 5-6V. I intended to use a fixed 5V voltage regulator in line with the power supply to this specific motor but as I soon discovered, the motor jacks reverse polarity when motor direction changes. The servo has it's own regulated 5V supply so that wasn't a problem. Anyway, the project is running albeit a bit slow. The wheel assemblies move in staccato fashion due to the time delays in the code. The claw close in an all or nothing fashion. Ideally, I would have liked to control the closing pressure.
 The following is a summary handout for the Expo exhibit:
Patients who have had surgery or trauma to the hands often need formal hand therapy.  The therapist often prescribes a home exercise program to complement the supervised sessions.  Compliance can be variable.
As an incentive to comply with the instructions, I thought a prototype interactive game using a glove with built in sensors might encourage the desired motions such as wrist flexion and extension.  
Our final project for the Physical Computing class is to create a physically interactive system focused on sensing the relevant actions of the user combined with the appropriate physical response. Representing hand motion in an abstract way, I chose the classic “claw game”, as seen in the arcades, to represent the physical component.  To substitute for the joystick, I constructed a sensor glove using a flex sensor and accelerometer.
The Arduino Duemilanove microcontroller and motor shield allowed me to use three DC motors and one servo.  The accelerometers’ three sensors, x, y, and z, provided the input for left/right, forward/back, and up/down motions respectively.  The flex sensor, attached to the middle finger, controlled the open/close of the claw.
Ideally, a method to record and store the actual joint angles would have been useful to monitor a patient’s progress.  In addition, a scoring system also helps reinforce the behavior.  The ability to control the amount of force applied by the claw is also desirable from the standpoint of incremental muscle recruitment.
The Arduino sketch code is :
const int xpin = A3;
const int ypin = A2;
const int zpin = A1;
const int cpin = A0;
int cVal = 0;
int yVal = 0;
int xVal = 0;
int zVal = 600;
#include <AFMotor.h>
#include <Servo.h>
#define BUTTON 2

int val = 0;
int old_val = 0;
int state = 0;

unsigned long time = 0;

Servo myservo;
AF_DCMotor motor(1, MOTOR12_64KHZ);
AF_DCMotor motor2(2, MOTOR12_64KHZ);
AF_DCMotor motor3(3, MOTOR34_64KHZ);

boolean downClaw = false;
void setup()
{
  pinMode(BUTTON, INPUT);
  myservo.attach(9);
  motor.setSpeed(255);
  motor2.setSpeed(255);
  motor3.setSpeed(75);
  // start serial port at 9600 bps:
  Serial.begin(9600);
}

void loop()
{
  val = digitalRead(BUTTON);
   if ((val == HIGH) && (old_val == LOW)){
      state = 1 - state;
      delay(10);
      }
  old_val = val;
  if (state == 0) { }
      else if(state == 1)
 {
      time = millis();  //start the clock
      if(time< 60000)  //30 seconds to play
   {
 xVal= analogRead(xpin);
  if((xVal >= 525)&&(zVal>450))
        {
        xRight();
        delay(15);
        }
      
        if((xVal <=480)&&(zVal>450))
        {
        xLeft();
        delay(15);
        }
      
        if(xVal <=525 && xVal >=480){}
        Serial.print(xVal, DEC);
  yVal= analogRead(ypin);
  if((yVal >= 525)&&(zVal>450))
        {
        yBack();
        delay(15);
        }
      
        if((yVal <=480)&&(zVal>450))
        {
        yFront();
        delay(15);
        }
      
        if(yVal <=525 && yVal >=480){}      
  Serial.println(yVal, DEC);
 
   zVal= analogRead(zpin);
   if((zVal <=450)&&(downClaw == false))
        {
        Serial.println(zVal, DEC);
        zLower();
        delay(15);
        }
      
     
      if((zVal >=550)&&(downClaw == true))
        {
        zRaise();
        Serial.println("down");
        delay(15);
        }
      
        //if(yVal <=525 && yVal >=480){}      
  Serial.println(zVal, DEC);
   cVal = analogRead(cpin);
  if(cVal>=920){
          cOpen();
        }
        if(cVal<=915){
          cClose();
      }
 Serial.println(cVal, DEC);
   Serial.println(millis());
  // wait 10ms for next reading:
  delay(500);               
}
   
      else if(time >= 60000){
       Serial.println("time's up");
       //lowerClaw();
    }
 }
}
void xRight(){
      motor.run(FORWARD);
      delay(250);
      motor.run(RELEASE);      // stopped
      delay(500);
}
void xLeft(){
      motor.run(BACKWARD);
      delay(250);
     motor.run(RELEASE);      // stopped
     delay(500);
}
void yBack(){
      motor2.run(FORWARD);
      delay(1000);
      motor2.run(RELEASE);      // stopped
      delay(500);
}
void yFront(){
      motor2.run(BACKWARD);
      delay(1000);
     motor2.run(RELEASE);      // stopped
     delay(500);
}
void zLower(){
      motor3.run(BACKWARD);
      delay(4000);
      motor3.run(RELEASE);      // stopped
      downClaw = true;
      //delay(1000);
}
void zRaise(){
      motor3.run(FORWARD);
      delay(6000);
     motor3.run(RELEASE);      // stopped
     downClaw = false;
     //delay(8000);
    // motor3.run(FORWARD);
    //  delay(8000);
      //motor3.run(RELEASE);      // stopped
      //delay(1000);
}
void cOpen(){
      myservo.write(180);                  // sets the servo position according to the scaled value
      delay(15);                           // waits for the servo to get there
      }
void cClose(){
      myservo.write(0);                  // sets the servo position according to the scaled value
      delay(15);                           // waits for the servo to get there
      }

No comments:

Post a Comment