Skip to content

Commit

Permalink
[lfc] Rename transition to pd_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurVal committed Jan 30, 2025
1 parent b1182e4 commit 0e7b1f2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tests/test_linear_feedback_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ TEST_P(LinearFeedbackControllerTest, SetInitialState) {
TEST_P(LinearFeedbackControllerTest, ComputeControl) {
auto ctrl = LinearFeedbackController{};
const auto refs = References::Random(GetParam().d_gains.size());

ASSERT_PRED2(SuccesfullyInitialized(ctrl), GetParam(), refs);

constexpr auto ToEigen = [](const std::vector<double>& v) {
Expand All @@ -242,7 +241,7 @@ TEST_P(LinearFeedbackControllerTest, ComputeControl) {
const auto expected_lf_control =
ExpectedLFControlFrom(sensor, control, GetParam().robot_has_free_flyer);

constexpr auto ComputePercentOf = [](const auto& min, const auto& val,
constexpr auto ComputePercentOf = [](const auto& val, const auto& min,
const auto& max) {
return (val - min) / (max - min);
};
Expand All @@ -254,28 +253,28 @@ TEST_P(LinearFeedbackControllerTest, ComputeControl) {

using time_point = linear_feedback_controller::TimePoint;
const time_point first_call = time_point::clock::now();
const time_point transition =
const time_point pd_timeout =
first_call + GetParam().pd_to_lf_transition_duration;

// First call always calls PDController
EXPECT_EQ(ctrl.compute_control(first_call, sensor, control, false),
expected_pd_control);

// When duration expired, always calls LFController
EXPECT_EQ(ctrl.compute_control(transition + 1ms, sensor, control, false),
EXPECT_EQ(ctrl.compute_control(pd_timeout + 1ms, sensor, control, false),
expected_lf_control);

// In between, compute both and apply a weight based on the time elapsed from
// the first call and the expected transition
for (const auto& [str, when] : {
MakeNamedValueOf(first_call + 1ms),
MakeNamedValueOf(first_call + 5ms),
MakeNamedValueOf(transition - 50ms),
MakeNamedValueOf(transition - 1ms),
MakeNamedValueOf(pd_timeout - 50ms),
MakeNamedValueOf(pd_timeout - 1ms),
}) {
EXPECT_PRED2(AreAlmostEquals(),
ctrl.compute_control(when, sensor, control, false),
ApplyWeight(ComputePercentOf(first_call, when, transition),
ApplyWeight(ComputePercentOf(when, first_call, pd_timeout),
expected_pd_control, expected_lf_control))
<< "when = " << std::quoted(str);
}
Expand Down

0 comments on commit 0e7b1f2

Please sign in to comment.