# two dimensional array problem

Hi,
i’m using Arduino by few days ad I don’t know it very well. I’m trying to control three servo motor to move a robotic arm. Some time ago i’m wrritten inverse kinematic algorithm with Matlab to simulate the moving of a robotic arm. Now i’m made a robotic arm and would to move it with Arduino. I’m trying to write an inverse kinematic algorithm using the Arduino language, but i’m encountered some problems and becouse of my inexperience i don’t succeeded in resolve it only using the information founded by google. I report in this message the code that i have written.

#include<Servo.h>

Servo M1;
Servo M2;
Servo M3;
int xe[3];
int xd = {1,1,1};
int J[2][2];
int q[2];
int dq[2];
int e[2];
int K={100,100,100};
int DH[2][3]={{0,90,0,0},
{12,0,0,0},
{6,0,0,0}};
int dt=15;

void setup () {
Serial.begin(9600);
M1.attach(9,500,2500);
M2.attach(10,500,2500);
M3.attach(11,500,2500);
}

void loop () {

T=cindir(DH);
xe={T[0][3],T[1][3],T[2][3]};
J=jacobian(DH);
e=xd-xe;
JT=transpose(J,2,2);
dq=JTKe;
q=q1+dqdt0.001;

M1.write(q[0]);
M2.write(q[1]);
M3.write(q[2]);

DH[0][3]=q[0];
DH[1][3]=q[1];
DH[2][3]=q[2];

delay(dt)
}

int cindir(DH) {
int T[3][3];
int t1=DH[0][3]*pi/180;
int t2=DH[1][3]*pi/180;
int t3=DH[2][3]*pi/180;
int a2=DH[1][1];
int a3=DH[1][2];

T={ {cos(t1)cos(t2+t3), -cos(t1)sin(t2+t3), sin(t1), cos(t1)(a2cos(t2)+a3cos(t2+t3))},
{sin(t1)cos(t1+t3), -sin(t1)sin(t2+t3), -cos(t1), sin(t1)(a2cos(t2)+a3
cos(t2+t3))},
{sin(t2+t3) , cos(t2+t3), 0 , a2sin(t2)+a3sin(t2+t3)},
{0, 0, 0, 1}};

return T;
}

int jacobian(DH) {

int J[2][2];
int t1=DH[0][3]*pi/180;
int t2=DH[1][3]*pi/180;
int t3=DH[2][3]*pi/180;
int a2=DH[1][1];
int a3=DH[1][2];

J = { {-sin(t1)(a2cos(t2)+a3cos(t2+t3)), -cos(t1)(a2sin(t2)+a3sin(t2+t3)), -a3cos(t1)sin(t2+t3)},
{cos(t1)
(a2
cos(t2)+a3cos(t2+t3)), -sin(t1)(a2sin(t2)+a3sin(t2+t3)), -a3sin(t1)sin(t2+t3)},
{0, a2
cos(t2)+a3
cos(t2+t3), a3*cos(t2+t3)}};

return J;

}

int transpose (A,dimR,dimC) {

int AT[dimR][dimC];

for(i=0;i<R;i=i+1) {

for(j=0;j<C;j=j+1) {

AT_[j]=A[j];_

* }*
* }*

return AT;

}

When the code is compiled i obtain these errors:
sketch_mar07a:7: error: ‘DH’ was not declared in this scope
sketch_mar07a:8: error: ‘DH’ was not declared in this scope
sketch_mar07a:9: error: ‘A’ was not declared in this scope
sketch_mar07a:9: error: ‘dimR’ was not declared in this scope
sketch_mar07a:9: error: ‘dimC’ was not declared in this scope
sketch_mar07a:9: error: initializer expression list treated as compound expression
sketch_mar07a:16: error: too many initializers for ‘int [3]’
sketch_mar07a:16: error: too many initializers for ‘int [3]’
sketch_mar07a:16: error: too many initializers for ‘int [2][3]’
sketch_mar07a.ino: In function ‘void loop()’:
sketch_mar07a:28: error: ‘T’ was not declared in this scope
sketch_mar07a:28: error: ‘cindir’ cannot be used as a function
sketch_mar07a:29: error: expected primary-expression before ‘{’ token
sketch_mar07a:29: error: expected `;' before '{' token*</em> <em>*sketch_mar07a:30: error: 'jacobian' cannot be used as a function*</em> <em>*sketch_mar07a:31: error: incompatible types in assignment of 'int' to 'int [2]'*</em> <em>*sketch_mar07a:32: error: 'JT' was not declared in this scope*</em> <em>*sketch_mar07a:32: error: 'transpose' cannot be used as a function*</em> <em>*sketch_mar07a:34: error: argument of type 'int (Servo::)()' does not match 'int'*</em> <em>*sketch_mar07a:34: error: argument of type 'int (Servo::)()' does not match 'int'*</em> <em>*sketch_mar07a:34: error: argument of type 'int (Servo::)()' does not match 'int'*</em> <em><em>sketch_mar07a:35: error: invalid operands of types 'int [2]' and 'int' to binary 'operator*'</em></em> <em>*sketch_mar07a:46: error: expected `;’ before ‘}’ token
sketch_mar07a.ino: At global scope:
sketch_mar07a:48: error: redefinition of ‘int cindir’
sketch_mar07a:7: error: ‘int cindir’ previously defined here
Could you give me some infomation about where find some materials that could help me?
Thaks

``````int DH[2][3]={{0,90,0,0},
{12,0,0,0},
{6,0,0,0}};
``````

Should be only 2 * 3 values = 6 values, you have twelve. Maybe:

``````int DH[2][3]={{0,90,0},
{12,0,0}
};
``````

or:

``````int DH[3][4]={{0,90,0,0},
{12,0,0,0},
{6,0,0,0}};
``````

Also, just in case.

The little UNO cant power 3 servos off its power alone. Multiple servos need an outside power source or they cause the UNO to reboot when the servos try to move. I learned this the hard way.

-jim lee