diff --git a/src/main/include/RobotMap.h b/src/main/include/RobotMap.h index bb2fc0c8..20869d3c 100644 --- a/src/main/include/RobotMap.h +++ b/src/main/include/RobotMap.h @@ -65,10 +65,10 @@ struct RobotMap { // front left module frc::Translation2d(10.761_in, 9.455_in), wom::Gearbox{ - new wom::VoltageController(driveMotors[0]), + driveMotors[0], new wom::TalonFXEncoder(driveMotors[0], 0.0445_m, 6.75), frc::DCMotor::Falcon500(1).WithReduction(6.75)}, - wom::Gearbox{new wom::VoltageController(turnMotors[0]), + wom::Gearbox{turnMotors[0], new wom::CanEncoder(19, 0.0445_m, 4096, 12.8), frc::DCMotor::Falcon500(1).WithReduction(12.8)}, &frontLeftCancoder, 4_in / 2}, @@ -76,10 +76,10 @@ struct RobotMap { // front right module frc::Translation2d(10.761_in, -9.455_in), wom::Gearbox{ - new wom::VoltageController(driveMotors[1]), + driveMotors[1], new wom::TalonFXEncoder(driveMotors[1], 0.0445_m, 6.75), frc::DCMotor::Falcon500(1).WithReduction(6.75)}, - wom::Gearbox{new wom::VoltageController(turnMotors[1]), + wom::Gearbox{turnMotors[1], new wom::CanEncoder(17, 0.0445_m, 4096, 12.8), frc::DCMotor::Falcon500(1).WithReduction(12.8)}, &frontRightCancoder, 4_in / 2}, @@ -87,10 +87,10 @@ struct RobotMap { // back left module frc::Translation2d(-10.761_in, 9.455_in), wom::Gearbox{ - new wom::VoltageController(driveMotors[2]), + driveMotors[2], new wom::TalonFXEncoder(driveMotors[2], 0.0445_m, 6.75), frc::DCMotor::Falcon500(1).WithReduction(6.75)}, - wom::Gearbox{new wom::VoltageController(turnMotors[2]), + wom::Gearbox{turnMotors[2], new wom::CanEncoder(16, 0.0445_m, 4096, 12.8), frc::DCMotor::Falcon500(1).WithReduction(12.8)}, &backRightCancoder, 4_in / 2}, @@ -98,10 +98,10 @@ struct RobotMap { // back right module frc::Translation2d(-10.761_in, -9.455_in), wom::Gearbox{ - new wom::VoltageController(driveMotors[3]), + driveMotors[3], new wom::TalonFXEncoder(driveMotors[3], 0.0445_m, 6.75), frc::DCMotor::Falcon500(1).WithReduction(6.75)}, - wom::Gearbox{new wom::VoltageController(turnMotors[3]), + wom::Gearbox{turnMotors[3], new wom::CanEncoder(18, 0.0445_m, 4096, 12.8), frc::DCMotor::Falcon500(1).WithReduction(12.8)}, &backLeftCancoder, 4_in / 2}, diff --git a/wombat/src/main/cpp/drivetrain/Drivetrain.cpp b/wombat/src/main/cpp/drivetrain/Drivetrain.cpp index 9345c3cf..96d14602 100644 --- a/wombat/src/main/cpp/drivetrain/Drivetrain.cpp +++ b/wombat/src/main/cpp/drivetrain/Drivetrain.cpp @@ -38,12 +38,12 @@ void wom::drivetrain::Drivetrain::OnUpdate(second_t dt) { case DrivetrainState::kTank: { double rightSpeed = wom::utils::deadzone(_driver.GetRightY()); double leftSpeed = wom::utils::deadzone(_driver.GetLeftY()); - _config->left1.transmission->SetVoltage(leftSpeed * maxVolts); - _config->left2.transmission->SetVoltage(leftSpeed * maxVolts); - _config->left3.transmission->SetVoltage(leftSpeed * maxVolts); - _config->right1.transmission->SetVoltage(rightSpeed * maxVolts); - _config->right2.transmission->SetVoltage(rightSpeed * maxVolts); - _config->right3.transmission->SetVoltage(rightSpeed * maxVolts); + _config->left1.motorController->SetVoltage(leftSpeed * maxVolts); + _config->left2.motorController->SetVoltage(leftSpeed * maxVolts); + _config->left3.motorController->SetVoltage(leftSpeed * maxVolts); + _config->right1.motorController->SetVoltage(rightSpeed * maxVolts); + _config->right2.motorController->SetVoltage(rightSpeed * maxVolts); + _config->right3.motorController->SetVoltage(rightSpeed * maxVolts); break; } case DrivetrainState::kAuto: diff --git a/wombat/src/main/cpp/drivetrain/SwerveDrive.cpp b/wombat/src/main/cpp/drivetrain/SwerveDrive.cpp index 4811baab..5db6a5c6 100644 --- a/wombat/src/main/cpp/drivetrain/SwerveDrive.cpp +++ b/wombat/src/main/cpp/drivetrain/SwerveDrive.cpp @@ -81,8 +81,8 @@ void SwerveModule::OnUpdate(units::second_t dt) { // turnVoltage = units::math::min(units::math::max(turnVoltage, -7_V), 7_V); // std::cout << "turn-voltage-max: " << turnVoltageMax.value() << std::endl; - _config.driveMotor.transmission->SetVoltage(driveVoltage); - _config.turnMotor.transmission->SetVoltage(turnVoltage); + _config.driveMotor.motorController->SetVoltage(driveVoltage); + _config.turnMotor.motorController->SetVoltage(turnVoltage); _table->GetEntry("speed").SetDouble(GetSpeed().value()); _table->GetEntry("angle").SetDouble( diff --git a/wombat/src/main/cpp/subsystems/Arm.cpp b/wombat/src/main/cpp/subsystems/Arm.cpp index d7be70e1..729b4671 100644 --- a/wombat/src/main/cpp/subsystems/Arm.cpp +++ b/wombat/src/main/cpp/subsystems/Arm.cpp @@ -88,8 +88,8 @@ void wom::subsystems::Arm::OnUpdate(units::second_t dt) { // std::cout << "voltage: " << voltage.value() << std::endl; - _config.leftGearbox.transmission->SetVoltage(voltage); - _config.rightGearbox.transmission->SetVoltage(voltage); + _config.leftGearbox.motorController->SetVoltage(voltage); + _config.rightGearbox.motorController->SetVoltage(voltage); // creates network table instances for the angle and config of the arm _table->GetEntry("angle").SetDouble(angle.convert().value()); diff --git a/wombat/src/main/cpp/subsystems/Elevator.cpp b/wombat/src/main/cpp/subsystems/Elevator.cpp index f655ce55..98e1b35f 100644 --- a/wombat/src/main/cpp/subsystems/Elevator.cpp +++ b/wombat/src/main/cpp/subsystems/Elevator.cpp @@ -87,8 +87,8 @@ void wom::subsystems::Elevator::OnUpdate(units::second_t dt) { // Set voltage to motors... voltage *= speedLimit; - _config.leftGearbox.transmission->SetVoltage(voltage); - _config.rightGearbox.transmission->SetVoltage(voltage); + _config.leftGearbox.motorController->SetVoltage(voltage); + _config.rightGearbox.motorController->SetVoltage(voltage); } void wom::subsystems::Elevator::SetManual(units::volt_t voltage) { diff --git a/wombat/src/main/cpp/subsystems/Shooter.cpp b/wombat/src/main/cpp/subsystems/Shooter.cpp index 5955e815..18497e24 100644 --- a/wombat/src/main/cpp/subsystems/Shooter.cpp +++ b/wombat/src/main/cpp/subsystems/Shooter.cpp @@ -39,7 +39,7 @@ void wom::subsystems::Shooter::OnUpdate(units::second_t dt) { voltage = 1_V * std::min(voltage.value(), max_voltage_for_current_limit.value()); - _params.gearbox.transmission->SetVoltage(voltage); + _params.gearbox.motorController->SetVoltage(voltage); _table->GetEntry("output_volts").SetDouble(voltage.value()); _table->GetEntry("speed_rpm").SetDouble(currentSpeed.value()); diff --git a/wombat/src/main/cpp/utils/Util.cpp b/wombat/src/main/cpp/utils/Util.cpp index a7be9a00..e529e245 100644 --- a/wombat/src/main/cpp/utils/Util.cpp +++ b/wombat/src/main/cpp/utils/Util.cpp @@ -6,6 +6,8 @@ #include +#include "units/voltage.h" + units::second_t wom::utils::now() { uint64_t now = frc::RobotController::GetFPGATime(); return static_cast(now) / 1000000 * 1_s; @@ -44,6 +46,10 @@ units::volt_t wom::utils::LimitVoltage(units::volt_t voltage) { return voltage; } +units::volt_t wom::utils::GetVoltage(frc::MotorController* controller) { + return controller->Get() * frc::RobotController::GetBatteryVoltage(); +} + void wom::utils::WriteTrajectory(std::shared_ptr table, frc::Trajectory trajectory) { table->GetEntry("length").SetDouble(trajectory.TotalTime().value()); diff --git a/wombat/src/main/cpp/utils/VoltageController.cpp b/wombat/src/main/cpp/utils/VoltageController.cpp deleted file mode 100644 index adac944d..00000000 --- a/wombat/src/main/cpp/utils/VoltageController.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2023-2024 CurtinFRC -// Open Source Software, you can modify it according to the terms -// of the MIT License at the root of this project - -#include "utils/VoltageController.h" - -#include - -units::volt_t wom::utils::VoltageController::GetEstimatedRealVoltage() const { - units::volt_t vb = frc::RobotController::GetBatteryVoltage(); - return units::math::min(units::math::max(-vb, GetVoltage()), vb); -} - -wom::utils::VoltageController::VoltageController( - frc::MotorController* MotorController) - : _MotorController(MotorController) {} - -void wom::utils::VoltageController::SetVoltage(units::volt_t voltage) { - _MotorController->Set(voltage / GetBusVoltage()); -} - -units::volt_t wom::utils::VoltageController::GetVoltage() const { - return _MotorController->Get() * GetBusVoltage(); -} - -units::volt_t wom::utils::VoltageController::GetBusVoltage() const { - return frc::RobotController::GetInputVoltage() * 1_V; -} - -void wom::utils::VoltageController::SetInverted(bool invert) { - _MotorController->SetInverted(invert); -} - -bool wom::utils::VoltageController::GetInverted() const { - return frc::RobotController::GetInputVoltage(); -} diff --git a/wombat/src/main/include/Wombat.h b/wombat/src/main/include/Wombat.h index f358564a..eef21a9d 100644 --- a/wombat/src/main/include/Wombat.h +++ b/wombat/src/main/include/Wombat.h @@ -18,7 +18,6 @@ #include "utils/PID.h" #include "utils/RobotStartup.h" #include "utils/Util.h" -#include "utils/VoltageController.h" namespace wom { using namespace wom; diff --git a/wombat/src/main/include/utils/Gearbox.h b/wombat/src/main/include/utils/Gearbox.h index e2472925..1872feeb 100644 --- a/wombat/src/main/include/utils/Gearbox.h +++ b/wombat/src/main/include/utils/Gearbox.h @@ -4,9 +4,9 @@ #pragma once +#include #include -#include "VoltageController.h" #include "utils/Encoder.h" namespace wom { @@ -19,9 +19,9 @@ namespace utils { */ struct Gearbox { /** - * The VoltageController (Motor Controller). May not be null. + * The MotorController. May not be null. */ - VoltageController* transmission; + frc::MotorController* motorController; /** * The Encoder. May be null, depending on the consumer of this structure. @@ -29,9 +29,9 @@ struct Gearbox { Encoder* encoder = nullptr; /** - * The motor being used. By default, this is a dual CIM. + * The motor being used. By default, this is a single Neo. */ - frc::DCMotor motor = frc::DCMotor::CIM(2); + frc::DCMotor motor = frc::DCMotor::NEO(1); }; } // namespace utils } // namespace wom diff --git a/wombat/src/main/include/utils/Util.h b/wombat/src/main/include/utils/Util.h index 2399109e..665c85ec 100644 --- a/wombat/src/main/include/utils/Util.h +++ b/wombat/src/main/include/utils/Util.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include #include @@ -106,5 +105,6 @@ double deadzone(double val, double deadzone = 0.05); double spow2(double val); units::volt_t LimitVoltage(units::volt_t voltage); +units::volt_t GetVoltage(frc::MotorController* controller); } // namespace utils } // namespace wom diff --git a/wombat/src/main/include/utils/VoltageController.h b/wombat/src/main/include/utils/VoltageController.h deleted file mode 100644 index 6f7e19fd..00000000 --- a/wombat/src/main/include/utils/VoltageController.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2023-2024 CurtinFRC -// Open Source Software, you can modify it according to the terms -// of the MIT License at the root of this project - -#pragma once - -#include -#include -#include - -namespace wom { -namespace utils { -/** - * A VoltageController is analagous to a MotorController, but in terms of - * voltage instead of speed. - */ -class VoltageController { - public: - explicit VoltageController(frc::MotorController* MotorController); - /** - * Set the voltage of the output. - */ - void SetVoltage(units::volt_t voltage); - /** - * Get the voltage of the output. - */ - units::volt_t GetVoltage() const; - - /** - * Set the output as inverted. - */ - void SetInverted(bool invert); - /** - * Get whether the output is inverted - */ - bool GetInverted() const; - - /** - * Get the estimated real voltage of the output, based on the controller - * voltage. - */ - units::volt_t GetEstimatedRealVoltage() const; - - units::volt_t GetBusVoltage() const; - - /** - * Create a VoltageController with a given frc::MotorController - * subclass. Please note that this creates an unsafe pointer (will never - * dealloc) - */ - template - static VoltageController Of(Args&... args) { - T* t = new T(args...); // Be warned, does not deallocate! - return VoltageController{t}; - } - - template - static VoltageController Group(Args&... args) { - return Of(args...); - } - - private: - frc::MotorController* _MotorController; -}; -} // namespace utils -} // namespace wom