Skip to content

Commit 8f46d27

Browse files
committed
Apply clang-tidy readability fixes
1 parent bfc5723 commit 8f46d27

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

PID_v1.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,44 +60,49 @@ bool PID::Compute(unsigned long now) {
6060
outputSum += (ki * error);
6161

6262
/*Add Proportional on Measurement, if P_ON_M is specified*/
63-
if (pOn == P_ON_M)
63+
if (pOn == P_ON_M) {
6464
outputSum -= kp * dInput;
65+
}
6566

66-
if (outputSum > outMax)
67+
if (outputSum > outMax) {
6768
outputSum = outMax;
68-
else if (outputSum < outMin)
69+
} else if (outputSum < outMin) {
6970
outputSum = outMin;
71+
}
7072

7173
/*Add Proportional on Error, if P_ON_E is specified*/
7274
double output;
73-
if (pOn == P_ON_E)
75+
if (pOn == P_ON_E) {
7476
output = kp * error;
75-
else
77+
} else {
7678
output = 0;
79+
}
7780

7881
/*Compute Rest of PID Output*/
7982
output += outputSum - kd * dInput;
8083

81-
if (output > outMax)
84+
if (output > outMax) {
8285
output = outMax;
83-
else if (output < outMin)
86+
} else if (output < outMin) {
8487
output = outMin;
88+
}
8589
*myOutput = output;
8690

8791
/*Remember some variables for next time*/
8892
lastInput = input;
8993
lastTime = now;
9094
return true;
91-
} else
92-
return false;
95+
}
96+
return false;
9397
}
9498

9599
// This function allows the controller's dynamic performance to be adjusted.
96100
// it's called automatically from the constructor, but tunings can also
97101
// be adjusted on the fly during normal operation
98102
void PID::SetTunings(double Kp, double Ki, double Kd, PIDProportionalOn POn) {
99-
if (Kp < 0 || Ki < 0 || Kd < 0)
103+
if (Kp < 0 || Ki < 0 || Kd < 0) {
100104
return;
105+
}
101106

102107
pOn = POn;
103108

@@ -139,21 +144,24 @@ void PID::SetSampleTime(int NewSampleTime) {
139144
// want to clamp it from 0-125. who knows. at any rate, that can all be done
140145
// here.
141146
void PID::SetOutputLimits(double Min, double Max) {
142-
if (Min >= Max)
147+
if (Min >= Max) {
143148
return;
149+
}
144150
outMin = Min;
145151
outMax = Max;
146152

147153
if (mode == AUTOMATIC) {
148-
if (*myOutput > outMax)
154+
if (*myOutput > outMax) {
149155
*myOutput = outMax;
150-
else if (*myOutput < outMin)
156+
} else if (*myOutput < outMin) {
151157
*myOutput = outMin;
158+
}
152159

153-
if (outputSum > outMax)
160+
if (outputSum > outMax) {
154161
outputSum = outMax;
155-
else if (outputSum < outMin)
162+
} else if (outputSum < outMin) {
156163
outputSum = outMin;
164+
}
157165
}
158166
}
159167

@@ -174,10 +182,11 @@ void PID::SetMode(PIDControllerMode Mode) {
174182
void PID::Initialize() {
175183
outputSum = *myOutput;
176184
lastInput = *myInput;
177-
if (outputSum > outMax)
185+
if (outputSum > outMax) {
178186
outputSum = outMax;
179-
else if (outputSum < outMin)
187+
} else if (outputSum < outMin) {
180188
outputSum = outMin;
189+
}
181190
}
182191

183192
// The PID will either be connected to a PIDControllerDirection::DIRECT acting
@@ -196,8 +205,8 @@ void PID::SetControllerDirection(PIDControllerDirection Direction) {
196205
// Just because you set the Kp=-1 doesn't mean it actually happened. these
197206
// functions query the internal state of the PID. they're here for display
198207
// purposes. this are the functions the PID Front-end uses for example
199-
double PID::GetKp() { return dispKp; }
200-
double PID::GetKi() { return dispKi; }
201-
double PID::GetKd() { return dispKd; }
208+
double PID::GetKp() const { return dispKp; }
209+
double PID::GetKi() const { return dispKi; }
210+
double PID::GetKd() const { return dispKd; }
202211
PIDControllerMode PID::GetMode() { return mode; }
203212
PIDControllerDirection PID::GetDirection() { return controllerDirection; }

PID_v1.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class PID {
5858
// they were created mainly for the pid front-end,
5959
// where it's important to know what is actually
6060
// inside the PID.
61-
double GetKp();
62-
double GetKi();
63-
double GetKd();
61+
double GetKp() const;
62+
double GetKi() const;
63+
double GetKd() const;
6464
PIDControllerMode GetMode();
6565
PIDControllerDirection GetDirection();
6666

0 commit comments

Comments
 (0)