mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilibc] Transition C++ classes to units::second_t (#3396)
A lot of these are breaking changes. frc::Timer was replaced with the contents of frc2::Timer. The others were in-place argument changes or removing deprecated non-unit overloads.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
// 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 <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/AnalogOutput.h"
|
||||
@@ -12,7 +14,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static const double kDelayTime = 0.01;
|
||||
static constexpr auto kDelayTime = 10_ms;
|
||||
|
||||
/**
|
||||
* A fixture with an analog input and an analog output wired together
|
||||
|
||||
@@ -34,14 +34,14 @@ class AnalogPotentiometerTest : public testing::Test {
|
||||
|
||||
TEST_F(AnalogPotentiometerTest, TestInitialSettings) {
|
||||
m_fakePot->SetVoltage(0.0);
|
||||
Wait(0.1);
|
||||
Wait(0.1_s);
|
||||
EXPECT_NEAR(0.0, m_pot->Get(), 5.0)
|
||||
<< "The potentiometer did not initialize to 0.";
|
||||
}
|
||||
|
||||
TEST_F(AnalogPotentiometerTest, TestRangeValues) {
|
||||
m_fakePot->SetVoltage(kAngle / kScale * RobotController::GetVoltage5V());
|
||||
Wait(0.1);
|
||||
Wait(0.1_s);
|
||||
EXPECT_NEAR(kAngle, m_pot->Get(), 2.0)
|
||||
<< "The potentiometer did not measure the correct angle.";
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ TEST(BuiltInAccelerometerTest, Accelerometer) {
|
||||
|
||||
/* The testbench sometimes shakes a little from a previous test. Give it
|
||||
some time. */
|
||||
Wait(1.0);
|
||||
Wait(1_s);
|
||||
|
||||
ASSERT_NEAR(0.0, accelerometer.GetX(), kAccelerationTolerance);
|
||||
ASSERT_NEAR(1.0, accelerometer.GetY(), kAccelerationTolerance);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc/Counter.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/motorcontrol/Jaguar.h"
|
||||
@@ -13,9 +15,9 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static const double kMotorDelay = 2.5;
|
||||
static constexpr auto kMotorDelay = 2.5_s;
|
||||
|
||||
static const double kMaxPeriod = 2.0;
|
||||
static constexpr auto kMaxPeriod = 2_s;
|
||||
|
||||
class CounterTest : public testing::Test {
|
||||
protected:
|
||||
@@ -63,13 +65,13 @@ TEST_F(CounterTest, CountTalon) {
|
||||
|
||||
/* Run the motor forward and determine if the counter is counting. */
|
||||
m_talon->Set(1.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
|
||||
EXPECT_NE(0.0, m_talonCounter->Get()) << "The counter did not count (talon)";
|
||||
|
||||
/* Set the motor to 0 and determine if the counter resets to 0. */
|
||||
m_talon->Set(0.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
m_talonCounter->Reset();
|
||||
|
||||
EXPECT_FLOAT_EQ(0.0, m_talonCounter->Get())
|
||||
@@ -81,14 +83,14 @@ TEST_F(CounterTest, CountVictor) {
|
||||
|
||||
/* Run the motor forward and determine if the counter is counting. */
|
||||
m_victor->Set(1.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
|
||||
EXPECT_NE(0.0, m_victorCounter->Get())
|
||||
<< "The counter did not count (victor)";
|
||||
|
||||
/* Set the motor to 0 and determine if the counter resets to 0. */
|
||||
m_victor->Set(0.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
m_victorCounter->Reset();
|
||||
|
||||
EXPECT_FLOAT_EQ(0.0, m_victorCounter->Get())
|
||||
@@ -100,14 +102,14 @@ TEST_F(CounterTest, CountJaguar) {
|
||||
|
||||
/* Run the motor forward and determine if the counter is counting. */
|
||||
m_jaguar->Set(1.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
|
||||
EXPECT_NE(0.0, m_jaguarCounter->Get())
|
||||
<< "The counter did not count (jaguar)";
|
||||
|
||||
/* Set the motor to 0 and determine if the counter resets to 0. */
|
||||
m_jaguar->Set(0.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
m_jaguarCounter->Reset();
|
||||
|
||||
EXPECT_FLOAT_EQ(0.0, m_jaguarCounter->Get())
|
||||
@@ -124,7 +126,7 @@ TEST_F(CounterTest, TalonGetStopped) {
|
||||
/* Set the Max Period of the counter and run the motor */
|
||||
m_talonCounter->SetMaxPeriod(kMaxPeriod);
|
||||
m_talon->Set(1.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
|
||||
EXPECT_FALSE(m_talonCounter->GetStopped()) << "The counter did not count.";
|
||||
|
||||
@@ -142,7 +144,7 @@ TEST_F(CounterTest, VictorGetStopped) {
|
||||
/* Set the Max Period of the counter and run the motor */
|
||||
m_victorCounter->SetMaxPeriod(kMaxPeriod);
|
||||
m_victor->Set(1.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
|
||||
EXPECT_FALSE(m_victorCounter->GetStopped()) << "The counter did not count.";
|
||||
|
||||
@@ -160,7 +162,7 @@ TEST_F(CounterTest, JaguarGetStopped) {
|
||||
/* Set the Max Period of the counter and run the motor */
|
||||
m_jaguarCounter->SetMaxPeriod(kMaxPeriod);
|
||||
m_jaguar->Set(1.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
|
||||
EXPECT_FALSE(m_jaguarCounter->GetStopped()) << "The counter did not count.";
|
||||
|
||||
|
||||
@@ -6,20 +6,26 @@
|
||||
|
||||
#include "frc/DigitalOutput.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <units/math.h>
|
||||
#include <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/InterruptableSensorBase.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define EXPECT_NEAR_UNITS(val1, val2, eps) \
|
||||
EXPECT_LE(units::math::abs(val1 - val2), eps)
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static const double kCounterTime = 0.001;
|
||||
static constexpr auto kCounterTime = 1_ms;
|
||||
|
||||
static const double kDelayTime = 0.1;
|
||||
static constexpr auto kDelayTime = 100_ms;
|
||||
|
||||
static const double kSynchronousInterruptTime = 2.0;
|
||||
static const double kSynchronousInterruptTimeTolerance = 0.01;
|
||||
static constexpr auto kSynchronousInterruptTime = 2_s;
|
||||
static constexpr auto kSynchronousInterruptTimeTolerance = 10_ms;
|
||||
|
||||
/**
|
||||
* A fixture with a digital input and a digital output physically wired
|
||||
@@ -75,31 +81,31 @@ TEST_F(DIOLoopTest, DIOPWM) {
|
||||
m_output->SetPWMRate(2.0);
|
||||
// Enable PWM, but leave it off
|
||||
m_output->EnablePWM(0.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
m_output->UpdateDutyCycle(0.5);
|
||||
m_input->RequestInterrupts();
|
||||
m_input->SetUpSourceEdge(false, true);
|
||||
InterruptableSensorBase::WaitResult result =
|
||||
m_input->WaitForInterrupt(3.0, true);
|
||||
m_input->WaitForInterrupt(3_s, true);
|
||||
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool firstCycle = m_input->Get();
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool secondCycle = m_input->Get();
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool thirdCycle = m_input->Get();
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool forthCycle = m_input->Get();
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool fifthCycle = m_input->Get();
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool sixthCycle = m_input->Get();
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool seventhCycle = m_input->Get();
|
||||
m_output->DisablePWM();
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool firstAfterStop = m_input->Get();
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
bool secondAfterStop = m_input->Get();
|
||||
|
||||
EXPECT_EQ(InterruptableSensorBase::WaitResult::kFallingEdge, result)
|
||||
@@ -179,7 +185,7 @@ TEST_F(DIOLoopTest, SynchronousInterruptWorks) {
|
||||
// Then this thread should pause and resume after that number of seconds
|
||||
Timer timer;
|
||||
timer.Start();
|
||||
m_input->WaitForInterrupt(kSynchronousInterruptTime + 1.0);
|
||||
EXPECT_NEAR(kSynchronousInterruptTime, timer.Get(),
|
||||
kSynchronousInterruptTimeTolerance);
|
||||
m_input->WaitForInterrupt(kSynchronousInterruptTime + 1_s);
|
||||
EXPECT_NEAR_UNITS(kSynchronousInterruptTime, timer.Get(),
|
||||
kSynchronousInterruptTimeTolerance);
|
||||
}
|
||||
|
||||
@@ -4,29 +4,30 @@
|
||||
|
||||
#include "frc/DriverStation.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <units/math.h>
|
||||
#include <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/RobotController.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define EXPECT_NEAR_UNITS(val1, val2, eps) \
|
||||
EXPECT_LE(units::math::abs(val1 - val2), eps)
|
||||
|
||||
using namespace frc;
|
||||
|
||||
constexpr double TIMER_TOLERANCE = 0.2;
|
||||
constexpr int64_t TIMER_RUNTIME = 1000000; // 1 second
|
||||
|
||||
class DriverStationTest : public testing::Test {};
|
||||
|
||||
/**
|
||||
* Test if the WaitForData function works
|
||||
*/
|
||||
TEST_F(DriverStationTest, WaitForData) {
|
||||
uint64_t initialTime = RobotController::GetFPGATime();
|
||||
TEST(DriverStationTest, WaitForData) {
|
||||
units::microsecond_t initialTime(RobotController::GetFPGATime());
|
||||
|
||||
// 20ms waiting intervals * 50 = 1s
|
||||
for (int i = 0; i < 50; i++) {
|
||||
DriverStation::GetInstance().WaitForData();
|
||||
}
|
||||
|
||||
uint64_t finalTime = RobotController::GetFPGATime();
|
||||
units::microsecond_t finalTime(RobotController::GetFPGATime());
|
||||
|
||||
EXPECT_NEAR(TIMER_RUNTIME, finalTime - initialTime,
|
||||
TIMER_TOLERANCE * TIMER_RUNTIME);
|
||||
EXPECT_NEAR_UNITS(1_s, finalTime - initialTime, 200_ms);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc/Encoder.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/AnalogOutput.h"
|
||||
#include "frc/AnalogTrigger.h"
|
||||
@@ -13,7 +15,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static const double kDelayTime = 0.001;
|
||||
static constexpr auto kDelayTime = 1_ms;
|
||||
|
||||
class FakeEncoderTest : public testing::Test {
|
||||
protected:
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/Encoder.h"
|
||||
#include "frc/LinearFilter.h"
|
||||
@@ -35,7 +37,7 @@ std::ostream& operator<<(std::ostream& os, MotorEncoderTestType const& type) {
|
||||
return os;
|
||||
}
|
||||
|
||||
static constexpr double kMotorTime = 0.5;
|
||||
static constexpr auto kMotorTime = 0.5_s;
|
||||
|
||||
/**
|
||||
* A fixture that includes a PWM motor controller and an encoder connected to
|
||||
@@ -150,7 +152,7 @@ TEST_P(MotorEncoderTest, PositionPIDController) {
|
||||
m_motorController->Set(std::clamp(speed, -0.2, 0.2));
|
||||
}};
|
||||
pidRunner.StartPeriodic(pidController.GetPeriod());
|
||||
Wait(10.0);
|
||||
Wait(10_s);
|
||||
pidRunner.Stop();
|
||||
|
||||
RecordProperty("PIDError", pidController.GetPositionError());
|
||||
@@ -177,7 +179,7 @@ TEST_P(MotorEncoderTest, VelocityPIDController) {
|
||||
m_motorController->Set(std::clamp(speed, -0.3, 0.3));
|
||||
}};
|
||||
pidRunner.StartPeriodic(pidController.GetPeriod());
|
||||
Wait(10.0);
|
||||
Wait(10_s);
|
||||
pidRunner.Stop();
|
||||
RecordProperty("PIDError", pidController.GetPositionError());
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// 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 <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/Encoder.h"
|
||||
#include "frc/Timer.h"
|
||||
@@ -13,8 +15,10 @@
|
||||
using namespace frc;
|
||||
|
||||
enum MotorInvertingTestType { TEST_VICTOR, TEST_JAGUAR, TEST_TALON };
|
||||
static const double motorSpeed = 0.15;
|
||||
static const double delayTime = 0.5;
|
||||
|
||||
static constexpr double kMotorSpeed = 0.15;
|
||||
static constexpr auto kDelayTime = 0.5_s;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, MotorInvertingTestType const& type) {
|
||||
switch (type) {
|
||||
case TEST_VICTOR:
|
||||
@@ -73,15 +77,15 @@ class MotorInvertingTest
|
||||
TEST_P(MotorInvertingTest, InvertingPositive) {
|
||||
Reset();
|
||||
|
||||
m_motorController->Set(motorSpeed);
|
||||
m_motorController->Set(kMotorSpeed);
|
||||
|
||||
Wait(delayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
bool initDirection = m_encoder->GetDirection();
|
||||
m_motorController->SetInverted(true);
|
||||
m_motorController->Set(motorSpeed);
|
||||
m_motorController->Set(kMotorSpeed);
|
||||
|
||||
Wait(delayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
EXPECT_TRUE(m_encoder->GetDirection() != initDirection)
|
||||
<< "Inverting with Positive value does not change direction";
|
||||
@@ -93,15 +97,15 @@ TEST_P(MotorInvertingTest, InvertingNegative) {
|
||||
Reset();
|
||||
|
||||
m_motorController->SetInverted(false);
|
||||
m_motorController->Set(-motorSpeed);
|
||||
m_motorController->Set(-kMotorSpeed);
|
||||
|
||||
Wait(delayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
bool initDirection = m_encoder->GetDirection();
|
||||
m_motorController->SetInverted(true);
|
||||
m_motorController->Set(-motorSpeed);
|
||||
m_motorController->Set(-kMotorSpeed);
|
||||
|
||||
Wait(delayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
EXPECT_TRUE(m_encoder->GetDirection() != initDirection)
|
||||
<< "Inverting with Negative value does not change direction";
|
||||
@@ -113,15 +117,15 @@ TEST_P(MotorInvertingTest, InvertingSwitchingPosToNeg) {
|
||||
Reset();
|
||||
|
||||
m_motorController->SetInverted(false);
|
||||
m_motorController->Set(motorSpeed);
|
||||
m_motorController->Set(kMotorSpeed);
|
||||
|
||||
Wait(delayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
bool initDirection = m_encoder->GetDirection();
|
||||
m_motorController->SetInverted(true);
|
||||
m_motorController->Set(-motorSpeed);
|
||||
m_motorController->Set(-kMotorSpeed);
|
||||
|
||||
Wait(delayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
EXPECT_TRUE(m_encoder->GetDirection() == initDirection)
|
||||
<< "Inverting with Switching value does change direction";
|
||||
@@ -133,15 +137,15 @@ TEST_P(MotorInvertingTest, InvertingSwitchingNegToPos) {
|
||||
Reset();
|
||||
|
||||
m_motorController->SetInverted(false);
|
||||
m_motorController->Set(-motorSpeed);
|
||||
m_motorController->Set(-kMotorSpeed);
|
||||
|
||||
Wait(delayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
bool initDirection = m_encoder->GetDirection();
|
||||
m_motorController->SetInverted(true);
|
||||
m_motorController->Set(motorSpeed);
|
||||
m_motorController->Set(kMotorSpeed);
|
||||
|
||||
Wait(delayTime);
|
||||
Wait(kDelayTime);
|
||||
|
||||
EXPECT_TRUE(m_encoder->GetDirection() == initDirection)
|
||||
<< "Inverting with Switching value does change direction";
|
||||
|
||||
@@ -27,10 +27,10 @@ TEST(NotifierTest, DISABLED_TestTimerNotifications) {
|
||||
wpi::outs() << "notifier(notifierHandler, nullptr)...\n";
|
||||
Notifier notifier(notifierHandler, nullptr);
|
||||
wpi::outs() << "Start Periodic...\n";
|
||||
notifier.StartPeriodic(1.0);
|
||||
notifier.StartPeriodic(1_s);
|
||||
|
||||
wpi::outs() << "Wait...\n";
|
||||
Wait(10.5);
|
||||
Wait(10.5_s);
|
||||
wpi::outs() << "...Wait\n";
|
||||
|
||||
EXPECT_EQ(10u, notifierCounter)
|
||||
|
||||
@@ -16,10 +16,10 @@ using namespace frc;
|
||||
|
||||
/* The PCM switches the compressor up to a couple seconds after the pressure
|
||||
switch changes. */
|
||||
static const double kCompressorDelayTime = 3.0;
|
||||
static constexpr auto kCompressorDelayTime = 3_s;
|
||||
|
||||
/* Solenoids should change much more quickly */
|
||||
static const double kSolenoidDelayTime = 0.5;
|
||||
static constexpr auto kSolenoidDelayTime = 0.5_s;
|
||||
|
||||
/* The voltage divider on the test bench should bring the compressor output
|
||||
to around these values. */
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
|
||||
#include "frc/PowerDistributionPanel.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/Timer.h"
|
||||
@@ -17,7 +16,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static const double kMotorTime = 0.25;
|
||||
static constexpr auto kMotorTime = 0.25_s;
|
||||
|
||||
class PowerDistributionPanelTest : public testing::Test {
|
||||
protected:
|
||||
@@ -50,7 +49,7 @@ TEST_F(PowerDistributionPanelTest, CheckRepeatedCalls) {
|
||||
}
|
||||
m_pdp->GetVoltage();
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
Wait(20_ms);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <ntcore.h>
|
||||
#include <units/time.h>
|
||||
|
||||
#include "frc/Timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -16,7 +17,7 @@
|
||||
using namespace frc;
|
||||
|
||||
static const char* kFileName = "networktables.ini";
|
||||
static const double kSaveTime = 1.2;
|
||||
static constexpr auto kSaveTime = 1.2_s;
|
||||
|
||||
/**
|
||||
* If we write a new networktables.ini with some sample values, test that
|
||||
@@ -71,24 +72,24 @@ TEST(PreferencesTest, WritePreferencesToFile) {
|
||||
|
||||
Wait(kSaveTime);
|
||||
|
||||
preferences->PutString("testFilePutString", "Hello, preferences file");
|
||||
preferences->PutInt("testFilePutInt", 1);
|
||||
preferences->PutDouble("testFilePutDouble", 0.5);
|
||||
preferences->PutFloat("testFilePutFloat", 0.25f);
|
||||
preferences->PutBoolean("testFilePutBoolean", true);
|
||||
preferences->PutLong("testFilePutLong", 1000000000000000000ll);
|
||||
preferences->SetString("testFileSetString", "Hello, preferences file");
|
||||
preferences->SetInt("testFileSetInt", 1);
|
||||
preferences->SetDouble("testFileSetDouble", 0.5);
|
||||
preferences->SetFloat("testFileSetFloat", 0.25f);
|
||||
preferences->SetBoolean("testFileSetBoolean", true);
|
||||
preferences->SetLong("testFileSetLong", 1000000000000000000ll);
|
||||
|
||||
Wait(kSaveTime);
|
||||
|
||||
static char const* kExpectedFileContents[] = {
|
||||
"[NetworkTables Storage 3.0]",
|
||||
"string \"/Preferences/.type\"=\"RobotPreferences\"",
|
||||
"boolean \"/Preferences/testFilePutBoolean\"=true",
|
||||
"double \"/Preferences/testFilePutDouble\"=0.5",
|
||||
"double \"/Preferences/testFilePutFloat\"=0.25",
|
||||
"double \"/Preferences/testFilePutInt\"=1",
|
||||
"double \"/Preferences/testFilePutLong\"=1e+18",
|
||||
"string \"/Preferences/testFilePutString\"=\"Hello, preferences file\""};
|
||||
"boolean \"/Preferences/testFileSetBoolean\"=true",
|
||||
"double \"/Preferences/testFileSetDouble\"=0.5",
|
||||
"double \"/Preferences/testFileSetFloat\"=0.25",
|
||||
"double \"/Preferences/testFileSetInt\"=1",
|
||||
"double \"/Preferences/testFileSetLong\"=1e+18",
|
||||
"string \"/Preferences/testFileSetString\"=\"Hello, preferences file\""};
|
||||
|
||||
std::ifstream preferencesFile(kFileName);
|
||||
for (auto& kExpectedFileContent : kExpectedFileContents) {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc/Relay.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/DigitalInput.h"
|
||||
#include "frc/Timer.h"
|
||||
@@ -11,7 +13,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static const double kDelayTime = 0.01;
|
||||
static constexpr auto kDelayTime = 10_ms;
|
||||
|
||||
class RelayTest : public testing::Test {
|
||||
protected:
|
||||
|
||||
@@ -53,7 +53,7 @@ class TestEnvironment : public testing::Environment {
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
Wait(0.1);
|
||||
Wait(0.1_s);
|
||||
|
||||
wpi::outs() << "Waiting for enable: " << enableCounter++ << "\n";
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <units/time.h>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "frc/ADXL345_SPI.h"
|
||||
#include "frc/AnalogGyro.h"
|
||||
@@ -13,14 +15,14 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr double kServoResetTime = 2.0;
|
||||
static constexpr auto kServoResetTime = 2_s;
|
||||
|
||||
static constexpr double kTestAngle = 90.0;
|
||||
|
||||
static constexpr double kTiltSetpoint0 = 0.22;
|
||||
static constexpr double kTiltSetpoint45 = 0.45;
|
||||
static constexpr double kTiltSetpoint90 = 0.68;
|
||||
static constexpr double kTiltTime = 1.0;
|
||||
static constexpr auto kTiltTime = 1_s;
|
||||
static constexpr double kAccelerometerTolerance = 0.2;
|
||||
static constexpr double kSensitivity = 0.013;
|
||||
|
||||
@@ -84,12 +86,12 @@ void TiltPanCameraTest::DefaultGyroAngle() {
|
||||
void TiltPanCameraTest::GyroAngle() {
|
||||
// Make sure that the gyro doesn't get jerked when the servo goes to zero.
|
||||
m_pan->SetAngle(0.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
m_gyro->Reset();
|
||||
|
||||
for (int32_t i = 0; i < 600; i++) {
|
||||
m_pan->Set(i / 1000.0);
|
||||
Wait(0.001);
|
||||
Wait(1_ms);
|
||||
}
|
||||
|
||||
double gyroAngle = m_gyro->GetAngle();
|
||||
@@ -114,18 +116,18 @@ void TiltPanCameraTest::GyroCalibratedParameters() {
|
||||
// Default gyro angle test
|
||||
// Accumulator needs a small amount of time to reset before being tested
|
||||
m_gyro->Reset();
|
||||
Wait(0.001);
|
||||
Wait(1_ms);
|
||||
EXPECT_NEAR(0.0, m_gyro->GetAngle(), 1.0);
|
||||
|
||||
// Gyro angle test
|
||||
// Make sure that the gyro doesn't get jerked when the servo goes to zero.
|
||||
m_pan->SetAngle(0.0);
|
||||
Wait(0.5);
|
||||
Wait(0.5_s);
|
||||
m_gyro->Reset();
|
||||
|
||||
for (int32_t i = 0; i < 600; i++) {
|
||||
m_pan->Set(i / 1000.0);
|
||||
Wait(0.001);
|
||||
Wait(1_ms);
|
||||
}
|
||||
|
||||
double gyroAngle = m_gyro->GetAngle();
|
||||
|
||||
@@ -4,35 +4,19 @@
|
||||
|
||||
#include "frc/Timer.h" // NOLINT(build/include_order)
|
||||
|
||||
#include "TestBench.h"
|
||||
#include <units/math.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace frc;
|
||||
#define EXPECT_NEAR_UNITS(val1, val2, eps) \
|
||||
EXPECT_LE(units::math::abs(val1 - val2), eps)
|
||||
|
||||
static const double kWaitTime = 0.5;
|
||||
TEST(TimerTest, Wait) {
|
||||
auto initialTime = frc::Timer::GetFPGATimestamp();
|
||||
|
||||
class TimerTest : public testing::Test {
|
||||
protected:
|
||||
Timer* m_timer;
|
||||
frc::Wait(500_ms);
|
||||
|
||||
void SetUp() override { m_timer = new Timer; }
|
||||
auto finalTime = frc::Timer::GetFPGATimestamp();
|
||||
|
||||
void TearDown() override { delete m_timer; }
|
||||
|
||||
void Reset() { m_timer->Reset(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if the Wait function works
|
||||
*/
|
||||
TEST_F(TimerTest, Wait) {
|
||||
Reset();
|
||||
|
||||
double initialTime = m_timer->GetFPGATimestamp();
|
||||
|
||||
Wait(kWaitTime);
|
||||
|
||||
double finalTime = m_timer->GetFPGATimestamp();
|
||||
|
||||
EXPECT_NEAR(kWaitTime, finalTime - initialTime, 0.001);
|
||||
EXPECT_NEAR_UNITS(500_ms, finalTime - initialTime, 1_ms);
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ TEST_F(CommandTest, ThreeCommandOnSubSystem) {
|
||||
command3->Requires(&subsystem);
|
||||
|
||||
CommandGroup commandGroup;
|
||||
commandGroup.AddSequential(command1, 1.0);
|
||||
commandGroup.AddSequential(command2, 2.0);
|
||||
commandGroup.AddSequential(command1, 1_s);
|
||||
commandGroup.AddSequential(command2, 2_s);
|
||||
commandGroup.AddSequential(command3);
|
||||
|
||||
AssertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
@@ -171,7 +171,7 @@ TEST_F(CommandTest, ThreeCommandOnSubSystem) {
|
||||
AssertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
AssertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
AssertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Wait(1); // command 1 timeout
|
||||
Wait(1_s);
|
||||
|
||||
Scheduler::GetInstance()->Run();
|
||||
AssertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
@@ -182,7 +182,7 @@ TEST_F(CommandTest, ThreeCommandOnSubSystem) {
|
||||
AssertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
AssertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
AssertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Wait(2); // command 2 timeout
|
||||
Wait(2_s);
|
||||
|
||||
Scheduler::GetInstance()->Run();
|
||||
AssertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
@@ -315,7 +315,7 @@ TEST_F(CommandTest,
|
||||
|
||||
class ModifiedMockCommand : public MockCommand {
|
||||
public:
|
||||
ModifiedMockCommand() : MockCommand() { SetTimeout(2.0); }
|
||||
ModifiedMockCommand() : MockCommand() { SetTimeout(2_s); }
|
||||
bool IsFinished() override {
|
||||
return MockCommand::IsFinished() || IsTimedOut();
|
||||
}
|
||||
@@ -336,7 +336,7 @@ TEST_F(CommandTest, TwoSecondTimeout) {
|
||||
AssertCommandState(&command, 1, 2, 2, 0, 0);
|
||||
Scheduler::GetInstance()->Run();
|
||||
AssertCommandState(&command, 1, 3, 3, 0, 0);
|
||||
Wait(2);
|
||||
Wait(2_s);
|
||||
Scheduler::GetInstance()->Run();
|
||||
AssertCommandState(&command, 1, 4, 4, 1, 0);
|
||||
Scheduler::GetInstance()->Run();
|
||||
|
||||
Reference in New Issue
Block a user