mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
SCRIPT: wpiformat
This commit is contained in:
committed by
Peter Johnson
parent
ae6bdc9d25
commit
2109161534
@@ -68,7 +68,8 @@ class AlertsTest : public ::testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
const wpi::nt::StringArraySubscriber GetSubscriberForType(Alert::AlertType type) {
|
||||
const wpi::nt::StringArraySubscriber GetSubscriberForType(
|
||||
Alert::AlertType type) {
|
||||
return wpi::nt::NetworkTableInstance::GetDefault()
|
||||
.GetStringArrayTopic(fmt::format("/SmartDashboard/{}/{}",
|
||||
GetGroupName(), GetSubtableName(type)))
|
||||
|
||||
@@ -1037,7 +1037,8 @@ void AssertIndexColor(std::span<AddressableLED::LEDData> data, int index,
|
||||
}
|
||||
|
||||
Color LerpColors(Color a, Color b, double t) {
|
||||
return Color{wpi::util::Lerp(a.red, b.red, t), wpi::util::Lerp(a.green, b.green, t),
|
||||
return Color{wpi::util::Lerp(a.red, b.red, t),
|
||||
wpi::util::Lerp(a.green, b.green, t),
|
||||
wpi::util::Lerp(a.blue, b.blue, t)};
|
||||
}
|
||||
} // namespace wpi
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
class UnitNetworkTablesTest : public ::testing::Test {
|
||||
public:
|
||||
UnitNetworkTablesTest() : inst{wpi::nt::NetworkTableInstance::Create()} {}
|
||||
~UnitNetworkTablesTest() override { wpi::nt::NetworkTableInstance::Destroy(inst); }
|
||||
~UnitNetworkTablesTest() override {
|
||||
wpi::nt::NetworkTableInstance::Destroy(inst);
|
||||
}
|
||||
wpi::nt::NetworkTableInstance inst;
|
||||
};
|
||||
|
||||
TEST_F(UnitNetworkTablesTest, Publish) {
|
||||
auto topic = wpi::nt::UnitTopic<wpi::units::meter_t>{inst.GetTopic("meterTest")};
|
||||
auto topic =
|
||||
wpi::nt::UnitTopic<wpi::units::meter_t>{inst.GetTopic("meterTest")};
|
||||
auto pub = topic.Publish();
|
||||
pub.Set(2_m);
|
||||
ASSERT_EQ(topic.GetProperty("unit"), "meter");
|
||||
@@ -25,7 +28,8 @@ TEST_F(UnitNetworkTablesTest, Publish) {
|
||||
}
|
||||
|
||||
TEST_F(UnitNetworkTablesTest, SubscribeDouble) {
|
||||
auto topic = wpi::nt::UnitTopic<wpi::units::meter_t>{inst.GetTopic("meterTest")};
|
||||
auto topic =
|
||||
wpi::nt::UnitTopic<wpi::units::meter_t>{inst.GetTopic("meterTest")};
|
||||
auto pub = topic.Publish();
|
||||
auto sub = inst.GetDoubleTopic("meterTest").Subscribe(0);
|
||||
ASSERT_EQ(sub.Get(), 0);
|
||||
@@ -35,7 +39,8 @@ TEST_F(UnitNetworkTablesTest, SubscribeDouble) {
|
||||
}
|
||||
|
||||
TEST_F(UnitNetworkTablesTest, SubscribeUnit) {
|
||||
auto topic = wpi::nt::UnitTopic<wpi::units::meter_t>{inst.GetTopic("meterTest")};
|
||||
auto topic =
|
||||
wpi::nt::UnitTopic<wpi::units::meter_t>{inst.GetTopic("meterTest")};
|
||||
auto pub = topic.Publish();
|
||||
auto sub = topic.Subscribe(0_m);
|
||||
ASSERT_EQ(sub.Get(), 0_m);
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
TEST(DCMotorSimTest, VoltageSteadyState) {
|
||||
wpi::math::DCMotor gearbox = wpi::math::DCMotor::NEO(1);
|
||||
auto plant = wpi::math::LinearSystemId::DCMotorSystem(
|
||||
wpi::math::DCMotor::NEO(1), wpi::units::kilogram_square_meter_t{0.0005}, 1.0);
|
||||
wpi::math::DCMotor::NEO(1), wpi::units::kilogram_square_meter_t{0.0005},
|
||||
1.0);
|
||||
wpi::sim::DCMotorSim sim{plant, gearbox};
|
||||
|
||||
wpi::Encoder encoder{0, 1};
|
||||
@@ -63,7 +64,8 @@ TEST(DCMotorSimTest, VoltageSteadyState) {
|
||||
TEST(DCMotorSimTest, PositionFeedbackControl) {
|
||||
wpi::math::DCMotor gearbox = wpi::math::DCMotor::NEO(1);
|
||||
auto plant = wpi::math::LinearSystemId::DCMotorSystem(
|
||||
wpi::math::DCMotor::NEO(1), wpi::units::kilogram_square_meter_t{0.0005}, 1.0);
|
||||
wpi::math::DCMotor::NEO(1), wpi::units::kilogram_square_meter_t{0.0005},
|
||||
1.0);
|
||||
wpi::sim::DCMotorSim sim{plant, gearbox};
|
||||
|
||||
wpi::math::PIDController controller{0.04, 0.0, 0.001};
|
||||
|
||||
@@ -51,7 +51,8 @@ TEST(DifferentialDrivetrainSimTest, Convergence) {
|
||||
feedforward.Calculate(wpi::math::Vectord<2>{l.value(), r.value()});
|
||||
|
||||
// Sim periodic code.
|
||||
sim.SetInputs(wpi::units::volt_t{voltages(0, 0)}, wpi::units::volt_t{voltages(1, 0)});
|
||||
sim.SetInputs(wpi::units::volt_t{voltages(0, 0)},
|
||||
wpi::units::volt_t{voltages(1, 0)});
|
||||
sim.Update(20_ms);
|
||||
|
||||
// Update ground truth.
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
EXPECT_LE(wpi::units::math::abs(val1 - val2), eps)
|
||||
|
||||
TEST(ElevatorSimTest, StateSpaceSim) {
|
||||
wpi::sim::ElevatorSim sim(wpi::math::DCMotor::Vex775Pro(4), 14.67, 8_kg, 0.75_in,
|
||||
0_m, 3_m, true, 0_m, {0.01});
|
||||
wpi::sim::ElevatorSim sim(wpi::math::DCMotor::Vex775Pro(4), 14.67, 8_kg,
|
||||
0.75_in, 0_m, 3_m, true, 0_m, {0.01});
|
||||
wpi::math::PIDController controller(10, 0.0, 0.0);
|
||||
|
||||
wpi::PWMVictorSPX motor(0);
|
||||
@@ -33,7 +33,8 @@ TEST(ElevatorSimTest, StateSpaceSim) {
|
||||
auto nextVoltage = controller.Calculate(encoderSim.GetDistance());
|
||||
motor.Set(nextVoltage / wpi::RobotController::GetInputVoltage());
|
||||
|
||||
wpi::math::Vectord<1> u{motor.Get() * wpi::RobotController::GetInputVoltage()};
|
||||
wpi::math::Vectord<1> u{motor.Get() *
|
||||
wpi::RobotController::GetInputVoltage()};
|
||||
sim.SetInput(u);
|
||||
sim.Update(20_ms);
|
||||
|
||||
@@ -46,16 +47,16 @@ TEST(ElevatorSimTest, StateSpaceSim) {
|
||||
|
||||
TEST(ElevatorSimTest, InitialState) {
|
||||
constexpr auto startingHeight = 0.5_m;
|
||||
wpi::sim::ElevatorSim sim(wpi::math::DCMotor::KrakenX60(2), 20, 8_kg, 0.1_m, 0_m,
|
||||
1_m, true, startingHeight, {0.01, 0.0});
|
||||
wpi::sim::ElevatorSim sim(wpi::math::DCMotor::KrakenX60(2), 20, 8_kg, 0.1_m,
|
||||
0_m, 1_m, true, startingHeight, {0.01, 0.0});
|
||||
|
||||
EXPECT_DOUBLE_EQ(startingHeight.value(), sim.GetPosition().value());
|
||||
EXPECT_DOUBLE_EQ(0, sim.GetVelocity().value());
|
||||
}
|
||||
|
||||
TEST(ElevatorSimTest, MinMax) {
|
||||
wpi::sim::ElevatorSim sim(wpi::math::DCMotor::Vex775Pro(4), 14.67, 8_kg, 0.75_in,
|
||||
0_m, 1_m, true, 0_m, {0.01});
|
||||
wpi::sim::ElevatorSim sim(wpi::math::DCMotor::Vex775Pro(4), 14.67, 8_kg,
|
||||
0.75_in, 0_m, 1_m, true, 0_m, {0.01});
|
||||
for (size_t i = 0; i < 100; ++i) {
|
||||
sim.SetInput(wpi::math::Vectord<1>{0.0});
|
||||
sim.Update(20_ms);
|
||||
@@ -74,8 +75,14 @@ TEST(ElevatorSimTest, MinMax) {
|
||||
}
|
||||
|
||||
TEST(ElevatorSimTest, Stability) {
|
||||
wpi::sim::ElevatorSim sim{
|
||||
wpi::math::DCMotor::Vex775Pro(4), 100, 4_kg, 0.5_in, 0_m, 10_m, false, 0_m};
|
||||
wpi::sim::ElevatorSim sim{wpi::math::DCMotor::Vex775Pro(4),
|
||||
100,
|
||||
4_kg,
|
||||
0.5_in,
|
||||
0_m,
|
||||
10_m,
|
||||
false,
|
||||
0_m};
|
||||
|
||||
sim.SetState(wpi::math::Vectord<2>{0.0, 0.0});
|
||||
sim.SetInput(wpi::math::Vectord<1>{12.0});
|
||||
@@ -84,11 +91,11 @@ TEST(ElevatorSimTest, Stability) {
|
||||
}
|
||||
|
||||
wpi::math::LinearSystem<2, 1, 1> system =
|
||||
wpi::math::LinearSystemId::ElevatorSystem(wpi::math::DCMotor::Vex775Pro(4), 4_kg,
|
||||
0.5_in, 100)
|
||||
wpi::math::LinearSystemId::ElevatorSystem(
|
||||
wpi::math::DCMotor::Vex775Pro(4), 4_kg, 0.5_in, 100)
|
||||
.Slice(0);
|
||||
EXPECT_NEAR_UNITS(
|
||||
wpi::units::meter_t{system.CalculateX(wpi::math::Vectord<2>{0.0, 0.0},
|
||||
wpi::math::Vectord<1>{12.0}, 20_ms * 50)(0)},
|
||||
sim.GetPosition(), 1_cm);
|
||||
EXPECT_NEAR_UNITS(wpi::units::meter_t{system.CalculateX(
|
||||
wpi::math::Vectord<2>{0.0, 0.0},
|
||||
wpi::math::Vectord<1>{12.0}, 20_ms * 50)(0)},
|
||||
sim.GetPosition(), 1_cm);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
#include "wpi/simulation/SingleJointedArmSim.hpp"
|
||||
|
||||
TEST(SingleJointedArmTest, Disabled) {
|
||||
wpi::sim::SingleJointedArmSim sim(wpi::math::DCMotor::Vex775Pro(2), 300, 3_kg_sq_m,
|
||||
30_in, -180_deg, 0_deg, true, 90_deg);
|
||||
wpi::sim::SingleJointedArmSim sim(wpi::math::DCMotor::Vex775Pro(2), 300,
|
||||
3_kg_sq_m, 30_in, -180_deg, 0_deg, true,
|
||||
90_deg);
|
||||
sim.SetState(wpi::math::Vectord<2>{0.0, 0.0});
|
||||
|
||||
for (size_t i = 0; i < 12 / 0.02; ++i) {
|
||||
@@ -24,8 +25,9 @@ TEST(SingleJointedArmTest, Disabled) {
|
||||
|
||||
TEST(SingleJointedArmTest, InitialState) {
|
||||
constexpr auto startingAngle = 45_deg;
|
||||
wpi::sim::SingleJointedArmSim sim(wpi::math::DCMotor::KrakenX60(2), 125, 3_kg_sq_m,
|
||||
30_in, 0_deg, 90_deg, true, startingAngle);
|
||||
wpi::sim::SingleJointedArmSim sim(wpi::math::DCMotor::KrakenX60(2), 125,
|
||||
3_kg_sq_m, 30_in, 0_deg, 90_deg, true,
|
||||
startingAngle);
|
||||
|
||||
EXPECT_EQ(startingAngle, sim.GetAngle());
|
||||
EXPECT_DOUBLE_EQ(0, sim.GetVelocity().value());
|
||||
|
||||
@@ -45,8 +45,8 @@ TEST(StateSpaceSimTest, FlywheelSim) {
|
||||
// Then, SimulationPeriodic runs
|
||||
wpi::sim::RoboRioSim::SetVInVoltage(
|
||||
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
|
||||
sim.SetInput(
|
||||
wpi::math::Vectord<1>{motor.Get() * wpi::RobotController::GetInputVoltage()});
|
||||
sim.SetInput(wpi::math::Vectord<1>{
|
||||
motor.Get() * wpi::RobotController::GetInputVoltage()});
|
||||
sim.Update(20_ms);
|
||||
encoderSim.SetRate(sim.GetAngularVelocity().value());
|
||||
}
|
||||
|
||||
@@ -58,7 +58,8 @@ TEST(Mechanism2dTest, Ligament) {
|
||||
"/SmartDashboard/mechanism/root/ligament/weight");
|
||||
wpi::MechanismRoot2d* root = mechanism.GetRoot("root", 1, 2);
|
||||
wpi::MechanismLigament2d* ligament = root->Append<wpi::MechanismLigament2d>(
|
||||
"ligament", 3, wpi::units::degree_t{90}, 1, wpi::Color8Bit{255, 255, 255});
|
||||
"ligament", 3, wpi::units::degree_t{90}, 1,
|
||||
wpi::Color8Bit{255, 255, 255});
|
||||
wpi::SmartDashboard::PutData("mechanism", &mechanism);
|
||||
EXPECT_EQ(ligament->GetAngle(), angleEntry.GetDouble(0.0));
|
||||
EXPECT_EQ(ligament->GetColor().HexString(), colorEntry.GetString(""));
|
||||
|
||||
Reference in New Issue
Block a user