История изменений
Исправление WRG, (текущая версия) :
последний вариант фукнции вот такой
int16_t pid_compute(int measured, int setpoint, uint16_t *prev_error, float *integral)
{
int16_t error = setpoint - measured;
int16_t output;
float derivate;
*integral = *integral + (error * kI);
derivate = (error - *prev_error) / (float)PID_INTERVAL;
output = (kP * error) + (kI * (*integral)) + (kD * derivate);
*prev_error = error;
if(output > MOTOR_MAX_SPEED) output = MOTOR_MAX_SPEED;
if(output < MOTOR_MIN_SPEED) output = MOTOR_MIN_SPEED;
return output;
}
Исходная версия WRG, :
последний вариант фукнции вот такой
int16_t pid_compute(int measured, int setpoint, uint16_t *prev_error, float *integral)
{
int16_t error = setpoint - measured;
int16_t output;
float derivate;
*integral = *integral + (error * kI);
derivate = (error - *prev_error) / (float)PID_INTERVAL;
output = (kP * error) + (kI * (*integral)) + (kD * derivate);
*prev_error = error;
if(output > MOTOR_MAX_SPEED) output = MOTOR_MAX_SPEED;
if(output < MOTOR_MIN_SPEED) output = MOTOR_MIN_SPEED;
return output;
}