mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal, wpilib] Remove analog accumulator and analog gyro (#7697)
The 2 high level classes were temporarily kept to keep the examples compiling. We will remove those when we have the interface into the built in IMU.
This commit is contained in:
@@ -1,88 +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/AnalogGyroSim.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <hal/HAL.h>
|
||||
|
||||
#include "callback_helpers/TestCallbackHelpers.h"
|
||||
#include "frc/AnalogGyro.h"
|
||||
#include "frc/AnalogInput.h"
|
||||
|
||||
namespace frc::sim {
|
||||
|
||||
TEST(AnalogGyroSimTest, InitializeGyro) {
|
||||
HAL_Initialize(500, 0);
|
||||
AnalogGyroSim sim{0};
|
||||
EXPECT_FALSE(sim.GetInitialized());
|
||||
|
||||
BooleanCallback initializedCallback;
|
||||
|
||||
auto cb =
|
||||
sim.RegisterInitializedCallback(initializedCallback.GetCallback(), false);
|
||||
AnalogGyro gyro(0);
|
||||
EXPECT_TRUE(sim.GetInitialized());
|
||||
EXPECT_TRUE(initializedCallback.WasTriggered());
|
||||
EXPECT_TRUE(initializedCallback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogGyroSimTest, SetAngle) {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
AnalogGyroSim sim{0};
|
||||
DoubleCallback callback;
|
||||
|
||||
AnalogInput ai(0);
|
||||
AnalogGyro gyro(&ai);
|
||||
auto cb = sim.RegisterAngleCallback(callback.GetCallback(), false);
|
||||
EXPECT_EQ(0, gyro.GetAngle());
|
||||
|
||||
constexpr double kTestAngle = 35.04;
|
||||
sim.SetAngle(kTestAngle);
|
||||
EXPECT_EQ(kTestAngle, sim.GetAngle());
|
||||
EXPECT_EQ(kTestAngle, gyro.GetAngle());
|
||||
EXPECT_EQ(-kTestAngle, gyro.GetRotation2d().Degrees().value());
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_EQ(kTestAngle, callback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogGyroSimTest, SetRate) {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
AnalogGyroSim sim{0};
|
||||
DoubleCallback callback;
|
||||
|
||||
std::shared_ptr<AnalogInput> ai(new AnalogInput(0));
|
||||
AnalogGyro gyro(ai);
|
||||
auto cb = sim.RegisterRateCallback(callback.GetCallback(), false);
|
||||
EXPECT_EQ(0, gyro.GetRate());
|
||||
|
||||
constexpr double kTestRate = -19.1;
|
||||
sim.SetRate(kTestRate);
|
||||
EXPECT_EQ(kTestRate, sim.GetRate());
|
||||
EXPECT_EQ(kTestRate, gyro.GetRate());
|
||||
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_EQ(kTestRate, callback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogGyroSimTest, Reset) {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
AnalogInput ai{0};
|
||||
AnalogGyro gyro(&ai);
|
||||
AnalogGyroSim sim(gyro);
|
||||
sim.SetAngle(12.34);
|
||||
sim.SetRate(43.21);
|
||||
|
||||
sim.ResetData();
|
||||
EXPECT_EQ(0, sim.GetAngle());
|
||||
EXPECT_EQ(0, sim.GetRate());
|
||||
EXPECT_EQ(0, gyro.GetAngle());
|
||||
EXPECT_EQ(0, gyro.GetRate());
|
||||
}
|
||||
} // namespace frc::sim
|
||||
@@ -92,97 +92,4 @@ TEST(AnalogInputSimTest, SetAverageBits) {
|
||||
EXPECT_EQ(3504, callback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogInputSimTest, InitAccumulator) {
|
||||
HAL_Initialize(500, 0);
|
||||
AnalogInput input{0};
|
||||
AnalogInputSim sim(input);
|
||||
|
||||
BooleanCallback callback;
|
||||
auto cb =
|
||||
sim.RegisterAccumulatorInitializedCallback(callback.GetCallback(), false);
|
||||
|
||||
input.InitAccumulator();
|
||||
input.ResetAccumulator();
|
||||
EXPECT_TRUE(sim.GetAccumulatorInitialized());
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_TRUE(callback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogInputSimTest, InitAccumulatorOnInvalidPort) {
|
||||
HAL_Initialize(500, 0);
|
||||
AnalogInput input{5};
|
||||
AnalogInputSim sim(input);
|
||||
|
||||
BooleanCallback callback;
|
||||
auto cb =
|
||||
sim.RegisterAccumulatorInitializedCallback(callback.GetCallback(), false);
|
||||
|
||||
EXPECT_THROW(input.InitAccumulator(), std::runtime_error);
|
||||
EXPECT_FALSE(callback.WasTriggered());
|
||||
}
|
||||
|
||||
TEST(AnalogInputSimTest, SetAccumulatorValue) {
|
||||
HAL_Initialize(500, 0);
|
||||
AnalogInput input{0};
|
||||
AnalogInputSim sim(input);
|
||||
|
||||
LongCallback callback;
|
||||
auto cb = sim.RegisterAccumulatorValueCallback(callback.GetCallback(), false);
|
||||
|
||||
input.InitAccumulator();
|
||||
sim.SetAccumulatorValue(3504191229);
|
||||
EXPECT_EQ(3504191229, sim.GetAccumulatorValue());
|
||||
EXPECT_EQ(3504191229, input.GetAccumulatorValue());
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_EQ(3504191229, callback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogInputSimTest, SetAccumulatorCount) {
|
||||
HAL_Initialize(500, 0);
|
||||
AnalogInput input{0};
|
||||
AnalogInputSim sim(input);
|
||||
|
||||
LongCallback callback;
|
||||
auto cb = sim.RegisterAccumulatorCountCallback(callback.GetCallback(), false);
|
||||
|
||||
input.InitAccumulator();
|
||||
sim.SetAccumulatorCount(3504191229);
|
||||
EXPECT_EQ(3504191229, sim.GetAccumulatorCount());
|
||||
EXPECT_EQ(3504191229, input.GetAccumulatorCount());
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_EQ(3504191229, callback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogInputSimTest, SetAccumulatorDeadband) {
|
||||
HAL_Initialize(500, 0);
|
||||
AnalogInput input{0};
|
||||
AnalogInputSim sim(input);
|
||||
|
||||
IntCallback callback;
|
||||
auto cb =
|
||||
sim.RegisterAccumulatorDeadbandCallback(callback.GetCallback(), false);
|
||||
|
||||
input.InitAccumulator();
|
||||
input.SetAccumulatorDeadband(3504);
|
||||
EXPECT_EQ(3504, sim.GetAccumulatorDeadband());
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_EQ(3504, callback.GetLastValue());
|
||||
}
|
||||
|
||||
TEST(AnalogInputSimTest, SetAccumulatorCenter) {
|
||||
HAL_Initialize(500, 0);
|
||||
AnalogInput input{0};
|
||||
AnalogInputSim sim(input);
|
||||
|
||||
IntCallback callback;
|
||||
auto cb =
|
||||
sim.RegisterAccumulatorCenterCallback(callback.GetCallback(), false);
|
||||
|
||||
input.InitAccumulator();
|
||||
input.SetAccumulatorCenter(3504);
|
||||
EXPECT_EQ(3504, sim.GetAccumulatorCenter());
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_EQ(3504, callback.GetLastValue());
|
||||
}
|
||||
|
||||
} // namespace frc::sim
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <hal/HAL.h>
|
||||
|
||||
#include "frc/simulation/AddressableLEDSim.h"
|
||||
#include "frc/simulation/AnalogGyroSim.h"
|
||||
#include "frc/simulation/AnalogInputSim.h"
|
||||
#include "frc/simulation/AnalogTriggerSim.h"
|
||||
#include "frc/simulation/BuiltInAccelerometerSim.h"
|
||||
@@ -27,7 +26,6 @@ using namespace frc::sim;
|
||||
TEST(SimInitializationTest, AllInitialize) {
|
||||
HAL_Initialize(500, 0);
|
||||
BuiltInAccelerometerSim biacsim;
|
||||
AnalogGyroSim agsim{0};
|
||||
AnalogInputSim aisim{0};
|
||||
EXPECT_THROW(AnalogTriggerSim::CreateForChannel(0), std::out_of_range);
|
||||
EXPECT_THROW(DigitalPWMSim::CreateForChannel(0), std::out_of_range);
|
||||
|
||||
Reference in New Issue
Block a user