The code below has three arguments of the type double*. The code is part of an Arduino PID library and the user would typically give a reading of an analogue port or some kind of sensor as the argument for the "input" term and some fixed value or user controlled variable as the value of the "setpoint" term. But the argument is of type double*. Shouldn't the user get an error when he provides a double?
PID::PID(double* Input, double* Output, double* Setpoint,
double Kp, double Ki, double Kd, int ControllerDirection)
{
myOutput = Output;
myInput = Input;
mySetpoint = Setpoint;
inAuto = false;
PID::SetOutputLimits(0, 255); // default output limit corresponds to
// the arduino pwm limits
SampleTime = 100; // default Controller Sample Time is 0.1 seconds
PID::SetControllerDirection(ControllerDirection);
PID::SetTunings(Kp, Ki, Kd);
lastTime = millis()-SampleTime;
}
Does the constructor just take the address of the double that the user provides?
If the user was reading some temperature data, say double temp=AnalogRead(1). So reading whatever comes in from the analogue pin 1, would myOutput just be the address of those incoming temperature readings?
myInput, myOutput and mySetpoint get de-referenced in another member function.
double input = *myInput;
double error = *mySetpoint - input;