-
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.
Added algae pivot subsystem and updated files paths to remove redunda…
…nt included files
- Loading branch information
Showing
6 changed files
with
126 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#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/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("elevator/elevator_softlimits/using_limits"); | ||
// double reduce_max_dc = | ||
// GetPreferenceValue_double("elevator/elevator_softlimits/reduce_max_dc"); | ||
|
||
motor_helper_.SetConversion(algae_pivot_reduction_); | ||
|
||
// 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 elevator motor"); | ||
return ok; | ||
} | ||
|
||
AlgaePivotReadings AlgaePivotSubsystem::ReadFromHardware() { | ||
AlgaePivotReadings readings; | ||
readings.position = motor_helper_.GetPosition(); | ||
Graph("algae_pivot/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_.WritePosition(target.position); | ||
} |
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
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,56 @@ | ||
#pragma once | ||
|
||
#include <units/math.h> | ||
|
||
#include "frc846/base/Loggable.h" | ||
#include "frc846/control/HMCHelper.h" | ||
#include "frc846/control/HigherMotorController.h" | ||
#include "frc846/control/base/motor_control_base.h" | ||
#include "frc846/control/config/construction_params.h" | ||
#include "frc846/robot/GenericSubsystem.h" | ||
#include "frc846/wpilib/units.h" | ||
#include "ports.h" | ||
|
||
struct AlgaePivotReadings { | ||
units::degree_t position; | ||
}; | ||
|
||
struct AlgaePivotTarget { | ||
units::degree_t position; | ||
}; | ||
|
||
using elevator_pos_conv_t = units::unit_t< | ||
units::compound_unit<units::degree, units::inverse<units::turn>>>; | ||
|
||
class AlgaePivotSubsystem | ||
: public frc846::robot::GenericSubsystem<AlgaePivotReadings, | ||
AlgaePivotTarget> { | ||
public: | ||
AlgaePivotSubsystem(); | ||
|
||
void Setup() override; | ||
|
||
AlgaePivotTarget ZeroTarget() const override; | ||
|
||
bool VerifyHardware() override; | ||
|
||
bool WithinTolerance(units::degree_t pos) { | ||
return units::math::abs(pos - GetReadings().position) < | ||
GetPreferenceValue_unit_type<units::degree_t>( | ||
"algae_pivot_tolerance_"); | ||
} | ||
|
||
private: | ||
bool hasZeroed = false; | ||
|
||
// TODO: Set to correct reduction later | ||
elevator_pos_conv_t algae_pivot_reduction_ = 1.0_deg / 1.0_tr; | ||
|
||
frc846::control::config::MotorConstructionParameters motor_configs; | ||
frc846::control::HigherMotorController pivot_; | ||
frc846::control::HMCHelper<units::degree> motor_helper_; | ||
|
||
AlgaePivotReadings ReadFromHardware() override; | ||
|
||
void WriteToHardware(AlgaePivotTarget target) override; | ||
}; |
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