Not Declared in Scope Error

I'm working on an autopilot program for an ATMega328. In one of my header files I'm defining the control function and asking it to constrain a number (so the plane doesn't try banking unsafely :wink: ). Constrain is a built in function, and so it should work just about anywhere, right? I keep getting "PID.h:23:error: ' constrain' was not declared in this scope"

Here's the code in question. Help?

#define  PITCHNAV  0
#define  ROLLNAV   1
#define  PITCHOUT  2
#define  ROLLOUT   3
#define  YAWOUT    4
#define  THROTOUT  5

#define  TURNBANK  30
#define  CLIMBRATE 2.032

#define  MAXPITCHUP  30
#define  MAXPITCHDOWN  -15
#define  MAXBANK  60

const int KP[] = {  15,  1,   0.1,     0.1,    5,   -0.5, 3000, 15};
const int KI[] = {0.03,  1,  0.01,   0.001,    1, -0.004,  600,  0};
const int KD[] = { -10,  1, 0.002, 0.00005, 0.05,  -0.03,    0,  1};

float integ[] = {0, 0, 0, 0, 0, 0, 0, 0};
float preverror[] = {0, 0, 0, 0, 0, 0, 0, 0};

float PID(int mode, float target, float actual, float dt){
  if (mode == PITCHOUT){
    target = constrain(target, MAXPITCHDOWN, MAXPITCHUP);
  }
  if (mode == ROLLOUT){
    target = constrain(target, -MAXBANK, MAXBANK);
  }
  float error = target - actual;
  integ[mode] = integ[mode] + error * dt;
  float deriv = (error - preverror[mode]) / dt;
  preverror[mode] = error;
  return ((KP[mode] * error) + (KI[mode] * integ[mode]) + (KD[mode] * deriv));
}

Where are you including it in your sketch?

I don't see any other includes in your header file.

constrain is a built in ARDUINO function, but that's only true for .pde files, because the Arduino environment automatically handles all the necessary includes for .pde files for you. To get the same effect with header files, you need to include WProgram.h yourself.

Oh man! Thank's a bunch! I totally did not know about that... I'm more than a little new to this.
Are there any other headers I might want to include?
Thanks!