Author Topic: Arduino, Controllers & PWM  (Read 5775 times)

0 Members and 1 Guest are viewing this topic.

Offline Lunat1cTopic starter

  • Contributor
  • Posts: 37
Arduino, Controllers & PWM
« on: April 14, 2012, 12:18:38 am »
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.
« Last Edit: April 14, 2012, 12:23:12 am by Lunat1c »
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: Arduino, Controllers & PWM
« Reply #1 on: April 14, 2012, 12:40:41 am »
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.

 

Offline amspire

  • Super Contributor
  • ***
  • Posts: 3802
  • Country: au
Re: Arduino, Controllers & PWM
« Reply #2 on: April 14, 2012, 02:29:14 am »
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%.

http://arduino.cc/playground/Code/PIDLibraryAdvancedMethods

Richard.
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11885
  • Country: us
Re: Arduino, Controllers & PWM
« Reply #3 on: April 14, 2012, 02:46:00 am »
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.
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: Arduino, Controllers & PWM
« Reply #4 on: April 15, 2012, 02:30:34 pm »
@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.

 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11885
  • Country: us
Re: Arduino, Controllers & PWM
« Reply #5 on: April 15, 2012, 05:00:46 pm »
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.

Yes that's true, PID controllers can be "direct acting" or "reverse acting". Suppose for example the error is defined as measured value minus setpoint. Then a direct acting controller will increase the output on positive error, whereas a reverse acting controller will decrease the output on positive error. For any given control loop only one setting will provide the required negative feedback and you have to configure it appropriately. For instance if you were controlling temperature in a water bath with a heater you would want the output to increase if the temperature were too low; on the other hand if you were controlling temperature in a cool box with a chiller you would want the output to increase if the temperature were too high.

If you get the action wrong the controller output will just wind up to one of the limits and stick there due to positive feedback.

Unfortunately there is no universal agreement on the labelling of this convention and one person's direct acting controller is another person's reverse acting controller. You have to read the documentation to find out what you have.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf