Arduino as a dc motor controler


Thread Starter



I'm learning control theory. I'm building a robot arm and I'm making my own servos for each joint. An arduino is used as a digital controller for the angular position of joints.

It works, and I am interested in ways to improve it's functioning, and which way of improving would be most cost-effective.

I'm using mini dc geared motors, like these:
I'm using a 9V power supply. Arduino provides logic and pwm signals to h-bridge chip SN754410.

Sensor is a 2.5 kOhm linear potentiometer, mounted on the output shaft of the motor.

Arduino has a 10 bit ADC to read from the sensor (last digit noisy). Velocity is estimated as the change of position from previous loop. Loop frequency is 100Hz.

I have an inner velocity loop and an outer position loop. Gains and other variables can be set from the computer. Velocity estimation is noisy.

Does any of this sound improvable so far?

Here is some relevant code:<pre>
starttime = micros ();
ref = analogRead (1);
pos = analogRead (0);

err = ref - pos;
vel = pos-lastpos;

lastpos = pos;

Qo = Kp*err - Kv*vel;

Qo = constrain (Qo, -255, 255);
Output (Qo);


if (starttime-micros() < period) // period is 10 000 microseconds
{ };