hi, i'm trying to implement a PID algorithm and i got into trouble while compiling, i'll leave you my code and the error i get below it:
void setup()
{
analogReference(DEFAULT);
pinMode (3, OUTPUT);
pinMode (5, OUTPUT);
Serial.begin(9600);
}
void loop()
{
actuate(PID(calculateError(getSetpoint(), getFeedback());
}
//setpoint data acquisition
float getSetpoint()
{
int setpointPin = A1;
float setpoint = analogRead(setpointPin);
return setpointPin;
}
//feedback data acquisition
float getFeedback()
{
int feedbackPin = A5;
float feedback = analogRead(sensePin);
return feedback;
}
//calculate error
float calculateError(float setpoint, float feedback)
{
float error;
error = setpoint - feedback;
return error;
}
//PID function===>returns output
float PID(error)
{
float pGain = 0;
float IGain = 0;
float DGain = 0;
float output;
output = proportional(error) + integral(error) + differential(error);
}
//proportional function
float proportional( float pError)
{
pOutput = pError * pGain; //calculate de proportional part of the output
return pOutput;
}
//integral function
float integral(float Error)
{
float iState = 0; //sum of the past errors
float iMax = 0; //max value of iState
float iMin = 0; //min value of iState
iState += Error; //update iState
iState = constrain(iState, iMin, iMax); //constrain iState to avoid windup
iOutput = iState * iGain; //calculate the integral output
return iOutput;
}
//differential function
float differential(float Error)
{
float lastError;
errorDifference = Error - lastError; //error variation
dOutput = dGain * errorDifference; //calculate the differential output
lastError = Error; //save the current error to reuse it next time
return dOutput;
}
//actuate
void actuate(output)
{
output = constrain(output, 0, 1023);
map(output, 0, 1023, 0, 255);
analogWrite(3, output);
analogWrite(5, output);
}
'error' was not declared in this scope
control_PID:6: error: 'error' was not declared in this scope
control_PID:10: error: variable or field 'actuate' declared void
control_PID:10: error: 'output' was not declared in this scope
control_PID.cpp: In function 'void loop()':
control_PID:21: error: expected `)' before ';' token
control_PID.cpp: In function 'float getFeedback()':
control_PID:40: error: 'sensePin' was not declared in this scope
control_PID.cpp: At global scope:
control_PID:53: error: redefinition of 'float PID'
control_PID:6: error: 'float PID' previously defined here
control_PID:53: error: 'error' was not declared in this scope
control_PID.cpp: In function 'float proportional(float)':
control_PID:66: error: 'pOutput' was not declared in this scope
control_PID:66: error: 'pGain' was not declared in this scope
control_PID.cpp: In function 'float integral(float)':
control_PID:80: error: 'iOutput' was not declared in this scope
control_PID:80: error: 'iGain' was not declared in this scope
control_PID.cpp: In function 'float differential(float)':
control_PID:88: error: 'errorDifference' was not declared in this scope
control_PID:89: error: 'dOutput' was not declared in this scope
control_PID:89: error: 'dGain' was not declared in this scope
control_PID.cpp: At global scope:
control_PID:96: error: variable or field 'actuate' declared void
control_PID:96: error: 'output' was not declared in this scope
that's all, thanks in advance for your help