4
Mutasim Ali [email protected] Tutorial Robotic Arm ROBOTIC ARM - LEAP MOTION - ARDUINO

Robotic arm Circuit and Codes

Embed Size (px)

DESCRIPTION

Robotic Arm built on RC Car, Using Arduino, The Servo controller MCU and Leap motion controller.Movements controlled by gestures detected by the leap motion controller. palm position:x_axis = right - lefty_axis = up - downz_axis = forward - backward pitch = pitch ! two fingers along the x_axis distances = catcher (gripper) Mutasim Aliemail: [email protected], Huazhong University Of Science andTechnology.

Citation preview

Mutasim Ali [email protected] Tutorial Robotic Arm !!ROBOTIC ARM - LEAP MOTION - ARDUINO

!

The Wiring Circuit !

� !!Wifi tx = arduino rxWifi rx = arduino tx!

The Arduino Code !

!!

#include <Servo.h> !//string hold the income data String readstring; !//define 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]; //define a new string for “P” data char carrayQ[Q.length() + 1]; //define a new string for “Q” data char carrayF[F.length() + 1]; //define a new string for “F” data char carrayK[K.length() + 1]; //define a new string for “K” data char carrayL[L.length() + 1]; //define 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; // define a tcp clientController leap; //define the leap motion controllerboolean work=false; // boolean for case the hand and the finger 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) { float 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 fingers = hand.fingers(); Vector hp = hand.palmPosition();! Pointable f1=fingers.get(0); Pointable f2=fingers.get(1);! float ff1=f1.tipPosition().getX(); float ff2=f2.tipPosition().getX(); float sub=ff1-ff2; // get the distance between the two fingers float 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); float zv=map(hp.getZ(),-180,180,160,8); // map z float yv=map(hp.getY(),150,445,0,179); //map y! double xv=180-cba(-hand.palmPosition().getX()/1.5); // get x float pv=map(pitch,-90,100,160,6); // map pitch float gv=map(sub,20,90,145,73); //map fingers distance if(fingers.count()>=2){work=true;} // set the caseelse{work=false;}//if in rangeif(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}