Trainable Robotic Arm

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Trainable Robotic Arm

Post by adafruit_support_bill »

Looking good! The lower arm servos are working together now I see.
Now that is taken care of, when I turn it on the robot is moving around and I assume it is trying to calibrate every servo?
Hard to say without looking at your complete code.

User avatar
mlandergan
 
Posts: 56
Joined: Sat Jul 23, 2011 6:15 pm

Re: Trainable Robotic Arm

Post by mlandergan »

Thanks! I'm really proud it is finally taking shape!

Here is the latest and greatest code

Code: Select all

  // Two up to forward
#include <Servo.h>
#include <EEPROM.h>

Servo one;
Servo two;
Servo three;
Servo four;
Servo five;
Servo six;

int minDegOne, minDegTwo, minDegThree, minDegFour, minDegFive, minDegSix; 
int maxDegOne, maxDegTwo, maxDegThree, maxDegFour, maxDegFive, maxDegSix;
int minFeedOne, minFeedTwo, minFeedThree, minFeedFour, minFeedFive, minFeedSix;
int maxFeedOne, maxFeedTwo, maxFeedThree, maxFeedFour, maxFeedFive, maxFeedSix;
int posOne, posTwo, posThree, posFour, posFive, posSix;
int posOne1, posTwo1, posThree1, posFour1, posFive1, posSix1;

int addr = 0;
boolean recorded = false;

void setup()
{
  Serial.begin(9600);
  one.attach(8);
  two.attach(9);
  three.attach(10);
  four.attach(11);
  five.attach(12);
  six.attach(13);
  pinMode(3, OUTPUT);  // LED
  pinMode(6, INPUT);    // Replay Button
  pinMode(7, INPUT);    // Train Button
  delay(100);
  // One center to left
  for (int i = 90; i > 29; i--)
  {
    one.write(i);
    delay(10);
  }
  minDegOne = 0;
  minFeedOne = analogRead(1);
  delay(500);
  // One left to right
  for (int i = 30; i < 151; i++)
  {
    one.write(i);
    delay(10);
  }
  maxDegOne = 180;
  maxFeedOne = analogRead(1);
  delay(500);
  // One right to center
  for (int i = 150; i > 89; i--)
  {
    one.write(i);
    delay(10);
  }
  delay(500);
  // Two up to forward
  for (int i = 90; i > 29; i--)
  {
    two.write(i);
    three.write(180-i);
    delay(10);
  }
  minDegTwo = 30;
  minDegThree = 30;
  minFeedTwo = analogRead(2);
  minFeedThree = analogRead(3);
  delay(500);
  // Two forward to backward
  for (int i = 25; i < 151; i++)
  {
    two.write(i);
    three.write(180-i);
    delay(10);
  }
  maxDegTwo = 150;
  maxDegThree = 150;
  maxFeedTwo = analogRead(2);
  maxFeedThree = analogRead(3);
  delay(500);
  // Two backward to up
  for (int i = 150; i > 89; i--)
  {
    two.write(i);
    three.write(180-i);
    delay(10);
  }
 
  delay(500);  
  // Four up to forward
  for (int i = 90; i > 29; i--)
  {
    four.write(i);
    delay(10);
  }
  minDegFour = 30;
  minFeedFour = analogRead(4);
  delay(500);
  // Four forward to backward
  for (int i = 30; i < 151; i++)
  {
    four.write(i);
    delay(10);
  }
  maxDegFour = 150;
  maxFeedFour = analogRead(4);
  delay(500);
  // Four backward to up
  for (int i = 150; i > 89; i--)
  {
    four.write(i);
    delay(10);
  }
  delay(500);
  // Five up to forward
  for (int i = 90; i > 19; i--)
  {
    five.write(i);
    delay(10);
  }
  minDegFive = 30;
  minFeedFive = analogRead(5);
  delay(500);
  // Five forward to backward
  for (int i = 20; i < 181; i++)
  {
    five.write(i);
    delay(10);
  }
  maxDegFive = 150;
  maxFeedFive = analogRead(5);
  delay(500);
  // Five backward to up
  for (int i = 180; i > 89; i--)
  {
    five.write(i);
    delay(10);
  }
    minDegSix = 30;
  minFeedFive = analogRead(6);
  delay(500);
  // Five forward to backward
  for (int i = 20; i < 181; i++)
  {
    six.write(i);
    delay(10);
  }
  maxDegSix = 150;
  maxFeedSix = analogRead(6);
  delay(500);
  // Five backward to up
  for (int i = 180; i > 89; i--)
  {
    five.write(i);
    delay(10);
  }
  delay(500);
  // Center all servos
  one.write(90);
  two.write(90);
  three.write(90);
  four.write(90);
  five.write(90);
  six.write(90);
  delay(1000);
  // Detach to save power and allow human manipulation
  one.detach();
  two.detach();
  three.detach();
  four.detach();
  five.detach();
  six.detach();
}

void loop()
{
  delay(100);
  if (digitalRead(7))
  {
    recorded = true;
    digitalWrite(3, HIGH);
    delay(1000);
    while (!digitalRead(7))
    {
      delay(50);
      int posOne = map(analogRead(1), minFeedOne, maxFeedOne, minDegOne, maxDegOne);
      EEPROM.write(addr, posOne);
      addr++;
      int posTwo = map(analogRead(2), minFeedTwo, maxFeedTwo, minDegTwo, maxDegTwo);
      EEPROM.write(addr, posTwo);
      addr++;
      int posThree = map(analogRead(3), minFeedThree, maxFeedThree, minDegThree, maxDegThree);
      EEPROM.write(addr, posThree);
      addr++;
      int posFour = map(analogRead(4), minFeedFour, maxFeedFour, minDegFour, maxDegFour);
      EEPROM.write(addr, posFour);
      addr++;
      int posFive = map(analogRead(5), minFeedFive, maxFeedFive, minDegFive, maxDegFive);
      EEPROM.write(addr, posFive);
      addr++;
      int posSix = map(analogRead(6), minFeedSix, maxFeedSix, minDegSix, maxDegSix);
      EEPROM.write(addr, posSix);
      if (addr == 512)
      {
        EEPROM.write(addr, 255);
        break;
      }
      delay(50);
    }
    EEPROM.write(addr, 255);
  }
  if (recorded || digitalRead(6))
  {
    digitalWrite(13, LOW);
    // Power up servos
    one.attach(8);
    two.attach(9);
    three.attach(10);
    four.attach(11);
    five.attach(12);
    six.attach(13);
    delay(1000);
    // Center servos
    one.write(90);
    two.write(90);
    three.write(90);
    four.write(90);
    five.write(90);
    six.write(90);
    delay(1000);
    // Start playback
    addr = 0;
    while (1)
    {
      posOne = EEPROM.read(addr);
      posOne1 = EEPROM.read(addr+5);
      addr++;
      posTwo = EEPROM.read(addr);
      posTwo1 = EEPROM.read(addr+5);
      addr++;
      posThree = EEPROM.read(addr);
      posThree1 = EEPROM.read(addr+5);
      addr++;
      posFour = EEPROM.read(addr);
      posFour1 = EEPROM.read(addr+5);
      addr++;
      posFive = EEPROM.read(addr);
      posFive1 = EEPROM.read(addr+5);
      addr++;
      posSix = EEPROM.read(addr);
      posSix1 = EEPROM.read(addr+5);
      
      // Check for the end of the recorded commands, if so then break out of the infinite loop
      if ((posOne == 255) || (posOne1 == 255) || (posTwo == 255) || (posTwo1 == 255) || (posThree == 255) || (posThree1 == 255) || (posFour == 255) || (posFour1 == 255) || (posFive == 255) || (posFive1 == 255) || (posSix = 255) || (posSix1))
      {
        break;
      }
      
      // Step from one recording to the next for each servo
      if ((posOne1 - posOne) > 0)
      {
        for (int i = posOne; i < posOne1; i++)
        {
          one.write(i);
          delay(5);
        }
      }   
      else if ((posOne1 - posOne) < 0)
      {
        for (int i = posOne; i > posOne1; i--)
        {
          one.write(i);
          delay(5);
        }
      }
      if ((posTwo1 - posTwo) > 0)
      {
        for (int i = posTwo; i < posTwo1; i++)
        {
          two.write(i);
          delay(5);
        }
      }   
      else if ((posTwo1 - posTwo) < 0)
      {
        for (int i = posTwo; i > posTwo1; i--)
        {
          two.write(i);
          delay(5);
        }
      }
      if ((posThree1 - posThree) > 0)
      {
        for (int i = posThree; i < posThree1; i++)
        {
          three.write(i);
          delay(5);
        }
      }   
      else if ((posThree1 - posThree) < 0)
      {
        for (int i = posThree; i > posThree1; i--)
        {
          three.write(i);
          delay(5);
        }
      }
      if ((posFour1 - posFour) > 0)
      {
        for (int i = posFour; i < posFour1; i++)
        {
          four.write(i);
          delay(5);
        }
      }   
      else if ((posFour1 - posFour) < 0)
      {
        for (int i = posFour; i > posFour1; i--)
        {
          four.write(i);
          delay(5);
        }
      }
      if ((posFive1 - posFive) > 0)
      {
        for (int i = posFive; i < posFive1; i++)
        {
          five.write(i);
          delay(5);
        }
      }   
      else if ((posFive1 - posFive) < 0)
      {
        for (int i = posFive; i > posFive1; i--)
        {
          five.write(i);
          delay(5);
        }
      }
      
            if ((posSix1 - posSix) > 0)
      {
        for (int i = posSix; i < posSix1; i++)
        {
          six.write(i);
          delay(5);
        }
      }   
      else if ((posSix1 - posSix) < 0)
      {
        for (int i = posSix; i > posSix1; i--)
        {
          six.write(i);
          delay(5);
        }
    }
    recorded = false;
    addr = 0;
    delay(1000);
    // Center all servos
    one.write(90);
    two.write(90);
    three.write(90);
    four.write(90);
    five.write(90);
    six.write(90);
    delay(500);
    // Detach them to save power and allow human manipulation
    one.detach();
    two.detach();
    three.detach();
    four.detach();
    five.detach();
    six.detach();
  }
}
}
  }

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Trainable Robotic Arm

Post by adafruit_support_bill »

That looks like the calibration moves from your setup code. It should exercise each of the arm joints and record the min and max for each one.

Be sure to post a video of the finished arm. We'll feature it in the blog :D

User avatar
mlandergan
 
Posts: 56
Joined: Sat Jul 23, 2011 6:15 pm

Re: Trainable Robotic Arm

Post by mlandergan »

Isn't that what the code is doing? How should I change around my code?
I will make sure to post a video when it's all done!!

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Trainable Robotic Arm

Post by adafruit_support_bill »

Isn't that what the code is doing?
Yes. That is what it looks like.

User avatar
mlandergan
 
Posts: 56
Joined: Sat Jul 23, 2011 6:15 pm

Re: Trainable Robotic Arm

Post by mlandergan »

Ok so why can't I do the record/playback for all of the six servos? Do you know what is preventing it from happening?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Trainable Robotic Arm

Post by adafruit_support_bill »

I assume that you have a button/switch wired to pin 7 and an LED on pin 3. After running the setup calibration, does the LED come on when you press the button?

User avatar
mlandergan
 
Posts: 56
Joined: Sat Jul 23, 2011 6:15 pm

Re: Trainable Robotic Arm

Post by mlandergan »

I believe so but I will check.

User avatar
mlandergan
 
Posts: 56
Joined: Sat Jul 23, 2011 6:15 pm

Re: Trainable Robotic Arm

Post by mlandergan »

when I hit the button connected to digital pin 6, the LED does not light up ):

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Trainable Robotic Arm

Post by adafruit_support_bill »

That tells me that either the button or LED is not wired properly. Can you post a photo or diagram of how it is wired?

User avatar
mlandergan
 
Posts: 56
Joined: Sat Jul 23, 2011 6:15 pm

Re: Trainable Robotic Arm

Post by mlandergan »

Here is a picture of the buttons. I am going off this diagram from arduino's website.

http://www.arduino.cc/en/Tutorial/Button#.Uw5fVkJdX2g

The record button on one side there is a 10k resistor connected to one leg of the button and the other to the gnd rail. The other leg on the same side is connected to 5v rail. On the opposite side the leg is connected to pin 7. The same is for the other button except the opposite leg is connected to pin 6 for playback.

http://i.imgur.com/bk4PkAd.jpg

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Trainable Robotic Arm

Post by adafruit_support_bill »

when I hit the button connected to digital pin 6, the LED does not light up ):
The code is looking for a button on pin 7 to start recording and turn on the LED on pin 3.

Code: Select all

void loop()
{
  delay(100);
  if (digitalRead(7))
  {
    recorded = true;
    digitalWrite(3, HIGH);
    delay(1000);
    while (!digitalRead(7))
The button wiring looks OK. I can't see what is connected to pin 3.

User avatar
mlandergan
 
Posts: 56
Joined: Sat Jul 23, 2011 6:15 pm

Re: Trainable Robotic Arm

Post by mlandergan »

I'm sorry I am mistaken 7 is the training button, and 6 is the playback. I haven't made any progress. But good news is I got 2nd place for this project at my high school science fair!

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Trainable Robotic Arm

Post by adafruit_support_bill »

But good news is I got 2nd place for this project at my high school science fair!
Congratulations :D

User avatar
mlandergan
 
Posts: 56
Joined: Sat Jul 23, 2011 6:15 pm

Re: Trainable Robotic Arm

Post by mlandergan »

Thanks, but I'm still running into issues to get the entire arm to record and playback. I dont know if its the buttons or if its the code.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”