-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from Team846/elevator_subsystem
merging the subsystem code
- Loading branch information
Showing
17 changed files
with
250 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 5 additions & 10 deletions
15
src/frc846/cpp/frc846/robot/calculators/VerticalArmCalculator.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
#include "frc846/robot/calculators/VerticalArmCalculator.h" | ||
|
||
#include <units/angle.h> | ||
#include <units/angular_velocity.h> | ||
#include <units/math.h> | ||
|
||
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; | ||
|
||
double duty_cycle = inputs.motor_gains.calculate(position_error.to<double>(), | ||
0.0, inputs.current_velocity.to<double>(), gravity_torque.to<double>()); | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "subsystems/hardware/algae_pivot.h" | ||
|
||
#include "subsystems/SubsystemHelper.h" | ||
|
||
AlgaePivotSubsystem::AlgaePivotSubsystem() | ||
: frc846::robot::GenericSubsystem<AlgaePivotReadings, AlgaePivotTarget>( | ||
"algae_pivot"), | ||
motor_configs(GET_MOTOR_CONFIG("algae_pivot/algae_pivot_one_", | ||
ports::algae_pivot_::kAlgaePivotOne_CANID, | ||
frc846::wpilib::unit_ohm{0.0}, frc846::wpilib::unit_kg_m_sq{0.0})), | ||
pivot_(frc846::control::base::MotorMonkeyType::SPARK_MAX_VORTEX, | ||
motor_configs) { | ||
RegisterPreference("algae_pivot_tolerance_", 0.25_deg); | ||
|
||
REGISTER_MOTOR_CONFIG( | ||
"algae_pivot/algae_pivot_one_", false, true, 40_A, 40_A, 16.0_V); | ||
REGISTER_PIDF_CONFIG("algae_pivot/algae_pivot_gains_", 0.0, 0.0, 0.0, 0.0); | ||
REGISTER_SOFTLIMIT_CONFIG("algae_pivot/algae_pivot_softlimits", true, 1.0); | ||
|
||
// bool using_limits = | ||
// GetPreferenceValue_bool("algae_pivot/algae_pivot_softlimits/using_limits"); | ||
// double reduce_max_dc = | ||
// GetPreferenceValue_double("algae_pivot/algae_pivot_softlimits/reduce_max_dc"); | ||
|
||
motor_helper_.SetConversion(algae_pivot_reduction_); | ||
|
||
arm_calculator_.setConstants({20.0_kg, 3.0_in, 0.0_deg, -1.0, 1.0}); | ||
|
||
// motor_helper_.SetSoftLimits( | ||
// using_limits, 90_deg, 0.0_deg, 80_deg, 5_deg, reduce_max_dc); | ||
|
||
motor_helper_.bind(&pivot_); | ||
} | ||
|
||
void AlgaePivotSubsystem::Setup() { | ||
pivot_.Setup(); | ||
pivot_.EnableStatusFrames( | ||
{frc846::control::config::StatusFrame::kPositionFrame, | ||
frc846::control::config::StatusFrame::kVelocityFrame}); | ||
motor_helper_.SetPosition(0.0_deg); | ||
} | ||
|
||
AlgaePivotTarget AlgaePivotSubsystem::ZeroTarget() const { | ||
return AlgaePivotTarget{0.0_deg}; | ||
} | ||
|
||
bool AlgaePivotSubsystem::VerifyHardware() { | ||
bool ok = true; | ||
FRC846_VERIFY( | ||
pivot_.VerifyConnected(), ok, "Could not verify algae pivot motor"); | ||
return ok; | ||
} | ||
|
||
AlgaePivotReadings AlgaePivotSubsystem::ReadFromHardware() { | ||
AlgaePivotReadings readings; | ||
readings.position = motor_helper_.GetPosition(); | ||
Graph("readings/algae_pivot_position", readings.position); | ||
return readings; | ||
} | ||
|
||
void AlgaePivotSubsystem::WriteToHardware(AlgaePivotTarget target) { | ||
pivot_.SetGains(GET_PIDF_GAINS("algae_pivot/algae_pivot_gains_")); | ||
motor_helper_.WriteDC(arm_calculator_.calculate({motor_helper_.GetPosition(), | ||
target.position, motor_helper_.GetVelocity(), | ||
GET_PIDF_GAINS("algae_pivot/algae_pivot_gains_")})); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.