-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
build/* | ||
build/* | ||
cmake-build-debug/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,54 @@ | ||
#include <gtest/gtest.h> | ||
#include "controllers/control_laws/PID/first_order/pid.hpp" | ||
|
||
class SimpleModel { | ||
double update(double u){ | ||
|
||
TEST(PID, SimpleModel){ | ||
PIDParameters param; | ||
param.kP = 10; | ||
param.kI = 1; | ||
param.kD = 0.1; | ||
param.kDt = 0.01; | ||
PID pid(param); | ||
|
||
double position = 0; | ||
double velocity = 0; | ||
|
||
// Run a simple simulation, check that setpoint is reached with full PID impl. | ||
for(int i = 0; i < 1000; i++){ | ||
double u = pid.update(position, 5); | ||
|
||
position += (velocity + u) * param.kDt; | ||
velocity += 0.1 * param.kDt; | ||
} | ||
}; | ||
|
||
// Position should be near setpoint. | ||
EXPECT_NEAR(position, 5, 0.1); | ||
} | ||
|
||
TEST(PID, ClampU) { | ||
PIDParameters param; | ||
param.kP = 1000; | ||
param.kUMax = 100; | ||
param.kUMin = -100; | ||
param.enable_ramp_rate_limit = false; | ||
|
||
PID pid(param); | ||
EXPECT_LE(pid.update(0, 1), 100); | ||
EXPECT_GE(pid.update(0, -1), -100); | ||
} | ||
|
||
TEST(PID, RampRateLimit){ | ||
PIDParameters param; | ||
param.kP = 1; | ||
param.enable_ramp_rate_limit = true; | ||
param.ramp_rate = 1; | ||
param.kDt = 0.1; | ||
|
||
PID pid(param); | ||
|
||
// U should only be allowed to rise by 0.1 | ||
EXPECT_NEAR(pid.update(0, 10), 0.1, 0.01); | ||
|
||
pid = PID(param); | ||
// U should rise to any value less than 0.1 | ||
EXPECT_NEAR(pid.update(0, 0.05), 0.05, 0.01); | ||
} |