Go Down

Topic: Arduino PID Library (Read 59 times) previous topic - next topic


Aug 21, 2009, 03:47 pm Last Edit: Aug 21, 2009, 06:58 pm by dogsop Reason: 1
Here is another vote for making it easier to embed the PID library in another class. I was in the process of creating a motor control class which would embed a PID controller to set the PWM signal to the motor when I saw psyber's post.

It may not be necessary to add a default constructor. I haven't tested this yet but it does compile.

Code: [Select]
#include "foo.h"

foo myFoo;



Code: [Select]
class foo

  PID myPID;
  double Input;
  double Output;
  double Setpoint;

Code: [Select]
#include "PID_Beta6.h"
#include "foo.h"

foo::foo() : myPID(&Input, &Output, &Setpoint,2,5,1)
  // initialize foo

I had to look up initialization lists, in my real life I've never used them. In another environment I'd include a pointer to a PID object in my class and use new to create it in the constructor.


I has use this libary to control angle of robot arm, it work as well on fixed setpoint.

if my setpoint is change it will not go to setpoint, it have offset. i try to increase D parameter, i would not help.

i guess my problem is my motor start moving at PWM 80%. when is start moving it's very fast and on next sampling it already overshoot.

anyone have some idea to slove this. ;)


on next sampling it already overshoot. anyone have some idea to slove this.

you can use the SetSampleTime() function to make the pid sample more quickly. (http://www.arduino.cc/playground/Code/PIDLibraryAdvancedMethods)



Aug 23, 2009, 02:08 pm Last Edit: Aug 23, 2009, 02:24 pm by Ro-Bot-X Reason: 1
I want to make a motor controller that uses distance as the target but is able to accelerate until reaches a certain speed (sometimes is max speed), continue with that speed until almost at destination and decelerate until it reaches the target distance and stops. Sometimes I need to make small adjustments and speed never reaches the set speed and needs to decelerate because it reaches the destination.
Any advices on how to do that?


Can this PID library include a function to accelerate from 0 to SetSpeed and continue at that speed until the SetPoint is reached (because it will automatically decelerate before reaching the SetPoint)?

I have tried to do a function that accelerates until Speed = SetSpeed and only then activate the PID controller, but sometimes I need to make small corrections so the Speed never reaches SetSpeed. Can this be done in the PID controller?

I don't think so. the pid is a "simple" control element whose job is to make Input = Setpoint.  once you want to do more complicated things, you'll need to make the pid part of a larger control strategy.  it sounds like that's what you're trying to do anyway, so let's talk about that.

First, I'm not sure I completely understand your application.  You use both SetSpeed and SetPoint in your question.  I'm would assume that Speed is the output from the pid, and Setpoint is the value you want the PID Input to achieve.  I'm not sure though.

I don't want to give you bad advice at this point.  Could you give a description of what it is you're trying to do in the real world (i.e.  "I've got this thermonuclear jetpack, and I'm tyring to control take-off velocity. my inputs and outputs are...")  I'll be able to give better advice once I know what it is you're trying to do.


Go Up