[wpimath] Move controller tests to wpimath (#3541)

This commit is contained in:
Tyler Veness
2021-09-06 17:00:13 -07:00
committed by GitHub
parent 01ba56a8a6
commit 32d9949e4d
5 changed files with 6 additions and 7 deletions

View File

@@ -0,0 +1,51 @@
// 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/PIDController.h"
#include "gtest/gtest.h"
static constexpr double kSetpoint = 50.0;
static constexpr double kRange = 200;
static constexpr double kTolerance = 10.0;
TEST(PIDToleranceTest, InitialTolerance) {
frc2::PIDController controller{0.5, 0.0, 0.0};
controller.EnableContinuousInput(-kRange / 2, kRange / 2);
EXPECT_TRUE(controller.AtSetpoint());
}
TEST(PIDToleranceTest, AbsoluteTolerance) {
frc2::PIDController controller{0.5, 0.0, 0.0};
controller.EnableContinuousInput(-kRange / 2, kRange / 2);
EXPECT_TRUE(controller.AtSetpoint())
<< "Error was not in tolerance when it should have been. Error was "
<< controller.GetPositionError();
controller.SetTolerance(kTolerance);
controller.SetSetpoint(kSetpoint);
EXPECT_FALSE(controller.AtSetpoint())
<< "Error was in tolerance when it should not have been. Error was "
<< controller.GetPositionError();
controller.Calculate(0.0);
EXPECT_FALSE(controller.AtSetpoint())
<< "Error was in tolerance when it should not have been. Error was "
<< controller.GetPositionError();
controller.Calculate(kSetpoint + kTolerance / 2);
EXPECT_TRUE(controller.AtSetpoint())
<< "Error was not in tolerance when it should have been. Error was "
<< controller.GetPositionError();
controller.Calculate(kSetpoint + 10 * kTolerance);
EXPECT_FALSE(controller.AtSetpoint())
<< "Error was in tolerance when it should not have been. Error was "
<< controller.GetPositionError();
}