Code:
void Robot::Posiition(int index){
/*--------------------------------------forward kinematics---------------------------------------------------------*/
int i;
float d=9, theta=1;
/*----- translational motion matices----*/
double Tx[4][4] = { {1, 0, 0, d},
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1}
};
double Ty[4][4] = { {1, 0, 0, 0},
{0, 1, 0, d},
{0, 0, 1, 0},
{0, 0, 0, 1}
};
double Tz[4][4] ={ {1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, d},
{0, 0, 0, 1}
};
/*----- Rotational motion matices----*/
double Rx[4][4] = { {1, 0, 0, 0},
{0, cos(theta), -sin(theta), 0},
{0, sin(theta), cos(theta), 0},
{0, 0, 0, 1}
};
double Ry[4][4]= { {cos(theta), 0, sin(theta), 0},
{0, 1, 0, 0},
{-sin(theta),0, cos(theta), 0},
{0, 0, 0, 1}
};
double Rz[4][4] = { {cos(theta), -sin(theta), 0, 0},
{sin(theta), cos(theta), 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1}
};
double result[4][4] = { {1, 0, 0, 0}, //Initalised to identity maxtix equivalant to 1
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1},
};
for(i=1;i<index+1;i++){
struct Joint *create=&Joints[i]; /*local pointer to make addressing quicker*/
theta=(create->position)*PI/180;
struct Section *temp=&Sections[i];
d=temp->length;
/*-----------------------------------Joint Actuation-----------------------------------*/
/*---Rotational Joints---*/
if(create->type=='r'){
if(create->axis=='x'){
Rx[1][1] = cos(theta);
Rx[1][2] = -sin(theta);
Rx[2][1] = sin(theta);
Rx[2][2] = cos(theta);
mult_matrices(Rx, result, result);
}
if(create->axis=='y'){
Ry[0][0] = cos(theta);
Ry[0][2] = sin(theta);
Ry[2][0] = -sin(theta);
Ry[2][2] = cos(theta);
mult_matrices(Ry, result, result);
}
if(create->axis=='z'){
Rz[0][0] = cos(theta);
Rz[0][1] = -sin(theta);
Rz[1][0] = sin(theta);
Rz[1][1] = cos(theta);
mult_matrices(Rz, result, result);
}
/*---section Length translation to next joint-------*/
Tz[2][3] = d;
mult_matrices(Tz, result, result);
}
/*---Translational Joints---*/
if(create->type=='t'){
if(create->axis=='x'){
Tx[0][3]=d;
mult_matrices(Tx, result, result);
}
if(create->axis=='y'){
Ty[1][3]=d;
mult_matrices(Ty, result, result);
}
if(create->axis=='z'){
Tz[2][3] = d;
mult_matrices(Tz, result, result);
}
}
/*----------Angular offset to next joint-------*/
if (i<3){
struct Joint *create2=&Joints[i+1];
if(create2->axis='x'){
}
}
}
}
appoliges for the indenting it all got changed when i copyed it in i have tried to tidy it up as best as possible