Sunday 16 August 2015

Relative motion of three links of robotic arm

Sample Output:
Robotics, C program for simulation of three link robotic arm movement


#include<graphics.h>
#include<math.h>
void main(){

 int gd=DETECT, gm;
 int k=1;
 float xra,xrb,xrc,yra,yrb,yrc,xr1,yr1,xr2,yr2,x1,y1,y2,x2,x3,y3,x4,y4,xr,yr;
 int second=0;
 initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
 x1=200;y1=200;
 x2=x1+100;y2=200;
 x3=x2+50;y3=200;
 x4=x3+25;y4=200;
setcolor(GREEN);
line(x1,y1,x2,y2);
setcolor(CYAN);
line(x2,y2,x3,y3);
setcolor(LIGHTRED);
line(x3,y3,x4,y4);

while(!kbhit()){
k+=1;
if(k%360) {
xr=(x4-x3)*cos(M_PI/180) - (y4-y3)*sin(M_PI/180) + x3;
yr=(x4-x3)*sin(M_PI/180) + (y4-y3)*cos(M_PI/180)+ y3;
x4=xr;
y4=yr;
delay(2);
cleardevice();
setcolor(GREEN);
line(x1,y1,x2,y2);
setcolor(CYAN);
line(x2,y2,x3,y3);
setcolor(LIGHTRED);
line(x3,y3,x4,y4);
}
else
{
second+=60;
xr1=(x3-x2)*cos(5*M_PI/180) - (y3-y2)*sin(5*M_PI/180) + x2;
yr1=(x3-x2)*sin(5*M_PI/180) + (y3-y2)*cos(5*M_PI/180)+ y2;
x3=xr1;
y3=yr1;


xr2=(x4-x2)*cos(5*M_PI/180) - (y4-y2)*sin(5*M_PI/180) + x2;
yr2=(x4-x2)*sin(5*M_PI/180) + (y4-y2)*cos(5*M_PI/180)+ y2;
x4=xr2;
y4=yr2;

setcolor(GREEN);
line(x1,y1,x2,y2);
setcolor(CYAN);
line(x2,y2,x3,y3);
setcolor(LIGHTRED);
line(x3,y3,x4,y4);

}

}
  getch();

}

No comments:

Post a Comment