Hi,
I am looking at the AP_PID source code and its example.
This is the example code:
[code]void loop()
{
// setup (unfortunately must be done here as we cannot create a global AC_PID object)
AC_PID pid(TEST_P, TEST_I, TEST_D, TEST_IMAX * 100);
uint16_t radio_in;
uint16_t radio_trim;
int error;
int control;
float dt = 1000/50;
// display PID gains
hal.console->printf("P %f I %f D %f imax %f\n", pid.kP(), pid.kI(), pid.kD(), pid.imax());
// capture radio trim
radio_trim = hal.rcin->read(0);
while( true ) {
radio_in = hal.rcin->read(0);
error = radio_in - radio_trim;
control = pid.get_pid(error, dt);
// display pid results
hal.console->printf("radio: %d\t err: %d\t pid:%d\n", radio_in, error, control);
hal.scheduler->delay(50);
}
}[/code]
I do not understand why dt is set as 1000/50. As I understand, dt should be the sampling period i.e. from the beginning of the loop towards the end of the loop, which is approximately 50ms+ in this case. Can anybody explain this to me?