[wpilib] Add bang-bang controller (#3676)

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Oblarg
2021-11-23 23:34:46 -05:00
committed by GitHub
parent 3aa54fa027
commit da90c1cd2c
7 changed files with 457 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/controller/BangBangController.h"
#include "gtest/gtest.h"
class BangBangInputOutputTest : public testing::Test {
protected:
frc::BangBangController controller;
};
TEST_F(BangBangInputOutputTest, ShouldOutput) {
EXPECT_DOUBLE_EQ(controller.Calculate(0, 1), 1);
}
TEST_F(BangBangInputOutputTest, ShouldNotOutput) {
EXPECT_DOUBLE_EQ(controller.Calculate(1, 0), 0);
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/controller/BangBangController.h"
#include "gtest/gtest.h"
class BangBangToleranceTest : public testing::Test {
protected:
frc::BangBangController controller{0.1};
};
TEST_F(BangBangToleranceTest, InTolerance) {
controller.SetSetpoint(1);
controller.Calculate(1);
EXPECT_TRUE(controller.AtSetpoint());
}
TEST_F(BangBangToleranceTest, OutOfTolerance) {
controller.SetSetpoint(1);
controller.Calculate(0);
EXPECT_FALSE(controller.AtSetpoint());
}