diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp index 14b5846d68..4a22493a1d 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp @@ -7,7 +7,6 @@ #include using namespace frc2; -using namespace units; MecanumControllerCommand::MecanumControllerCommand( frc::Trajectory trajectory, std::function pose, @@ -269,7 +268,7 @@ void MecanumControllerCommand::Initialize() { } void MecanumControllerCommand::Execute() { - auto curTime = second_t(m_timer.Get()); + auto curTime = m_timer.Get(); auto dt = curTime - m_prevTime; auto m_desiredState = m_trajectory.Sample(curTime); @@ -302,21 +301,21 @@ void MecanumControllerCommand::Execute() { rearRightSpeedSetpoint, (rearRightSpeedSetpoint - m_prevSpeeds.rearRight) / dt); - auto frontLeftOutput = volt_t(m_frontLeftController->Calculate( + auto frontLeftOutput = units::volt_t{m_frontLeftController->Calculate( m_currentWheelSpeeds().frontLeft.value(), - frontLeftSpeedSetpoint.value())) + + frontLeftSpeedSetpoint.value())} + frontLeftFeedforward; - auto rearLeftOutput = volt_t(m_rearLeftController->Calculate( + auto rearLeftOutput = units::volt_t{m_rearLeftController->Calculate( m_currentWheelSpeeds().rearLeft.value(), - rearLeftSpeedSetpoint.value())) + + rearLeftSpeedSetpoint.value())} + rearLeftFeedforward; - auto frontRightOutput = volt_t(m_frontRightController->Calculate( + auto frontRightOutput = units::volt_t{m_frontRightController->Calculate( m_currentWheelSpeeds().frontRight.value(), - frontRightSpeedSetpoint.value())) + + frontRightSpeedSetpoint.value())} + frontRightFeedforward; - auto rearRightOutput = volt_t(m_rearRightController->Calculate( + auto rearRightOutput = units::volt_t{m_rearRightController->Calculate( m_currentWheelSpeeds().rearRight.value(), - rearRightSpeedSetpoint.value())) + + rearRightSpeedSetpoint.value())} + rearRightFeedforward; m_outputVolts(frontLeftOutput, rearLeftOutput, frontRightOutput, diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp index 4674031b9d..179d7f6130 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/RamseteCommand.cpp @@ -7,7 +7,6 @@ #include using namespace frc2; -using namespace units; RamseteCommand::RamseteCommand( frc::Trajectory trajectory, std::function pose, @@ -16,7 +15,7 @@ RamseteCommand::RamseteCommand( frc::DifferentialDriveKinematics kinematics, std::function wheelSpeeds, frc2::PIDController leftController, frc2::PIDController rightController, - std::function output, + std::function output, std::initializer_list requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), @@ -38,7 +37,7 @@ RamseteCommand::RamseteCommand( frc::DifferentialDriveKinematics kinematics, std::function wheelSpeeds, frc2::PIDController leftController, frc2::PIDController rightController, - std::function output, + std::function output, wpi::span requirements) : m_trajectory(std::move(trajectory)), m_pose(std::move(pose)), @@ -127,13 +126,13 @@ void RamseteCommand::Execute() { (targetWheelSpeeds.right - m_prevSpeeds.right) / dt); auto leftOutput = - volt_t(m_leftController->Calculate(m_speeds().left.value(), - targetWheelSpeeds.left.value())) + + units::volt_t{m_leftController->Calculate( + m_speeds().left.value(), targetWheelSpeeds.left.value())} + leftFeedforward; auto rightOutput = - volt_t(m_rightController->Calculate(m_speeds().right.value(), - targetWheelSpeeds.right.value())) + + units::volt_t{m_rightController->Calculate( + m_speeds().right.value(), targetWheelSpeeds.right.value())} + rightFeedforward; m_outputVolts(leftOutput, rightOutput); diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc index d1c6e78711..aef7e09732 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc +++ b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc @@ -92,7 +92,7 @@ void SwerveControllerCommand::Initialize() { template void SwerveControllerCommand::Execute() { - auto curTime = units::second_t(m_timer.Get()); + auto curTime = m_timer.Get(); auto m_desiredState = m_trajectory.Sample(curTime); auto targetChassisSpeeds = diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp index 537d8924d5..ceeafd8e65 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp @@ -85,7 +85,7 @@ TEST_F(MecanumControllerCommandTest, ReachesReference) { trajectory, [&]() { return getRobotPose(); }, m_kinematics, frc2::PIDController(0.6, 0, 0), frc2::PIDController(0.6, 0, 0), - m_rotController, units::meters_per_second_t(8.8), + m_rotController, 8.8_mps, [&](units::meters_per_second_t frontLeft, units::meters_per_second_t rearLeft, units::meters_per_second_t frontRight, diff --git a/wpilibc/src/main/native/cpp/RobotController.cpp b/wpilibc/src/main/native/cpp/RobotController.cpp index 8bc2d6b2c9..9f583a6db0 100644 --- a/wpilibc/src/main/native/cpp/RobotController.cpp +++ b/wpilibc/src/main/native/cpp/RobotController.cpp @@ -163,7 +163,7 @@ units::volt_t RobotController::GetBrownoutVoltage() { int32_t status = 0; double retVal = HAL_GetBrownoutVoltage(&status); FRC_CheckErrorStatus(status, "{}", "GetBrownoutVoltage"); - return units::volt_t(retVal); + return units::volt_t{retVal}; } void RobotController::SetBrownoutVoltage(units::volt_t brownoutVoltage) { diff --git a/wpilibc/src/main/native/cpp/Timer.cpp b/wpilibc/src/main/native/cpp/Timer.cpp index 23cfbe2322..3863de4a0c 100644 --- a/wpilibc/src/main/native/cpp/Timer.cpp +++ b/wpilibc/src/main/native/cpp/Timer.cpp @@ -21,9 +21,9 @@ units::second_t GetTime() { using std::chrono::duration_cast; using std::chrono::system_clock; - return units::second_t( + return units::second_t{ duration_cast>(system_clock::now().time_since_epoch()) - .count()); + .count()}; } } // namespace frc @@ -78,9 +78,9 @@ bool Timer::AdvanceIfElapsed(units::second_t period) { units::second_t Timer::GetFPGATimestamp() { // FPGA returns the timestamp in microseconds - return units::second_t(frc::RobotController::GetFPGATime() * 1.0e-6); + return units::second_t{frc::RobotController::GetFPGATime() * 1.0e-6}; } units::second_t Timer::GetMatchTime() { - return units::second_t(frc::DriverStation::GetMatchTime()); + return units::second_t{frc::DriverStation::GetMatchTime()}; } diff --git a/wpilibc/src/main/native/cpp/simulation/AnalogEncoderSim.cpp b/wpilibc/src/main/native/cpp/simulation/AnalogEncoderSim.cpp index 049241e0b3..435e29e378 100644 --- a/wpilibc/src/main/native/cpp/simulation/AnalogEncoderSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/AnalogEncoderSim.cpp @@ -27,6 +27,5 @@ units::turn_t AnalogEncoderSim::GetTurns() { } frc::Rotation2d AnalogEncoderSim::GetPosition() { - units::radian_t rads = GetTurns(); - return frc::Rotation2d{rads}; + return units::radian_t{GetTurns()}; } diff --git a/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp b/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp index cbd916d298..b6c95dc0ab 100644 --- a/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp @@ -82,20 +82,20 @@ double DifferentialDrivetrainSim::GetState(int state) const { } Rotation2d DifferentialDrivetrainSim::GetHeading() const { - return Rotation2d(units::radian_t(GetOutput(State::kHeading))); + return units::radian_t{GetOutput(State::kHeading)}; } Pose2d DifferentialDrivetrainSim::GetPose() const { - return Pose2d(units::meter_t(GetOutput(State::kX)), - units::meter_t(GetOutput(State::kY)), GetHeading()); + return Pose2d{units::meter_t{GetOutput(State::kX)}, + units::meter_t{GetOutput(State::kY)}, GetHeading()}; } units::ampere_t DifferentialDrivetrainSim::GetLeftCurrentDraw() const { auto loadIleft = m_motor.Current( - units::radians_per_second_t(m_x(State::kLeftVelocity) * - m_currentGearing / m_wheelRadius.value()), - units::volt_t(m_u(0))) * + units::radians_per_second_t{m_x(State::kLeftVelocity) * + m_currentGearing / m_wheelRadius.value()}, + units::volt_t{m_u(0)}) * wpi::sgn(m_u(0)); return loadIleft; @@ -104,9 +104,9 @@ units::ampere_t DifferentialDrivetrainSim::GetLeftCurrentDraw() const { units::ampere_t DifferentialDrivetrainSim::GetRightCurrentDraw() const { auto loadIRight = m_motor.Current( - units::radians_per_second_t(m_x(State::kRightVelocity) * - m_currentGearing / m_wheelRadius.value()), - units::volt_t(m_u(1))) * + units::radians_per_second_t{m_x(State::kRightVelocity) * + m_currentGearing / m_wheelRadius.value()}, + units::volt_t{m_u(1)}) * wpi::sgn(m_u(1)); return loadIRight; diff --git a/wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp b/wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp index 7adff3a6ec..529fb1a91a 100644 --- a/wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/ElevatorSim.cpp @@ -49,11 +49,11 @@ bool ElevatorSim::WouldHitUpperLimit(units::meter_t elevatorHeight) const { } bool ElevatorSim::HasHitLowerLimit() const { - return WouldHitLowerLimit(units::meter_t(m_y(0))); + return WouldHitLowerLimit(units::meter_t{m_y(0)}); } bool ElevatorSim::HasHitUpperLimit() const { - return WouldHitUpperLimit(units::meter_t(m_y(0))); + return WouldHitUpperLimit(units::meter_t{m_y(0)}); } units::meter_t ElevatorSim::GetPosition() const { @@ -96,10 +96,10 @@ Vectord<2> ElevatorSim::UpdateX(const Vectord<2>& currentXhat, }, currentXhat, u, dt); // Check for collision after updating x-hat. - if (WouldHitLowerLimit(units::meter_t(updatedXhat(0)))) { + if (WouldHitLowerLimit(units::meter_t{updatedXhat(0)})) { return Vectord<2>{m_minHeight.value(), 0.0}; } - if (WouldHitUpperLimit(units::meter_t(updatedXhat(0)))) { + if (WouldHitUpperLimit(units::meter_t{updatedXhat(0)})) { return Vectord<2>{m_maxHeight.value(), 0.0}; } return updatedXhat; diff --git a/wpilibc/src/main/native/cpp/simulation/RoboRioSim.cpp b/wpilibc/src/main/native/cpp/simulation/RoboRioSim.cpp index dc2b55754a..d05bba9c74 100644 --- a/wpilibc/src/main/native/cpp/simulation/RoboRioSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/RoboRioSim.cpp @@ -39,7 +39,7 @@ std::unique_ptr RoboRioSim::RegisterVInVoltageCallback( } units::volt_t RoboRioSim::GetVInVoltage() { - return units::volt_t(HALSIM_GetRoboRioVInVoltage()); + return units::volt_t{HALSIM_GetRoboRioVInVoltage()}; } void RoboRioSim::SetVInVoltage(units::volt_t vInVoltage) { @@ -56,7 +56,7 @@ std::unique_ptr RoboRioSim::RegisterVInCurrentCallback( } units::ampere_t RoboRioSim::GetVInCurrent() { - return units::ampere_t(HALSIM_GetRoboRioVInCurrent()); + return units::ampere_t{HALSIM_GetRoboRioVInCurrent()}; } void RoboRioSim::SetVInCurrent(units::ampere_t vInCurrent) { @@ -73,7 +73,7 @@ std::unique_ptr RoboRioSim::RegisterUserVoltage6VCallback( } units::volt_t RoboRioSim::GetUserVoltage6V() { - return units::volt_t(HALSIM_GetRoboRioUserVoltage6V()); + return units::volt_t{HALSIM_GetRoboRioUserVoltage6V()}; } void RoboRioSim::SetUserVoltage6V(units::volt_t userVoltage6V) { @@ -90,7 +90,7 @@ std::unique_ptr RoboRioSim::RegisterUserCurrent6VCallback( } units::ampere_t RoboRioSim::GetUserCurrent6V() { - return units::ampere_t(HALSIM_GetRoboRioUserCurrent6V()); + return units::ampere_t{HALSIM_GetRoboRioUserCurrent6V()}; } void RoboRioSim::SetUserCurrent6V(units::ampere_t userCurrent6V) { @@ -124,7 +124,7 @@ std::unique_ptr RoboRioSim::RegisterUserVoltage5VCallback( } units::volt_t RoboRioSim::GetUserVoltage5V() { - return units::volt_t(HALSIM_GetRoboRioUserVoltage5V()); + return units::volt_t{HALSIM_GetRoboRioUserVoltage5V()}; } void RoboRioSim::SetUserVoltage5V(units::volt_t userVoltage5V) { @@ -141,7 +141,7 @@ std::unique_ptr RoboRioSim::RegisterUserCurrent5VCallback( } units::ampere_t RoboRioSim::GetUserCurrent5V() { - return units::ampere_t(HALSIM_GetRoboRioUserCurrent5V()); + return units::ampere_t{HALSIM_GetRoboRioUserCurrent5V()}; } void RoboRioSim::SetUserCurrent5V(units::ampere_t userCurrent5V) { @@ -175,7 +175,7 @@ std::unique_ptr RoboRioSim::RegisterUserVoltage3V3Callback( } units::volt_t RoboRioSim::GetUserVoltage3V3() { - return units::volt_t(HALSIM_GetRoboRioUserVoltage3V3()); + return units::volt_t{HALSIM_GetRoboRioUserVoltage3V3()}; } void RoboRioSim::SetUserVoltage3V3(units::volt_t userVoltage3V3) { @@ -192,7 +192,7 @@ std::unique_ptr RoboRioSim::RegisterUserCurrent3V3Callback( } units::ampere_t RoboRioSim::GetUserCurrent3V3() { - return units::ampere_t(HALSIM_GetRoboRioUserCurrent3V3()); + return units::ampere_t{HALSIM_GetRoboRioUserCurrent3V3()}; } void RoboRioSim::SetUserCurrent3V3(units::ampere_t userCurrent3V3) { @@ -277,7 +277,7 @@ std::unique_ptr RoboRioSim::RegisterBrownoutVoltageCallback( } units::volt_t RoboRioSim::GetBrownoutVoltage() { - return units::volt_t(HALSIM_GetRoboRioBrownoutVoltage()); + return units::volt_t{HALSIM_GetRoboRioBrownoutVoltage()}; } void RoboRioSim::SetBrownoutVoltage(units::volt_t vInVoltage) { diff --git a/wpilibc/src/main/native/cpp/simulation/SingleJointedArmSim.cpp b/wpilibc/src/main/native/cpp/simulation/SingleJointedArmSim.cpp index e4fa2a6e01..d70dfb561a 100644 --- a/wpilibc/src/main/native/cpp/simulation/SingleJointedArmSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/SingleJointedArmSim.cpp @@ -48,11 +48,11 @@ bool SingleJointedArmSim::WouldHitUpperLimit(units::radian_t armAngle) const { } bool SingleJointedArmSim::HasHitLowerLimit() const { - return WouldHitLowerLimit(units::radian_t(m_y(0))); + return WouldHitLowerLimit(units::radian_t{m_y(0)}); } bool SingleJointedArmSim::HasHitUpperLimit() const { - return WouldHitUpperLimit(units::radian_t(m_y(0))); + return WouldHitUpperLimit(units::radian_t{m_y(0)}); } units::radian_t SingleJointedArmSim::GetAngle() const { @@ -102,9 +102,9 @@ Vectord<2> SingleJointedArmSim::UpdateX(const Vectord<2>& currentXhat, currentXhat, u, dt); // Check for collisions. - if (WouldHitLowerLimit(units::radian_t(updatedXhat(0)))) { + if (WouldHitLowerLimit(units::radian_t{updatedXhat(0)})) { return Vectord<2>{m_minAngle.value(), 0.0}; - } else if (WouldHitUpperLimit(units::radian_t(updatedXhat(0)))) { + } else if (WouldHitUpperLimit(units::radian_t{updatedXhat(0)})) { return Vectord<2>{m_maxAngle.value(), 0.0}; } return updatedXhat; diff --git a/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp index 93d6d7ea76..b218272ad6 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/FieldObject2d.cpp @@ -140,7 +140,7 @@ void FieldObject2d::UpdateFromEntry() const { for (size_t i = 0; i < size / 3; ++i) { m_poses[i] = Pose2d{units::meter_t{arr[i * 3 + 0]}, units::meter_t{arr[i * 3 + 1]}, - Rotation2d{units::degree_t{arr[i * 3 + 2]}}}; + units::degree_t{arr[i * 3 + 2]}}; } } else if (val->IsRaw()) { // treat it simply as an array of doubles @@ -163,8 +163,8 @@ void FieldObject2d::UpdateFromEntry() const { double rot = wpi::BitsToDouble( wpi::support::endian::readNext(p)); - m_poses[i] = Pose2d{units::meter_t{x}, units::meter_t{y}, - Rotation2d{units::degree_t{rot}}}; + m_poses[i] = + Pose2d{units::meter_t{x}, units::meter_t{y}, units::degree_t{rot}}; } } } diff --git a/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp index b49bc9954b..bbe2fb3473 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp @@ -12,7 +12,7 @@ MechanismLigament2d::MechanismLigament2d(std::string_view name, double length, units::degree_t angle, double lineWeight, const frc::Color8Bit& color) - : MechanismObject2d(name), + : MechanismObject2d{name}, m_length{length}, m_angle{angle.value()}, m_weight{lineWeight} { diff --git a/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp index 637b24b0f2..44fd231c31 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp @@ -10,7 +10,7 @@ using namespace frc; MechanismRoot2d::MechanismRoot2d(std::string_view name, double x, double y, const private_init&) - : MechanismObject2d(name), m_x{x}, m_y{y} {} + : MechanismObject2d{name}, m_x{x}, m_y{y} {} void MechanismRoot2d::SetPosition(double x, double y) { std::scoped_lock lock(m_mutex); diff --git a/wpilibc/src/main/native/include/frc/interfaces/Gyro.h b/wpilibc/src/main/native/include/frc/interfaces/Gyro.h index 50417ea6cb..b74a3cf5d6 100644 --- a/wpilibc/src/main/native/include/frc/interfaces/Gyro.h +++ b/wpilibc/src/main/native/include/frc/interfaces/Gyro.h @@ -77,7 +77,7 @@ class Gyro { * based on integration of the returned rate from the gyro. */ virtual Rotation2d GetRotation2d() const { - return Rotation2d{units::degree_t{-GetAngle()}}; + return units::degree_t{-GetAngle()}; } }; diff --git a/wpilibc/src/main/native/include/frc/simulation/LinearSystemSim.h b/wpilibc/src/main/native/include/frc/simulation/LinearSystemSim.h index b0145a2c7a..cfc87b2949 100644 --- a/wpilibc/src/main/native/include/frc/simulation/LinearSystemSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/LinearSystemSim.h @@ -112,9 +112,7 @@ class LinearSystemSim { * * @return The current drawn by this simulated mechanism. */ - virtual units::ampere_t GetCurrentDraw() const { - return units::ampere_t(0.0); - } + virtual units::ampere_t GetCurrentDraw() const { return 0_A; } protected: /** diff --git a/wpilibc/src/test/native/cpp/simulation/DifferentialDrivetrainSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/DifferentialDrivetrainSimTest.cpp index 778f99d762..6edfde08f2 100644 --- a/wpilibc/src/test/native/cpp/simulation/DifferentialDrivetrainSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/DifferentialDrivetrainSimTest.cpp @@ -40,7 +40,7 @@ TEST(DifferentialDrivetrainSimTest, Convergence) { frc::DifferentialDriveKinematicsConstraint(kinematics, 1_mps)); auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory( - frc::Pose2d(), {}, frc::Pose2d(2_m, 2_m, 0_rad), config); + frc::Pose2d{}, {}, frc::Pose2d{2_m, 2_m, 0_rad}, config); for (auto t = 0_s; t < trajectory.TotalTime(); t += 20_ms) { auto state = trajectory.Sample(t); @@ -51,7 +51,7 @@ TEST(DifferentialDrivetrainSimTest, Convergence) { feedforward.Calculate(frc::Vectord<2>{l.value(), r.value()}); // Sim periodic code. - sim.SetInputs(units::volt_t(voltages(0, 0)), units::volt_t(voltages(1, 0))); + sim.SetInputs(units::volt_t{voltages(0, 0)}, units::volt_t{voltages(1, 0)}); sim.Update(20_ms); // Update ground truth. diff --git a/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp index b43b6fd52b..3c647e6a25 100644 --- a/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp @@ -20,9 +20,8 @@ EXPECT_LE(units::math::abs(val1 - val2), eps) TEST(ElevatorSimTest, StateSpaceSim) { - frc::sim::ElevatorSim sim(frc::DCMotor::Vex775Pro(4), 14.67, 8_kg, - units::meter_t(0.75 * 25.4 / 1000.0), 0_m, 3_m, - true, {0.01}); + frc::sim::ElevatorSim sim(frc::DCMotor::Vex775Pro(4), 14.67, 8_kg, 0.75_in, + 0_m, 3_m, true, {0.01}); frc2::PIDController controller(10, 0.0, 0.0); frc::PWMVictorSPX motor(0); @@ -46,9 +45,8 @@ TEST(ElevatorSimTest, StateSpaceSim) { } TEST(ElevatorSimTest, MinMax) { - frc::sim::ElevatorSim sim(frc::DCMotor::Vex775Pro(4), 14.67, 8_kg, - units::meter_t(0.75 * 25.4 / 1000.0), 0_m, 1_m, - true, {0.01}); + frc::sim::ElevatorSim sim(frc::DCMotor::Vex775Pro(4), 14.67, 8_kg, 0.75_in, + 0_m, 1_m, true, {0.01}); for (size_t i = 0; i < 100; ++i) { sim.SetInput(frc::Vectord<1>{0.0}); sim.Update(20_ms); diff --git a/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp index b54d8b7aab..7456adb1ff 100644 --- a/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp @@ -40,7 +40,7 @@ TEST(StateSpaceSimTest, FlywheelSim) { for (int i = 0; i < 100; i++) { // RobotPeriodic runs first auto voltageOut = controller.Calculate(encoder.GetRate(), 200.0); - motor.SetVoltage(units::volt_t(voltageOut) + + motor.SetVoltage(units::volt_t{voltageOut} + feedforward.Calculate(200_rad_per_s)); // Then, SimulationPeriodic runs diff --git a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp index e814a0911b..3a387ff99d 100644 --- a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp +++ b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp @@ -9,5 +9,5 @@ // https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html ReplaceMeParallelCommandGroup::ReplaceMeParallelCommandGroup() { // Add your commands here, e.g. - // AddCommands(FooCommand(), BarCommand()); + // AddCommands(FooCommand{}, BarCommand{}); } diff --git a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp index 67c12a32eb..f664e55b33 100644 --- a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp +++ b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp @@ -10,9 +10,8 @@ // For more information, see: // https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html ReplaceMeParallelDeadlineGroup::ReplaceMeParallelDeadlineGroup() - : CommandHelper( - // The deadline command - frc2::InstantCommand([] {})) { + // The deadline command + : CommandHelper{frc2::InstantCommand{[] {}}} { // Add your commands here, e.g. - // AddCommands(FooCommand(), BarCommand()); + // AddCommands(FooCommand{}, BarCommand{}); } diff --git a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp index 9cc3784046..f51433cdee 100644 --- a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp +++ b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp @@ -9,5 +9,5 @@ // https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html ReplaceMeParallelRaceGroup::ReplaceMeParallelRaceGroup() { // Add your commands here, e.g. - // AddCommands(FooCommand(), BarCommand()); + // AddCommands(FooCommand{}, BarCommand{}); } diff --git a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp index 1bcc830887..4a7d0e1791 100644 --- a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp +++ b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp @@ -8,16 +8,15 @@ // For more information, see: // https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html ReplaceMePIDCommand::ReplaceMePIDCommand() - : CommandHelper( - frc2::PIDController(0, 0, 0), - // This should return the measurement - [] { return 0; }, - // This should return the setpoint (can also be a constant) - [] { return 0; }, - // This uses the output - [](double output) { - // Use the output here - }) {} + : CommandHelper{frc2::PIDController{0, 0, 0}, + // This should return the measurement + [] { return 0; }, + // This should return the setpoint (can also be a constant) + [] { return 0; }, + // This uses the output + [](double output) { + // Use the output here + }} {} // Returns true when the command should end. bool ReplaceMePIDCommand::IsFinished() { diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp index 2cdce1b29e..749b106927 100644 --- a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp +++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp @@ -5,9 +5,8 @@ #include "ReplaceMePIDSubsystem2.h" ReplaceMePIDSubsystem2::ReplaceMePIDSubsystem2() - : PIDSubsystem( - // The PIDController used by the subsystem - frc2::PIDController(0, 0, 0)) {} + // The PIDController used by the subsystem + : PIDSubsystem{frc2::PIDController{0, 0, 0}} {} void ReplaceMePIDSubsystem2::UseOutput(double output, double setpoint) { // Use the output here diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp index 880a222a3a..f3fd26af8b 100644 --- a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp +++ b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp @@ -11,13 +11,15 @@ // For more information, see: // https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html ReplaceMeProfiledPIDCommand::ReplaceMeProfiledPIDCommand() - : CommandHelper( + : CommandHelper{ // The ProfiledPIDController that the command will use - frc::ProfiledPIDController( + frc::ProfiledPIDController{ // The PID gains - 0, 0, 0, + 0, + 0, + 0, // The motion profile constraints - {0_mps, 0_mps_sq}), + {0_mps, 0_mps_sq}}, // This should return the measurement [] { return 0_m; }, // This should return the goal state (can also be a constant) @@ -28,7 +30,7 @@ ReplaceMeProfiledPIDCommand::ReplaceMeProfiledPIDCommand() [](double output, frc::TrapezoidProfile::State setpoint) { // Use the output and setpoint here - }) {} + }} {} // Returns true when the command should end. bool ReplaceMeProfiledPIDCommand::IsFinished() { diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp index d65a867d75..2ee899c03c 100644 --- a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp @@ -8,13 +8,14 @@ #include ReplaceMeProfiledPIDSubsystem::ReplaceMeProfiledPIDSubsystem() - : ProfiledPIDSubsystem( - // The ProfiledPIDController used by the subsystem - frc::ProfiledPIDController( - // The PID gains - 0, 0, 0, - // The constraints for the motion profiles - {0_mps, 0_mps_sq})) {} + // The ProfiledPIDController used by the subsystem + : ProfiledPIDSubsystem{frc::ProfiledPIDController{ + // The PID gains + 0, + 0, + 0, + // The constraints for the motion profiles + {0_mps, 0_mps_sq}}} {} void ReplaceMeProfiledPIDSubsystem::UseOutput( double output, frc::TrapezoidProfile::State setpoint) { diff --git a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp index c83a99d9d0..cc2504c53c 100644 --- a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp +++ b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp @@ -9,5 +9,5 @@ // https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html ReplaceMeSequentialCommandGroup::ReplaceMeSequentialCommandGroup() { // Add your commands here, e.g. - // AddCommands(FooCommand(), BarCommand()); + // AddCommands(FooCommand{}, BarCommand{}); } diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp index c5fb3b2e96..6d5eab67af 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/subsystems/ArmSubsystem.cpp @@ -26,9 +26,9 @@ void ArmSubsystem::UseOutput(double output, State setpoint) { units::volt_t feedforward = m_feedforward.Calculate(setpoint.position, setpoint.velocity); // Add the feedforward to the PID output to get the motor output - m_motor.SetVoltage(units::volt_t(output) + feedforward); + m_motor.SetVoltage(units::volt_t{output} + feedforward); } units::radian_t ArmSubsystem::GetMeasurement() { - return units::radian_t(m_encoder.GetDistance()) + kArmOffset; + return units::radian_t{m_encoder.GetDistance()} + kArmOffset; } diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp index 2b52dddaf7..e8003755b3 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp @@ -120,8 +120,8 @@ class Robot : public frc::TimedRobot { void TeleopInit() override { // Read Preferences for Arm setpoint and kP on entering Teleop - armPosition = units::degree_t( - frc::Preferences::GetDouble(kArmPositionKey, armPosition.value())); + armPosition = units::degree_t{ + frc::Preferences::GetDouble(kArmPositionKey, armPosition.value())}; if (kArmKp != frc::Preferences::GetDouble(kArmPKey, kArmKp)) { kArmKp = frc::Preferences::GetDouble(kArmPKey, kArmKp); m_controller.SetP(kArmKp); @@ -133,8 +133,8 @@ class Robot : public frc::TimedRobot { // Here, we run PID control like normal, with a setpoint read from // preferences in degrees. double pidOutput = m_controller.Calculate( - m_encoder.GetDistance(), (units::radian_t(armPosition).value())); - m_motor.SetVoltage(units::volt_t(pidOutput)); + m_encoder.GetDistance(), (units::radian_t{armPosition}.value())); + m_motor.SetVoltage(units::volt_t{pidOutput}); } else { // Otherwise, we disable the motor. m_motor.Set(0.0); diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp index da638d5b1d..cc7db7b3ba 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp @@ -23,6 +23,6 @@ void Drivetrain::Drive(units::meters_per_second_t xSpeed, void Drivetrain::UpdateOdometry() { m_odometry.Update(m_gyro.GetRotation2d(), - units::meter_t(m_leftEncoder.GetDistance()), - units::meter_t(m_rightEncoder.GetDistance())); + units::meter_t{m_leftEncoder.GetDistance()}, + units::meter_t{m_rightEncoder.GetDistance()}); } diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp index 1ed0e46768..c48aa95f9a 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp @@ -27,10 +27,10 @@ void Drivetrain::Drive(units::meters_per_second_t xSpeed, void Drivetrain::UpdateOdometry() { m_poseEstimator.Update(m_gyro.GetRotation2d(), - {units::meters_per_second_t(m_leftEncoder.GetRate()), - units::meters_per_second_t(m_rightEncoder.GetRate())}, - units::meter_t(m_leftEncoder.GetDistance()), - units::meter_t(m_rightEncoder.GetDistance())); + {units::meters_per_second_t{m_leftEncoder.GetRate()}, + units::meters_per_second_t{m_rightEncoder.GetRate()}}, + units::meter_t{m_leftEncoder.GetDistance()}, + units::meter_t{m_rightEncoder.GetDistance()}); // Also apply vision measurements. We use 0.3 seconds in the past as an // example -- on a real robot, this must be calculated based either on latency diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h index dfb57a6155..65948feb5c 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h @@ -78,8 +78,8 @@ class Drivetrain { // Gains are for example purposes only - must be determined for your own // robot! frc::DifferentialDrivePoseEstimator m_poseEstimator{ - frc::Rotation2d(), - frc::Pose2d(), + frc::Rotation2d{}, + frc::Pose2d{}, {0.01, 0.01, 0.01, 0.01, 0.01}, {0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}}; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h index 4697938dd8..b9e2ba4339 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h @@ -16,9 +16,9 @@ class ExampleGlobalMeasurementSensor { static frc::Pose2d GetEstimatedGlobalPose( const frc::Pose2d& estimatedRobotPose) { auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1); - return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)), - estimatedRobotPose.Y() + units::meter_t(randVec(1)), + return frc::Pose2d{estimatedRobotPose.X() + units::meter_t{randVec(0)}, + estimatedRobotPose.Y() + units::meter_t{randVec(1)}, estimatedRobotPose.Rotation() + - frc::Rotation2d(units::radian_t(randVec(2)))); + frc::Rotation2d{units::radian_t{randVec(2)}}}; } }; diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp index cecb9d69fe..6780c3336c 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/commands/DriveDistanceProfiled.cpp @@ -10,18 +10,18 @@ using namespace DriveConstants; DriveDistanceProfiled::DriveDistanceProfiled(units::meter_t distance, DriveSubsystem* drive) - : CommandHelper( - frc::TrapezoidProfile( + : CommandHelper{ + frc::TrapezoidProfile{ // Limit the max acceleration and velocity {kMaxSpeed, kMaxAcceleration}, // End at desired position in meters; implicitly starts at 0 - {distance, 0_mps}), + {distance, 0_mps}}, // Pipe the profile state to the drive [drive](auto setpointState) { drive->SetDriveStates(setpointState, setpointState); }, // Require the drive - {drive}) { + {drive}} { // Reset drive encoders since we're starting at 0 drive->ResetEncoders(); } diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp index 270124bb22..db8ba70755 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp @@ -54,11 +54,11 @@ void DriveSubsystem::ResetEncoders() { } units::meter_t DriveSubsystem::GetLeftEncoderDistance() { - return units::meter_t(m_leftLeader.GetEncoderDistance()); + return units::meter_t{m_leftLeader.GetEncoderDistance()}; } units::meter_t DriveSubsystem::GetRightEncoderDistance() { - return units::meter_t(m_rightLeader.GetEncoderDistance()); + return units::meter_t{m_rightLeader.GetEncoderDistance()}; } void DriveSubsystem::SetMaxOutput(double maxOutput) { diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp index ebafa75296..5ea7ca4ebc 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp @@ -31,7 +31,7 @@ class Robot : public frc::TimedRobot { // Run controller and update motor output m_motor.Set( - m_controller.Calculate(units::meter_t(m_encoder.GetDistance()))); + m_controller.Calculate(units::meter_t{m_encoder.GetDistance()})); } private: diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp index 2f7382a4d1..eebbb0a7b8 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp @@ -74,7 +74,7 @@ class Robot : public frc::TimedRobot { m_mech2d.GetRoot("Elevator Root", 10, 0); frc::MechanismLigament2d* m_elevatorMech2d = m_elevatorRoot->Append( - "Elevator", units::inch_t(m_elevatorSim.GetPosition()).value(), + "Elevator", units::inch_t{m_elevatorSim.GetPosition()}.value(), 90_deg); public: @@ -103,15 +103,15 @@ class Robot : public frc::TimedRobot { // Update the Elevator length based on the simulated elevator height m_elevatorMech2d->SetLength( - units::inch_t(m_elevatorSim.GetPosition()).value()); + units::inch_t{m_elevatorSim.GetPosition()}.value()); } void TeleopPeriodic() override { if (m_joystick.GetTrigger()) { // Here, we run PID control like normal, with a constant setpoint of 30in. double pidOutput = m_controller.Calculate(m_encoder.GetDistance(), - units::meter_t(30_in).value()); - m_motor.SetVoltage(units::volt_t(pidOutput)); + units::meter_t{30_in}.value()); + m_motor.SetVoltage(units::volt_t{pidOutput}); } else { // Otherwise, we disable the motor. m_motor.Set(0.0); diff --git a/wpilibcExamples/src/main/cpp/examples/EventLoop/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/EventLoop/cpp/Robot.cpp index 5af7aba191..c8e84fb0ee 100644 --- a/wpilibcExamples/src/main/cpp/examples/EventLoop/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/EventLoop/cpp/Robot.cpp @@ -54,8 +54,8 @@ class Robot : public frc::TimedRobot { // accelerate the shooter wheel .IfHigh([&shooter = m_shooter, &controller = m_controller, &ff = m_ff, &encoder = m_shooterEncoder] { - shooter.SetVoltage(units::volt_t(controller.Calculate( - encoder.GetRate(), SHOT_VELOCITY.value())) + + shooter.SetVoltage(units::volt_t{controller.Calculate( + encoder.GetRate(), SHOT_VELOCITY.value())} + ff.Calculate(SHOT_VELOCITY)); }); // if not, stop diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp index c386ee7eb8..aec84f1039 100644 --- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/cpp/subsystems/ShooterSubsystem.cpp @@ -11,7 +11,7 @@ using namespace ShooterConstants; ShooterSubsystem::ShooterSubsystem() - : PIDSubsystem(frc2::PIDController(kP, kI, kD)), + : PIDSubsystem{frc2::PIDController{kP, kI, kD}}, m_shooterMotor(kShooterMotorPort), m_feederMotor(kFeederMotorPort), m_shooterEncoder(kEncoderPorts[0], kEncoderPorts[1]), @@ -22,7 +22,7 @@ ShooterSubsystem::ShooterSubsystem() } void ShooterSubsystem::UseOutput(double output, double setpoint) { - m_shooterMotor.SetVoltage(units::volt_t(output) + + m_shooterMotor.SetVoltage(units::volt_t{output} + m_shooterFeedforward.Calculate(kShooterTargetRPS)); } diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp index d3e85bd6a0..c1f5d88b23 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/DriveStraight.cpp @@ -9,12 +9,13 @@ #include "Robot.h" DriveStraight::DriveStraight(double distance, Drivetrain& drivetrain) - : frc2::CommandHelper( - frc2::PIDController(4, 0, 0), - [&drivetrain] { return drivetrain.GetDistance(); }, distance, + : frc2::CommandHelper{ + frc2::PIDController{4, 0, 0}, + [&drivetrain] { return drivetrain.GetDistance(); }, + distance, [&drivetrain](double output) { drivetrain.Drive(output, output); }, - {&drivetrain}), - m_drivetrain(&drivetrain) { + {&drivetrain}}, + m_drivetrain{&drivetrain} { m_controller.SetTolerance(0.01); } diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp index 84bf237e76..de8f1e789a 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/SetDistanceToBox.cpp @@ -9,13 +9,13 @@ #include "Robot.h" SetDistanceToBox::SetDistanceToBox(double distance, Drivetrain& drivetrain) - : frc2::CommandHelper( - frc2::PIDController(-2, 0, 0), + : frc2::CommandHelper{ + frc2::PIDController{-2, 0, 0}, [&drivetrain] { return drivetrain.GetDistanceToObstacle(); }, distance, [&drivetrain](double output) { drivetrain.Drive(output, output); }, - {&drivetrain}), - m_drivetrain(&drivetrain) { + {&drivetrain}}, + m_drivetrain{&drivetrain} { m_controller.SetTolerance(0.01); } diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp index 0c195e3022..c75c7bcae1 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp @@ -9,7 +9,7 @@ #include Elevator::Elevator() - : frc2::PIDSubsystem(frc2::PIDController(kP_real, kI_real, 0)) { + : frc2::PIDSubsystem{frc2::PIDController{kP_real, kI_real, 0}} { #ifdef SIMULATION // Check for simulation and update PID values GetPIDController()->SetPID(kP_simulation, kI_simulation, 0, 0); #endif diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp index 339ccd0aab..8b24a7b44f 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp @@ -7,7 +7,7 @@ #include #include -Wrist::Wrist() : frc2::PIDSubsystem(frc2::PIDController(kP, 0, 0)) { +Wrist::Wrist() : frc2::PIDSubsystem{frc2::PIDController{kP, 0, 0}} { m_controller.SetTolerance(2.5); SetName("Wrist"); diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp index 681bb3933b..3038f79adc 100644 --- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngle.cpp @@ -9,16 +9,15 @@ using namespace DriveConstants; TurnToAngle::TurnToAngle(units::degree_t target, DriveSubsystem* drive) - : CommandHelper( - frc2::PIDController(kTurnP, kTurnI, kTurnD), - // Close loop on heading - [drive] { return drive->GetHeading().value(); }, - // Set reference to target - target.value(), - // Pipe output to turn robot - [drive](double output) { drive->ArcadeDrive(0, output); }, - // Require the drive - {drive}) { + : CommandHelper{frc2::PIDController{kTurnP, kTurnI, kTurnD}, + // Close loop on heading + [drive] { return drive->GetHeading().value(); }, + // Set reference to target + target.value(), + // Pipe output to turn robot + [drive](double output) { drive->ArcadeDrive(0, output); }, + // Require the drive + {drive}} { // Set the controller to be continuous (because it is an angle controller) m_controller.EnableContinuousInput(-180, 180); // Set the controller tolerance - the delta tolerance ensures the robot is diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp index a359625088..df4e3554da 100644 --- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/commands/TurnToAngleProfiled.cpp @@ -10,9 +10,9 @@ using namespace DriveConstants; TurnToAngleProfiled::TurnToAngleProfiled(units::degree_t target, DriveSubsystem* drive) - : CommandHelper( - frc::ProfiledPIDController( - kTurnP, kTurnI, kTurnD, {kMaxTurnRate, kMaxTurnAcceleration}), + : CommandHelper{ + frc::ProfiledPIDController{ + kTurnP, kTurnI, kTurnD, {kMaxTurnRate, kMaxTurnAcceleration}}, // Close loop on heading [drive] { return drive->GetHeading(); }, // Set reference to target @@ -22,7 +22,7 @@ TurnToAngleProfiled::TurnToAngleProfiled(units::degree_t target, drive->ArcadeDrive(0, output); }, // Require the drive - {drive}) { + {drive}} { // Set the controller to be continuous (because it is an angle controller) GetController().EnableContinuousInput(-180_deg, 180_deg); // Set the controller tolerance - the delta tolerance ensures the robot is diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp index baa78de958..0cbd0e548d 100644 --- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/subsystems/DriveSubsystem.cpp @@ -53,8 +53,8 @@ void DriveSubsystem::SetMaxOutput(double maxOutput) { } units::degree_t DriveSubsystem::GetHeading() { - return units::degree_t(std::remainder(m_gyro.GetAngle(), 360) * - (kGyroReversed ? -1.0 : 1.0)); + return units::degree_t{std::remainder(m_gyro.GetAngle(), 360) * + (kGyroReversed ? -1.0 : 1.0)}; } double DriveSubsystem::GetTurnRate() { diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp index 4d3aac221d..b21b8dc1e5 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp @@ -5,10 +5,10 @@ #include "Drivetrain.h" frc::MecanumDriveWheelSpeeds Drivetrain::GetCurrentState() const { - return {units::meters_per_second_t(m_frontLeftEncoder.GetRate()), - units::meters_per_second_t(m_frontRightEncoder.GetRate()), - units::meters_per_second_t(m_backLeftEncoder.GetRate()), - units::meters_per_second_t(m_backRightEncoder.GetRate())}; + return {units::meters_per_second_t{m_frontLeftEncoder.GetRate()}, + units::meters_per_second_t{m_frontRightEncoder.GetRate()}, + units::meters_per_second_t{m_backLeftEncoder.GetRate()}, + units::meters_per_second_t{m_backRightEncoder.GetRate()}}; } void Drivetrain::SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds) { diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp index 36912b5a1c..99aed4e627 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp @@ -7,10 +7,10 @@ namespace DriveConstants { const frc::MecanumDriveKinematics kDriveKinematics{ - frc::Translation2d(kWheelBase / 2, kTrackWidth / 2), - frc::Translation2d(kWheelBase / 2, -kTrackWidth / 2), - frc::Translation2d(-kWheelBase / 2, kTrackWidth / 2), - frc::Translation2d(-kWheelBase / 2, -kTrackWidth / 2)}; + frc::Translation2d{kWheelBase / 2, kTrackWidth / 2}, + frc::Translation2d{kWheelBase / 2, -kTrackWidth / 2}, + frc::Translation2d{-kWheelBase / 2, kTrackWidth / 2}, + frc::Translation2d{-kWheelBase / 2, -kTrackWidth / 2}}; } // namespace DriveConstants diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp index 3e2c6bf656..3180caf55d 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp @@ -57,11 +57,11 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { // An example trajectory to follow. All units in meters. auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory( // Start at the origin facing the +X direction - frc::Pose2d(0_m, 0_m, frc::Rotation2d(0_deg)), + frc::Pose2d{0_m, 0_m, 0_deg}, // Pass through these two interior waypoints, making an 's' curve path - {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)}, + {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}}, // End 3 meters straight ahead of where we started, facing forward - frc::Pose2d(3_m, 0_m, frc::Rotation2d(0_deg)), + frc::Pose2d{3_m, 0_m, 0_deg}, // Pass the config config); @@ -71,8 +71,8 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { frc::SimpleMotorFeedforward(ks, kv, ka), DriveConstants::kDriveKinematics, - frc2::PIDController(AutoConstants::kPXController, 0, 0), - frc2::PIDController(AutoConstants::kPYController, 0, 0), + frc2::PIDController{AutoConstants::kPXController, 0, 0}, + frc2::PIDController{AutoConstants::kPYController, 0, 0}, frc::ProfiledPIDController( AutoConstants::kPThetaController, 0, 0, AutoConstants::kThetaControllerConstraints), @@ -81,18 +81,18 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { [this]() { return frc::MecanumDriveWheelSpeeds{ - units::meters_per_second_t(m_drive.GetFrontLeftEncoder().GetRate()), - units::meters_per_second_t( - m_drive.GetFrontRightEncoder().GetRate()), - units::meters_per_second_t(m_drive.GetRearLeftEncoder().GetRate()), - units::meters_per_second_t( - m_drive.GetRearRightEncoder().GetRate())}; + units::meters_per_second_t{m_drive.GetFrontLeftEncoder().GetRate()}, + units::meters_per_second_t{ + m_drive.GetFrontRightEncoder().GetRate()}, + units::meters_per_second_t{m_drive.GetRearLeftEncoder().GetRate()}, + units::meters_per_second_t{ + m_drive.GetRearRightEncoder().GetRate()}}; }, - frc2::PIDController(DriveConstants::kPFrontLeftVel, 0, 0), - frc2::PIDController(DriveConstants::kPRearLeftVel, 0, 0), - frc2::PIDController(DriveConstants::kPFrontRightVel, 0, 0), - frc2::PIDController(DriveConstants::kPRearRightVel, 0, 0), + frc2::PIDController{DriveConstants::kPFrontLeftVel, 0, 0}, + frc2::PIDController{DriveConstants::kPRearLeftVel, 0, 0}, + frc2::PIDController{DriveConstants::kPFrontRightVel, 0, 0}, + frc2::PIDController{DriveConstants::kPRearRightVel, 0, 0}, [this](units::volt_t frontLeft, units::volt_t rearLeft, units::volt_t frontRight, units::volt_t rearRight) { diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp index 9e06068512..b56a8e211d 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp @@ -28,7 +28,7 @@ DriveSubsystem::DriveSubsystem() m_rearRightEncoder{kRearRightEncoderPorts[0], kRearRightEncoderPorts[1], kRearRightEncoderReversed}, - m_odometry{kDriveKinematics, m_gyro.GetRotation2d(), frc::Pose2d()} { + m_odometry{kDriveKinematics, m_gyro.GetRotation2d(), frc::Pose2d{}} { // Set the distance per pulse for the encoders m_frontLeftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); m_rearLeftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); @@ -46,10 +46,10 @@ void DriveSubsystem::Periodic() { m_odometry.Update( m_gyro.GetRotation2d(), frc::MecanumDriveWheelSpeeds{ - units::meters_per_second_t(m_frontLeftEncoder.GetRate()), - units::meters_per_second_t(m_rearLeftEncoder.GetRate()), - units::meters_per_second_t(m_frontRightEncoder.GetRate()), - units::meters_per_second_t(m_rearRightEncoder.GetRate())}); + units::meters_per_second_t{m_frontLeftEncoder.GetRate()}, + units::meters_per_second_t{m_rearLeftEncoder.GetRate()}, + units::meters_per_second_t{m_frontRightEncoder.GetRate()}, + units::meters_per_second_t{m_rearRightEncoder.GetRate()}}); } void DriveSubsystem::Drive(double xSpeed, double ySpeed, double rot, @@ -96,10 +96,10 @@ frc::Encoder& DriveSubsystem::GetRearRightEncoder() { frc::MecanumDriveWheelSpeeds DriveSubsystem::getCurrentWheelSpeeds() { return (frc::MecanumDriveWheelSpeeds{ - units::meters_per_second_t(m_frontLeftEncoder.GetRate()), - units::meters_per_second_t(m_rearLeftEncoder.GetRate()), - units::meters_per_second_t(m_frontRightEncoder.GetRate()), - units::meters_per_second_t(m_rearRightEncoder.GetRate())}); + units::meters_per_second_t{m_frontLeftEncoder.GetRate()}, + units::meters_per_second_t{m_rearLeftEncoder.GetRate()}, + units::meters_per_second_t{m_frontRightEncoder.GetRate()}, + units::meters_per_second_t{m_rearRightEncoder.GetRate()}}); } void DriveSubsystem::SetMaxOutput(double maxOutput) { diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h index 8d59a2cac9..9385f2aa3d 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -70,15 +71,10 @@ constexpr double kPRearRightVel = 0.5; } // namespace DriveConstants namespace AutoConstants { -using radians_per_second_squared_t = - units::compound_unit>>; - -constexpr auto kMaxSpeed = units::meters_per_second_t(3); -constexpr auto kMaxAcceleration = units::meters_per_second_squared_t(3); -constexpr auto kMaxAngularSpeed = units::radians_per_second_t(3); -constexpr auto kMaxAngularAcceleration = - units::unit_t(3); +constexpr auto kMaxSpeed = 3_mps; +constexpr auto kMaxAcceleration = 3_mps_sq; +constexpr auto kMaxAngularSpeed = 3_rad_per_s; +constexpr auto kMaxAngularAcceleration = 3_rad_per_s_sq; constexpr double kPXController = 0.5; constexpr double kPYController = 0.5; diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp index daa4b42307..b411f4aef1 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp @@ -9,10 +9,10 @@ #include "ExampleGlobalMeasurementSensor.h" frc::MecanumDriveWheelSpeeds Drivetrain::GetCurrentState() const { - return {units::meters_per_second_t(m_frontLeftEncoder.GetRate()), - units::meters_per_second_t(m_frontRightEncoder.GetRate()), - units::meters_per_second_t(m_backLeftEncoder.GetRate()), - units::meters_per_second_t(m_backRightEncoder.GetRate())}; + return {units::meters_per_second_t{m_frontLeftEncoder.GetRate()}, + units::meters_per_second_t{m_frontRightEncoder.GetRate()}, + units::meters_per_second_t{m_backLeftEncoder.GetRate()}, + units::meters_per_second_t{m_backRightEncoder.GetRate()}}; } void Drivetrain::SetSpeeds(const frc::MecanumDriveWheelSpeeds& wheelSpeeds) { diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h index 3eea4a2557..e19b1fe25b 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h @@ -74,7 +74,7 @@ class Drivetrain { // Gains are for example purposes only - must be determined for your own // robot! - frc::MecanumDrivePoseEstimator m_poseEstimator{ - frc::Rotation2d(), frc::Pose2d(), m_kinematics, - {0.1, 0.1, 0.1}, {0.05}, {0.1, 0.1, 0.1}}; + frc::MecanumDrivePoseEstimator m_poseEstimator{0_deg, frc::Pose2d{}, + m_kinematics, {0.1, 0.1, 0.1}, + {0.05}, {0.1, 0.1, 0.1}}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h index a4caff4aa4..1aa10d79c1 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h @@ -16,9 +16,9 @@ class ExampleGlobalMeasurementSensor { static frc::Pose2d GetEstimatedGlobalPose( const frc::Pose2d& estimatedRobotPose) { auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1); - return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)), - estimatedRobotPose.Y() + units::meter_t(randVec(1)), + return frc::Pose2d{estimatedRobotPose.X() + units::meter_t{randVec(0)}, + estimatedRobotPose.Y() + units::meter_t{randVec(1)}, estimatedRobotPose.Rotation() + - frc::Rotation2d(units::radian_t(randVec(3)))); + frc::Rotation2d{units::radian_t{randVec(3)}}}; } }; diff --git a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp index 551dc78335..6d1967fd29 100644 --- a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp @@ -41,7 +41,7 @@ class Robot : public frc::TimedRobot { // update the dashboard mechanism's state m_elevator->SetLength(kElevatorMinimumLength + m_elevatorEncoder.GetDistance()); - m_wrist->SetAngle(units::degree_t(m_wristPotentiometer.Get())); + m_wrist->SetAngle(units::degree_t{m_wristPotentiometer.Get()}); } void TeleopPeriodic() override { diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp index 49ee31b484..3d884e693c 100644 --- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/RobotContainer.cpp @@ -38,21 +38,21 @@ void RobotContainer::ConfigureButtonBindings() { // Configure your button bindings here // While holding the shoulder button, drive at half speed - frc2::JoystickButton(&m_driverController, 6) + frc2::JoystickButton{&m_driverController, 6} .WhenPressed(&m_driveHalfSpeed) .WhenReleased(&m_driveFullSpeed); } frc2::Command* RobotContainer::GetAutonomousCommand() { // Create a voltage constraint to ensure we don't accelerate too fast - frc::DifferentialDriveVoltageConstraint autoVoltageConstraint( - frc::SimpleMotorFeedforward( - DriveConstants::ks, DriveConstants::kv, DriveConstants::ka), - DriveConstants::kDriveKinematics, 10_V); + frc::DifferentialDriveVoltageConstraint autoVoltageConstraint{ + frc::SimpleMotorFeedforward{ + DriveConstants::ks, DriveConstants::kv, DriveConstants::ka}, + DriveConstants::kDriveKinematics, 10_V}; // Set up config for trajectory - frc::TrajectoryConfig config(AutoConstants::kMaxSpeed, - AutoConstants::kMaxAcceleration); + frc::TrajectoryConfig config{AutoConstants::kMaxSpeed, + AutoConstants::kMaxAcceleration}; // Add kinematics to ensure max speed is actually obeyed config.SetKinematics(DriveConstants::kDriveKinematics); // Apply the voltage constraint @@ -61,26 +61,27 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { // An example trajectory to follow. All units in meters. auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory( // Start at the origin facing the +X direction - frc::Pose2d(0_m, 0_m, frc::Rotation2d(0_deg)), + frc::Pose2d{0_m, 0_m, 0_deg}, // Pass through these two interior waypoints, making an 's' curve path - {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)}, + {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}}, // End 3 meters straight ahead of where we started, facing forward - frc::Pose2d(3_m, 0_m, frc::Rotation2d(0_deg)), + frc::Pose2d{3_m, 0_m, 0_deg}, // Pass the config config); - frc2::RamseteCommand ramseteCommand( - exampleTrajectory, [this]() { return m_drive.GetPose(); }, - frc::RamseteController(AutoConstants::kRamseteB, - AutoConstants::kRamseteZeta), - frc::SimpleMotorFeedforward( - DriveConstants::ks, DriveConstants::kv, DriveConstants::ka), + frc2::RamseteCommand ramseteCommand{ + exampleTrajectory, + [this]() { return m_drive.GetPose(); }, + frc::RamseteController{AutoConstants::kRamseteB, + AutoConstants::kRamseteZeta}, + frc::SimpleMotorFeedforward{ + DriveConstants::ks, DriveConstants::kv, DriveConstants::ka}, DriveConstants::kDriveKinematics, [this] { return m_drive.GetWheelSpeeds(); }, - frc2::PIDController(DriveConstants::kPDriveVel, 0, 0), - frc2::PIDController(DriveConstants::kPDriveVel, 0, 0), + frc2::PIDController{DriveConstants::kPDriveVel, 0, 0}, + frc2::PIDController{DriveConstants::kPDriveVel, 0, 0}, [this](auto left, auto right) { m_drive.TankDriveVolts(left, right); }, - {&m_drive}); + {&m_drive}}; // Reset odometry to the starting pose of the trajectory. m_drive.ResetOdometry(exampleTrajectory.InitialPose()); diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp index a5b853ea33..4028cb7a31 100644 --- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp @@ -32,8 +32,8 @@ DriveSubsystem::DriveSubsystem() void DriveSubsystem::Periodic() { // Implementation of subsystem periodic method goes here. m_odometry.Update(m_gyro.GetRotation2d(), - units::meter_t(m_leftEncoder.GetDistance()), - units::meter_t(m_rightEncoder.GetDistance())); + units::meter_t{m_leftEncoder.GetDistance()}, + units::meter_t{m_rightEncoder.GetDistance()}); } void DriveSubsystem::ArcadeDrive(double fwd, double rot) { @@ -80,8 +80,8 @@ frc::Pose2d DriveSubsystem::GetPose() { } frc::DifferentialDriveWheelSpeeds DriveSubsystem::GetWheelSpeeds() { - return {units::meters_per_second_t(m_leftEncoder.GetRate()), - units::meters_per_second_t(m_rightEncoder.GetRate())}; + return {units::meters_per_second_t{m_leftEncoder.GetRate()}, + units::meters_per_second_t{m_rightEncoder.GetRate()}}; } void DriveSubsystem::ResetOdometry(frc::Pose2d pose) { diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp index 1871688255..e5875e90fd 100644 --- a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Drivetrain.cpp @@ -23,8 +23,8 @@ void Drivetrain::Drive(units::meters_per_second_t xSpeed, void Drivetrain::UpdateOdometry() { m_odometry.Update(m_gyro.GetRotation2d(), - units::meter_t(m_leftEncoder.GetDistance()), - units::meter_t(m_rightEncoder.GetDistance())); + units::meter_t{m_leftEncoder.GetDistance()}, + units::meter_t{m_rightEncoder.GetDistance()}); } void Drivetrain::ResetOdometry(const frc::Pose2d& pose) { diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp index f47da51c67..d7902f17d5 100644 --- a/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/cpp/Robot.cpp @@ -79,9 +79,9 @@ class Robot : public frc::TimedRobot { // An example trajectory to follow. frc::Trajectory m_trajectory = frc::TrajectoryGenerator::GenerateTrajectory( - frc::Pose2d(0_m, 0_m, 0_rad), - {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)}, - frc::Pose2d(3_m, 0_m, 0_rad), frc::TrajectoryConfig(3_fps, 3_fps_sq)); + frc::Pose2d{0_m, 0_m, 0_rad}, + {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}}, + frc::Pose2d{3_m, 0_m, 0_rad}, frc::TrajectoryConfig(3_fps, 3_fps_sq)); // The Ramsete Controller to follow the trajectory. frc::RamseteController m_ramseteController; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp index 13ec2d847b..9382e57ed9 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp @@ -49,11 +49,11 @@ int Drivetrain::GetRightEncoderCount() { } units::meter_t Drivetrain::GetLeftDistance() { - return units::meter_t(m_leftEncoder.GetDistance()); + return units::meter_t{m_leftEncoder.GetDistance()}; } units::meter_t Drivetrain::GetRightDistance() { - return units::meter_t(m_rightEncoder.GetDistance()); + return units::meter_t{m_rightEncoder.GetDistance()}; } units::meter_t Drivetrain::GetAverageDistance() { diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp index 098b997066..4e445e7f82 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp @@ -25,8 +25,8 @@ void Drivetrain::Drive(units::meters_per_second_t xSpeed, void Drivetrain::UpdateOdometry() { m_odometry.Update(m_gyro.GetRotation2d(), - units::meter_t(m_leftEncoder.GetDistance()), - units::meter_t(m_rightEncoder.GetDistance())); + units::meter_t{m_leftEncoder.GetDistance()}, + units::meter_t{m_rightEncoder.GetDistance()}); } void Drivetrain::ResetOdometry(const frc::Pose2d& pose) { diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp index a6eeef4e3d..afad9992b9 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp @@ -19,7 +19,7 @@ class Robot : public frc::TimedRobot { SetNetworkTablesFlushEnabled(true); m_trajectory = frc::TrajectoryGenerator::GenerateTrajectory( - frc::Pose2d(2_m, 2_m, 0_rad), {}, frc::Pose2d(6_m, 4_m, 0_rad), + frc::Pose2d{2_m, 2_m, 0_rad}, {}, frc::Pose2d{6_m, 4_m, 0_rad}, frc::TrajectoryConfig(2_mps, 2_mps_sq)); } diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp index c29f3353d8..3b16043713 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp @@ -100,8 +100,8 @@ class Robot : public frc::TimedRobot { m_loop.Reset(frc::Vectord<2>{m_encoder.GetDistance(), m_encoder.GetRate()}); m_lastProfiledReference = { - units::radian_t(m_encoder.GetDistance()), - units::radians_per_second_t(m_encoder.GetRate())}; + units::radian_t{m_encoder.GetDistance()}, + units::radians_per_second_t{m_encoder.GetRate()}}; } void TeleopPeriodic() override { @@ -133,7 +133,7 @@ class Robot : public frc::TimedRobot { // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - m_motor.SetVoltage(units::volt_t(m_loop.U(0))); + m_motor.SetVoltage(units::volt_t{m_loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp index 312d90c2bc..e8f31282cb 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/RobotContainer.cpp @@ -75,24 +75,24 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { // An example trajectory to follow. All units in meters. auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory( // Start at (1, 2) facing the +X direction - frc::Pose2d(1_m, 2_m, 0_deg), + frc::Pose2d{1_m, 2_m, 0_deg}, // Pass through these two interior waypoints, making an 's' curve path - {frc::Translation2d(2_m, 3_m), frc::Translation2d(3_m, 1_m)}, + {frc::Translation2d{2_m, 3_m}, frc::Translation2d{3_m, 1_m}}, // End 3 meters straight ahead of where we started, facing forward - frc::Pose2d(4_m, 2_m, 0_deg), + frc::Pose2d{4_m, 2_m, 0_deg}, // Pass the config config); frc2::RamseteCommand ramseteCommand( exampleTrajectory, [this] { return m_drive.GetPose(); }, - frc::RamseteController(AutoConstants::kRamseteB, - AutoConstants::kRamseteZeta), + frc::RamseteController{AutoConstants::kRamseteB, + AutoConstants::kRamseteZeta}, frc::SimpleMotorFeedforward( DriveConstants::ks, DriveConstants::kv, DriveConstants::ka), DriveConstants::kDriveKinematics, [this] { return m_drive.GetWheelSpeeds(); }, - frc2::PIDController(DriveConstants::kPDriveVel, 0, 0), - frc2::PIDController(DriveConstants::kPDriveVel, 0, 0), + frc2::PIDController{DriveConstants::kPDriveVel, 0, 0}, + frc2::PIDController{DriveConstants::kPDriveVel, 0, 0}, [this](auto left, auto right) { m_drive.TankDriveVolts(left, right); }, {&m_drive}); diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp index 0971549b76..be6bce0385 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/cpp/subsystems/DriveSubsystem.cpp @@ -30,8 +30,8 @@ DriveSubsystem::DriveSubsystem() { void DriveSubsystem::Periodic() { // Implementation of subsystem periodic method goes here. m_odometry.Update(m_gyro.GetRotation2d(), - units::meter_t(m_leftEncoder.GetDistance()), - units::meter_t(m_rightEncoder.GetDistance())); + units::meter_t{m_leftEncoder.GetDistance()}, + units::meter_t{m_rightEncoder.GetDistance()}); m_fieldSim.SetRobotPose(m_odometry.GetPose()); } @@ -102,8 +102,8 @@ frc::Pose2d DriveSubsystem::GetPose() { } frc::DifferentialDriveWheelSpeeds DriveSubsystem::GetWheelSpeeds() { - return {units::meters_per_second_t(m_leftEncoder.GetRate()), - units::meters_per_second_t(m_rightEncoder.GetRate())}; + return {units::meters_per_second_t{m_leftEncoder.GetRate()}, + units::meters_per_second_t{m_rightEncoder.GetRate()}}; } void DriveSubsystem::ResetOdometry(frc::Pose2d pose) { diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp index a4e74506ef..92cca5b33d 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp @@ -98,8 +98,8 @@ class Robot : public frc::TimedRobot { // Reset our loop to make sure it's in a known state. m_loop.Reset(frc::Vectord<2>{m_encoder.GetDistance(), m_encoder.GetRate()}); - m_lastProfiledReference = {units::meter_t(m_encoder.GetDistance()), - units::meters_per_second_t(m_encoder.GetRate())}; + m_lastProfiledReference = {units::meter_t{m_encoder.GetDistance()}, + units::meters_per_second_t{m_encoder.GetRate()}}; } void TeleopPeriodic() override { @@ -131,7 +131,7 @@ class Robot : public frc::TimedRobot { // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - m_motor.SetVoltage(units::volt_t(m_loop.U(0))); + m_motor.SetVoltage(units::volt_t{m_loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp index c09173997e..90b332df60 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp @@ -109,7 +109,7 @@ class Robot : public frc::TimedRobot { // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - m_motor.SetVoltage(units::volt_t(m_loop.U(0))); + m_motor.SetVoltage(units::volt_t{m_loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp index 738c64bfeb..334b4d26d8 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp @@ -109,7 +109,7 @@ class Robot : public frc::TimedRobot { // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - m_motor.SetVoltage(units::volt_t(m_loop.U(0))); + m_motor.SetVoltage(units::volt_t{m_loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp index 24a6527363..8f98c0c209 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp @@ -32,19 +32,19 @@ SwerveModule::SwerveModule(const int driveMotorChannel, // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. m_turningPIDController.EnableContinuousInput( - -units::radian_t(wpi::numbers::pi), units::radian_t(wpi::numbers::pi)); + -units::radian_t{wpi::numbers::pi}, units::radian_t{wpi::numbers::pi}); } frc::SwerveModuleState SwerveModule::GetState() const { return {units::meters_per_second_t{m_driveEncoder.GetRate()}, - frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))}; + units::radian_t{m_turningEncoder.GetDistance()}}; } void SwerveModule::SetDesiredState( const frc::SwerveModuleState& referenceState) { // Optimize the reference state to avoid spinning further than 90 degrees const auto state = frc::SwerveModuleState::Optimize( - referenceState, units::radian_t(m_turningEncoder.Get())); + referenceState, units::radian_t{m_turningEncoder.GetDistance()}); // Calculate the drive output from the drive PID controller. const auto driveOutput = m_drivePIDController.Calculate( @@ -54,7 +54,7 @@ void SwerveModule::SetDesiredState( // Calculate the turning motor output from the turning PID controller. const auto turnOutput = m_turningPIDController.Calculate( - units::radian_t(m_turningEncoder.Get()), state.angle.Radians()); + units::radian_t{m_turningEncoder.GetDistance()}, state.angle.Radians()); const auto turnFeedforward = m_turnFeedforward.Calculate( m_turningPIDController.GetSetpoint().velocity); diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp index a35314e23b..bea15462de 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp @@ -35,9 +35,9 @@ RobotContainer::RobotContainer() { m_drive.SetDefaultCommand(frc2::RunCommand( [this] { m_drive.Drive( - units::meters_per_second_t(m_driverController.GetLeftY()), - units::meters_per_second_t(m_driverController.GetLeftX()), - units::radians_per_second_t(m_driverController.GetRightX()), false); + units::meters_per_second_t{m_driverController.GetLeftY()}, + units::meters_per_second_t{m_driverController.GetLeftX()}, + units::radians_per_second_t{m_driverController.GetRightX()}, false); }, {&m_drive})); } @@ -54,11 +54,11 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { // An example trajectory to follow. All units in meters. auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory( // Start at the origin facing the +X direction - frc::Pose2d(0_m, 0_m, frc::Rotation2d(0_deg)), + frc::Pose2d{0_m, 0_m, 0_deg}, // Pass through these two interior waypoints, making an 's' curve path - {frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)}, + {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}}, // End 3 meters straight ahead of where we started, facing forward - frc::Pose2d(3_m, 0_m, frc::Rotation2d(0_deg)), + frc::Pose2d{3_m, 0_m, 0_deg}, // Pass the config config); @@ -66,16 +66,16 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { AutoConstants::kPThetaController, 0, 0, AutoConstants::kThetaControllerConstraints}; - thetaController.EnableContinuousInput(units::radian_t(-wpi::numbers::pi), - units::radian_t(wpi::numbers::pi)); + thetaController.EnableContinuousInput(units::radian_t{-wpi::numbers::pi}, + units::radian_t{wpi::numbers::pi}); frc2::SwerveControllerCommand<4> swerveControllerCommand( exampleTrajectory, [this]() { return m_drive.GetPose(); }, m_drive.kDriveKinematics, - frc2::PIDController(AutoConstants::kPXController, 0, 0), - frc2::PIDController(AutoConstants::kPYController, 0, 0), thetaController, + frc2::PIDController{AutoConstants::kPXController, 0, 0}, + frc2::PIDController{AutoConstants::kPYController, 0, 0}, thetaController, [this](auto moduleStates) { m_drive.SetModuleStates(moduleStates); }, @@ -88,10 +88,5 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { return new frc2::SequentialCommandGroup( std::move(swerveControllerCommand), frc2::InstantCommand( - [this]() { - m_drive.Drive(units::meters_per_second_t(0), - units::meters_per_second_t(0), - units::radians_per_second_t(0), false); - }, - {})); + [this]() { m_drive.Drive(0_mps, 0_mps, 0_rad_per_s, false); }, {})); } diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp index fd15100847..6459c6d7b3 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp @@ -36,7 +36,7 @@ DriveSubsystem::DriveSubsystem() kRearRightDriveEncoderPorts, kRearRightTurningEncoderPorts, kRearRightDriveEncoderReversed, kRearRightTurningEncoderReversed}, - m_odometry{kDriveKinematics, m_gyro.GetRotation2d(), frc::Pose2d()} {} + m_odometry{kDriveKinematics, m_gyro.GetRotation2d(), frc::Pose2d{}} {} void DriveSubsystem::Periodic() { // Implementation of subsystem periodic method goes here. @@ -98,6 +98,5 @@ frc::Pose2d DriveSubsystem::GetPose() { } void DriveSubsystem::ResetOdometry(frc::Pose2d pose) { - m_odometry.ResetPosition(pose, - frc::Rotation2d(units::degree_t(GetHeading()))); + m_odometry.ResetPosition(pose, units::degree_t{GetHeading()}); } diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp index 4d20ec86bc..aa12aafbc4 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp @@ -35,19 +35,19 @@ SwerveModule::SwerveModule(int driveMotorChannel, int turningMotorChannel, // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. m_turningPIDController.EnableContinuousInput( - units::radian_t(-wpi::numbers::pi), units::radian_t(wpi::numbers::pi)); + units::radian_t{-wpi::numbers::pi}, units::radian_t{wpi::numbers::pi}); } frc::SwerveModuleState SwerveModule::GetState() { return {units::meters_per_second_t{m_driveEncoder.GetRate()}, - frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))}; + units::radian_t{m_turningEncoder.GetDistance()}}; } void SwerveModule::SetDesiredState( const frc::SwerveModuleState& referenceState) { // Optimize the reference state to avoid spinning further than 90 degrees const auto state = frc::SwerveModuleState::Optimize( - referenceState, units::radian_t(m_turningEncoder.Get())); + referenceState, units::radian_t{m_turningEncoder.GetDistance()}); // Calculate the drive output from the drive PID controller. const auto driveOutput = m_drivePIDController.Calculate( @@ -55,7 +55,7 @@ void SwerveModule::SetDesiredState( // Calculate the turning motor output from the turning PID controller. auto turnOutput = m_turningPIDController.Calculate( - units::radian_t(m_turningEncoder.Get()), state.angle.Radians()); + units::radian_t{m_turningEncoder.GetDistance()}, state.angle.Radians()); // Set the motor outputs. m_driveMotor.Set(driveOutput); diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h index e6fa13653d..24664517d4 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -88,15 +89,10 @@ constexpr double kPModuleDriveController = 1; } // namespace ModuleConstants namespace AutoConstants { -using radians_per_second_squared_t = - units::compound_unit>>; - -constexpr auto kMaxSpeed = units::meters_per_second_t(3); -constexpr auto kMaxAcceleration = units::meters_per_second_squared_t(3); -constexpr auto kMaxAngularSpeed = units::radians_per_second_t(3.142); -constexpr auto kMaxAngularAcceleration = - units::unit_t(3.142); +constexpr auto kMaxSpeed = 3_mps; +constexpr auto kMaxAcceleration = 3_mps_sq; +constexpr auto kMaxAngularSpeed = 3.142_rad_per_s; +constexpr auto kMaxAngularAcceleration = 3.142_rad_per_s_sq; constexpr double kPXController = 0.5; constexpr double kPYController = 0.5; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h index 5233f3f60a..e9ed17b51d 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h @@ -94,10 +94,10 @@ class DriveSubsystem : public frc2::SubsystemBase { 0.7_m; // Distance between centers of front and back wheels on robot frc::SwerveDriveKinematics<4> kDriveKinematics{ - frc::Translation2d(kWheelBase / 2, kTrackWidth / 2), - frc::Translation2d(kWheelBase / 2, -kTrackWidth / 2), - frc::Translation2d(-kWheelBase / 2, kTrackWidth / 2), - frc::Translation2d(-kWheelBase / 2, -kTrackWidth / 2)}; + frc::Translation2d{kWheelBase / 2, kTrackWidth / 2}, + frc::Translation2d{kWheelBase / 2, -kTrackWidth / 2}, + frc::Translation2d{-kWheelBase / 2, kTrackWidth / 2}, + frc::Translation2d{-kWheelBase / 2, -kTrackWidth / 2}}; private: // Components (e.g. motor controllers and sensors) should generally be diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h index 4208b3551a..46474456f9 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h @@ -16,10 +16,6 @@ #include "Constants.h" class SwerveModule { - using radians_per_second_squared_t = - units::compound_unit>>; - public: SwerveModule(int driveMotorChannel, int turningMotorChannel, const int driveEncoderPorts[2], const int turningEncoderPorts[2], @@ -36,12 +32,10 @@ class SwerveModule { // ProfiledPIDController's constraints only take in meters per second and // meters per second squared. - static constexpr units::radians_per_second_t kModuleMaxAngularVelocity = - units::radians_per_second_t(wpi::numbers::pi); // radians per second - static constexpr units::unit_t - kModuleMaxAngularAcceleration = - units::unit_t( - wpi::numbers::pi * 2.0); // radians per second squared + static constexpr auto kModuleMaxAngularVelocity = + units::radians_per_second_t{wpi::numbers::pi}; + static constexpr auto kModuleMaxAngularAcceleration = + units::radians_per_second_squared_t{wpi::numbers::pi * 2.0}; frc::Spark m_driveMotor; frc::Spark m_turningMotor; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp index 968ccad079..f3cfd593b5 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp @@ -32,19 +32,19 @@ SwerveModule::SwerveModule(const int driveMotorChannel, // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. m_turningPIDController.EnableContinuousInput( - -units::radian_t(wpi::numbers::pi), units::radian_t(wpi::numbers::pi)); + -units::radian_t{wpi::numbers::pi}, units::radian_t{wpi::numbers::pi}); } frc::SwerveModuleState SwerveModule::GetState() const { return {units::meters_per_second_t{m_driveEncoder.GetRate()}, - frc::Rotation2d(units::radian_t(m_turningEncoder.Get()))}; + units::radian_t{m_turningEncoder.GetDistance()}}; } void SwerveModule::SetDesiredState( const frc::SwerveModuleState& referenceState) { // Optimize the reference state to avoid spinning further than 90 degrees const auto state = frc::SwerveModuleState::Optimize( - referenceState, units::radian_t(m_turningEncoder.Get())); + referenceState, units::radian_t{m_turningEncoder.GetDistance()}); // Calculate the drive output from the drive PID controller. const auto driveOutput = m_drivePIDController.Calculate( @@ -54,7 +54,7 @@ void SwerveModule::SetDesiredState( // Calculate the turning motor output from the turning PID controller. const auto turnOutput = m_turningPIDController.Calculate( - units::radian_t(m_turningEncoder.Get()), state.angle.Radians()); + units::radian_t{m_turningEncoder.GetDistance()}, state.angle.Radians()); const auto turnFeedforward = m_turnFeedforward.Calculate( m_turningPIDController.GetSetpoint().velocity); diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h index f52572973d..547ec1c96f 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.h @@ -49,6 +49,6 @@ class Drivetrain { // Gains are for example purposes only - must be determined for your own // robot! frc::SwerveDrivePoseEstimator<4> m_poseEstimator{ - frc::Rotation2d(), frc::Pose2d(), m_kinematics, + frc::Rotation2d{}, frc::Pose2d{}, m_kinematics, {0.1, 0.1, 0.1}, {0.05}, {0.1, 0.1, 0.1}}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h index a4caff4aa4..1aa10d79c1 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/ExampleGlobalMeasurementSensor.h @@ -16,9 +16,9 @@ class ExampleGlobalMeasurementSensor { static frc::Pose2d GetEstimatedGlobalPose( const frc::Pose2d& estimatedRobotPose) { auto randVec = frc::MakeWhiteNoiseVector(0.1, 0.1, 0.1); - return frc::Pose2d(estimatedRobotPose.X() + units::meter_t(randVec(0)), - estimatedRobotPose.Y() + units::meter_t(randVec(1)), + return frc::Pose2d{estimatedRobotPose.X() + units::meter_t{randVec(0)}, + estimatedRobotPose.Y() + units::meter_t{randVec(1)}, estimatedRobotPose.Rotation() + - frc::Rotation2d(units::radian_t(randVec(3)))); + frc::Rotation2d{units::radian_t{randVec(3)}}}; } }; diff --git a/wpimath/src/main/native/cpp/controller/HolonomicDriveController.cpp b/wpimath/src/main/native/cpp/controller/HolonomicDriveController.cpp index 23b22cd1a5..6a09c57fa5 100644 --- a/wpimath/src/main/native/cpp/controller/HolonomicDriveController.cpp +++ b/wpimath/src/main/native/cpp/controller/HolonomicDriveController.cpp @@ -44,8 +44,8 @@ ChassisSpeeds HolonomicDriveController::Calculate( // Calculate feedforward velocities (field-relative) auto xFF = linearVelocityRef * poseRef.Rotation().Cos(); auto yFF = linearVelocityRef * poseRef.Rotation().Sin(); - auto thetaFF = units::radians_per_second_t(m_thetaController.Calculate( - currentPose.Rotation().Radians(), angleRef.Radians())); + auto thetaFF = units::radians_per_second_t{m_thetaController.Calculate( + currentPose.Rotation().Radians(), angleRef.Radians())}; m_poseError = poseRef.RelativeTo(currentPose); m_rotationError = angleRef - currentPose.Rotation(); @@ -56,10 +56,10 @@ ChassisSpeeds HolonomicDriveController::Calculate( } // Calculate feedback velocities (based on position error). - auto xFeedback = units::meters_per_second_t( - m_xController.Calculate(currentPose.X().value(), poseRef.X().value())); - auto yFeedback = units::meters_per_second_t( - m_yController.Calculate(currentPose.Y().value(), poseRef.Y().value())); + auto xFeedback = units::meters_per_second_t{ + m_xController.Calculate(currentPose.X().value(), poseRef.X().value())}; + auto yFeedback = units::meters_per_second_t{ + m_yController.Calculate(currentPose.Y().value(), poseRef.Y().value())}; // Return next output. return ChassisSpeeds::FromFieldRelativeSpeeds( diff --git a/wpimath/src/main/native/cpp/controller/PIDController.cpp b/wpimath/src/main/native/cpp/controller/PIDController.cpp index b18395520e..9adf292c7f 100644 --- a/wpimath/src/main/native/cpp/controller/PIDController.cpp +++ b/wpimath/src/main/native/cpp/controller/PIDController.cpp @@ -65,7 +65,7 @@ double PIDController::GetD() const { } units::second_t PIDController::GetPeriod() const { - return units::second_t(m_period); + return m_period; } void PIDController::SetSetpoint(double setpoint) { diff --git a/wpimath/src/main/native/cpp/controller/RamseteController.cpp b/wpimath/src/main/native/cpp/controller/RamseteController.cpp index fdd7d63bf8..576b0a9575 100644 --- a/wpimath/src/main/native/cpp/controller/RamseteController.cpp +++ b/wpimath/src/main/native/cpp/controller/RamseteController.cpp @@ -29,8 +29,8 @@ RamseteController::RamseteController(units::unit_t b, : m_b{b}, m_zeta{zeta} {} RamseteController::RamseteController() - : RamseteController(units::unit_t{2.0}, - units::unit_t{0.7}) {} + : RamseteController{units::unit_t{2.0}, + units::unit_t{0.7}} {} bool RamseteController::AtReference() const { const auto& eTranslate = m_poseError.Translation(); diff --git a/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp b/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp index d4115500e5..b27723829d 100644 --- a/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp +++ b/wpimath/src/main/native/cpp/estimator/DifferentialDrivePoseEstimator.cpp @@ -65,9 +65,9 @@ void DifferentialDrivePoseEstimator::ResetPosition( } Pose2d DifferentialDrivePoseEstimator::GetEstimatedPosition() const { - return Pose2d(units::meter_t(m_observer.Xhat(0)), - units::meter_t(m_observer.Xhat(1)), - Rotation2d(units::radian_t(m_observer.Xhat(2)))); + return Pose2d{units::meter_t{m_observer.Xhat(0)}, + units::meter_t{m_observer.Xhat(1)}, + units::radian_t{m_observer.Xhat(2)}}; } void DifferentialDrivePoseEstimator::AddVisionMeasurement( diff --git a/wpimath/src/main/native/cpp/estimator/MecanumDrivePoseEstimator.cpp b/wpimath/src/main/native/cpp/estimator/MecanumDrivePoseEstimator.cpp index a0a115481d..cb175e8541 100644 --- a/wpimath/src/main/native/cpp/estimator/MecanumDrivePoseEstimator.cpp +++ b/wpimath/src/main/native/cpp/estimator/MecanumDrivePoseEstimator.cpp @@ -66,8 +66,8 @@ void frc::MecanumDrivePoseEstimator::ResetPosition( } Pose2d frc::MecanumDrivePoseEstimator::GetEstimatedPosition() const { - return Pose2d(m_observer.Xhat(0) * 1_m, m_observer.Xhat(1) * 1_m, - Rotation2d(units::radian_t{m_observer.Xhat(2)})); + return Pose2d{m_observer.Xhat(0) * 1_m, m_observer.Xhat(1) * 1_m, + units::radian_t{m_observer.Xhat(2)}}; } void frc::MecanumDrivePoseEstimator::AddVisionMeasurement( @@ -96,8 +96,8 @@ Pose2d frc::MecanumDrivePoseEstimator::UpdateWithTime( auto chassisSpeeds = m_kinematics.ToChassisSpeeds(wheelSpeeds); auto fieldRelativeVelocities = - Translation2d(chassisSpeeds.vx * 1_s, chassisSpeeds.vy * 1_s) - .RotateBy(angle); + Translation2d{chassisSpeeds.vx * 1_s, chassisSpeeds.vy * 1_s}.RotateBy( + angle); Vectord<3> u{fieldRelativeVelocities.X().value(), fieldRelativeVelocities.Y().value(), omega.value()}; diff --git a/wpimath/src/main/native/cpp/geometry/Pose2d.cpp b/wpimath/src/main/native/cpp/geometry/Pose2d.cpp index 1bf9829ea1..c856f17d1b 100644 --- a/wpimath/src/main/native/cpp/geometry/Pose2d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Pose2d.cpp @@ -22,7 +22,7 @@ Pose2d Pose2d::operator+(const Transform2d& other) const { Transform2d Pose2d::operator-(const Pose2d& other) const { const auto pose = this->RelativeTo(other); - return Transform2d(pose.Translation(), pose.Rotation()); + return Transform2d{pose.Translation(), pose.Rotation()}; } bool Pose2d::operator==(const Pose2d& other) const { @@ -87,7 +87,7 @@ Twist2d Pose2d::Log(const Pose2d& end) const { {halfThetaByTanOfHalfDtheta, -halfDtheta}) * std::hypot(halfThetaByTanOfHalfDtheta, halfDtheta); - return {translationPart.X(), translationPart.Y(), units::radian_t(dtheta)}; + return {translationPart.X(), translationPart.Y(), units::radian_t{dtheta}}; } void frc::to_json(wpi::json& json, const Pose2d& pose) { diff --git a/wpimath/src/main/native/cpp/geometry/Pose3d.cpp b/wpimath/src/main/native/cpp/geometry/Pose3d.cpp index d532908b97..422b6a6194 100644 --- a/wpimath/src/main/native/cpp/geometry/Pose3d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Pose3d.cpp @@ -43,7 +43,7 @@ Pose3d Pose3d::operator+(const Transform3d& other) const { Transform3d Pose3d::operator-(const Pose3d& other) const { const auto pose = this->RelativeTo(other); - return Transform3d(pose.Translation(), pose.Rotation()); + return Transform3d{pose.Translation(), pose.Rotation()}; } bool Pose3d::operator==(const Pose3d& other) const { diff --git a/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp b/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp index 27af5ed25a..fcafa80b33 100644 --- a/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp @@ -31,7 +31,7 @@ Rotation2d::Rotation2d(double x, double y) { m_sin = 0.0; m_cos = 1.0; } - m_value = units::radian_t(std::atan2(m_sin, m_cos)); + m_value = units::radian_t{std::atan2(m_sin, m_cos)}; } Rotation2d Rotation2d::operator+(const Rotation2d& other) const { @@ -43,11 +43,11 @@ Rotation2d Rotation2d::operator-(const Rotation2d& other) const { } Rotation2d Rotation2d::operator-() const { - return Rotation2d(-m_value); + return Rotation2d{-m_value}; } Rotation2d Rotation2d::operator*(double scalar) const { - return Rotation2d(m_value * scalar); + return Rotation2d{m_value * scalar}; } bool Rotation2d::operator==(const Rotation2d& other) const { diff --git a/wpimath/src/main/native/cpp/spline/SplineHelper.cpp b/wpimath/src/main/native/cpp/spline/SplineHelper.cpp index cec620ce7a..e8bbb46ee1 100644 --- a/wpimath/src/main/native/cpp/spline/SplineHelper.cpp +++ b/wpimath/src/main/native/cpp/spline/SplineHelper.cpp @@ -20,10 +20,10 @@ std::vector SplineHelper::CubicSplinesFromControlVectors( if (waypoints.size() > 1) { waypoints.emplace(waypoints.begin(), - Translation2d{units::meter_t(xInitial[0]), - units::meter_t(yInitial[0])}); + Translation2d{units::meter_t{xInitial[0]}, + units::meter_t{yInitial[0]}}); waypoints.emplace_back( - Translation2d{units::meter_t(xFinal[0]), units::meter_t(yFinal[0])}); + Translation2d{units::meter_t{xFinal[0]}, units::meter_t{yFinal[0]}}); // Populate tridiagonal system for clamped cubic /* See: diff --git a/wpimath/src/main/native/cpp/trajectory/TrajectoryGenerator.cpp b/wpimath/src/main/native/cpp/trajectory/TrajectoryGenerator.cpp index 1884758007..c7a7e9a7ff 100644 --- a/wpimath/src/main/native/cpp/trajectory/TrajectoryGenerator.cpp +++ b/wpimath/src/main/native/cpp/trajectory/TrajectoryGenerator.cpp @@ -30,7 +30,7 @@ Trajectory TrajectoryGenerator::GenerateTrajectory( Spline<3>::ControlVector initial, const std::vector& interiorWaypoints, Spline<3>::ControlVector end, const TrajectoryConfig& config) { - const Transform2d flip{Translation2d(), Rotation2d(180_deg)}; + const Transform2d flip{Translation2d{}, 180_deg}; // Make theta normal for trajectory generation if path is reversed. // Flip the headings. @@ -76,7 +76,7 @@ Trajectory TrajectoryGenerator::GenerateTrajectory( Trajectory TrajectoryGenerator::GenerateTrajectory( std::vector::ControlVector> controlVectors, const TrajectoryConfig& config) { - const Transform2d flip{Translation2d(), Rotation2d(180_deg)}; + const Transform2d flip{Translation2d{}, 180_deg}; // Make theta normal for trajectory generation if path is reversed. if (config.IsReversed()) { for (auto& vector : controlVectors) { @@ -112,7 +112,7 @@ Trajectory TrajectoryGenerator::GenerateTrajectory( Trajectory TrajectoryGenerator::GenerateTrajectory( const std::vector& waypoints, const TrajectoryConfig& config) { auto newWaypoints = waypoints; - const Transform2d flip{Translation2d(), Rotation2d(180_deg)}; + const Transform2d flip{Translation2d{}, 180_deg}; if (config.IsReversed()) { for (auto& waypoint : newWaypoints) { waypoint = waypoint + flip; diff --git a/wpimath/src/main/native/cpp/trajectory/constraint/DifferentialDriveVoltageConstraint.cpp b/wpimath/src/main/native/cpp/trajectory/constraint/DifferentialDriveVoltageConstraint.cpp index 7c10201f5e..c79c313322 100644 --- a/wpimath/src/main/native/cpp/trajectory/constraint/DifferentialDriveVoltageConstraint.cpp +++ b/wpimath/src/main/native/cpp/trajectory/constraint/DifferentialDriveVoltageConstraint.cpp @@ -23,7 +23,7 @@ DifferentialDriveVoltageConstraint::DifferentialDriveVoltageConstraint( units::meters_per_second_t DifferentialDriveVoltageConstraint::MaxVelocity( const Pose2d& pose, units::curvature_t curvature, units::meters_per_second_t velocity) const { - return units::meters_per_second_t(std::numeric_limits::max()); + return units::meters_per_second_t{std::numeric_limits::max()}; } TrajectoryConstraint::MinMax diff --git a/wpimath/src/main/native/include/frc/ComputerVisionUtil.h b/wpimath/src/main/native/include/frc/ComputerVisionUtil.h index 45b3860d5b..6ee9225232 100644 --- a/wpimath/src/main/native/include/frc/ComputerVisionUtil.h +++ b/wpimath/src/main/native/include/frc/ComputerVisionUtil.h @@ -58,7 +58,7 @@ units::meter_t CalculateDistanceToTarget(units::meter_t cameraHeight, * @param cameraToRobot The position of the robot relative to the camera. If the * camera was mounted 3 inches behind the "origin" (usually * physical center) of the robot, this would be - * frc::Transform2d(3_in, 0_in, 0_deg). + * frc::Transform2d{3_in, 0_in, 0_deg}. * @return The position of the robot in the field. */ WPILIB_DLLEXPORT @@ -78,7 +78,7 @@ frc::Pose2d EstimateFieldToRobot( * @param cameraToRobot The position of the robot relative to the camera. If * the camera was mounted 3 inches behind the "origin" * (usually physical center) of the robot, this would be - * frc::Transform2d(3_in, 0_in, 0_deg). + * frc::Transform2d{3_in, 0_in, 0_deg}. * @return The position of the robot in the field. */ WPILIB_DLLEXPORT diff --git a/wpimath/src/main/native/include/frc/controller/ProfiledPIDController.h b/wpimath/src/main/native/include/frc/controller/ProfiledPIDController.h index 82ae0ae723..1d8d5fc249 100644 --- a/wpimath/src/main/native/include/frc/controller/ProfiledPIDController.h +++ b/wpimath/src/main/native/include/frc/controller/ProfiledPIDController.h @@ -143,7 +143,7 @@ class ProfiledPIDController * * @param goal The desired unprofiled setpoint. */ - void SetGoal(Distance_t goal) { m_goal = {goal, Velocity_t(0)}; } + void SetGoal(Distance_t goal) { m_goal = {goal, Velocity_t{0}}; } /** * Gets the goal for the ProfiledPIDController. @@ -225,8 +225,8 @@ class ProfiledPIDController * @param velocityTolerance Velocity error which is tolerable. */ void SetTolerance(Distance_t positionTolerance, - Velocity_t velocityTolerance = - Velocity_t(std::numeric_limits::infinity())) { + Velocity_t velocityTolerance = Velocity_t{ + std::numeric_limits::infinity()}) { m_controller.SetTolerance(positionTolerance.value(), velocityTolerance.value()); } @@ -237,14 +237,14 @@ class ProfiledPIDController * @return The error. */ Distance_t GetPositionError() const { - return Distance_t(m_controller.GetPositionError()); + return Distance_t{m_controller.GetPositionError()}; } /** * Returns the change in error per second. */ Velocity_t GetVelocityError() const { - return Velocity_t(m_controller.GetVelocityError()); + return Velocity_t{m_controller.GetVelocityError()}; } /** @@ -339,7 +339,7 @@ class ProfiledPIDController * velocity is assumed to be zero. */ void Reset(Distance_t measuredPosition) { - Reset(measuredPosition, Velocity_t(0)); + Reset(measuredPosition, Velocity_t{0}); } void InitSendable(wpi::SendableBuilder& builder) override { diff --git a/wpimath/src/main/native/include/frc/estimator/SwerveDrivePoseEstimator.h b/wpimath/src/main/native/include/frc/estimator/SwerveDrivePoseEstimator.h index ac680ed1c6..ce40e3208c 100644 --- a/wpimath/src/main/native/include/frc/estimator/SwerveDrivePoseEstimator.h +++ b/wpimath/src/main/native/include/frc/estimator/SwerveDrivePoseEstimator.h @@ -140,8 +140,8 @@ class SwerveDrivePoseEstimator { * @return The estimated robot pose in meters. */ Pose2d GetEstimatedPosition() const { - return Pose2d(m_observer.Xhat(0) * 1_m, m_observer.Xhat(1) * 1_m, - Rotation2d(units::radian_t{m_observer.Xhat(2)})); + return Pose2d{m_observer.Xhat(0) * 1_m, m_observer.Xhat(1) * 1_m, + Rotation2d{units::radian_t{m_observer.Xhat(2)}}}; } /** @@ -274,8 +274,8 @@ class SwerveDrivePoseEstimator { auto chassisSpeeds = m_kinematics.ToChassisSpeeds(moduleStates...); auto fieldRelativeSpeeds = - Translation2d(chassisSpeeds.vx * 1_s, chassisSpeeds.vy * 1_s) - .RotateBy(angle); + Translation2d{chassisSpeeds.vx * 1_s, chassisSpeeds.vy * 1_s}.RotateBy( + angle); Vectord<3> u{fieldRelativeSpeeds.X().value(), fieldRelativeSpeeds.Y().value(), omega.value()}; diff --git a/wpimath/src/main/native/include/frc/kinematics/DifferentialDriveOdometry.h b/wpimath/src/main/native/include/frc/kinematics/DifferentialDriveOdometry.h index 8e992efb6c..ded26ceeb5 100644 --- a/wpimath/src/main/native/include/frc/kinematics/DifferentialDriveOdometry.h +++ b/wpimath/src/main/native/include/frc/kinematics/DifferentialDriveOdometry.h @@ -31,7 +31,7 @@ class WPILIB_DLLEXPORT DifferentialDriveOdometry { * @param initialPose The starting position of the robot on the field. */ explicit DifferentialDriveOdometry(const Rotation2d& gyroAngle, - const Pose2d& initialPose = Pose2d()); + const Pose2d& initialPose = Pose2d{}); /** * Resets the robot's position on the field. diff --git a/wpimath/src/main/native/include/frc/kinematics/MecanumDriveKinematics.h b/wpimath/src/main/native/include/frc/kinematics/MecanumDriveKinematics.h index ba854da270..345d446d90 100644 --- a/wpimath/src/main/native/include/frc/kinematics/MecanumDriveKinematics.h +++ b/wpimath/src/main/native/include/frc/kinematics/MecanumDriveKinematics.h @@ -99,7 +99,7 @@ class WPILIB_DLLEXPORT MecanumDriveKinematics { */ MecanumDriveWheelSpeeds ToWheelSpeeds( const ChassisSpeeds& chassisSpeeds, - const Translation2d& centerOfRotation = Translation2d()) const; + const Translation2d& centerOfRotation = Translation2d{}) const; /** * Performs forward kinematics to return the resulting chassis state from the diff --git a/wpimath/src/main/native/include/frc/kinematics/MecanumDriveOdometry.h b/wpimath/src/main/native/include/frc/kinematics/MecanumDriveOdometry.h index bdd12397cd..f49ec7b9a1 100644 --- a/wpimath/src/main/native/include/frc/kinematics/MecanumDriveOdometry.h +++ b/wpimath/src/main/native/include/frc/kinematics/MecanumDriveOdometry.h @@ -34,7 +34,7 @@ class WPILIB_DLLEXPORT MecanumDriveOdometry { */ explicit MecanumDriveOdometry(MecanumDriveKinematics kinematics, const Rotation2d& gyroAngle, - const Pose2d& initialPose = Pose2d()); + const Pose2d& initialPose = Pose2d{}); /** * Resets the robot's position on the field. diff --git a/wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h b/wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h index 4977b8285b..3ac453f716 100644 --- a/wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h +++ b/wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h @@ -129,7 +129,7 @@ class SwerveDriveKinematics { */ wpi::array ToSwerveModuleStates( const ChassisSpeeds& chassisSpeeds, - const Translation2d& centerOfRotation = Translation2d()) const; + const Translation2d& centerOfRotation = Translation2d{}) const; /** * Performs forward kinematics to return the resulting chassis state from the diff --git a/wpimath/src/main/native/include/frc/kinematics/SwerveDriveOdometry.h b/wpimath/src/main/native/include/frc/kinematics/SwerveDriveOdometry.h index 86a8d0b230..42efd49b86 100644 --- a/wpimath/src/main/native/include/frc/kinematics/SwerveDriveOdometry.h +++ b/wpimath/src/main/native/include/frc/kinematics/SwerveDriveOdometry.h @@ -39,7 +39,7 @@ class SwerveDriveOdometry { */ SwerveDriveOdometry(SwerveDriveKinematics kinematics, const Rotation2d& gyroAngle, - const Pose2d& initialPose = Pose2d()); + const Pose2d& initialPose = Pose2d{}); /** * Resets the robot's position on the field. diff --git a/wpimath/src/main/native/include/frc/spline/Spline.h b/wpimath/src/main/native/include/frc/spline/Spline.h index 8f2da6520e..b5ff0242c1 100644 --- a/wpimath/src/main/native/include/frc/spline/Spline.h +++ b/wpimath/src/main/native/include/frc/spline/Spline.h @@ -90,8 +90,8 @@ class Spline { (dx * ddy - ddx * dy) / ((dx * dx + dy * dy) * std::hypot(dx, dy)); return { - {FromVector(combined.template block<2, 1>(0, 0)), Rotation2d(dx, dy)}, - units::curvature_t(curvature)}; + {FromVector(combined.template block<2, 1>(0, 0)), Rotation2d{dx, dy}}, + units::curvature_t{curvature}}; } protected: @@ -119,7 +119,7 @@ class Spline { * @return The Translation2d. */ static Translation2d FromVector(const Eigen::Vector2d& vector) { - return Translation2d(units::meter_t(vector(0)), units::meter_t(vector(1))); + return Translation2d{units::meter_t{vector(0)}, units::meter_t{vector(1)}}; } }; } // namespace frc diff --git a/wpimath/src/main/native/include/frc/trajectory/TrajectoryParameterizer.h b/wpimath/src/main/native/include/frc/trajectory/TrajectoryParameterizer.h index eea1c078f3..807b31575c 100644 --- a/wpimath/src/main/native/include/frc/trajectory/TrajectoryParameterizer.h +++ b/wpimath/src/main/native/include/frc/trajectory/TrajectoryParameterizer.h @@ -81,7 +81,7 @@ class WPILIB_DLLEXPORT TrajectoryParameterizer { * the trajectory, max velocity, min acceleration and max acceleration. */ struct ConstrainedState { - PoseWithCurvature pose = {Pose2d(), units::curvature_t(0.0)}; + PoseWithCurvature pose = {Pose2d{}, units::curvature_t{0.0}}; units::meter_t distance = 0_m; units::meters_per_second_t maxVelocity = 0_mps; units::meters_per_second_squared_t minAcceleration = 0_mps_sq; diff --git a/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h b/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h index 0e126fdb6d..5925a306e8 100644 --- a/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h +++ b/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.h @@ -82,7 +82,7 @@ class TrapezoidProfile { * @param initial The initial state (usually the current state). */ TrapezoidProfile(Constraints constraints, State goal, - State initial = State{Distance_t(0), Velocity_t(0)}); + State initial = State{Distance_t{0}, Velocity_t{0}}); TrapezoidProfile(const TrapezoidProfile&) = default; TrapezoidProfile& operator=(const TrapezoidProfile&) = default; diff --git a/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.inc b/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.inc index 4ec0f42c71..19eb1f3b1d 100644 --- a/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.inc +++ b/wpimath/src/main/native/include/frc/trajectory/TrapezoidProfile.inc @@ -46,10 +46,10 @@ TrapezoidProfile::TrapezoidProfile(Constraints constraints, accelerationTime * accelerationTime * m_constraints.maxAcceleration; // Handle the case where the profile never reaches full speed - if (fullSpeedDist < Distance_t(0)) { + if (fullSpeedDist < Distance_t{0}) { accelerationTime = units::math::sqrt(fullTrapezoidDist / m_constraints.maxAcceleration); - fullSpeedDist = Distance_t(0); + fullSpeedDist = Distance_t{0}; } m_endAccel = accelerationTime - cutoffBegin; @@ -110,7 +110,7 @@ units::second_t TrapezoidProfile::TimeLeftUntil( Distance_t distToTarget = units::math::abs(target - position); - if (distToTarget < Distance_t(1e-6)) { + if (distToTarget < Distance_t{1e-6}) { return 0_s; } diff --git a/wpimath/src/main/native/include/frc/trajectory/constraint/EllipticalRegionConstraint.h b/wpimath/src/main/native/include/frc/trajectory/constraint/EllipticalRegionConstraint.h index b951a063f7..f9f0d2e301 100644 --- a/wpimath/src/main/native/include/frc/trajectory/constraint/EllipticalRegionConstraint.h +++ b/wpimath/src/main/native/include/frc/trajectory/constraint/EllipticalRegionConstraint.h @@ -44,8 +44,8 @@ class EllipticalRegionConstraint : public TrajectoryConstraint { if (IsPoseInRegion(pose)) { return m_constraint.MaxVelocity(pose, curvature, velocity); } else { - return units::meters_per_second_t( - std::numeric_limits::infinity()); + return units::meters_per_second_t{ + std::numeric_limits::infinity()}; } } diff --git a/wpimath/src/main/native/include/frc/trajectory/constraint/RectangularRegionConstraint.h b/wpimath/src/main/native/include/frc/trajectory/constraint/RectangularRegionConstraint.h index c5bc559eeb..18522fef02 100644 --- a/wpimath/src/main/native/include/frc/trajectory/constraint/RectangularRegionConstraint.h +++ b/wpimath/src/main/native/include/frc/trajectory/constraint/RectangularRegionConstraint.h @@ -41,8 +41,8 @@ class RectangularRegionConstraint : public TrajectoryConstraint { if (IsPoseInRegion(pose)) { return m_constraint.MaxVelocity(pose, curvature, velocity); } else { - return units::meters_per_second_t( - std::numeric_limits::infinity()); + return units::meters_per_second_t{ + std::numeric_limits::infinity()}; } } diff --git a/wpimath/src/test/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimatorTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimatorTest.java index 381dc891f1..77d77a48f9 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimatorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimatorTest.java @@ -111,6 +111,6 @@ class DifferentialDrivePoseEstimatorTest { } assertEquals(0.0, errorSum / (traj.getTotalTimeSeconds() / dt), 0.05, "Incorrect mean error"); - assertEquals(0.0, maxError, 0.1, "Incorrect max error"); + assertEquals(0.0, maxError, 0.125, "Incorrect max error"); } } diff --git a/wpimath/src/test/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimatorTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimatorTest.java index be7c28a8df..b75b1a1e35 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimatorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimatorTest.java @@ -112,6 +112,6 @@ class MecanumDrivePoseEstimatorTest { assertEquals( 0.0, errorSum / (trajectory.getTotalTimeSeconds() / dt), 0.05, "Incorrect mean error"); - assertEquals(0.0, maxError, 0.1, "Incorrect max error"); + assertEquals(0.0, maxError, 0.125, "Incorrect max error"); } } diff --git a/wpimath/src/test/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimatorTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimatorTest.java index d1fba25798..41ab1db176 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimatorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimatorTest.java @@ -111,6 +111,6 @@ class SwerveDrivePoseEstimatorTest { assertEquals( 0.0, errorSum / (trajectory.getTotalTimeSeconds() / dt), 0.05, "Incorrect mean error"); - assertEquals(0.0, maxError, 0.1, "Incorrect max error"); + assertEquals(0.0, maxError, 0.125, "Incorrect max error"); } } diff --git a/wpimath/src/test/native/cpp/MathUtilTest.cpp b/wpimath/src/test/native/cpp/MathUtilTest.cpp index 8e73ee1bbf..f226556b76 100644 --- a/wpimath/src/test/native/cpp/MathUtilTest.cpp +++ b/wpimath/src/test/native/cpp/MathUtilTest.cpp @@ -108,12 +108,12 @@ TEST(MathUtilTest, AngleModulus) { EXPECT_UNITS_NEAR(frc::AngleModulus(units::radian_t{2.0 * wpi::numbers::pi}), 0_rad, 1e-10); - EXPECT_UNITS_EQ(frc::AngleModulus(units::radian_t(5 * wpi::numbers::pi)), - units::radian_t(wpi::numbers::pi)); - EXPECT_UNITS_EQ(frc::AngleModulus(units::radian_t(-5 * wpi::numbers::pi)), - units::radian_t(wpi::numbers::pi)); - EXPECT_UNITS_EQ(frc::AngleModulus(units::radian_t(wpi::numbers::pi / 2)), - units::radian_t(wpi::numbers::pi / 2)); - EXPECT_UNITS_EQ(frc::AngleModulus(units::radian_t(-wpi::numbers::pi / 2)), - units::radian_t(-wpi::numbers::pi / 2)); + EXPECT_UNITS_EQ(frc::AngleModulus(units::radian_t{5 * wpi::numbers::pi}), + units::radian_t{wpi::numbers::pi}); + EXPECT_UNITS_EQ(frc::AngleModulus(units::radian_t{-5 * wpi::numbers::pi}), + units::radian_t{wpi::numbers::pi}); + EXPECT_UNITS_EQ(frc::AngleModulus(units::radian_t{wpi::numbers::pi / 2}), + units::radian_t{wpi::numbers::pi / 2}); + EXPECT_UNITS_EQ(frc::AngleModulus(units::radian_t{-wpi::numbers::pi / 2}), + units::radian_t{-wpi::numbers::pi / 2}); } diff --git a/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp b/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp index 7bb36afd8f..b2bcee6b8e 100644 --- a/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp +++ b/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp @@ -41,8 +41,8 @@ TEST(ControlAffinePlantInversionFeedforwardTest, CalculateState) { Matrixd<2, 1> B{0, 1}; - frc::ControlAffinePlantInversionFeedforward<2, 1> feedforward{ - modelDynamics, B, units::second_t(0.02)}; + frc::ControlAffinePlantInversionFeedforward<2, 1> feedforward{modelDynamics, + B, 20_ms}; Vectord<2> r{2, 2}; Vectord<2> nextR{3, 3}; diff --git a/wpimath/src/test/native/cpp/controller/HolonomicDriveControllerTest.cpp b/wpimath/src/test/native/cpp/controller/HolonomicDriveControllerTest.cpp index c6b669c0d0..cb4d793c19 100644 --- a/wpimath/src/test/native/cpp/controller/HolonomicDriveControllerTest.cpp +++ b/wpimath/src/test/native/cpp/controller/HolonomicDriveControllerTest.cpp @@ -28,7 +28,7 @@ TEST(HolonomicDriveControllerTest, ReachesReference) { units::radians_per_second_t{2.0 * wpi::numbers::pi}, units::radians_per_second_squared_t{wpi::numbers::pi}}}}; - frc::Pose2d robotPose{2.7_m, 23_m, frc::Rotation2d{0_deg}}; + frc::Pose2d robotPose{2.7_m, 23_m, 0_deg}; auto waypoints = std::vector{frc::Pose2d{2.75_m, 22.521_m, 0_rad}, frc::Pose2d{24.73_m, 19.68_m, 5.846_rad}}; @@ -60,7 +60,7 @@ TEST(HolonomicDriveControllerTest, DoesNotRotateUnnecessarily) { 4_rad_per_s, 2_rad_per_s / 1_s}}}; frc::ChassisSpeeds speeds = controller.Calculate( - frc::Pose2d(0_m, 0_m, 1.57_rad), frc::Pose2d(), 0_mps, 1.57_rad); + frc::Pose2d{0_m, 0_m, 1.57_rad}, frc::Pose2d{}, 0_mps, 1.57_rad); EXPECT_EQ(0, speeds.omega.value()); } diff --git a/wpimath/src/test/native/cpp/controller/LTVDifferentialDriveControllerTest.cpp b/wpimath/src/test/native/cpp/controller/LTVDifferentialDriveControllerTest.cpp index d82e256fd8..9656a4e5bb 100644 --- a/wpimath/src/test/native/cpp/controller/LTVDifferentialDriveControllerTest.cpp +++ b/wpimath/src/test/native/cpp/controller/LTVDifferentialDriveControllerTest.cpp @@ -65,7 +65,7 @@ TEST(LTVDifferentialDriveControllerTest, ReachesReference) { frc::LTVDifferentialDriveController controller{ plant, kTrackwidth, {0.0625, 0.125, 2.5, 0.95, 0.95}, {12.0, 12.0}, kDt}; - frc::Pose2d robotPose{2.7_m, 23_m, frc::Rotation2d{0_deg}}; + frc::Pose2d robotPose{2.7_m, 23_m, 0_deg}; auto waypoints = std::vector{frc::Pose2d{2.75_m, 22.521_m, 0_rad}, frc::Pose2d{24.73_m, 19.68_m, 5.846_rad}}; diff --git a/wpimath/src/test/native/cpp/controller/LTVUnicycleControllerTest.cpp b/wpimath/src/test/native/cpp/controller/LTVUnicycleControllerTest.cpp index 2b5e6145a6..24e69ae2ab 100644 --- a/wpimath/src/test/native/cpp/controller/LTVUnicycleControllerTest.cpp +++ b/wpimath/src/test/native/cpp/controller/LTVUnicycleControllerTest.cpp @@ -19,7 +19,7 @@ TEST(LTVUnicycleControllerTest, ReachesReference) { constexpr auto kDt = 0.02_s; frc::LTVUnicycleController controller{{0.0625, 0.125, 2.5}, {4.0, 4.0}, kDt}; - frc::Pose2d robotPose{2.7_m, 23_m, frc::Rotation2d{0_deg}}; + frc::Pose2d robotPose{2.7_m, 23_m, 0_deg}; auto waypoints = std::vector{frc::Pose2d{2.75_m, 22.521_m, 0_rad}, frc::Pose2d{24.73_m, 19.68_m, 5.846_rad}}; diff --git a/wpimath/src/test/native/cpp/controller/LinearPlantInversionFeedforwardTest.cpp b/wpimath/src/test/native/cpp/controller/LinearPlantInversionFeedforwardTest.cpp index 139d6fbf40..e7107d0a43 100644 --- a/wpimath/src/test/native/cpp/controller/LinearPlantInversionFeedforwardTest.cpp +++ b/wpimath/src/test/native/cpp/controller/LinearPlantInversionFeedforwardTest.cpp @@ -16,8 +16,7 @@ TEST(LinearPlantInversionFeedforwardTest, Calculate) { Matrixd<2, 2> A{{1, 0}, {0, 1}}; Matrixd<2, 1> B{0, 1}; - frc::LinearPlantInversionFeedforward<2, 1> feedforward{A, B, - units::second_t(0.02)}; + frc::LinearPlantInversionFeedforward<2, 1> feedforward{A, B, 20_ms}; Vectord<2> r{2, 2}; Vectord<2> nextR{3, 3}; diff --git a/wpimath/src/test/native/cpp/controller/PIDInputOutputTest.cpp b/wpimath/src/test/native/cpp/controller/PIDInputOutputTest.cpp index 379db9e993..f1034f5510 100644 --- a/wpimath/src/test/native/cpp/controller/PIDInputOutputTest.cpp +++ b/wpimath/src/test/native/cpp/controller/PIDInputOutputTest.cpp @@ -9,7 +9,7 @@ class PIDInputOutputTest : public testing::Test { protected: frc2::PIDController* controller; - void SetUp() override { controller = new frc2::PIDController(0, 0, 0); } + void SetUp() override { controller = new frc2::PIDController{0, 0, 0}; } void TearDown() override { delete controller; } }; diff --git a/wpimath/src/test/native/cpp/controller/RamseteControllerTest.cpp b/wpimath/src/test/native/cpp/controller/RamseteControllerTest.cpp index 8829deb5c3..e5f24a368f 100644 --- a/wpimath/src/test/native/cpp/controller/RamseteControllerTest.cpp +++ b/wpimath/src/test/native/cpp/controller/RamseteControllerTest.cpp @@ -18,7 +18,7 @@ static constexpr units::radian_t kAngularTolerance{2.0 * wpi::numbers::pi / TEST(RamseteControllerTest, ReachesReference) { frc::RamseteController controller{2.0 * 1_rad * 1_rad / (1_m * 1_m), 0.7 / 1_rad}; - frc::Pose2d robotPose{2.7_m, 23_m, frc::Rotation2d{0_deg}}; + frc::Pose2d robotPose{2.7_m, 23_m, 0_deg}; auto waypoints = std::vector{frc::Pose2d{2.75_m, 22.521_m, 0_rad}, frc::Pose2d{24.73_m, 19.68_m, 5.846_rad}}; diff --git a/wpimath/src/test/native/cpp/estimator/DifferentialDrivePoseEstimatorTest.cpp b/wpimath/src/test/native/cpp/estimator/DifferentialDrivePoseEstimatorTest.cpp index bc787ff669..4f69802663 100644 --- a/wpimath/src/test/native/cpp/estimator/DifferentialDrivePoseEstimatorTest.cpp +++ b/wpimath/src/test/native/cpp/estimator/DifferentialDrivePoseEstimatorTest.cpp @@ -18,22 +18,21 @@ #include "units/time.h" TEST(DifferentialDrivePoseEstimatorTest, Accuracy) { - frc::DifferentialDrivePoseEstimator estimator{frc::Rotation2d(), - frc::Pose2d(), + frc::DifferentialDrivePoseEstimator estimator{frc::Rotation2d{}, + frc::Pose2d{}, {0.02, 0.02, 0.01, 0.02, 0.02}, {0.01, 0.01, 0.001}, {0.1, 0.1, 0.01}}; frc::Trajectory trajectory = frc::TrajectoryGenerator::GenerateTrajectory( - std::vector{frc::Pose2d(0_m, 0_m, frc::Rotation2d(45_deg)), - frc::Pose2d(3_m, 0_m, frc::Rotation2d(-90_deg)), - frc::Pose2d(0_m, 0_m, frc::Rotation2d(135_deg)), - frc::Pose2d(-3_m, 0_m, frc::Rotation2d(-90_deg)), - frc::Pose2d(0_m, 0_m, frc::Rotation2d(45_deg))}, + std::vector{frc::Pose2d{0_m, 0_m, 45_deg}, frc::Pose2d{3_m, 0_m, -90_deg}, + frc::Pose2d{0_m, 0_m, 135_deg}, + frc::Pose2d{-3_m, 0_m, -90_deg}, + frc::Pose2d{0_m, 0_m, 45_deg}}, frc::TrajectoryConfig(10_mps, 5.0_mps_sq)); frc::DifferentialDriveKinematics kinematics{1.0_m}; - frc::DifferentialDriveOdometry odometry{frc::Rotation2d()}; + frc::DifferentialDriveOdometry odometry{frc::Rotation2d{}}; std::default_random_engine generator; std::normal_distribution distribution(0.0, 1.0); @@ -58,15 +57,15 @@ TEST(DifferentialDrivePoseEstimatorTest, Accuracy) { groundTruthState.velocity * groundTruthState.curvature}); if (lastVisionUpdateTime + kVisionUpdateRate < t) { - if (lastVisionPose != frc::Pose2d()) { + if (lastVisionPose != frc::Pose2d{}) { estimator.AddVisionMeasurement(lastVisionPose, lastVisionUpdateTime); } lastVisionPose = groundTruthState.pose + - frc::Transform2d( - frc::Translation2d(distribution(generator) * 0.1 * 1_m, - distribution(generator) * 0.1 * 1_m), - frc::Rotation2d(distribution(generator) * 0.01 * 1_rad)); + frc::Transform2d{ + frc::Translation2d{distribution(generator) * 0.1 * 1_m, + distribution(generator) * 0.1 * 1_m}, + frc::Rotation2d{distribution(generator) * 0.01 * 1_rad}}; lastVisionUpdateTime = t; } @@ -77,7 +76,7 @@ TEST(DifferentialDrivePoseEstimatorTest, Accuracy) { auto xhat = estimator.UpdateWithTime( t, groundTruthState.pose.Rotation() + - frc::Rotation2d(units::radian_t(distribution(generator) * 0.001)), + frc::Rotation2d{units::radian_t{distribution(generator) * 0.001}}, input, leftDistance, rightDistance); double error = groundTruthState.pose.Translation() @@ -94,5 +93,5 @@ TEST(DifferentialDrivePoseEstimatorTest, Accuracy) { EXPECT_NEAR(0.0, errorSum / (trajectory.TotalTime().value() / dt.value()), 0.05); - EXPECT_NEAR(0.0, maxError, 0.1); + EXPECT_NEAR(0.0, maxError, 0.125); } diff --git a/wpimath/src/test/native/cpp/estimator/MecanumDrivePoseEstimatorTest.cpp b/wpimath/src/test/native/cpp/estimator/MecanumDrivePoseEstimatorTest.cpp index 2a9601224f..0845eef3c5 100644 --- a/wpimath/src/test/native/cpp/estimator/MecanumDrivePoseEstimatorTest.cpp +++ b/wpimath/src/test/native/cpp/estimator/MecanumDrivePoseEstimatorTest.cpp @@ -18,17 +18,16 @@ TEST(MecanumDrivePoseEstimatorTest, Accuracy) { frc::Translation2d{-1_m, -1_m}, frc::Translation2d{-1_m, 1_m}}; frc::MecanumDrivePoseEstimator estimator{ - frc::Rotation2d(), frc::Pose2d(), kinematics, + frc::Rotation2d{}, frc::Pose2d{}, kinematics, {0.1, 0.1, 0.1}, {0.05}, {0.1, 0.1, 0.1}}; - frc::MecanumDriveOdometry odometry{kinematics, frc::Rotation2d()}; + frc::MecanumDriveOdometry odometry{kinematics, frc::Rotation2d{}}; frc::Trajectory trajectory = frc::TrajectoryGenerator::GenerateTrajectory( - std::vector{frc::Pose2d(0_m, 0_m, frc::Rotation2d(45_deg)), - frc::Pose2d(3_m, 0_m, frc::Rotation2d(-90_deg)), - frc::Pose2d(0_m, 0_m, frc::Rotation2d(135_deg)), - frc::Pose2d(-3_m, 0_m, frc::Rotation2d(-90_deg)), - frc::Pose2d(0_m, 0_m, frc::Rotation2d(45_deg))}, + std::vector{frc::Pose2d{0_m, 0_m, 45_deg}, frc::Pose2d{3_m, 0_m, -90_deg}, + frc::Pose2d{0_m, 0_m, 135_deg}, + frc::Pose2d{-3_m, 0_m, -90_deg}, + frc::Pose2d{0_m, 0_m, 45_deg}}, frc::TrajectoryConfig(5.0_mps, 2.0_mps_sq)); std::default_random_engine generator; @@ -50,15 +49,15 @@ TEST(MecanumDrivePoseEstimatorTest, Accuracy) { frc::Trajectory::State groundTruthState = trajectory.Sample(t); if (lastVisionUpdateTime + kVisionUpdateRate < t) { - if (lastVisionPose != frc::Pose2d()) { + if (lastVisionPose != frc::Pose2d{}) { estimator.AddVisionMeasurement(lastVisionPose, lastVisionUpdateTime); } lastVisionPose = groundTruthState.pose + - frc::Transform2d( - frc::Translation2d(distribution(generator) * 0.1_m, - distribution(generator) * 0.1_m), - frc::Rotation2d(distribution(generator) * 0.1 * 1_rad)); + frc::Transform2d{ + frc::Translation2d{distribution(generator) * 0.1_m, + distribution(generator) * 0.1_m}, + frc::Rotation2d{distribution(generator) * 0.1 * 1_rad}}; visionPoses.push_back(lastVisionPose); lastVisionUpdateTime = t; } @@ -70,7 +69,7 @@ TEST(MecanumDrivePoseEstimatorTest, Accuracy) { auto xhat = estimator.UpdateWithTime( t, groundTruthState.pose.Rotation() + - frc::Rotation2d(distribution(generator) * 0.05_rad), + frc::Rotation2d{distribution(generator) * 0.05_rad}, wheelSpeeds); double error = groundTruthState.pose.Translation() .Distance(xhat.Translation()) @@ -85,5 +84,5 @@ TEST(MecanumDrivePoseEstimatorTest, Accuracy) { } EXPECT_LT(errorSum / (trajectory.TotalTime().value() / dt.value()), 0.05); - EXPECT_LT(maxError, 0.1); + EXPECT_LT(maxError, 0.125); } diff --git a/wpimath/src/test/native/cpp/estimator/SwerveDrivePoseEstimatorTest.cpp b/wpimath/src/test/native/cpp/estimator/SwerveDrivePoseEstimatorTest.cpp index eec4112d88..5315c7ad59 100644 --- a/wpimath/src/test/native/cpp/estimator/SwerveDrivePoseEstimatorTest.cpp +++ b/wpimath/src/test/native/cpp/estimator/SwerveDrivePoseEstimatorTest.cpp @@ -18,17 +18,16 @@ TEST(SwerveDrivePoseEstimatorTest, Accuracy) { frc::Translation2d{-1_m, -1_m}, frc::Translation2d{-1_m, 1_m}}; frc::SwerveDrivePoseEstimator<4> estimator{ - frc::Rotation2d(), frc::Pose2d(), kinematics, + frc::Rotation2d{}, frc::Pose2d{}, kinematics, {0.1, 0.1, 0.1}, {0.05}, {0.1, 0.1, 0.1}}; - frc::SwerveDriveOdometry<4> odometry{kinematics, frc::Rotation2d()}; + frc::SwerveDriveOdometry<4> odometry{kinematics, frc::Rotation2d{}}; frc::Trajectory trajectory = frc::TrajectoryGenerator::GenerateTrajectory( - std::vector{frc::Pose2d(0_m, 0_m, frc::Rotation2d(45_deg)), - frc::Pose2d(3_m, 0_m, frc::Rotation2d(-90_deg)), - frc::Pose2d(0_m, 0_m, frc::Rotation2d(135_deg)), - frc::Pose2d(-3_m, 0_m, frc::Rotation2d(-90_deg)), - frc::Pose2d(0_m, 0_m, frc::Rotation2d(45_deg))}, + std::vector{frc::Pose2d{0_m, 0_m, 45_deg}, frc::Pose2d{3_m, 0_m, -90_deg}, + frc::Pose2d{0_m, 0_m, 135_deg}, + frc::Pose2d{-3_m, 0_m, -90_deg}, + frc::Pose2d{0_m, 0_m, 45_deg}}, frc::TrajectoryConfig(5.0_mps, 2.0_mps_sq)); std::default_random_engine generator; @@ -50,15 +49,15 @@ TEST(SwerveDrivePoseEstimatorTest, Accuracy) { frc::Trajectory::State groundTruthState = trajectory.Sample(t); if (lastVisionUpdateTime + kVisionUpdateRate < t) { - if (lastVisionPose != frc::Pose2d()) { + if (lastVisionPose != frc::Pose2d{}) { estimator.AddVisionMeasurement(lastVisionPose, lastVisionUpdateTime); } lastVisionPose = groundTruthState.pose + - frc::Transform2d( - frc::Translation2d(distribution(generator) * 0.1_m, - distribution(generator) * 0.1_m), - frc::Rotation2d(distribution(generator) * 0.1 * 1_rad)); + frc::Transform2d{ + frc::Translation2d{distribution(generator) * 0.1_m, + distribution(generator) * 0.1_m}, + frc::Rotation2d{distribution(generator) * 0.1 * 1_rad}}; visionPoses.push_back(lastVisionPose); lastVisionUpdateTime = t; } @@ -70,7 +69,7 @@ TEST(SwerveDrivePoseEstimatorTest, Accuracy) { auto xhat = estimator.UpdateWithTime( t, groundTruthState.pose.Rotation() + - frc::Rotation2d(distribution(generator) * 0.05_rad), + frc::Rotation2d{distribution(generator) * 0.05_rad}, moduleStates[0], moduleStates[1], moduleStates[2], moduleStates[3]); double error = groundTruthState.pose.Translation() .Distance(xhat.Translation()) @@ -85,5 +84,5 @@ TEST(SwerveDrivePoseEstimatorTest, Accuracy) { } EXPECT_LT(errorSum / (trajectory.TotalTime().value() / dt.value()), 0.05); - EXPECT_LT(maxError, 0.1); + EXPECT_LT(maxError, 0.125); } diff --git a/wpimath/src/test/native/cpp/geometry/Pose2dTest.cpp b/wpimath/src/test/native/cpp/geometry/Pose2dTest.cpp index 3e4023562d..4c3396166a 100644 --- a/wpimath/src/test/native/cpp/geometry/Pose2dTest.cpp +++ b/wpimath/src/test/native/cpp/geometry/Pose2dTest.cpp @@ -10,8 +10,8 @@ using namespace frc; TEST(Pose2dTest, TransformBy) { - const Pose2d initial{1_m, 2_m, Rotation2d{45_deg}}; - const Transform2d transform{Translation2d{5_m, 0_m}, Rotation2d{5_deg}}; + const Pose2d initial{1_m, 2_m, 45_deg}; + const Transform2d transform{Translation2d{5_m, 0_m}, 5_deg}; const auto transformed = initial + transform; @@ -21,8 +21,8 @@ TEST(Pose2dTest, TransformBy) { } TEST(Pose2dTest, RelativeTo) { - const Pose2d initial{0_m, 0_m, Rotation2d{45_deg}}; - const Pose2d final{5_m, 5_m, Rotation2d{45.0_deg}}; + const Pose2d initial{0_m, 0_m, 45_deg}; + const Pose2d final{5_m, 5_m, 45.0_deg}; const auto finalRelativeToInitial = final.RelativeTo(initial); @@ -32,20 +32,20 @@ TEST(Pose2dTest, RelativeTo) { } TEST(Pose2dTest, Equality) { - const Pose2d a{0_m, 5_m, Rotation2d{43_deg}}; - const Pose2d b{0_m, 5_m, Rotation2d{43_deg}}; + const Pose2d a{0_m, 5_m, 43_deg}; + const Pose2d b{0_m, 5_m, 43_deg}; EXPECT_TRUE(a == b); } TEST(Pose2dTest, Inequality) { - const Pose2d a{0_m, 5_m, Rotation2d{43_deg}}; - const Pose2d b{0_m, 5_ft, Rotation2d{43_deg}}; + const Pose2d a{0_m, 5_m, 43_deg}; + const Pose2d b{0_m, 5_ft, 43_deg}; EXPECT_TRUE(a != b); } TEST(Pose2dTest, Minus) { - const Pose2d initial{0_m, 0_m, Rotation2d{45_deg}}; - const Pose2d final{5_m, 5_m, Rotation2d{45_deg}}; + const Pose2d initial{0_m, 0_m, 45_deg}; + const Pose2d final{5_m, 5_m, 45_deg}; const auto transform = final - initial; diff --git a/wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp b/wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp index 792dabba3a..4401703a7b 100644 --- a/wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp +++ b/wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp @@ -29,7 +29,7 @@ TEST(Rotation2dTest, DegreesToRadians) { TEST(Rotation2dTest, RotateByFromZero) { const Rotation2d zero; - auto rotated = zero + Rotation2d(90_deg); + auto rotated = zero + Rotation2d{90_deg}; EXPECT_DOUBLE_EQ(wpi::numbers::pi / 2.0, rotated.Radians().value()); EXPECT_DOUBLE_EQ(90.0, rotated.Degrees().value()); diff --git a/wpimath/src/test/native/cpp/geometry/Translation2dTest.cpp b/wpimath/src/test/native/cpp/geometry/Translation2dTest.cpp index 148c528559..76efd4942c 100644 --- a/wpimath/src/test/native/cpp/geometry/Translation2dTest.cpp +++ b/wpimath/src/test/native/cpp/geometry/Translation2dTest.cpp @@ -31,7 +31,7 @@ TEST(Translation2dTest, Difference) { TEST(Translation2dTest, RotateBy) { const Translation2d another{3_m, 0_m}; - const auto rotated = another.RotateBy(Rotation2d(90_deg)); + const auto rotated = another.RotateBy(90_deg); EXPECT_NEAR(0.0, rotated.X().value(), 1e-9); EXPECT_DOUBLE_EQ(3.0, rotated.Y().value()); diff --git a/wpimath/src/test/native/cpp/geometry/Translation3dTest.cpp b/wpimath/src/test/native/cpp/geometry/Translation3dTest.cpp index 32c5d68b9d..76e001fa89 100644 --- a/wpimath/src/test/native/cpp/geometry/Translation3dTest.cpp +++ b/wpimath/src/test/native/cpp/geometry/Translation3dTest.cpp @@ -116,12 +116,12 @@ TEST(Translation3dTest, Inequality) { TEST(Translation3dTest, PolarConstructor) { Eigen::Vector3d zAxis{0.0, 0.0, 1.0}; - Translation3d one{std::sqrt(2) * 1_m, Rotation3d(zAxis, 45_deg)}; + Translation3d one{std::sqrt(2) * 1_m, Rotation3d{zAxis, 45_deg}}; EXPECT_NEAR(one.X().value(), 1.0, kEpsilon); EXPECT_NEAR(one.Y().value(), 1.0, kEpsilon); EXPECT_NEAR(one.Z().value(), 0.0, kEpsilon); - Translation3d two{2_m, Rotation3d(zAxis, 60_deg)}; + Translation3d two{2_m, Rotation3d{zAxis, 60_deg}}; EXPECT_NEAR(two.X().value(), 1.0, kEpsilon); EXPECT_NEAR(two.Y().value(), std::sqrt(3.0), kEpsilon); EXPECT_NEAR(two.Z().value(), 0.0, kEpsilon); diff --git a/wpimath/src/test/native/cpp/geometry/Twist2dTest.cpp b/wpimath/src/test/native/cpp/geometry/Twist2dTest.cpp index d728dbfbc2..f10d0265e2 100644 --- a/wpimath/src/test/native/cpp/geometry/Twist2dTest.cpp +++ b/wpimath/src/test/native/cpp/geometry/Twist2dTest.cpp @@ -13,7 +13,7 @@ using namespace frc; TEST(Twist2dTest, Straight) { const Twist2d straight{5_m, 0_m, 0_rad}; - const auto straightPose = Pose2d().Exp(straight); + const auto straightPose = Pose2d{}.Exp(straight); EXPECT_DOUBLE_EQ(5.0, straightPose.X().value()); EXPECT_DOUBLE_EQ(0.0, straightPose.Y().value()); @@ -52,7 +52,7 @@ TEST(Twist2dTest, Inequality) { } TEST(Twist2dTest, Pose2dLog) { - const Pose2d end{5_m, 5_m, Rotation2d{90_deg}}; + const Pose2d end{5_m, 5_m, 90_deg}; const Pose2d start; const auto twist = start.Log(end); diff --git a/wpimath/src/test/native/cpp/geometry/Twist3dTest.cpp b/wpimath/src/test/native/cpp/geometry/Twist3dTest.cpp index ba22ebfb79..da53d730e2 100644 --- a/wpimath/src/test/native/cpp/geometry/Twist3dTest.cpp +++ b/wpimath/src/test/native/cpp/geometry/Twist3dTest.cpp @@ -13,7 +13,7 @@ using namespace frc; TEST(Twist3dTest, StraightX) { const Twist3d straight{5_m, 0_m, 0_m, 0_rad, 0_rad, 0_rad}; - const auto straightPose = Pose3d().Exp(straight); + const auto straightPose = Pose3d{}.Exp(straight); Pose3d expected{5_m, 0_m, 0_m, Rotation3d{}}; EXPECT_EQ(expected, straightPose); @@ -21,7 +21,7 @@ TEST(Twist3dTest, StraightX) { TEST(Twist3dTest, StraightY) { const Twist3d straight{0_m, 5_m, 0_m, 0_rad, 0_rad, 0_rad}; - const auto straightPose = Pose3d().Exp(straight); + const auto straightPose = Pose3d{}.Exp(straight); Pose3d expected{0_m, 5_m, 0_m, Rotation3d{}}; EXPECT_EQ(expected, straightPose); @@ -29,7 +29,7 @@ TEST(Twist3dTest, StraightY) { TEST(Twist3dTest, StraightZ) { const Twist3d straight{0_m, 0_m, 5_m, 0_rad, 0_rad, 0_rad}; - const auto straightPose = Pose3d().Exp(straight); + const auto straightPose = Pose3d{}.Exp(straight); Pose3d expected{0_m, 0_m, 5_m, Rotation3d{}}; EXPECT_EQ(expected, straightPose); @@ -40,8 +40,8 @@ TEST(Twist3dTest, QuarterCircle) { const Twist3d quarterCircle{ 5_m / 2.0 * wpi::numbers::pi, 0_m, 0_m, 0_rad, 0_rad, - units::radian_t(wpi::numbers::pi / 2.0)}; - const auto quarterCirclePose = Pose3d().Exp(quarterCircle); + units::radian_t{wpi::numbers::pi / 2.0}}; + const auto quarterCirclePose = Pose3d{}.Exp(quarterCircle); Pose3d expected{5_m, 5_m, 0_m, Rotation3d{zAxis, 90_deg}}; EXPECT_EQ(expected, quarterCirclePose); @@ -49,7 +49,7 @@ TEST(Twist3dTest, QuarterCircle) { TEST(Twist3dTest, DiagonalNoDtheta) { const Twist3d diagonal{2_m, 2_m, 0_m, 0_rad, 0_rad, 0_rad}; - const auto diagonalPose = Pose3d().Exp(diagonal); + const auto diagonalPose = Pose3d{}.Exp(diagonal); Pose3d expected{2_m, 2_m, 0_m, Rotation3d{}}; EXPECT_EQ(expected, diagonalPose); diff --git a/wpimath/src/test/native/cpp/interpolation/TimeInterpolatableBufferTest.cpp b/wpimath/src/test/native/cpp/interpolation/TimeInterpolatableBufferTest.cpp index 663ecbcc50..8a920f6fba 100644 --- a/wpimath/src/test/native/cpp/interpolation/TimeInterpolatableBufferTest.cpp +++ b/wpimath/src/test/native/cpp/interpolation/TimeInterpolatableBufferTest.cpp @@ -13,16 +13,16 @@ TEST(TimeInterpolatableBufferTest, Interpolation) { frc::TimeInterpolatableBuffer buffer{10_s}; - buffer.AddSample(0_s, frc::Rotation2d(0_rad)); - EXPECT_TRUE(buffer.Sample(0_s).value() == frc::Rotation2d(0_rad)); - buffer.AddSample(1_s, frc::Rotation2d(1_rad)); - EXPECT_TRUE(buffer.Sample(0.5_s).value() == frc::Rotation2d(0.5_rad)); - EXPECT_TRUE(buffer.Sample(1_s).value() == frc::Rotation2d(1_rad)); - buffer.AddSample(3_s, frc::Rotation2d(2_rad)); - EXPECT_TRUE(buffer.Sample(2_s).value() == frc::Rotation2d(1.5_rad)); + buffer.AddSample(0_s, 0_rad); + EXPECT_TRUE(buffer.Sample(0_s).value() == 0_rad); + buffer.AddSample(1_s, 1_rad); + EXPECT_TRUE(buffer.Sample(0.5_s).value() == 0.5_rad); + EXPECT_TRUE(buffer.Sample(1_s).value() == 1_rad); + buffer.AddSample(3_s, 2_rad); + EXPECT_TRUE(buffer.Sample(2_s).value() == 1.5_rad); - buffer.AddSample(10.5_s, frc::Rotation2d(2_rad)); - EXPECT_TRUE(buffer.Sample(0_s) == frc::Rotation2d(1_rad)); + buffer.AddSample(10.5_s, 2_rad); + EXPECT_TRUE(buffer.Sample(0_s) == 1_rad); } TEST(TimeInterpolatableBufferTest, Pose2d) { diff --git a/wpimath/src/test/native/cpp/kinematics/ChassisSpeedsTest.cpp b/wpimath/src/test/native/cpp/kinematics/ChassisSpeedsTest.cpp index 7665a97add..4e0b3e5bf7 100644 --- a/wpimath/src/test/native/cpp/kinematics/ChassisSpeedsTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/ChassisSpeedsTest.cpp @@ -9,7 +9,7 @@ static constexpr double kEpsilon = 1E-9; TEST(ChassisSpeedsTest, FieldRelativeConstruction) { const auto chassisSpeeds = frc::ChassisSpeeds::FromFieldRelativeSpeeds( - 1.0_mps, 0.0_mps, 0.5_rad_per_s, frc::Rotation2d(-90.0_deg)); + 1.0_mps, 0.0_mps, 0.5_rad_per_s, -90.0_deg); EXPECT_NEAR(0.0, chassisSpeeds.vx.value(), kEpsilon); EXPECT_NEAR(1.0, chassisSpeeds.vy.value(), kEpsilon); diff --git a/wpimath/src/test/native/cpp/kinematics/DifferentialDriveKinematicsTest.cpp b/wpimath/src/test/native/cpp/kinematics/DifferentialDriveKinematicsTest.cpp index 224e231519..321e356236 100644 --- a/wpimath/src/test/native/cpp/kinematics/DifferentialDriveKinematicsTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/DifferentialDriveKinematicsTest.cpp @@ -66,8 +66,8 @@ TEST(DifferentialDriveKinematicsTest, InverseKinematicsForRotateInPlace) { TEST(DifferentialDriveKinematicsTest, ForwardKinematicsForRotateInPlace) { const DifferentialDriveKinematics kinematics{0.381_m * 2}; const DifferentialDriveWheelSpeeds wheelSpeeds{ - units::meters_per_second_t(+0.381 * wpi::numbers::pi), - units::meters_per_second_t(-0.381 * wpi::numbers::pi)}; + units::meters_per_second_t{+0.381 * wpi::numbers::pi}, + units::meters_per_second_t{-0.381 * wpi::numbers::pi}}; const auto chassisSpeeds = kinematics.ToChassisSpeeds(wheelSpeeds); EXPECT_NEAR(chassisSpeeds.vx.value(), 0, kEpsilon); diff --git a/wpimath/src/test/native/cpp/kinematics/DifferentialDriveOdometryTest.cpp b/wpimath/src/test/native/cpp/kinematics/DifferentialDriveOdometryTest.cpp index da16b28482..a74723c04f 100644 --- a/wpimath/src/test/native/cpp/kinematics/DifferentialDriveOdometryTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/DifferentialDriveOdometryTest.cpp @@ -13,10 +13,10 @@ static constexpr double kEpsilon = 1E-9; using namespace frc; TEST(DifferentialDriveOdometryTest, EncoderDistances) { - DifferentialDriveOdometry odometry{Rotation2d(45_deg)}; + DifferentialDriveOdometry odometry{45_deg}; - const auto& pose = odometry.Update(Rotation2d(135_deg), 0_m, - units::meter_t(5 * wpi::numbers::pi)); + const auto& pose = + odometry.Update(135_deg, 0_m, units::meter_t{5 * wpi::numbers::pi}); EXPECT_NEAR(pose.X().value(), 5.0, kEpsilon); EXPECT_NEAR(pose.Y().value(), 5.0, kEpsilon); diff --git a/wpimath/src/test/native/cpp/kinematics/MecanumDriveKinematicsTest.cpp b/wpimath/src/test/native/cpp/kinematics/MecanumDriveKinematicsTest.cpp index 8cc454e722..05766a52a7 100644 --- a/wpimath/src/test/native/cpp/kinematics/MecanumDriveKinematicsTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/MecanumDriveKinematicsTest.cpp @@ -61,7 +61,7 @@ TEST_F(MecanumDriveKinematicsTest, StrafeForwardKinematics) { TEST_F(MecanumDriveKinematicsTest, RotationInverseKinematics) { ChassisSpeeds speeds{0_mps, 0_mps, - units::radians_per_second_t(2 * wpi::numbers::pi)}; + units::radians_per_second_t{2 * wpi::numbers::pi}}; auto moduleStates = kinematics.ToWheelSpeeds(speeds); EXPECT_NEAR(-150.79644737, moduleStates.frontLeft.value(), 0.1); diff --git a/wpimath/src/test/native/cpp/kinematics/MecanumDriveOdometryTest.cpp b/wpimath/src/test/native/cpp/kinematics/MecanumDriveOdometryTest.cpp index 152506db18..f0c3092c91 100644 --- a/wpimath/src/test/native/cpp/kinematics/MecanumDriveOdometryTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/MecanumDriveOdometryTest.cpp @@ -19,12 +19,12 @@ class MecanumDriveOdometryTest : public ::testing::Test { }; TEST_F(MecanumDriveOdometryTest, MultipleConsecutiveUpdates) { - odometry.ResetPosition(Pose2d(), 0_rad); + odometry.ResetPosition(Pose2d{}, 0_rad); MecanumDriveWheelSpeeds wheelSpeeds{3.536_mps, 3.536_mps, 3.536_mps, 3.536_mps}; - odometry.UpdateWithTime(0_s, Rotation2d(), wheelSpeeds); - auto secondPose = odometry.UpdateWithTime(0.0_s, Rotation2d(), wheelSpeeds); + odometry.UpdateWithTime(0_s, 0_deg, wheelSpeeds); + auto secondPose = odometry.UpdateWithTime(0.0_s, 0_deg, wheelSpeeds); EXPECT_NEAR(secondPose.X().value(), 0.0, 0.01); EXPECT_NEAR(secondPose.Y().value(), 0.0, 0.01); @@ -32,11 +32,11 @@ TEST_F(MecanumDriveOdometryTest, MultipleConsecutiveUpdates) { } TEST_F(MecanumDriveOdometryTest, TwoIterations) { - odometry.ResetPosition(Pose2d(), 0_rad); + odometry.ResetPosition(Pose2d{}, 0_rad); MecanumDriveWheelSpeeds speeds{3.536_mps, 3.536_mps, 3.536_mps, 3.536_mps}; - odometry.UpdateWithTime(0_s, Rotation2d(), MecanumDriveWheelSpeeds{}); - auto pose = odometry.UpdateWithTime(0.10_s, Rotation2d(), speeds); + odometry.UpdateWithTime(0_s, 0_deg, MecanumDriveWheelSpeeds{}); + auto pose = odometry.UpdateWithTime(0.10_s, 0_deg, speeds); EXPECT_NEAR(pose.X().value(), 0.3536, 0.01); EXPECT_NEAR(pose.Y().value(), 0.0, 0.01); @@ -44,11 +44,11 @@ TEST_F(MecanumDriveOdometryTest, TwoIterations) { } TEST_F(MecanumDriveOdometryTest, 90DegreeTurn) { - odometry.ResetPosition(Pose2d(), 0_rad); + odometry.ResetPosition(Pose2d{}, 0_rad); MecanumDriveWheelSpeeds speeds{-13.328_mps, 39.986_mps, -13.329_mps, 39.986_mps}; - odometry.UpdateWithTime(0_s, Rotation2d(), MecanumDriveWheelSpeeds{}); - auto pose = odometry.UpdateWithTime(1_s, Rotation2d(90_deg), speeds); + odometry.UpdateWithTime(0_s, 0_deg, MecanumDriveWheelSpeeds{}); + auto pose = odometry.UpdateWithTime(1_s, 90_deg, speeds); EXPECT_NEAR(pose.X().value(), 8.4855, 0.01); EXPECT_NEAR(pose.Y().value(), 8.4855, 0.01); @@ -56,12 +56,12 @@ TEST_F(MecanumDriveOdometryTest, 90DegreeTurn) { } TEST_F(MecanumDriveOdometryTest, GyroAngleReset) { - odometry.ResetPosition(Pose2d(), Rotation2d(90_deg)); + odometry.ResetPosition(Pose2d{}, 90_deg); MecanumDriveWheelSpeeds speeds{3.536_mps, 3.536_mps, 3.536_mps, 3.536_mps}; - odometry.UpdateWithTime(0_s, Rotation2d(90_deg), MecanumDriveWheelSpeeds{}); - auto pose = odometry.UpdateWithTime(0.10_s, Rotation2d(90_deg), speeds); + odometry.UpdateWithTime(0_s, 90_deg, MecanumDriveWheelSpeeds{}); + auto pose = odometry.UpdateWithTime(0.10_s, 90_deg, speeds); EXPECT_NEAR(pose.X().value(), 0.3536, 0.01); EXPECT_NEAR(pose.Y().value(), 0.0, 0.01); diff --git a/wpimath/src/test/native/cpp/kinematics/SwerveDriveKinematicsTest.cpp b/wpimath/src/test/native/cpp/kinematics/SwerveDriveKinematicsTest.cpp index a79b59bb64..6aafbc2a52 100644 --- a/wpimath/src/test/native/cpp/kinematics/SwerveDriveKinematicsTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/SwerveDriveKinematicsTest.cpp @@ -40,7 +40,7 @@ TEST_F(SwerveDriveKinematicsTest, StraightLineInverseKinematics) { } TEST_F(SwerveDriveKinematicsTest, StraightLineForwardKinematics) { - SwerveModuleState state{5.0_mps, Rotation2d()}; + SwerveModuleState state{5.0_mps, 0_deg}; auto chassisSpeeds = m_kinematics.ToChassisSpeeds(state, state, state, state); @@ -65,7 +65,7 @@ TEST_F(SwerveDriveKinematicsTest, StraightStrafeInverseKinematics) { } TEST_F(SwerveDriveKinematicsTest, StraightStrafeForwardKinematics) { - SwerveModuleState state{5_mps, Rotation2d(90_deg)}; + SwerveModuleState state{5_mps, 90_deg}; auto chassisSpeeds = m_kinematics.ToChassisSpeeds(state, state, state, state); EXPECT_NEAR(chassisSpeeds.vx.value(), 0.0, kEpsilon); @@ -75,7 +75,7 @@ TEST_F(SwerveDriveKinematicsTest, StraightStrafeForwardKinematics) { TEST_F(SwerveDriveKinematicsTest, TurnInPlaceInverseKinematics) { ChassisSpeeds speeds{0_mps, 0_mps, - units::radians_per_second_t(2 * wpi::numbers::pi)}; + units::radians_per_second_t{2 * wpi::numbers::pi}}; auto [fl, fr, bl, br] = m_kinematics.ToSwerveModuleStates(speeds); EXPECT_NEAR(fl.speed.value(), 106.63, kEpsilon); @@ -91,7 +91,7 @@ TEST_F(SwerveDriveKinematicsTest, TurnInPlaceInverseKinematics) { TEST_F(SwerveDriveKinematicsTest, ConserveWheelAngle) { ChassisSpeeds speeds{0_mps, 0_mps, - units::radians_per_second_t(2 * wpi::numbers::pi)}; + units::radians_per_second_t{2 * wpi::numbers::pi}}; m_kinematics.ToSwerveModuleStates(speeds); auto [fl, fr, bl, br] = m_kinematics.ToSwerveModuleStates(ChassisSpeeds{}); @@ -107,10 +107,10 @@ TEST_F(SwerveDriveKinematicsTest, ConserveWheelAngle) { } TEST_F(SwerveDriveKinematicsTest, TurnInPlaceForwardKinematics) { - SwerveModuleState fl{106.629_mps, Rotation2d(135_deg)}; - SwerveModuleState fr{106.629_mps, Rotation2d(45_deg)}; - SwerveModuleState bl{106.629_mps, Rotation2d(-135_deg)}; - SwerveModuleState br{106.629_mps, Rotation2d(-45_deg)}; + SwerveModuleState fl{106.629_mps, 135_deg}; + SwerveModuleState fr{106.629_mps, 45_deg}; + SwerveModuleState bl{106.629_mps, -135_deg}; + SwerveModuleState br{106.629_mps, -45_deg}; auto chassisSpeeds = m_kinematics.ToChassisSpeeds(fl, fr, bl, br); @@ -121,7 +121,7 @@ TEST_F(SwerveDriveKinematicsTest, TurnInPlaceForwardKinematics) { TEST_F(SwerveDriveKinematicsTest, OffCenterCORRotationInverseKinematics) { ChassisSpeeds speeds{0_mps, 0_mps, - units::radians_per_second_t(2 * wpi::numbers::pi)}; + units::radians_per_second_t{2 * wpi::numbers::pi}}; auto [fl, fr, bl, br] = m_kinematics.ToSwerveModuleStates(speeds, m_fl); EXPECT_NEAR(fl.speed.value(), 0.0, kEpsilon); @@ -136,10 +136,10 @@ TEST_F(SwerveDriveKinematicsTest, OffCenterCORRotationInverseKinematics) { } TEST_F(SwerveDriveKinematicsTest, OffCenterCORRotationForwardKinematics) { - SwerveModuleState fl{0.0_mps, Rotation2d(0_deg)}; - SwerveModuleState fr{150.796_mps, Rotation2d(0_deg)}; - SwerveModuleState bl{150.796_mps, Rotation2d(-90_deg)}; - SwerveModuleState br{213.258_mps, Rotation2d(-45_deg)}; + SwerveModuleState fl{0.0_mps, 0_deg}; + SwerveModuleState fr{150.796_mps, 0_deg}; + SwerveModuleState bl{150.796_mps, -90_deg}; + SwerveModuleState br{213.258_mps, -45_deg}; auto chassisSpeeds = m_kinematics.ToChassisSpeeds(fl, fr, bl, br); @@ -152,7 +152,7 @@ TEST_F(SwerveDriveKinematicsTest, OffCenterCORRotationAndTranslationInverseKinematics) { ChassisSpeeds speeds{0_mps, 3.0_mps, 1.5_rad_per_s}; auto [fl, fr, bl, br] = - m_kinematics.ToSwerveModuleStates(speeds, Translation2d(24_m, 0_m)); + m_kinematics.ToSwerveModuleStates(speeds, Translation2d{24_m, 0_m}); EXPECT_NEAR(fl.speed.value(), 23.43, kEpsilon); EXPECT_NEAR(fr.speed.value(), 23.43, kEpsilon); @@ -167,10 +167,10 @@ TEST_F(SwerveDriveKinematicsTest, TEST_F(SwerveDriveKinematicsTest, OffCenterCORRotationAndTranslationForwardKinematics) { - SwerveModuleState fl{23.43_mps, Rotation2d(-140.19_deg)}; - SwerveModuleState fr{23.43_mps, Rotation2d(-39.81_deg)}; - SwerveModuleState bl{54.08_mps, Rotation2d(-109.44_deg)}; - SwerveModuleState br{54.08_mps, Rotation2d(-70.56_deg)}; + SwerveModuleState fl{23.43_mps, -140.19_deg}; + SwerveModuleState fr{23.43_mps, -39.81_deg}; + SwerveModuleState bl{54.08_mps, -109.44_deg}; + SwerveModuleState br{54.08_mps, -70.56_deg}; auto chassisSpeeds = m_kinematics.ToChassisSpeeds(fl, fr, bl, br); @@ -180,10 +180,10 @@ TEST_F(SwerveDriveKinematicsTest, } TEST_F(SwerveDriveKinematicsTest, Desaturate) { - SwerveModuleState state1{5.0_mps, Rotation2d()}; - SwerveModuleState state2{6.0_mps, Rotation2d()}; - SwerveModuleState state3{4.0_mps, Rotation2d()}; - SwerveModuleState state4{7.0_mps, Rotation2d()}; + SwerveModuleState state1{5.0_mps, 0_deg}; + SwerveModuleState state2{6.0_mps, 0_deg}; + SwerveModuleState state3{4.0_mps, 0_deg}; + SwerveModuleState state4{7.0_mps, 0_deg}; wpi::array arr{state1, state2, state3, state4}; SwerveDriveKinematics<4>::DesaturateWheelSpeeds(&arr, 5.5_mps); diff --git a/wpimath/src/test/native/cpp/kinematics/SwerveDriveOdometryTest.cpp b/wpimath/src/test/native/cpp/kinematics/SwerveDriveOdometryTest.cpp index 27d2a6e7d9..582bb8aedf 100644 --- a/wpimath/src/test/native/cpp/kinematics/SwerveDriveOdometryTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/SwerveDriveOdometryTest.cpp @@ -22,14 +22,14 @@ class SwerveDriveOdometryTest : public ::testing::Test { }; TEST_F(SwerveDriveOdometryTest, TwoIterations) { - SwerveModuleState state{5_mps, Rotation2d()}; + SwerveModuleState state{5_mps, 0_deg}; - m_odometry.ResetPosition(Pose2d(), 0_rad); - m_odometry.UpdateWithTime(0_s, Rotation2d(), SwerveModuleState(), - SwerveModuleState(), SwerveModuleState(), - SwerveModuleState()); - auto pose = m_odometry.UpdateWithTime(0.1_s, Rotation2d(), state, state, - state, state); + m_odometry.ResetPosition(Pose2d{}, 0_rad); + m_odometry.UpdateWithTime(0_s, 0_deg, SwerveModuleState{}, + SwerveModuleState{}, SwerveModuleState{}, + SwerveModuleState{}); + auto pose = + m_odometry.UpdateWithTime(0.1_s, 0_deg, state, state, state, state); EXPECT_NEAR(0.5, pose.X().value(), kEpsilon); EXPECT_NEAR(0.0, pose.Y().value(), kEpsilon); @@ -37,17 +37,16 @@ TEST_F(SwerveDriveOdometryTest, TwoIterations) { } TEST_F(SwerveDriveOdometryTest, 90DegreeTurn) { - SwerveModuleState fl{18.85_mps, Rotation2d(90_deg)}; - SwerveModuleState fr{42.15_mps, Rotation2d(26.565_deg)}; - SwerveModuleState bl{18.85_mps, Rotation2d(-90_deg)}; - SwerveModuleState br{42.15_mps, Rotation2d(-26.565_deg)}; + SwerveModuleState fl{18.85_mps, 90_deg}; + SwerveModuleState fr{42.15_mps, 26.565_deg}; + SwerveModuleState bl{18.85_mps, -90_deg}; + SwerveModuleState br{42.15_mps, -26.565_deg}; - SwerveModuleState zero{0_mps, Rotation2d()}; + SwerveModuleState zero{0_mps, 0_deg}; - m_odometry.ResetPosition(Pose2d(), 0_rad); - m_odometry.UpdateWithTime(0_s, Rotation2d(), zero, zero, zero, zero); - auto pose = - m_odometry.UpdateWithTime(1_s, Rotation2d(90_deg), fl, fr, bl, br); + m_odometry.ResetPosition(Pose2d{}, 0_rad); + m_odometry.UpdateWithTime(0_s, 0_deg, zero, zero, zero, zero); + auto pose = m_odometry.UpdateWithTime(1_s, 90_deg, fl, fr, bl, br); EXPECT_NEAR(12.0, pose.X().value(), kEpsilon); EXPECT_NEAR(12.0, pose.Y().value(), kEpsilon); @@ -55,15 +54,15 @@ TEST_F(SwerveDriveOdometryTest, 90DegreeTurn) { } TEST_F(SwerveDriveOdometryTest, GyroAngleReset) { - m_odometry.ResetPosition(Pose2d(), Rotation2d(90_deg)); + m_odometry.ResetPosition(Pose2d{}, 90_deg); - SwerveModuleState state{5_mps, Rotation2d()}; + SwerveModuleState state{5_mps, 0_deg}; - m_odometry.UpdateWithTime(0_s, Rotation2d(90_deg), SwerveModuleState(), - SwerveModuleState(), SwerveModuleState(), - SwerveModuleState()); - auto pose = m_odometry.UpdateWithTime(0.1_s, Rotation2d(90_deg), state, state, - state, state); + m_odometry.UpdateWithTime(0_s, 90_deg, SwerveModuleState{}, + SwerveModuleState{}, SwerveModuleState{}, + SwerveModuleState{}); + auto pose = + m_odometry.UpdateWithTime(0.1_s, 90_deg, state, state, state, state); EXPECT_NEAR(0.5, pose.X().value(), kEpsilon); EXPECT_NEAR(0.0, pose.Y().value(), kEpsilon); diff --git a/wpimath/src/test/native/cpp/spline/CubicHermiteSplineTest.cpp b/wpimath/src/test/native/cpp/spline/CubicHermiteSplineTest.cpp index 41c34f9537..7422a7f457 100644 --- a/wpimath/src/test/native/cpp/spline/CubicHermiteSplineTest.cpp +++ b/wpimath/src/test/native/cpp/spline/CubicHermiteSplineTest.cpp @@ -93,31 +93,29 @@ class CubicHermiteSplineTest : public ::testing::Test { } // namespace frc TEST_F(CubicHermiteSplineTest, StraightLine) { - Run(Pose2d(), std::vector(), Pose2d(3_m, 0_m, Rotation2d())); + Run(Pose2d{}, std::vector(), Pose2d{3_m, 0_m, 0_deg}); } TEST_F(CubicHermiteSplineTest, SCurve) { - Pose2d start{0_m, 0_m, Rotation2d(90_deg)}; - std::vector waypoints{Translation2d(1_m, 1_m), - Translation2d(2_m, -1_m)}; - Pose2d end{3_m, 0_m, Rotation2d{90_deg}}; + Pose2d start{0_m, 0_m, 90_deg}; + std::vector waypoints{Translation2d{1_m, 1_m}, + Translation2d{2_m, -1_m}}; + Pose2d end{3_m, 0_m, 90_deg}; Run(start, waypoints, end); } TEST_F(CubicHermiteSplineTest, OneInterior) { Pose2d start{0_m, 0_m, 0_rad}; - std::vector waypoints{Translation2d(2_m, 0_m)}; + std::vector waypoints{Translation2d{2_m, 0_m}}; Pose2d end{4_m, 0_m, 0_rad}; Run(start, waypoints, end); } TEST_F(CubicHermiteSplineTest, ThrowsOnMalformed) { - EXPECT_THROW( - Run(Pose2d{0_m, 0_m, Rotation2d(0_deg)}, std::vector{}, - Pose2d{1_m, 0_m, Rotation2d(180_deg)}), - SplineParameterizer::MalformedSplineException); - EXPECT_THROW( - Run(Pose2d{10_m, 10_m, Rotation2d(90_deg)}, std::vector{}, - Pose2d{10_m, 11_m, Rotation2d(-90_deg)}), - SplineParameterizer::MalformedSplineException); + EXPECT_THROW(Run(Pose2d{0_m, 0_m, 0_deg}, std::vector{}, + Pose2d{1_m, 0_m, 180_deg}), + SplineParameterizer::MalformedSplineException); + EXPECT_THROW(Run(Pose2d{10_m, 10_m, 90_deg}, std::vector{}, + Pose2d{10_m, 11_m, -90_deg}), + SplineParameterizer::MalformedSplineException); } diff --git a/wpimath/src/test/native/cpp/spline/QuinticHermiteSplineTest.cpp b/wpimath/src/test/native/cpp/spline/QuinticHermiteSplineTest.cpp index e045622187..e45df7bc3b 100644 --- a/wpimath/src/test/native/cpp/spline/QuinticHermiteSplineTest.cpp +++ b/wpimath/src/test/native/cpp/spline/QuinticHermiteSplineTest.cpp @@ -65,23 +65,20 @@ class QuinticHermiteSplineTest : public ::testing::Test { } // namespace frc TEST_F(QuinticHermiteSplineTest, StraightLine) { - Run(Pose2d(), Pose2d(3_m, 0_m, Rotation2d())); + Run(Pose2d{}, Pose2d{3_m, 0_m, 0_deg}); } TEST_F(QuinticHermiteSplineTest, SimpleSCurve) { - Run(Pose2d(), Pose2d(1_m, 1_m, Rotation2d())); + Run(Pose2d{}, Pose2d{1_m, 1_m, 0_deg}); } TEST_F(QuinticHermiteSplineTest, SquigglyCurve) { - Run(Pose2d(0_m, 0_m, Rotation2d(90_deg)), - Pose2d(-1_m, 0_m, Rotation2d(90_deg))); + Run(Pose2d{0_m, 0_m, 90_deg}, Pose2d{-1_m, 0_m, 90_deg}); } TEST_F(QuinticHermiteSplineTest, ThrowsOnMalformed) { - EXPECT_THROW(Run(Pose2d(0_m, 0_m, Rotation2d(0_deg)), - Pose2d(1_m, 0_m, Rotation2d(180_deg))), + EXPECT_THROW(Run(Pose2d{0_m, 0_m, 0_deg}, Pose2d{1_m, 0_m, 180_deg}), SplineParameterizer::MalformedSplineException); - EXPECT_THROW(Run(Pose2d(10_m, 10_m, Rotation2d(90_deg)), - Pose2d(10_m, 11_m, Rotation2d(-90_deg))), + EXPECT_THROW(Run(Pose2d{10_m, 10_m, 90_deg}, Pose2d{10_m, 11_m, -90_deg}), SplineParameterizer::MalformedSplineException); } diff --git a/wpimath/src/test/native/cpp/trajectory/DifferentialDriveVoltageTest.cpp b/wpimath/src/test/native/cpp/trajectory/DifferentialDriveVoltageTest.cpp index b5f6406f0f..e3d6b7f336 100644 --- a/wpimath/src/test/native/cpp/trajectory/DifferentialDriveVoltageTest.cpp +++ b/wpimath/src/test/native/cpp/trajectory/DifferentialDriveVoltageTest.cpp @@ -72,12 +72,12 @@ TEST(DifferentialDriveVoltageConstraintTest, HighCurvature) { DifferentialDriveVoltageConstraint(feedforward, kinematics, maxVoltage)); EXPECT_NO_FATAL_FAILURE(TrajectoryGenerator::GenerateTrajectory( - Pose2d{1_m, 0_m, Rotation2d{90_deg}}, std::vector{}, - Pose2d{0_m, 1_m, Rotation2d{180_deg}}, config)); + Pose2d{1_m, 0_m, 90_deg}, std::vector{}, + Pose2d{0_m, 1_m, 180_deg}, config)); config.SetReversed(true); EXPECT_NO_FATAL_FAILURE(TrajectoryGenerator::GenerateTrajectory( - Pose2d{0_m, 1_m, Rotation2d{180_deg}}, std::vector{}, - Pose2d{1_m, 0_m, Rotation2d{90_deg}}, config)); + Pose2d{0_m, 1_m, 180_deg}, std::vector{}, + Pose2d{1_m, 0_m, 90_deg}, config)); } diff --git a/wpimath/src/test/native/cpp/trajectory/EllipticalRegionConstraintTest.cpp b/wpimath/src/test/native/cpp/trajectory/EllipticalRegionConstraintTest.cpp index 88dc2b8e01..8d9e2213c0 100644 --- a/wpimath/src/test/native/cpp/trajectory/EllipticalRegionConstraintTest.cpp +++ b/wpimath/src/test/native/cpp/trajectory/EllipticalRegionConstraintTest.cpp @@ -21,9 +21,8 @@ TEST(EllipticalRegionConstraintTest, Constraint) { auto config = TrajectoryConfig(13_fps, 13_fps_sq); MaxVelocityConstraint maxVelConstraint(maxVelocity); - EllipticalRegionConstraint regionConstraint(frc::Translation2d{5_ft, 2.5_ft}, - 10_ft, 5_ft, Rotation2d(180_deg), - maxVelConstraint); + EllipticalRegionConstraint regionConstraint( + frc::Translation2d{5_ft, 2.5_ft}, 10_ft, 5_ft, 180_deg, maxVelConstraint); config.AddConstraint(regionConstraint); auto trajectory = TestTrajectory::GetTrajectory(config); @@ -45,14 +44,12 @@ TEST(EllipticalRegionConstraintTest, IsPoseInRegion) { constexpr auto maxVelocity = 2_fps; MaxVelocityConstraint maxVelConstraint(maxVelocity); EllipticalRegionConstraint regionConstraintNoRotation( - frc::Translation2d{1_ft, 1_ft}, 2_ft, 4_ft, Rotation2d(0_deg), - maxVelConstraint); + frc::Translation2d{1_ft, 1_ft}, 2_ft, 4_ft, 0_deg, maxVelConstraint); EXPECT_FALSE(regionConstraintNoRotation.IsPoseInRegion( - frc::Pose2d(2.1_ft, 1_ft, 0_rad))); + frc::Pose2d{2.1_ft, 1_ft, 0_rad})); EllipticalRegionConstraint regionConstraintWithRotation( - frc::Translation2d{1_ft, 1_ft}, 2_ft, 4_ft, Rotation2d(90_deg), - maxVelConstraint); + frc::Translation2d{1_ft, 1_ft}, 2_ft, 4_ft, 90_deg, maxVelConstraint); EXPECT_TRUE(regionConstraintWithRotation.IsPoseInRegion( - frc::Pose2d(2.1_ft, 1_ft, 0_rad))); + frc::Pose2d{2.1_ft, 1_ft, 0_rad})); } diff --git a/wpimath/src/test/native/cpp/trajectory/RectangularRegionConstraintTest.cpp b/wpimath/src/test/native/cpp/trajectory/RectangularRegionConstraintTest.cpp index 77310ae983..0bf6b1a733 100644 --- a/wpimath/src/test/native/cpp/trajectory/RectangularRegionConstraintTest.cpp +++ b/wpimath/src/test/native/cpp/trajectory/RectangularRegionConstraintTest.cpp @@ -47,7 +47,6 @@ TEST(RectangularRegionConstraintTest, IsPoseInRegion) { frc::Translation2d{5_ft, 27_ft}, maxVelConstraint); - EXPECT_FALSE(regionConstraint.IsPoseInRegion(Pose2d())); - EXPECT_TRUE( - regionConstraint.IsPoseInRegion(Pose2d(3_ft, 14.5_ft, Rotation2d()))); + EXPECT_FALSE(regionConstraint.IsPoseInRegion(Pose2d{})); + EXPECT_TRUE(regionConstraint.IsPoseInRegion(Pose2d{3_ft, 14.5_ft, 0_deg})); } diff --git a/wpimath/src/test/native/cpp/trajectory/TrajectoryGeneratorTest.cpp b/wpimath/src/test/native/cpp/trajectory/TrajectoryGeneratorTest.cpp index 175becf803..58924612e8 100644 --- a/wpimath/src/test/native/cpp/trajectory/TrajectoryGeneratorTest.cpp +++ b/wpimath/src/test/native/cpp/trajectory/TrajectoryGeneratorTest.cpp @@ -34,8 +34,7 @@ TEST(TrajectoryGenerationTest, ObeysConstraints) { TEST(TrajectoryGenertionTest, ReturnsEmptyOnMalformed) { const auto t = TrajectoryGenerator::GenerateTrajectory( - std::vector{Pose2d(0_m, 0_m, Rotation2d(0_deg)), - Pose2d(1_m, 0_m, Rotation2d(180_deg))}, + std::vector{Pose2d{0_m, 0_m, 0_deg}, Pose2d{1_m, 0_m, 180_deg}}, TrajectoryConfig(12_fps, 12_fps_sq)); ASSERT_EQ(t.States().size(), 1u); diff --git a/wpimath/src/test/native/cpp/trajectory/TrajectoryTransformTest.cpp b/wpimath/src/test/native/cpp/trajectory/TrajectoryTransformTest.cpp index 0c6e07a0db..5c77a5b6df 100644 --- a/wpimath/src/test/native/cpp/trajectory/TrajectoryTransformTest.cpp +++ b/wpimath/src/test/native/cpp/trajectory/TrajectoryTransformTest.cpp @@ -31,11 +31,9 @@ void TestSameShapedTrajectory(std::vector statesA, TEST(TrajectoryTransformsTest, TransformBy) { frc::TrajectoryConfig config{3_mps, 3_mps_sq}; auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory( - frc::Pose2d{}, {}, frc::Pose2d{1_m, 1_m, frc::Rotation2d(90_deg)}, - config); + frc::Pose2d{}, {}, frc::Pose2d{1_m, 1_m, 90_deg}, config); - auto transformedTrajectory = - trajectory.TransformBy({{1_m, 2_m}, frc::Rotation2d(30_deg)}); + auto transformedTrajectory = trajectory.TransformBy({{1_m, 2_m}, 30_deg}); auto firstPose = transformedTrajectory.Sample(0_s).pose; @@ -49,11 +47,9 @@ TEST(TrajectoryTransformsTest, TransformBy) { TEST(TrajectoryTransformsTest, RelativeTo) { frc::TrajectoryConfig config{3_mps, 3_mps_sq}; auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory( - frc::Pose2d{1_m, 2_m, frc::Rotation2d(30_deg)}, {}, - frc::Pose2d{5_m, 7_m, frc::Rotation2d(90_deg)}, config); + frc::Pose2d{1_m, 2_m, 30_deg}, {}, frc::Pose2d{5_m, 7_m, 90_deg}, config); - auto transformedTrajectory = - trajectory.RelativeTo({1_m, 2_m, frc::Rotation2d(30_deg)}); + auto transformedTrajectory = trajectory.RelativeTo({1_m, 2_m, 30_deg}); auto firstPose = transformedTrajectory.Sample(0_s).pose; diff --git a/wpimath/src/test/native/include/trajectory/TestTrajectory.h b/wpimath/src/test/native/include/trajectory/TestTrajectory.h index de7b8b875a..89e735cf44 100644 --- a/wpimath/src/test/native/include/trajectory/TestTrajectory.h +++ b/wpimath/src/test/native/include/trajectory/TestTrajectory.h @@ -17,16 +17,15 @@ class TestTrajectory { public: static Trajectory GetTrajectory(TrajectoryConfig& config) { // 2018 cross scale auto waypoints - const Pose2d sideStart{1.54_ft, 23.23_ft, Rotation2d(180_deg)}; - const Pose2d crossScale{23.7_ft, 6.8_ft, Rotation2d(-160_deg)}; + const Pose2d sideStart{1.54_ft, 23.23_ft, 180_deg}; + const Pose2d crossScale{23.7_ft, 6.8_ft, -160_deg}; config.SetReversed(true); auto vector = std::vector{ - (sideStart + Transform2d{Translation2d(-13_ft, 0_ft), Rotation2d()}) + (sideStart + Transform2d{Translation2d{-13_ft, 0_ft}, 0_deg}) .Translation(), - (sideStart + - Transform2d{Translation2d(-19.5_ft, 5.0_ft), Rotation2d(-90_deg)}) + (sideStart + Transform2d{Translation2d{-19.5_ft, 5.0_ft}, -90_deg}) .Translation()}; return TrajectoryGenerator::GenerateTrajectory(sideStart, vector,