Beispiel #1
0
/*Constructor (...)*********************************************************
 *    The parameters specified here are those for for which we can't set up
 *    reliable defaults, so we need to have the user set them.
 ***************************************************************************/
pid_data_t config_data(float Input, float Output, float Setpoint,
                       float kp, float ki, float kd, int ControllerDirection)
{
	pid_data_t pid_data = malloc(sizeof(struct pid_data_t));
	pid_data->Input    = Input;
	pid_data->Output   = Output;
	pid_data->Setpoint = Setpoint;
    pid_data->inAuto   = FALSE;

	pid_setOutputLimits(pid_data, 0, 255);                //default output limit
	pid_data->SampleTime = 100;	                //default Controller Sample Time is 0.1 seconds

    pid_setControllerDirection(pid_data, ControllerDirection);
    pid_setTunings(pid_data, kp, ki, kd);

    return pid_data;
}//config_data
Beispiel #2
0
/*Initialization() *********************************************************
 *    The parameters specified here are those for for which we can't set up 
 *    reliable defaults, so we need to have the user set them.
 ***************************************************************************/
void pid_init()
{
	// initialize the input, output and setpoint arrays
	for (uint8 i=0; i<PID_DIMENSION; i++) {
		pid_input[i] = 0;
		pid_output[i] = 0;
		pid_setpoint[i] = 0; 
		integral_term[i] = 0;
	}
	
	// set basic properties
	pid_setOutputLimits(0-OUTPUT_LIMIT, OUTPUT_LIMIT);	// default output limit - see pid.h
    sample_time = SAMPLE_INTERVAL;			// default Controller sample time is 16ms
    pid_setControllerDirection(DIRECT);		// direct mode
	// pid_setControllerDirection(REVERSE);		// reverse mode
	
	// set default tuning values - see pid.h
    pid_setTunings(DEFAULT_KP, DEFAULT_KI, DEFAULT_KD);		
	
	// set sample time and initialize timer
	pid_setSampleTime(SAMPLE_INTERVAL);
	last_time = millis() - sample_time;		// initialize time keeping variable		
    inAuto = FALSE;							// don't start the controller until needed
}