Go Down

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

psyber

br3ttb,

You might want to include a default constructor in your next build.  This might be my lack of experience with this platform but the following would not compile:
Code: [Select]

include <WProgram.h>
include<PID_Beta6.h>
class foo{
public:
PID myPID;
}


Apparently it would not compile b/c it could not find a matching function call to PID();

I am new to this particular platform, so I could be missing something, however to get this to work in my class I had add the default constructor to your code and recompile.  

Otherwise your package looks good.

br3ttb

I never considered that people would be embedding my class into another class.  COOL!

The reason I didn't go with a default constructor is that for the pid to run correctly, it HAS to have the things specified in the current constructor (input, output, setpoint, tuning parameters.)   I figured that would be a gentle way to get people to specify them.

maybe a middle of the road option would be to include a default constructor but have it commented out?  if you're writing a new class you'll likely have the know-how to find/ uncomment.  if you're the standard Arduino user you'll notice no change.  thoughts?

Brett

betwys

[his example 1]
********************************************************
* PID Simple Example
* Reading analog input 0 to control analog PWM output 3
********************************************************/

#include <PID_Beta6.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1);

void setup()
{
 //initialize the variables we're linked to
 Input = analogRead(0);
 Setpoint = 100;

 //turn the PID on
 myPID.SetMode(AUTO);
}

void loop()
{
 Input = analogRead(0);
 myPID.Compute();
 analogWrite(3,Output);
}

***************************************
[Your non-working example]
include <WProgram.h>
include<PID_Beta6.h>
class foo{
public:
PID myPID;
}

*******************************

I guess I don't understand your critique - your example stuff doesn't look like his example stuff????

Can you 'splain the problem in words of at most two syllables?  :)

Brian W

retrolefty

Class? The only thing I recall about class is that if your late too often you could receive saturday detention.  ;)

Lefty

br3ttb

Brian:

psyber is using the library in a way I never even considered.  Most people will take the pid library and use it right in their Arduino program, the way my example illustrates.

the way I understand it, psyber encountered a problem trying to embed a pid within a library of his own creation.  On the library creation side, the rules are a little different.  To make it work, he needed to -very lightly- massage the pid library code.  His suggestion was aimed at saving the next guy some trouble.

Lefty:  This is all I know about class ;) : http://www.imdb.com/name/nm0001627/

Brett

Go Up