From b68fd9ec3014d965cabbd715cfeffe1b605d1354 Mon Sep 17 00:00:00 2001 From: prak132 Date: Wed, 15 Jan 2025 16:39:23 -0800 Subject: [PATCH] Added vertical arm control to algae pivot and fixed issues with vertical arm calculator --- .../robot/calculators/VerticalArmCalculator.cc | 13 +++++-------- .../robot/calculators/VerticalArmCalculator.h | 9 +-------- src/y2025/cpp/subsystems/hardware/algae_pivot.cc | 6 +++++- src/y2025/include/subsystems/SubsystemHelper.h | 8 ++++---- src/y2025/include/subsystems/hardware/algae_pivot.h | 3 +++ 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/frc846/cpp/frc846/robot/calculators/VerticalArmCalculator.cc b/src/frc846/cpp/frc846/robot/calculators/VerticalArmCalculator.cc index 52f9c6d..75c1c7a 100644 --- a/src/frc846/cpp/frc846/robot/calculators/VerticalArmCalculator.cc +++ b/src/frc846/cpp/frc846/robot/calculators/VerticalArmCalculator.cc @@ -6,16 +6,13 @@ namespace frc846::robot::calculators { -VerticalArmCalculator::VerticalArmCalculator(VerticalArmConfigs& configs) - : configs_(configs) { - setConstants(configs); -} +VerticalArmCalculator::VerticalArmCalculator() {} double VerticalArmCalculator::calculate(VerticalArmInputs inputs) { units::newton_meter_t gravity_torque = - configs_.arm_mass * configs_.center_of_mass * + constants_.arm_mass * constants_.center_of_mass * frc846::math::constants::physics::g * - units::math::cos(inputs.arm_position + configs_.offset_angle); + units::math::cos(inputs.arm_position + constants_.offset_angle); units::degree_t position_error = inputs.target_arm_position - inputs.arm_position; @@ -23,8 +20,8 @@ double VerticalArmCalculator::calculate(VerticalArmInputs inputs) { double duty_cycle = inputs.motor_gains.calculate(position_error.to(), 0.0, inputs.current_velocity.to(), gravity_torque.to()); - return std::max(std::min(duty_cycle, configs_.peak_output_forward), - configs_.peak_output_reverse); + return std::clamp(duty_cycle, constants_.peak_output_reverse, + constants_.peak_output_forward); } } // namespace frc846::robot::calculators \ No newline at end of file diff --git a/src/frc846/include/frc846/robot/calculators/VerticalArmCalculator.h b/src/frc846/include/frc846/robot/calculators/VerticalArmCalculator.h index 38fab9b..bc1587c 100644 --- a/src/frc846/include/frc846/robot/calculators/VerticalArmCalculator.h +++ b/src/frc846/include/frc846/robot/calculators/VerticalArmCalculator.h @@ -20,8 +20,6 @@ Contains all parameters necessary to construct a new Vertical Arm Calculator. @param arm_mass: The mass of the arm. @param center_of_mass: The distance from the pivot point to center of mass. @param offset_angle: The fixed angle offset relative to the horizontal axis. -@param max_pos: The maximum allowed position. -@param min_pos: The minimum allowed position. @param peak_output_forward: The maximum duty cycle for forward motion [0, 1] @param peak_output_reverse: The maximum duty cycle for reverse motion [-1, 0] */ @@ -29,8 +27,6 @@ struct VerticalArmConfigs { units::kilogram_t arm_mass; units::inch_t center_of_mass; units::degree_t offset_angle = 0.0_deg; - units::degree_t max_pos; - units::degree_t min_pos; double peak_output_forward = 1.0; double peak_output_reverse = -1.0; }; @@ -62,7 +58,7 @@ characteristics of an arm. class VerticalArmCalculator : public frc846::math::Calculator { public: - VerticalArmCalculator(VerticalArmConfigs& configs); + VerticalArmCalculator(); /* calculate() @@ -76,9 +72,6 @@ class VerticalArmCalculator : public frc846::math::Calculator motor_helper_; + frc846::robot::calculators::VerticalArmCalculator arm_calculator_; + AlgaePivotReadings ReadFromHardware() override; void WriteToHardware(AlgaePivotTarget target) override;