You are on page 1of 4

Mutasim Ali erorr62@hotmail.

com

! !

Tutorial Robotic Arm

ROBOTIC ARM - LEAP MOTION - ARDUINO

! !

The Wiring Circuit !

Wi tx = arduino rx" Wi rx = arduino tx"

! !

"

The Arduino Code ! ! ! ! !


#include <Servo.h> //string hold the income data String readstring; //dene motors Servo m,m1,m2,m3,m4; void setup() { //start Serial connection Serial.begin(115200); m.attach(9); //x m1.attach(10); //z m2.attach(5); //y m3.attach(11);//p m4.attach(6);}//g

! ! ! ! ! !

void loop() { //serial available and working while (Serial.available()) { //delay to get all the income delayMicroseconds(65); //if there is income data if (Serial.available() >0) { // store character char c =Serial.read(); //add it to the income string readstring += c;}} ! 3 //if the string has value if(readstring.length() >0) { String P=readstring.substring(0,readstring.indexOf(P));//position P String Q=readstring.substring(readstring.indexOf(P')+1,readstring.indexOf('Q')); //position Q String F=readstring.substring(readstring.indexOf(Q')+1,readstring.indexOf('F')); //position F String K=readstring.substring(readstring.indexOf(F')+1,readstring.indexOf('K')); //position K String L=readstring.substring(readstring.indexOf(K')+1,readstring.indexOf('L')); //position L char carrayP[P.length() + 1]; //dene a new string for P data char carrayQ[Q.length() + 1]; //dene a new string for Q data char carrayF[F.length() + 1]; //dene a new string for F data char carrayK[K.length() + 1]; //dene a new string for K data char carrayL[L.length() + 1]; //dene a new string for L data P.toCharArray(carrayP, sizeof(carrayP)); // initialize the string P Q.toCharArray(carrayQ, sizeof(carrayQ)); // initialize the string Q F.toCharArray(carrayF, sizeof(carrayF)); // initialize the string F K.toCharArray(carrayK, sizeof(carrayK)); // initialize the string K L.toCharArray(carrayL, sizeof(carrayL)); // initialize the string L int pv = atoi(carrayP); //convert from string to int to write to the motor int qv = atoi(carrayQ); //convert from string to int to write to the motor int fv = atoi(carrayF); //convert from string to int to write to the motor int kv = atoi(carrayK); //convert from string to int to write to the motor int lv = atoi(carrayL); //convert from string to int to write to the motor m.write(pv); //write the int to motor to move m1.write(qv); //write the int to motor to move m2.write(fv); //write the int to motor to move m3.write(kv); //write the int to motor to move m4.write(lv); //write the int to motor to move readstring=""; // sign the income string to nothing

!
}

! !

Processing Code (java) ! !


import com.leapmotion.leap.*;" import processing.net.*;" Client arm; // dene a tcp client" Controller leap; //dene the leap motion controller" boolean work=false; // boolean for case the hand and the nger is detected " " void setup() {" size(300, 200); //set the app window size" leap = new Controller(); // initialize leap motion controller" arm = new Client(this, "192.168.0.1", 55555); //start the client connection ip + port" }" //base motor formula " double cba(double a) {" oat n = 100*3;" a = 1.5+2*a/n;" double angle = 90+Math.cos(a)*90;" return angle;}"

! ! ! ! !
"

void draw()" {" //leap motion" HandList hands = leap.frame().hands();" Hand hand = hands.get(0);" FingerList ngers = hand.ngers();" Vector hp = hand.palmPosition();" Pointable f1=ngers.get(0);" Pointable f2=ngers.get(1);" oat #1=f1.tipPosition().getX();" oat #2=f2.tipPosition().getX();" oat sub=#1-#2; // get the distance between the two ngers " " oat pitch = hand.direction().pitch()* 100; // get pitch "

//set maximum and minimum values for the controller range" if(hp.getY()<150) hp.setY(150);" if(hp.getY()>445) hp.setY(445);" if(hp.getZ()<-180) hp.setZ(-180);" if(hp.getZ()>180) hp.setZ(180);" " oat zv=map(hp.getZ(),-180,180,160,8); // map z" oat yv=map(hp.getY(),150,445,0,179); //map y" double xv=180-cba(-hand.palmPosition().getX()/1.5); // get x"

oat pv=map(pitch,-90,100,160,6); // map pitch" oat gv=map(sub,20,90,145,73); //map ngers distance" " if(ngers.count()>=2){work=true;} // set the case" else{work=false;}" //if in range" if(work&&zv<=180&&zv>=0&&yv<=150&&yv>=0&&xv<=180&&xv>=0&&pv<=160&&pv>=6&&gv<=145&&gv>=73){" String v1=(int)xv+"P";" String v2=(int)zv+"Q";" String v3=(int)yv+"F";" String v4=(int)pv+"K";" String v5=(int)gv+"L";" arm.write(v1+v2+v3+v4+v5); // write to the MCU" } " //leap motion" background(205);//set background color" }"