Skip to content

Commit 00b4bb4

Browse files
committed
Clean up comment style
I find the current style extremely distracting.
1 parent 5f2c7a0 commit 00b4bb4

File tree

3 files changed

+91
-112
lines changed

3 files changed

+91
-112
lines changed

PID_v1.cpp

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313

1414
#include "PID_v1.h"
1515

16-
/*Constructor (...)*********************************************************
17-
* The parameters specified here are those for for which we can't set up
18-
* reliable defaults, so we need to have the user set them.
19-
***************************************************************************/
16+
// The parameters specified here are those for for which we can't set up
17+
// reliable defaults, so we need to have the user set them.
2018
PID::PID(double *Input, double *Output, double *Setpoint, double Kp, double Ki,
2119
double Kd, PIDProportionalOn POn,
2220
PIDControllerDirection ControllerDirection) {
@@ -25,8 +23,9 @@ PID::PID(double *Input, double *Output, double *Setpoint, double Kp, double Ki,
2523
mySetpoint = Setpoint;
2624
mode = MANUAL;
2725

28-
PID::SetOutputLimits(0, 255); // default output limit corresponds to
29-
// the arduino pwm limits
26+
// default output limit corresponds to
27+
PID::SetOutputLimits(0, 255);
28+
// the arduino pwm limits
3029

3130
SampleTime = 100; // default Controller Sample Time is 0.1 seconds
3231

@@ -36,23 +35,18 @@ PID::PID(double *Input, double *Output, double *Setpoint, double Kp, double Ki,
3635
lastTime = millis() - SampleTime;
3736
}
3837

39-
/*Constructor (...)*********************************************************
40-
* To allow backwards compatability for v1.1, or for people that just want
41-
* to use Proportional on Error without explicitly saying so
42-
***************************************************************************/
43-
38+
// To allow backwards compatability for v1.1, or for people that just want to
39+
// use Proportional on Error without explicitly saying so
4440
PID::PID(double *Input, double *Output, double *Setpoint, double Kp, double Ki,
4541
double Kd, PIDControllerDirection ControllerDirection)
4642
: PID::PID(Input, Output, Setpoint, Kp, Ki, Kd, P_ON_E,
4743
ControllerDirection) {}
4844

49-
/* Compute()
50-
*********************************************************************** This,
51-
*as they say, is where the magic happens. this function should be called every
52-
*time "void loop()" executes. the function will decide for itself whether a
53-
*new pid Output needs to be computed. returns true when the output is
54-
*computed, false when nothing has been done.
55-
**********************************************************************************/
45+
// This, as they say, is where the magic happens.
46+
// This function should be called every time "void loop()" executes.
47+
// The function will decide for itself whether a new pid Output needs to be
48+
// computed. returns true when the output is computed, false when nothing has
49+
// been done.
5650
bool PID::Compute() {
5751
if (mode != AUTOMATIC) {
5852
return false;
@@ -100,11 +94,9 @@ bool PID::Compute() {
10094
return false;
10195
}
10296

103-
/* SetTunings(...)*************************************************************
104-
* This function allows the controller's dynamic performance to be adjusted.
105-
* it's called automatically from the constructor, but tunings can also
106-
* be adjusted on the fly during normal operation
107-
******************************************************************************/
97+
// This function allows the controller's dynamic performance to be adjusted.
98+
// it's called automatically from the constructor, but tunings can also
99+
// be adjusted on the fly during normal operation
108100
void PID::SetTunings(double Kp, double Ki, double Kd, PIDProportionalOn POn) {
109101
if (Kp < 0 || Ki < 0 || Kd < 0)
110102
return;
@@ -127,16 +119,12 @@ void PID::SetTunings(double Kp, double Ki, double Kd, PIDProportionalOn POn) {
127119
}
128120
}
129121

130-
/* SetTunings(...)*************************************************************
131-
* Set Tunings using the last-rembered POn setting
132-
******************************************************************************/
122+
// Set Tunings using the last-rembered POn setting
133123
void PID::SetTunings(double Kp, double Ki, double Kd) {
134124
SetTunings(Kp, Ki, Kd, pOn);
135125
}
136126

137-
/* SetSampleTime(...) *********************************************************
138-
* sets the period, in Milliseconds, at which the calculation is performed
139-
******************************************************************************/
127+
// sets the period, in Milliseconds, at which the calculation is performed
140128
void PID::SetSampleTime(int NewSampleTime) {
141129
if (NewSampleTime > 0) {
142130
double ratio = (double)NewSampleTime / (double)SampleTime;
@@ -146,14 +134,12 @@ void PID::SetSampleTime(int NewSampleTime) {
146134
}
147135
}
148136

149-
/* SetOutputLimits(...)****************************************************
150-
* This function will be used far more often than SetInputLimits. while
151-
* the input to the controller will generally be in the 0-1023 range (which is
152-
* the default already,) the output will be a little different. maybe they'll
153-
* be doing a time window and will need 0-8000 or something. or maybe they'll
154-
* want to clamp it from 0-125. who knows. at any rate, that can all be done
155-
* here.
156-
**************************************************************************/
137+
// This function will be used far more often than SetInputLimits. while
138+
// the input to the controller will generally be in the 0-1023 range (which is
139+
// the default already,) the output will be a little different. maybe they'll
140+
// be doing a time window and will need 0-8000 or something. or maybe they'll
141+
// want to clamp it from 0-125. who knows. at any rate, that can all be done
142+
// here.
157143
void PID::SetOutputLimits(double Min, double Max) {
158144
if (Min >= Max)
159145
return;
@@ -173,11 +159,9 @@ void PID::SetOutputLimits(double Min, double Max) {
173159
}
174160
}
175161

176-
/* SetMode(...)****************************************************************
177-
* Allows the controller Mode to be set to manual (0) or Automatic (non-zero)
178-
* when the transition from manual to auto occurs, the controller is
179-
* automatically initialized
180-
******************************************************************************/
162+
// Allows the controller Mode to be set to manual (0) or Automatic (non-zero)
163+
// when the transition from manual to auto occurs, the controller is
164+
// automatically initialized
181165
void PID::SetMode(PIDControllerMode Mode) {
182166
/*we just went from manual to auto*/
183167
if (Mode == AUTOMATIC && mode != AUTOMATIC) {
@@ -187,10 +171,8 @@ void PID::SetMode(PIDControllerMode Mode) {
187171
mode = Mode;
188172
}
189173

190-
/* Initialize()****************************************************************
191-
* does all the things that need to happen to ensure a bumpless transfer
192-
* from manual to automatic mode.
193-
******************************************************************************/
174+
// does all the things that need to happen to ensure a bumpless transfer
175+
// from manual to automatic mode.
194176
void PID::Initialize() {
195177
outputSum = *myOutput;
196178
lastInput = *myInput;
@@ -200,12 +182,10 @@ void PID::Initialize() {
200182
outputSum = outMin;
201183
}
202184

203-
/* SetControllerDirection(...)*************************************************
204-
* The PID will either be connected to a PIDControllerDirection::DIRECT acting
205-
*process (+Output leads to +Input) or a REVERSE acting process(+Output leads to
206-
*-Input.) we need to know which one, because otherwise we may increase the
207-
*output when we should be decreasing. This is called from the constructor.
208-
******************************************************************************/
185+
// The PID will either be connected to a PIDControllerDirection::DIRECT acting
186+
// process (+Output leads to +Input) or a REVERSE acting process(+Output leads
187+
// to -Input.) we need to know which one, because otherwise we may increase the
188+
// output when we should be decreasing. This is called from the constructor.
209189
void PID::SetControllerDirection(PIDControllerDirection Direction) {
210190
if (mode == AUTOMATIC && Direction != controllerDirection) {
211191
kp = (0 - kp);
@@ -215,11 +195,9 @@ void PID::SetControllerDirection(PIDControllerDirection Direction) {
215195
controllerDirection = Direction;
216196
}
217197

218-
/* Status Funcions*************************************************************
219-
* Just because you set the Kp=-1 doesn't mean it actually happened. these
220-
* functions query the internal state of the PID. they're here for display
221-
* purposes. this are the functions the PID Front-end uses for example
222-
******************************************************************************/
198+
// Just because you set the Kp=-1 doesn't mean it actually happened. these
199+
// functions query the internal state of the PID. they're here for display
200+
// purposes. this are the functions the PID Front-end uses for example
223201
double PID::GetKp() { return dispKp; }
224202
double PID::GetKi() { return dispKi; }
225203
double PID::GetKd() { return dispKd; }

PID_v1.h

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,80 @@ enum PIDProportionalOn { P_ON_M, P_ON_E };
99
class PID {
1010

1111
public:
12-
// commonly used functions
13-
// **************************************************************************
14-
PID(double *, double *,
15-
double *, // * constructor. links the PID to the Input, Output, and
16-
double, double, double, PIDProportionalOn,
17-
PIDControllerDirection); // Setpoint. Initial tuning parameters are
18-
// also set here. (overload for specifying
19-
// proportional mode)
20-
21-
PID(double *, double *,
22-
double *, // * constructor. links the PID to the Input, Output, and
23-
double, double, double,
24-
PIDControllerDirection); // Setpoint. Initial tuning parameters are
25-
// also set here
26-
27-
void SetMode(PIDControllerMode Mode); // * sets PID to either Manual (0) or Auto (non-0)
28-
29-
// * performs the PID calculation. it should be
30-
// called every time loop() cycles. ON/OFF and
31-
// calculation frequency can be set using SetMode
32-
// SetSampleTime respectively
12+
// constructor. links the PID to the Input, Output, and
13+
// Setpoint. Initial tuning parameters are
14+
// also set here. (overload for specifying proportional mode)
15+
PID(double *, double *, double *, double, double, double, PIDProportionalOn,
16+
PIDControllerDirection);
17+
18+
// constructor. links the PID to the Input, Output, and
19+
// Setpoint. Initial tuning parameters are
20+
// also set here
21+
PID(double *, double *, double *, double, double, double,
22+
PIDControllerDirection);
23+
24+
// sets PID to either Manual (0) or Auto (non-0)
25+
void SetMode(PIDControllerMode Mode);
26+
27+
// performs the PID calculation. it should be
28+
// called every time loop() cycles. ON/OFF and
29+
// calculation frequency can be set using SetMode
30+
// SetSampleTime respectively
3331
bool Compute();
3432

35-
// * clamps the output to a specific range. 0-255 by default, but
36-
// it's likely the user will want to change this depending on
37-
// the application
33+
// clamps the output to a specific range. 0-255 by default, but
34+
// it's likely the user will want to change this depending on
35+
// the application
3836
void SetOutputLimits(double, double);
3937

40-
// available but not commonly used functions
41-
// ********************************************************
42-
void SetTunings(
43-
double, double, // * While most users will set the tunings once in the
44-
double); // constructor, this function gives the user the option
45-
// of changing tunings during runtime for Adaptive control
46-
void SetTunings(double, double, // * overload for specifying proportional mode
47-
double, PIDProportionalOn);
48-
49-
// * Sets the Direction, or "Action" of the controller. DIRECT
50-
// means the output will increase when error is positive. REVERSE
51-
// means the opposite. it's very unlikely that this will be
52-
// needed once it is set in the constructor.
38+
// While most users will set the tunings once in the
39+
// constructor, this function gives the user the option
40+
// of changing tunings during runtime for Adaptive control
41+
void SetTunings(double, double, double);
42+
// overload for specifying proportional mode
43+
void SetTunings(double, double, double, PIDProportionalOn);
44+
45+
// Sets the Direction, or "Action" of the controller. DIRECT
46+
// means the output will increase when error is positive. REVERSE
47+
// means the opposite. it's very unlikely that this will be
48+
// needed once it is set in the constructor.
5349
void SetControllerDirection(PIDControllerDirection);
5450

55-
// * sets the frequency, in Milliseconds, with which
56-
// the PID calculation is performed. default is 100
51+
// sets the frequency, in Milliseconds, with which
52+
// the PID calculation is performed. default is 100
5753
void SetSampleTime(int);
5854

59-
// Display functions
60-
// ****************************************************************
61-
double GetKp(); // These functions query the pid for interal values.
62-
double GetKi(); // they were created mainly for the pid front-end,
63-
double GetKd(); // where it's important to know what is actually
64-
PIDControllerMode GetMode(); // inside the PID.
65-
PIDControllerDirection GetDirection(); //
55+
// These functions query the pid for interal values.
56+
// they were created mainly for the pid front-end,
57+
// where it's important to know what is actually
58+
// inside the PID.
59+
double GetKp();
60+
double GetKi();
61+
double GetKd();
62+
PIDControllerMode GetMode();
63+
PIDControllerDirection GetDirection();
6664

6765
private:
6866
void Initialize();
6967

70-
double dispKp; // * we'll hold on to the tuning parameters in user-entered
71-
double dispKi; // format for display purposes
72-
double dispKd; //
68+
// we'll hold on to the tuning parameters in user-entered format for display
69+
// purposes
70+
double dispKp;
71+
double dispKi;
72+
double dispKd;
7373

74-
double kp; // * (P)roportional Tuning Parameter
75-
double ki; // * (I)ntegral Tuning Parameter
76-
double kd; // * (D)erivative Tuning Parameter
74+
double kp; // (P)roportional Tuning Parameter
75+
double ki; // (I)ntegral Tuning Parameter
76+
double kd; // (D)erivative Tuning Parameter
7777

7878
PIDControllerDirection controllerDirection;
7979
PIDProportionalOn pOn;
8080
PIDControllerMode mode;
8181

82-
double *myInput; // * Pointers to the Input, Output, and Setpoint variables
83-
double *myOutput; // This creates a hard link between the variables and the
82+
// Pointers to the Input, Output, and Setpoint variables
83+
// This creates a hard link between the variables and the
84+
double *myInput;
85+
double *myOutput;
8486

8587
// PID, freeing the user from having to constantly tell us
8688
// what these values are. with pointers we'll just know.

examples/PID_Basic/PID_Basic.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ double Setpoint, Input, Output;
1414
// Specify the links and initial tuning parameters
1515
double Kp = 2, Ki = 5, Kd = 1;
1616
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
17-
>>>>>>> 6b7c36a (Implement controller direction as an enum)
1817

1918
void setup() {
2019
// initialize the variables we're linked to

0 commit comments

Comments
 (0)