Electronics > Microcontrollers

Arduino, Controllers & PWM

(1/2) > >>

Lunat1c:
Hi,

I'm currently working on a project where by means of an accelerometer I am getting an acceleration which I'm converting into displacement (which is my input), and then I'm moving an object the same distance by controlling a dc motor with an Arduino through an h-bridge (I am getting positional feedback from a magnetic encoder). One of the major issues I'm having is that by making use of the PID library of the arduino, when the PID input is 100 (and the setpoint is 0), the output is not 255. It's not just that it's not 255, but it's almost negligble (less than 20). What am I doing wrong?

Also, for this application I don't even need Integral control because my object remains at rest when I stop the motor. So PD control should be enough.

Any help will be greatly appreciated. Thank you.

HackedFridgeMagnet:
I am fairly sure if you set the constant "I_Param : Integral Parameter. Must be non-negative. " to zero, that would give you PD control.

Also are you sure you don't need the integral component?
ps. I am just trying to learn about this stuff myself, I haven't actually used the library.

amspire:
Have you set your InMin and INMax input limits. As I understand it, the input is a floating point number that gets scaled so that when the input = INMax, it will be at 100%.

Richard.

IanB:
Turning off integral action on a PID controller can be problematic. The non-obvious function of integral action is to automatically set an appropriate output bias so that the controller output moves to where you want it to be. If you turn off integral action there is an unsatisfied degree of freedom and there is no longer a direct relationship between the output position and the input signal (if you think calculus, this is analogous  to the constant of integration in an indefinite integral--the constant is arbitrary and must be determined by some suitable constraint). What this means in practice with a P or PD controller is that you must bias the output manually to some suitable value (a bit like how you must bias a transistor into the correct operating region when using it as an analog amplifier--a transistor amplifier is a proportional controller that moves the output signal in response to the input signal).

So what you might try doing is introducing some integral action. Keep it small, but non-zero.

HackedFridgeMagnet:
@Lunat1c

I had a bit of a go with that library,
from my understanding, when you have the setpoint at zero the controller will try to move the input towards it. If the input is 100 then the output should move to zero.
Assuming the output moves in the default direction, it will do this by reducing the output.
So from my understanding it is behaving normally.
Maybe you need to set the output sign to negative, it's in the constructor, I forgot the terminology (Direct or "something else") see the source.

Things you may need to play with are the Kp, Ki, Kd and sample time, sample time should be slow enough for the output to stabilise before the next iteration.
To tune I think you set Ki and Kd to zero and set Kp so you get a bit of overshoot.
Then just fiddle around with the others, but keep them small.

I was just playing with a small light controller circuit, it was working a bit strangely until I found what I thought are a couple of obvious bugs, they were so obvious I am worried that it is just my understanding that is at fault.
But I put in a couple of fixes and now it is nice and stable. I will email the guy who wrote it and see what he says.