SubZero Common
Common library components for an FRC CommandRobot
Loading...
Searching...
No Matches
subzero::BaseSingleAxisSubsystem< TController, TDistance > Class Template Referenceabstract

The ultimate solution for turrets, arms, and much more. This class allows for absolute, relative, and joystick control across both linear and rotational axes. Even better, it checks motion limits, outputs real-time stats via SmartDashboard, and allows for out-of-the-box simulations via Mechanism2d. More...

#include <BaseSingleAxisSubsystem.h>

+ Inheritance diagram for subzero::BaseSingleAxisSubsystem< TController, TDistance >:
+ Collaboration diagram for subzero::BaseSingleAxisSubsystem< TController, TDistance >:

Public Types

using PidState = typename frc::TrapezoidProfile<TDistance>::State
 
using Distance_t = units::unit_t<TDistance>
 
using Velocity
 
using Velocity_t = units::unit_t<Velocity>
 
using Acceleration
 
using Acceleration_t = units::unit_t<Acceleration>
 
- Public Types inherited from subzero::ISingleAxisSubsystem< TDistance >
using Distance_t
 
using Velocity
 
using Velocity_t
 
using Acceleration
 
using Acceleration_t
 

Public Member Functions

 BaseSingleAxisSubsystem (std::string name, TController &controller, ISingleAxisSubsystem< TDistance >::SingleAxisConfig config, frc::MechanismObject2d *mechanismNode=nullptr)
 
void Periodic () override
 Runs the absolute positioning task and updates relevant info on SmartDashboard.
 
virtual void RunMotorVelocity (Velocity_t speed, bool ignoreEncoder=false)=0
 Run at the given velocity; disables any in-progress absolute movements.
 
void UseState (PidState setpoint) override
 
void RunMotorSpeedDefault (bool ignoreEncoder=false) override
 Run at the default motor speed.
 
void RunMotorPercentage (double percentSpeed, bool ignoreEncoder=false) override
 Run at the given velocity percentage; disables any in-progress absolute movements.
 
Distance_t GetCurrentPosition () override
 Get the current position in terms of converted distance.
 
void Stop () override
 Stop the axis.
 
void ResetEncoder () override
 Reset encoder back to 0 ticks.
 
bool AtHome () override
 Check if axis is at the mimimum extent of motion.
 
bool AtMax () override
 Check if axis is at the maximum extent of motion.
 
bool AtLimitSwitchMin () override
 Only check the limit switch for mimimum extent.
 
bool AtLimitSwitchMax () override
 Only check the limit switch for maximum extent.
 
frc2::CommandPtr MoveToPositionAbsolute (Distance_t position) override
 Start moving to the absolute position.
 
frc2::CommandPtr MoveToPositionRelative (Distance_t position) override
 Start moving to the position given the current distance and relative position.
 
frc2::CommandPtr Home () override
 Start the homing sequence.
 
frc2::CommandPtr ResetRelativeEncoder ()
 
frc::MechanismLigament2d * GetLigament ()
 
bool IsEnabled () override
 Check if absolute positioning is active.
 
void DisablePid () override
 Stop and disable any in-progress absolute movements.
 
void EnablePid () override
 Enable absolute movements.
 
void OnInit ()
 This must be called once upon robot startup.
 

Protected Member Functions

bool IsMovementAllowed (double speed, bool ignoreEncoder=false)
 
bool IsMovementAllowed (bool ignoreEncoder=false)
 

Protected Attributes

std::optional< frc::DigitalInput * > m_minLimitSwitch
 
std::optional< frc::DigitalInput * > m_maxLimitSwitch
 
TController & m_controller
 
ISingleAxisSubsystem< TDistance >::SingleAxisConfig m_config
 
std::string m_name
 
Distance_t m_goalPosition
 
bool m_pidEnabled
 
bool m_home
 
bool resetOccurred = false
 
double m_latestSpeed
 
frc2::CommandPtr m_resetEncCmd = EmptyCommand().ToPtr()
 
frc::MechanismLigament2d * m_ligament2d
 

Detailed Description

template<typename TController, typename TDistance>
class subzero::BaseSingleAxisSubsystem< TController, TDistance >

The ultimate solution for turrets, arms, and much more. This class allows for absolute, relative, and joystick control across both linear and rotational axes. Even better, it checks motion limits, outputs real-time stats via SmartDashboard, and allows for out-of-the-box simulations via Mechanism2d.

Template Parameters
TControllerPidMotorController
TDistanceDistance unit

Definition at line 44 of file BaseSingleAxisSubsystem.h.

Member Typedef Documentation

◆ Acceleration

template<typename TController , typename TDistance >
using subzero::BaseSingleAxisSubsystem< TController, TDistance >::Acceleration
Initial value:
units::compound_unit<Velocity, units::inverse<units::seconds>>

Definition at line 53 of file BaseSingleAxisSubsystem.h.

◆ Acceleration_t

template<typename TController , typename TDistance >
using subzero::BaseSingleAxisSubsystem< TController, TDistance >::Acceleration_t = units::unit_t<Acceleration>

Definition at line 55 of file BaseSingleAxisSubsystem.h.

◆ Distance_t

template<typename TController , typename TDistance >
using subzero::BaseSingleAxisSubsystem< TController, TDistance >::Distance_t = units::unit_t<TDistance>

Definition at line 49 of file BaseSingleAxisSubsystem.h.

◆ PidState

template<typename TController , typename TDistance >
using subzero::BaseSingleAxisSubsystem< TController, TDistance >::PidState = typename frc::TrapezoidProfile<TDistance>::State

Definition at line 48 of file BaseSingleAxisSubsystem.h.

◆ Velocity

template<typename TController , typename TDistance >
using subzero::BaseSingleAxisSubsystem< TController, TDistance >::Velocity
Initial value:
units::compound_unit<TDistance, units::inverse<units::seconds>>

Definition at line 50 of file BaseSingleAxisSubsystem.h.

◆ Velocity_t

template<typename TController , typename TDistance >
using subzero::BaseSingleAxisSubsystem< TController, TDistance >::Velocity_t = units::unit_t<Velocity>

Definition at line 52 of file BaseSingleAxisSubsystem.h.

Constructor & Destructor Documentation

◆ BaseSingleAxisSubsystem()

template<typename TController , typename TDistance >
subzero::BaseSingleAxisSubsystem< TController, TDistance >::BaseSingleAxisSubsystem ( std::string name,
TController & controller,
ISingleAxisSubsystem< TDistance >::SingleAxisConfig config,
frc::MechanismObject2d * mechanismNode = nullptr )

Member Function Documentation

◆ AtHome()

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::AtHome ( )
inlineoverridevirtual

Check if axis is at the mimimum extent of motion.

Returns
true
false

Implements subzero::ISingleAxisSubsystem< TDistance >.

Definition at line 97 of file BaseSingleAxisSubsystem.h.

◆ AtLimitSwitchMax()

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::AtLimitSwitchMax ( )
overridevirtual

Only check the limit switch for maximum extent.

Returns
true
false

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ AtLimitSwitchMin()

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::AtLimitSwitchMin ( )
overridevirtual

Only check the limit switch for mimimum extent.

Returns
true
false

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ AtMax()

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::AtMax ( )
inlineoverridevirtual

Check if axis is at the maximum extent of motion.

Returns
true
false

Implements subzero::ISingleAxisSubsystem< TDistance >.

Definition at line 101 of file BaseSingleAxisSubsystem.h.

◆ DisablePid()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::DisablePid ( )
overridevirtual

Stop and disable any in-progress absolute movements.

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ EnablePid()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::EnablePid ( )
overridevirtual

Enable absolute movements.

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ GetCurrentPosition()

template<typename TController , typename TDistance >
Distance_t subzero::BaseSingleAxisSubsystem< TController, TDistance >::GetCurrentPosition ( )
inlineoverridevirtual

Get the current position in terms of converted distance.

Returns
Distance_t

Implements subzero::ISingleAxisSubsystem< TDistance >.

Definition at line 89 of file BaseSingleAxisSubsystem.h.

◆ GetLigament()

template<typename TController , typename TDistance >
frc::MechanismLigament2d * subzero::BaseSingleAxisSubsystem< TController, TDistance >::GetLigament ( )
inline

Definition at line 121 of file BaseSingleAxisSubsystem.h.

◆ Home()

template<typename TController , typename TDistance >
frc2::CommandPtr subzero::BaseSingleAxisSubsystem< TController, TDistance >::Home ( )
overridevirtual

Start the homing sequence.

Returns
frc2::CommandPtr

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ IsEnabled()

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::IsEnabled ( )
inlineoverridevirtual

Check if absolute positioning is active.

Returns
true
false

Implements subzero::ISingleAxisSubsystem< TDistance >.

Definition at line 123 of file BaseSingleAxisSubsystem.h.

◆ IsMovementAllowed() [1/2]

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::IsMovementAllowed ( bool ignoreEncoder = false)
protected

◆ IsMovementAllowed() [2/2]

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::IsMovementAllowed ( double speed,
bool ignoreEncoder = false )
protected

◆ MoveToPositionAbsolute()

template<typename TController , typename TDistance >
frc2::CommandPtr subzero::BaseSingleAxisSubsystem< TController, TDistance >::MoveToPositionAbsolute ( Distance_t position)
overridevirtual

Start moving to the absolute position.

Parameters
position
Returns
frc2::CommandPtr

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ MoveToPositionRelative()

template<typename TController , typename TDistance >
frc2::CommandPtr subzero::BaseSingleAxisSubsystem< TController, TDistance >::MoveToPositionRelative ( Distance_t position)
inlineoverridevirtual

Start moving to the position given the current distance and relative position.

Parameters
position
Returns
frc2::CommandPtr

Implements subzero::ISingleAxisSubsystem< TDistance >.

Definition at line 111 of file BaseSingleAxisSubsystem.h.

◆ OnInit()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::OnInit ( )

This must be called once upon robot startup.

◆ Periodic()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::Periodic ( )
override

Runs the absolute positioning task and updates relevant info on SmartDashboard.

◆ ResetEncoder()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::ResetEncoder ( )
overridevirtual

Reset encoder back to 0 ticks.

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ ResetRelativeEncoder()

template<typename TController , typename TDistance >
frc2::CommandPtr subzero::BaseSingleAxisSubsystem< TController, TDistance >::ResetRelativeEncoder ( )
inline

Definition at line 117 of file BaseSingleAxisSubsystem.h.

◆ RunMotorPercentage()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::RunMotorPercentage ( double percentSpeed,
bool ignoreEncoder = false )
overridevirtual

Run at the given velocity percentage; disables any in-progress absolute movements.

Parameters
speed
ignoreEncoder

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ RunMotorSpeedDefault()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::RunMotorSpeedDefault ( bool ignoreEncoder = false)
inlineoverridevirtual

Run at the default motor speed.

Parameters
ignoreEncoder

Implements subzero::ISingleAxisSubsystem< TDistance >.

Definition at line 82 of file BaseSingleAxisSubsystem.h.

◆ RunMotorVelocity()

template<typename TController , typename TDistance >
virtual void subzero::BaseSingleAxisSubsystem< TController, TDistance >::RunMotorVelocity ( Velocity_t speed,
bool ignoreEncoder = false )
pure virtual

Run at the given velocity; disables any in-progress absolute movements.

Parameters
speed
ignoreEncoder

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ Stop()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::Stop ( )
overridevirtual

Stop the axis.

Implements subzero::ISingleAxisSubsystem< TDistance >.

◆ UseState()

template<typename TController , typename TDistance >
void subzero::BaseSingleAxisSubsystem< TController, TDistance >::UseState ( PidState setpoint)
inlineoverride

Definition at line 78 of file BaseSingleAxisSubsystem.h.

Member Data Documentation

◆ m_config

template<typename TController , typename TDistance >
ISingleAxisSubsystem<TDistance>::SingleAxisConfig subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_config
protected

Definition at line 139 of file BaseSingleAxisSubsystem.h.

◆ m_controller

template<typename TController , typename TDistance >
TController& subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_controller
protected

Definition at line 138 of file BaseSingleAxisSubsystem.h.

◆ m_goalPosition

template<typename TController , typename TDistance >
Distance_t subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_goalPosition
protected

Definition at line 141 of file BaseSingleAxisSubsystem.h.

◆ m_home

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_home
protected

Definition at line 143 of file BaseSingleAxisSubsystem.h.

◆ m_latestSpeed

template<typename TController , typename TDistance >
double subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_latestSpeed
protected

Definition at line 145 of file BaseSingleAxisSubsystem.h.

◆ m_ligament2d

template<typename TController , typename TDistance >
frc::MechanismLigament2d* subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_ligament2d
protected

Definition at line 147 of file BaseSingleAxisSubsystem.h.

◆ m_maxLimitSwitch

template<typename TController , typename TDistance >
std::optional<frc::DigitalInput *> subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_maxLimitSwitch
protected

Definition at line 137 of file BaseSingleAxisSubsystem.h.

◆ m_minLimitSwitch

template<typename TController , typename TDistance >
std::optional<frc::DigitalInput *> subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_minLimitSwitch
protected

Definition at line 136 of file BaseSingleAxisSubsystem.h.

◆ m_name

template<typename TController , typename TDistance >
std::string subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_name
protected

Definition at line 140 of file BaseSingleAxisSubsystem.h.

◆ m_pidEnabled

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_pidEnabled
protected

Definition at line 142 of file BaseSingleAxisSubsystem.h.

◆ m_resetEncCmd

template<typename TController , typename TDistance >
frc2::CommandPtr subzero::BaseSingleAxisSubsystem< TController, TDistance >::m_resetEncCmd = EmptyCommand().ToPtr()
protected

Definition at line 146 of file BaseSingleAxisSubsystem.h.

◆ resetOccurred

template<typename TController , typename TDistance >
bool subzero::BaseSingleAxisSubsystem< TController, TDistance >::resetOccurred = false
protected

Definition at line 144 of file BaseSingleAxisSubsystem.h.


The documentation for this class was generated from the following file: