3#include <frc/DigitalInput.h>
4#include <frc/DutyCycleEncoder.h>
5#include <frc/controller/PIDController.h>
6#include <frc/smartdashboard/MechanismLigament2d.h>
7#include <frc/smartdashboard/MechanismRoot2d.h>
8#include <frc2/command/CommandPtr.h>
9#include <frc2/command/FunctionalCommand.h>
10#include <frc2/command/InstantCommand.h>
11#include <frc2/command/TrapezoidProfileSubsystem.h>
12#include <rev/CANSparkFlex.h>
13#include <rev/CANSparkMax.h>
14#include <rev/SparkMaxPIDController.h>
15#include <units/acceleration.h>
16#include <units/angle.h>
17#include <units/angular_acceleration.h>
18#include <units/angular_velocity.h>
19#include <units/length.h>
20#include <units/velocity.h>
43template <
typename TController,
typename TDistance>
46 public frc2::TrapezoidProfileSubsystem<TDistance> {
48 using PidState =
typename frc::TrapezoidProfile<TDistance>::State;
51 units::compound_unit<TDistance, units::inverse<units::seconds>>;
54 units::compound_unit<Velocity, units::inverse<units::seconds>>;
64 std::string name, TController &controller,
66 frc::MechanismObject2d *mechanismNode =
nullptr);
76 bool ignoreEncoder =
false) = 0;
87 bool ignoreEncoder =
false)
override;
115 frc2::CommandPtr
Home()
override;
118 return frc2::InstantCommand([
this] {
ResetEncoder(); }).ToPtr();
The ultimate solution for turrets, arms, and much more. This class allows for absolute,...
Distance_t GetCurrentPosition() override
Get the current position in terms of converted distance.
std::optional< frc::DigitalInput * > m_minLimitSwitch
virtual void RunMotorVelocity(Velocity_t speed, bool ignoreEncoder=false)=0
Run at the given velocity; disables any in-progress absolute movements.
void Periodic() override
Runs the absolute positioning task and updates relevant info on SmartDashboard.
void EnablePid() override
Enable absolute movements.
Distance_t m_goalPosition
void UseState(PidState setpoint) override
bool AtMax() override
Check if axis is at the maximum extent of motion.
frc::MechanismLigament2d * m_ligament2d
typename frc::TrapezoidProfile< TDistance >::State PidState
frc2::CommandPtr MoveToPositionRelative(Distance_t position) override
Start moving to the position given the current distance and relative position.
bool IsMovementAllowed(double speed, bool ignoreEncoder=false)
void Stop() override
Stop the axis.
bool AtHome() override
Check if axis is at the mimimum extent of motion.
frc2::CommandPtr Home() override
Start the homing sequence.
ISingleAxisSubsystem< TDistance >::SingleAxisConfig m_config
units::unit_t< Velocity > Velocity_t
units::compound_unit< Velocity, units::inverse< units::seconds > > Acceleration
frc2::CommandPtr m_resetEncCmd
frc2::CommandPtr MoveToPositionAbsolute(Distance_t position) override
Start moving to the absolute position.
void RunMotorPercentage(double percentSpeed, bool ignoreEncoder=false) override
Run at the given velocity percentage; disables any in-progress absolute movements.
frc::MechanismLigament2d * GetLigament()
units::unit_t< TDistance > Distance_t
bool AtLimitSwitchMin() override
Only check the limit switch for mimimum extent.
BaseSingleAxisSubsystem(std::string name, TController &controller, ISingleAxisSubsystem< TDistance >::SingleAxisConfig config, frc::MechanismObject2d *mechanismNode=nullptr)
std::optional< frc::DigitalInput * > m_maxLimitSwitch
void RunMotorSpeedDefault(bool ignoreEncoder=false) override
Run at the default motor speed.
void OnInit()
This must be called once upon robot startup.
units::unit_t< Acceleration > Acceleration_t
units::compound_unit< TDistance, units::inverse< units::seconds > > Velocity
void ResetEncoder() override
Reset encoder back to 0 ticks.
bool IsEnabled() override
Check if absolute positioning is active.
bool IsMovementAllowed(bool ignoreEncoder=false)
bool AtLimitSwitchMax() override
Only check the limit switch for maximum extent.
TController & m_controller
void DisablePid() override
Stop and disable any in-progress absolute movements.
frc2::CommandPtr ResetRelativeEncoder()
The configuration for single-axis mechanisms.