Transform

You might also like

You are on page 1of 2

#include"stdafx.

h"

ifstream fin("DH_INPUT.txt");
ofstream fout("DH_OUTPUT.doc");
int_tmain(int argc,TCHAR*argv[])
{
float T[4][4]={{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};
float TK[4][4];
float Temp[4][4];
int dof;
float theta,d,a,alpha,garb;
string line;

fin>>line;
fin>>dof;
fin>>line>>line>>line>>line>>line>>line; //to skip words written in file

for(int i=0;i<dof,i++)
{
fin>>garb //stores the value of serial number
>>theta
>>d
>>a
>>alpha;

theta=(theta*22)/(180*7);
alpha=(alpha*22)/(180*7);

//Calculates transformation matrix for joints


TK[0][0]= cos(theta);
TK[0][1]= -cos(alpha)*sin(theta);
TK[0][2]= sin(alpha)*sin(theta);
TK[0][3]= cos(theta)*a;
TK[1][0]= sin(theta);
TK[1][1]= cos(alpha)*cos(theta);
TK[1][2]= -sin(alpha)*cos(theta);
TK[1][3]= sin(Theta)*a;
TK[2][0]= 0;
TK[2][1]= sin(alpha);
TK[2][2]= cos(alpha);
TK[2][3]=d;
TK[3][0]=0;
TK[3][1]=0;
TK[3][2]=0;
TK[3][3]=1;

//saves transformation matrix of each joint in output file


fout<<"\n\nTransformation matrix for joint no.="<<i+1<<"is\n";

for(intj=0:j<4:j++)
{
fout<<endl;
for(intk=0;k<4;k++)
{
fout<<setw(10)<<setprecision(3)<<fixed<<TK[j]
[k]<<"\t\t";
}
}
//Post multiplication of transformation matrix with overall transformation matrix
for(int i=0;i<4;i++)
{
for(intj=0:j<4:j++)
}
Temp[i][j]=0;
for(int k=0;k<4;k++)
{
Temp[i][j]+=T[i][k]*TK[k][j];
}
}
}

for(inti=0;i<4;i++)
{
for(intj=0;j<4;j++)
{
T[i][j]=Temp[i][j];
}
}
}

//saves overall transformation matrix/arm equation in output file


fout<<"\n\nThe arm equation of the robot is\n";
for(inti=0;i<4;i++)
{
fout<<endl;
for(intj=0;j<4;j++)
{
fout<<setw(10)<<setprecision(3)<<fixed<<T[i][j]<<"\t\t";
}
}
cout<<"All steps executed successfully.\n\t Open "DH_Output.doc"file for output\n\n
Press any key to exit....";
getch();
return 0;
}

You might also like