mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal, wpilib] Remove analog output (#7696)
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
// 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/simulation/AnalogOutputSim.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <hal/HAL.h>
|
||||
|
||||
#include "callback_helpers/TestCallbackHelpers.h"
|
||||
#include "frc/AnalogOutput.h"
|
||||
|
||||
namespace frc::sim {
|
||||
|
||||
TEST(AnalogOutputSimTest, Initialize) {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
AnalogOutputSim outputSim{0};
|
||||
EXPECT_FALSE(outputSim.GetInitialized());
|
||||
|
||||
BooleanCallback callback;
|
||||
|
||||
auto cb =
|
||||
outputSim.RegisterInitializedCallback(callback.GetCallback(), false);
|
||||
AnalogOutput output(0);
|
||||
EXPECT_TRUE(outputSim.GetInitialized());
|
||||
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_TRUE(callback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogOutputSimTest, SetCallback) {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
AnalogOutput output{0};
|
||||
output.SetVoltage(0.5);
|
||||
|
||||
AnalogOutputSim outputSim(output);
|
||||
|
||||
DoubleCallback voltageCallback;
|
||||
|
||||
auto cb =
|
||||
outputSim.RegisterVoltageCallback(voltageCallback.GetCallback(), false);
|
||||
|
||||
EXPECT_FALSE(voltageCallback.WasTriggered());
|
||||
|
||||
for (int i = 0; i < 50; ++i) {
|
||||
double voltage = i * .1;
|
||||
voltageCallback.Reset();
|
||||
|
||||
output.SetVoltage(0);
|
||||
|
||||
EXPECT_EQ(0, output.GetVoltage());
|
||||
EXPECT_EQ(0, outputSim.GetVoltage());
|
||||
|
||||
// 0 -> 0 isn't a change, so callback not called
|
||||
if (i > 2) {
|
||||
EXPECT_TRUE(voltageCallback.WasTriggered()) << " on " << i;
|
||||
EXPECT_NEAR(voltageCallback.GetLastValue(), 0, 0.001) << " on " << i;
|
||||
}
|
||||
|
||||
voltageCallback.Reset();
|
||||
|
||||
output.SetVoltage(voltage);
|
||||
|
||||
EXPECT_EQ(voltage, output.GetVoltage());
|
||||
EXPECT_EQ(voltage, outputSim.GetVoltage());
|
||||
|
||||
// 0 -> 0 isn't a change, so callback not called
|
||||
if (i != 0) {
|
||||
EXPECT_TRUE(voltageCallback.WasTriggered());
|
||||
EXPECT_NEAR(voltageCallback.GetLastValue(), voltage, 0.001);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(AnalogOutputSimTest, Reset) {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
AnalogOutputSim outputSim{0};
|
||||
|
||||
AnalogOutput output{0};
|
||||
output.SetVoltage(1.2);
|
||||
|
||||
outputSim.ResetData();
|
||||
EXPECT_EQ(0, output.GetVoltage());
|
||||
EXPECT_EQ(0, outputSim.GetVoltage());
|
||||
}
|
||||
} // namespace frc::sim
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "frc/simulation/AddressableLEDSim.h"
|
||||
#include "frc/simulation/AnalogGyroSim.h"
|
||||
#include "frc/simulation/AnalogInputSim.h"
|
||||
#include "frc/simulation/AnalogOutputSim.h"
|
||||
#include "frc/simulation/AnalogTriggerSim.h"
|
||||
#include "frc/simulation/BuiltInAccelerometerSim.h"
|
||||
#include "frc/simulation/CTREPCMSim.h"
|
||||
@@ -31,7 +30,6 @@ TEST(SimInitializationTest, AllInitialize) {
|
||||
BuiltInAccelerometerSim biacsim;
|
||||
AnalogGyroSim agsim{0};
|
||||
AnalogInputSim aisim{0};
|
||||
AnalogOutputSim aosim{0};
|
||||
EXPECT_THROW(AnalogTriggerSim::CreateForChannel(0), std::out_of_range);
|
||||
EXPECT_THROW(DigitalPWMSim::CreateForChannel(0), std::out_of_range);
|
||||
DIOSim diosim{0};
|
||||
|
||||
Reference in New Issue
Block a user