Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the PID output constraint for the attitude PIDs (rate/angle) … #194

Merged
merged 1 commit into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/modules/interface/pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
#define PID_YAW_INTEGRATION_LIMIT 360.0


#define DEFAULT_PID_INTEGRATION_LIMIT 5000.0
#define DEFAULT_PID_INTEGRATION_LIMIT 5000.0
#define DEFAULT_PID_OUTPUT_LIMIT 0.0

#else

Expand Down Expand Up @@ -98,7 +99,8 @@
#define PID_YAW_INTEGRATION_LIMIT 360.0


#define DEFAULT_PID_INTEGRATION_LIMIT 10000.0
#define DEFAULT_PID_INTEGRATION_LIMIT 10000.0
#define DEFAULT_PID_OUTPUT_LIMIT 0.0

#endif

Expand All @@ -115,8 +117,8 @@ typedef struct
float outP; //< proportional output (debugging)
float outI; //< integral output (debugging)
float outD; //< derivative output (debugging)
float iLimit; //< integral limit
float outputLimit; //< output limit
float iLimit; //< integral limit, absolute value. '0' means no limit.
float outputLimit; //< total PID output limit, absolute value. '0' means no limit.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think it's a great idea to have the outputLimit functionality at all -- if the output of the PID needs to be limited, that suggests the coefficients need to be tuned instead. However, the current position controller makes use of this functionality, and I don't have a way to test out changes to that layer, so I've left it in.

See my comments on issue #185 for some more details.

float dt; //< delta-time dt
lpf2pData dFilter; //< filter for D term
bool enableDFilter; //< filter for D term enable flag
Expand Down
14 changes: 0 additions & 14 deletions src/modules/src/attitude_pid_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ static int16_t rollOutput;
static int16_t pitchOutput;
static int16_t yawOutput;

static float rpRateLimit = 150.0f;
static float yawRateLimit = 150.0f;
static float rpyRateLimitOverhead = 1.1f;

static bool isInit;

void attitudeControllerInit(const float updateDt)
Expand Down Expand Up @@ -94,10 +90,6 @@ void attitudeControllerInit(const float updateDt)
pidSetIntegralLimit(&pidPitch, PID_PITCH_INTEGRATION_LIMIT);
pidSetIntegralLimit(&pidYaw, PID_YAW_INTEGRATION_LIMIT);

pidRollRate.outputLimit = INT16_MAX;
pidPitchRate.outputLimit = INT16_MAX;
pidYawRate.outputLimit = INT16_MAX;

isInit = true;
}

Expand Down Expand Up @@ -125,10 +117,6 @@ void attitudeControllerCorrectAttitudePID(
float eulerRollDesired, float eulerPitchDesired, float eulerYawDesired,
float* rollRateDesired, float* pitchRateDesired, float* yawRateDesired)
{
pidRoll.outputLimit = rpRateLimit * rpyRateLimitOverhead;
pidPitch.outputLimit = rpRateLimit * rpyRateLimitOverhead;
pidYaw.outputLimit = yawRateLimit * rpyRateLimitOverhead;

pidSetDesired(&pidRoll, eulerRollDesired);
*rollRateDesired = pidUpdate(&pidRoll, eulerRollActual, true);

Expand Down Expand Up @@ -201,8 +189,6 @@ PARAM_ADD(PARAM_FLOAT, yaw_kd, &pidYaw.kd)
PARAM_GROUP_STOP(pid_attitude)

PARAM_GROUP_START(pid_rate)
PARAM_ADD(PARAM_FLOAT, rpRateLimit, &rpRateLimit)
PARAM_ADD(PARAM_FLOAT, yawRateLimit, &yawRateLimit)
PARAM_ADD(PARAM_FLOAT, roll_kp, &pidRollRate.kp)
PARAM_ADD(PARAM_FLOAT, roll_ki, &pidRollRate.ki)
PARAM_ADD(PARAM_FLOAT, roll_kd, &pidRollRate.kd)
Expand Down
19 changes: 13 additions & 6 deletions src/modules/src/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void pidInit(PidObject* pid, const float desired, const float kp,
pid->ki = ki;
pid->kd = kd;
pid->iLimit = DEFAULT_PID_INTEGRATION_LIMIT;
pid->outputLimit = DEFAULT_PID_INTEGRATION_LIMIT;
pid->outputLimit = DEFAULT_PID_OUTPUT_LIMIT;
pid->dt = dt;
pid->enableDFilter = enableDFilter;
if (pid->enableDFilter)
Expand Down Expand Up @@ -77,16 +77,23 @@ float pidUpdate(PidObject* pid, const float measured, const bool updateError)
pid->outD = pid->kd * pid->deriv;
output += pid->outD;

float i = pid->integ + pid->error * pid->dt;
// Check if integral is saturated
if (abs(i) <= pid->iLimit || abs(pid->ki * i + output) <= pid->outputLimit) {
pid->integ = i;
pid->integ += pid->error * pid->dt;

// Constrain the integral (unless the iLimit is zero)
if(pid->iLimit != 0)
{
pid->integ = constrain(pid->integ, -pid->iLimit, pid->iLimit);
}

pid->outI = pid->ki * pid->integ;
output += pid->outI;

output = constrain(output, -pid->outputLimit, pid->outputLimit);
// Constrain the total PID output (unless the outputLimit is zero)
if(pid->outputLimit != 0)
{
output = constrain(output, -pid->outputLimit, pid->outputLimit);
}


pid->prevError = pid->error;

Expand Down