-
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
199 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
76 changes: 76 additions & 0 deletions
76
tests/controllers/feedback_linearization/fblin_pid_test.cpp
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <gtest/gtest.h> | ||
#include "controllers/feedback_linearization/PID/first_order/fblin_pid.hpp" | ||
|
||
TEST(PIDLin, SimpleModel){ | ||
|
||
PIDParameters params; | ||
params.kP = 10; | ||
params.kI = 10; | ||
params.kD = 0.1; | ||
params.kDt = 0.01; | ||
|
||
double FB_LIN_UMAX = 255; | ||
double FB_LIN_UMIN = -255; | ||
double g_x = 1; | ||
double accel_d = 1; | ||
|
||
double position = 0; | ||
double velocity = 0; | ||
|
||
double position_d = 5; | ||
double distance = 0.1; | ||
|
||
PIDLin pid(FB_LIN_UMAX, FB_LIN_UMIN, params); | ||
|
||
pid.g_x_ = g_x; | ||
|
||
// u_ = g_x_^(-1)*(chi1_dot_d - f_x_ + u_n - u_aux) | ||
// Run a simple simulation, check that setpoint is reached with full PID impl. | ||
for(int i = 0; i < 100; i++){ | ||
double u = pid.calculateManipulations(position, position_d, accel_d); | ||
position += (velocity + u) * params.kDt; | ||
velocity += 0.1 * params.kDt; | ||
} | ||
|
||
// Position should be near setpoint. | ||
EXPECT_NEAR(position, position_d, distance); | ||
|
||
pid = PIDLin(FB_LIN_UMAX, FB_LIN_UMIN, params); | ||
position = 0; | ||
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.calculateManipulations(position, -position_d, accel_d); | ||
position -= (velocity + u) * params.kDt; | ||
velocity += 0.1 * params.kDt; | ||
} | ||
|
||
EXPECT_NEAR(position, -position_d, distance); | ||
} | ||
|
||
TEST(PIDLin, ClampU) { | ||
|
||
PIDParameters params; | ||
params.kP = 100; | ||
params.kDt = 0.01; | ||
|
||
double FB_LIN_UMAX = 10; | ||
double FB_LIN_UMIN = -10; | ||
double g_x = 1; | ||
double accel_d = 1; | ||
|
||
double vel = 0; | ||
double vel_d = 5; | ||
double distance = 0.1; | ||
|
||
PIDLin pid(FB_LIN_UMAX, FB_LIN_UMIN, params); | ||
|
||
EXPECT_LE(pid.calculateManipulations(vel, vel_d, accel_d), FB_LIN_UMAX); | ||
EXPECT_GE(pid.calculateManipulations(vel, -vel_d, accel_d), FB_LIN_UMIN); | ||
|
||
FB_LIN_UMIN = 0; | ||
pid = PIDLin(FB_LIN_UMAX, FB_LIN_UMIN, params); | ||
|
||
EXPECT_GE(pid.calculateManipulations(vel, -vel_d, accel_d), FB_LIN_UMIN); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <gtest/gtest.h> | ||
#include "controllers/feedback_linearization/base/fb_lin_control.hpp" | ||
|
||
TEST(FBLin, SimpleModel){ | ||
double f_x{5}; | ||
double g_x{1}; | ||
|
||
double U_MAX{255}; | ||
double U_MIN{-255}; | ||
double u_aux{10}; | ||
double u_n{2}; | ||
double chiX_dot_d{1}; | ||
|
||
FBLin controller(U_MAX, U_MIN); | ||
controller.f_x_ = f_x; | ||
controller.g_x_ = g_x; | ||
|
||
controller.u_n_ = u_n; | ||
controller.u_aux_ = u_aux; | ||
controller.chiX_dot_d_ = chiX_dot_d; | ||
|
||
controller.updateControlSignal(); | ||
// u_ = g_x_^(-1)*(chi1_dot_d - f_x_ + u_n - u_aux) | ||
double expected_u = -12; | ||
EXPECT_EQ(controller.u_, expected_u); | ||
} | ||
|
||
TEST(FBLin, ClampU){ | ||
double f_x{5}; | ||
double g_x{1}; | ||
|
||
double U_MAX{255}; | ||
double U_MIN{-255}; | ||
double u_aux{300}; | ||
double u_n{2}; | ||
double chiX_dot_d{1}; | ||
|
||
FBLin controller(U_MAX, U_MIN); | ||
controller.f_x_ = f_x; | ||
controller.g_x_ = g_x; | ||
|
||
controller.u_n_ = u_n; | ||
controller.u_aux_ = u_aux; | ||
controller.chiX_dot_d_ = chiX_dot_d; | ||
|
||
controller.updateControlSignal(); | ||
// u_ = g_x_^(-1)*(chi1_dot_d - f_x_ + u_n - u_aux) | ||
|
||
EXPECT_LE(controller.u_, U_MAX); | ||
EXPECT_GE(controller.u_, U_MIN); | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/controllers/feedback_linearization/vtec_sdc1_pid_test.cpp
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// #include <gtest/gtest.h> | ||
// #include "controllers/feedback_linearization/base/fb_lin_control.hpp" | ||
|
||
// TEST(FBLin, SimpleModel){ | ||
// double f_x{5}; | ||
// double g_x{1}; | ||
|
||
// double U_MAX{255}; | ||
// double U_MIN{-255}; | ||
// double u_aux{10}; | ||
// double u_n{2}; | ||
// double chiX_dot_d{1}; | ||
|
||
// FBLin controller(U_MAX, U_MIN); | ||
// controller.f_x_ = f_x; | ||
// controller.g_x_ = g_x; | ||
|
||
// controller.u_n_ = u_n; | ||
// controller.u_aux_ = u_aux; | ||
// controller.chiX_dot_d_ = chiX_dot_d; | ||
|
||
// controller.updateControlSignal(); | ||
// // u_ = g_x_^(-1)*(chi1_dot_d - f_x_ + u_n - u_aux) | ||
|
||
// EXPECT_EQ(controller.u_, -12); | ||
// } | ||
|
||
// TEST(FBLin, ClampU){ | ||
// double f_x{5}; | ||
// double g_x{1}; | ||
|
||
// double U_MAX{255}; | ||
// double U_MIN{-255}; | ||
// double u_aux{300}; | ||
// double u_n{2}; | ||
// double chiX_dot_d{1}; | ||
|
||
// FBLin controller(U_MAX, U_MIN); | ||
// controller.f_x_ = f_x; | ||
// controller.g_x_ = g_x; | ||
|
||
// controller.u_n_ = u_n; | ||
// controller.u_aux_ = u_aux; | ||
// controller.chiX_dot_d_ = chiX_dot_d; | ||
|
||
// controller.updateControlSignal(); | ||
// // u_ = g_x_^(-1)*(chi1_dot_d - f_x_ + u_n - u_aux) | ||
|
||
// EXPECT_LE(controller.u_, U_MAX); | ||
// EXPECT_GE(controller.u_, U_MIN); | ||
// } |