# Observer Design for a DC motor

I am doing work in which the goal is to design a state observer to estimate the speed of a DC motor using only armature current. The first part is ready, where I got the engine characteristics and designed the observer on MATLAB. My difficulty now is to implement the observer in arduino. The observer expression is: x '^ = (A-LC) x ^ + B * u + L * y
Where A, L, C, B are already defined matrices, u = armature voltage (voltage applied to the motor) and y = armature current. My difficulty is assembling this expression in code, can someone help me. Remembering that u and y will be real time readings of the armature voltage and current respectively.

Its my first time using Arduino and i really don’t know how to program this.

i have done this code so far and i don’t know if it’s right. The “for” part is not working.

float Va = 0;
float y = 0;

const double matr_A_LC[2][2] = {
{-8, 46400},
{-7, -959}
};

const double matr_L[2][1] = {
{-29889},
{-261}
};

const double ent[1][1] = {
{Va}
};

const double saida[1][1] = {
{y}
};

const double B[2][1] = {
{0},
{289.8551}
};

double states[2][1] = {
{0},
{0}
};

double nstates[2][1] = {
{0},
{0}
};

void setup() {

Serial.begin(9600);

}

void loop() {
Va = map(Va, 0, 1023, 0, 15);

for (int i = 0; i<2; i++){
for (int j = 0; j < 2; j++){
nstates = matr_A_LC[j]states[j]; //+ ent + matr_L_saida;_

* }*
* }*
}

i don't know if it's right.

Sorry, not even close. Google "matrix vector multiplication C/C++" for tutorials.

Assuming you’re planning to do this with an AVR processor, your biggest problem is likely to be the rather slow A/D. That alone will surely limit you to either very low RPM, or very imprecise RPM calculations.

Regards,
Ray L.

Note: map() returns a long integer value. You should probably do your math in float.

`````` Va = (Va * 15.0) / 1024.0;
``````