2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2020-09-20 09:39:52 -07:00
|
|
|
|
2022-10-15 16:33:14 -07:00
|
|
|
#include <numbers>
|
2020-09-20 09:39:52 -07:00
|
|
|
|
2023-08-28 15:13:34 -07:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2020-09-20 09:39:52 -07:00
|
|
|
#include "frc/simulation/SingleJointedArmSim.h"
|
|
|
|
|
|
|
|
|
|
TEST(SingleJointedArmTest, Disabled) {
|
2023-01-18 23:40:39 -05:00
|
|
|
frc::sim::SingleJointedArmSim sim(frc::DCMotor::Vex775Pro(2), 300, 3_kg_sq_m,
|
2023-07-18 16:00:27 -04:00
|
|
|
30_in, -180_deg, 0_deg, true, 90_deg);
|
2022-04-29 22:29:20 -07:00
|
|
|
sim.SetState(frc::Vectord<2>{0.0, 0.0});
|
2020-09-20 09:39:52 -07:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 12 / 0.02; ++i) {
|
2022-04-29 22:29:20 -07:00
|
|
|
sim.SetInput(frc::Vectord<1>{0.0});
|
2020-09-20 09:39:52 -07:00
|
|
|
sim.Update(20_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The arm should swing down.
|
2022-10-15 16:33:14 -07:00
|
|
|
EXPECT_NEAR(sim.GetAngle().value(), -std::numbers::pi / 2, 0.01);
|
2020-09-20 09:39:52 -07:00
|
|
|
}
|
2025-02-19 01:49:28 -05:00
|
|
|
|
|
|
|
|
TEST(SingleJointedArmTest, InitialState) {
|
|
|
|
|
constexpr auto startingAngle = 45_deg;
|
|
|
|
|
frc::sim::SingleJointedArmSim sim(frc::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());
|
|
|
|
|
}
|