ardupilot/libraries/APM_PI/APM_PI.cpp
tridge60@gmail.com fc0c75963b renamed ACM_PI to APM_PI to fix build
the library name needs to match the header name for the arduino build
to work

git-svn-id: https://arducopter.googlecode.com/svn/trunk@3254 f9c3cf11-9bcb-44bc-f272-b75c42450872
2011-09-05 01:15:24 +00:00

50 lines
742 B
C++

// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
/// @file ACM_PI.cpp
/// @brief Generic PI algorithm
#include <math.h>
#include "APM_PI.h"
long
APM_PI::get_pi(int32_t error, uint16_t dt)
{
float output = 0;
float delta_time = (float)dt / 1000.0;
// Compute proportional component
output += error * _kp;
// Compute integral component if time has elapsed
_integrator += (error * _ki) * delta_time;
if (_integrator < -_imax) {
_integrator = -_imax;
} else if (_integrator > _imax) {
_integrator = _imax;
}
output += _integrator;
return output;
}
void
APM_PI::reset_I()
{
_integrator = 0;
}
void
APM_PI::load_gains()
{
_group.load();
}
void
APM_PI::save_gains()
{
_group.save();
}