PID - linear encoder - Arduino<>Arduino communication approach

Hi All,

I Started fiddling around with serial communication in my project but I just can't get it to work.
However, this might not be the most effecient approach so I'm asking here.

I hope someone can give me some suggestions on the following.

My goal is to PID control a set of electro magnets, I want to control the movement.
To test and play around with PID I build a system :

  • A DC motor with a belt attached
  • attached to the belt : a 150 lpi encoder strip from a printer
  • The strip moves though a linear encoder giving 600 pulses per inch

I would like to do the PID on an Arduino Mega. I read however that the many interrupts from the linear encoder (using encoder.h) could interfere with the PID control.

So I set up an Arduino Micro to do the sensor reading. It computes the movement in mm and is it 0.1mm accurate. This part works.

But how do I get the data from the Micro to the Mega that is going to do do the PID computing ?
Should the Micro be pushing data or might it be better to let the Mega ask a value when it needs it for computing ?

Is serial the way to go or are there other options ?

Thanks for reading.

Hi,
Can you draw a diagram of what you are trying to achieve, the belt, encoder and magnets.

You want to PID control the belt with a magnet on it, what does it need to follow under PID control?

Tom.... :slight_smile:

I read however that the many interrupts from the linear encoder (using encoder.h) could interfere with the PID control.

There is no reason to assume that this "interference" will actually be a serious problem, so I suggest to have the Mega do everything at first. It will surely work at low interrupt rates.

If PID control stops working well as you go to higher interrupt rates, then you can take the more complicated route.

TomGeorge:
Hi,
Can you draw a diagram of what you are trying to achieve, the belt, encoder and magnets.

You want to PID control the belt with a magnet on it, what does it need to follow under PID control?

Tom.... :slight_smile:

No, the belt and linear encoder attached to it is a test/explore setup. The motor drives a belt, a linear encoder strip is attached to the belt, the strip is then fed through an encoder that outputs the position to the Micro. In this test-setup I use the DC motor as an equivalent for the magnets. The motor is an actuator in this test-setup. In the end the magnets will be the actuators.

jremington:
There is no reason to assume that this "interference" will actually be a serious problem, so I suggest to have the Mega do everything at first. It will surely work at low interrupt rates.

If PID control stops working well as you go to higher interrupt rates, then you can take the more complicated route.

Yes, I did try to make the Mega handle everything (get position, interrupts, PID) The PID seems to work somewhat but "shaky" and irregular. At the moment I'm not sure if the interrupts mess up the PID or if my PID parameters have to be tuned better.
This is why I would like to rule out the interrupts messing up the PID. If I can rule this out I can focus on the PID parameters

if my PID parameters have to be tuned better.

That is the most likely scenario.

Yes, I am aware of the fact that understanding and tuning is important in PID.

But to rule out the interference of interrupts I am now using i2c : Master Reader/Slave Sender

This way I can have the Mega read the current position from the micro when it is needed.

I found this site with useful info on transmitting bigger numbers:
Sending 16 bit and 32 bit numbers with Arduino I2C

Communication works fine now, next is the PID. I'll do some reading on that subject.

Hi,
is this thread associated with this

http://forum.arduino.cc/index.php?topic=428980.msg2957022#msg2957022

thread?

Tom.... :slight_smile:

Yes it is. I have the communication worked out however.
I'm using i2c as mentioned above.