Valkyrie 2026
Loading...
Searching...
No Matches
valor::WorldAlign Class Reference

A field-relative position controller utilizing Profiled PID loops for 3-axis robot alignment. More...

#include <valkyrie/WorldAlign.h>

Inheritance diagram for valor::WorldAlign:
valor::Loggable valor::WorldAlignCommand

Public Types

using TranslationalPIDF_t = valor::PIDF<units::meter, units::meters_per_second>
using RotationalPIDF_t = valor::PIDF<units::radian, units::radians_per_second>

Public Member Functions

 WorldAlign ()
 Constructs a WorldAlign object.
void SetPID (TranslationalPIDF_t x, TranslationalPIDF_t y, RotationalPIDF_t rot)
 A convenience method to set the PID gains for all three controllers at once.
TranslationalPIDF_t GetXPID () const
 Gets the PID gains for the X-axis controller.
TranslationalPIDF_t GetYPID () const
 Gets the PID gains for the Y-axis controller.
RotationalPIDF_t GetRotationalPID () const
 Gets the PID gains for the rotation controller.
void ResetControllers (frc::Pose2d, frc::ChassisSpeeds)
 Resets all controllers with the current robot state. This synchronizes the controller's internal state with the actual robot position and velocity.
void SetGoal (frc::Pose2d goal, frc::ChassisSpeeds state)
 Sets the desired goal state for the alignment controllers.
void SetPositionTolerance (units::meter_t xTol, units::meter_t yTol, units::radian_t rotTol)
void SetVelocityTolerance (units::meters_per_second_t xTol, units::meters_per_second_t yTol, units::radians_per_second_t rotTol)
std::pair< frc::Pose2d, frc::ChassisSpeeds > GetGoal () const
 Gets the current goal.
std::pair< frc::Pose2d, frc::ChassisSpeeds > GetSetpoint () const
frc::ChassisSpeeds Calculate (frc::Pose2d pose, frc::ChassisSpeeds currentSpeeds)
 Calculates the required chassis speeds to reach the last set goal. This is an overload that uses the currently stored goal state.
constexpr bool AtGoal () const
constexpr bool AtSetpoint () const
ProfiledPIDController< units::meter, units::meters_per_second > & GetXController ()
ProfiledPIDController< units::meter, units::meters_per_second > & GetYController ()
ProfiledPIDController< units::radian, units::radians_per_second > & GetRotationalController ()
void LoggablePeriodic () override
 Periodic callback for logging updates.
Public Member Functions inherited from valor::Loggable
 Loggable (std::string_view name)
 Construct a Loggable that registers a top-level table name.
 Loggable (std::shared_ptr< nt::NetworkTable > table)
 Construct a Loggable that uses an existing NetworkTable.
 Loggable ()=default
 Default construct an uninitialized Loggable.
void LogChild (std::string_view name, Loggable *child)
 Register a child Loggable under a named subtree.
void LogChild (std::string_view name, wpi::Sendable *child)
 Register a child Sendable under a named subtree.
bool WriteLog (std::string_view field, bool data)
double WriteLog (std::string_view field, double data)
void WriteLog (std::string_view field, const std::vector< double > &data)
template<typename U>
requires units::traits::is_unit_t_v<U>
U WriteLog (std::string_view field, U data)
void WriteLog (std::string_view field, std::string_view data)
template<typename E>
requires std::is_enum_v<E>
void WriteLog (std::string_view field, E data)
template<typename T>
requires wpi::StructSerializable<T> && (!std::is_arithmetic_v<T>)
void WriteLog (std::string_view field, const T &data)
template<typename T>
requires wpi::StructSerializable<T> && (!std::is_arithmetic_v<T>)
void WriteLog (std::string_view field, const std::vector< T > &data)
bool ReadLog (std::string_view field, bool defaultValue)
double ReadLog (std::string_view field, double defaultValue)
template<typename U>
requires units::traits::is_unit_t_v<U>
U ReadLog (std::string_view field, U defaultValue)

Additional Inherited Members

Static Public Member Functions inherited from valor::Loggable
static constexpr Loggable & GetRoot ()
Protected Member Functions inherited from valor::Loggable
virtual void OnLoggingStart ()
 Hook invoked when logging is started for this object.

Detailed Description

A field-relative position controller utilizing Profiled PID loops for 3-axis robot alignment.

WorldAlign provides a high-level interface for driving a robot to a specific target pose (X, Y, and Rotation) within the world coordinate frame. It encapsulates three independent frc::ProfiledPIDController instances, allowing for smooth, trapezoidal motion-profiled movement towards a goal.

This class is designed to handle:

  • Field-Relative Control: All calculations and setpoints are handled in the world frame.
  • Motion Profiling: Uses velocity and acceleration constraints to ensure robot movements stay within physical limits.
  • Rotation Wrapping: Supports continuous input for the rotational axis to determine the shortest path between angles (e.g., -180 to 180 degrees).
  • Telemetry: Inherits from valor::Loggable to facilitate real-time monitoring of setpoints and controller states
Note
This controller expects field-relative frc::ChassisSpeeds and frc::Pose2d as inputs and returns field-relative frc::ChassisSpeeds as outputs

Constructor & Destructor Documentation

◆ WorldAlign()

valor::WorldAlign::WorldAlign ( )

Constructs a WorldAlign object.

This controller uses three independent ProfiledPIDControllers to align the robot to a target pose in the world coordinate frame (field-relative).

Parameters
xPIDFPIDF gains for the X-axis controller.
yPIDFPIDF gains for the Y-axis controller.
rotationalPIDFPIDF gains for the rotation controller.

Member Function Documentation

◆ Calculate()

frc::ChassisSpeeds valor::WorldAlign::Calculate ( frc::Pose2d pose,
frc::ChassisSpeeds currentSpeeds )

Calculates the required chassis speeds to reach the last set goal. This is an overload that uses the currently stored goal state.

Parameters
poseThe current pose of the robot in the world frame.
currentSpeedsThe current chassis speeds of the robot (must be field-relative).
Returns
The calculated field-relative chassis speeds.

◆ GetGoal()

std::pair< frc::Pose2d, frc::ChassisSpeeds > valor::WorldAlign::GetGoal ( ) const

Gets the current goal.

Returns
A pair containing the goal pose and the goal state vector, both in the world frame.

◆ GetRotationalPID()

RotationalPIDF_t valor::WorldAlign::GetRotationalPID ( ) const
inline

Gets the PID gains for the rotation controller.

Returns
The current PIDF values for rotation.

◆ GetXPID()

TranslationalPIDF_t valor::WorldAlign::GetXPID ( ) const
inline

Gets the PID gains for the X-axis controller.

Returns
The current PIDF values for the X-axis.

◆ GetYPID()

TranslationalPIDF_t valor::WorldAlign::GetYPID ( ) const
inline

Gets the PID gains for the Y-axis controller.

Returns
The current PIDF values for the Y-axis.

◆ LoggablePeriodic()

void valor::WorldAlign::LoggablePeriodic ( )
overridevirtual

Periodic callback for logging updates.

If a derived class needs to perform periodic updates to published values, override this method. It is intended to be called by the logging framework; this base class provides an empty implementation.

Reimplemented from valor::Loggable.

◆ ResetControllers()

void valor::WorldAlign::ResetControllers ( frc::Pose2d ,
frc::ChassisSpeeds  )

Resets all controllers with the current robot state. This synchronizes the controller's internal state with the actual robot position and velocity.

Parameters
poseThe current pose of the robot in the world frame.
velocityThe current chassis speeds of the robot (must be field-relative).

◆ SetGoal()

void valor::WorldAlign::SetGoal ( frc::Pose2d goal,
frc::ChassisSpeeds state )

Sets the desired goal state for the alignment controllers.

Parameters
goalThe target pose (position and rotation) in the world frame.
stateThe target state vector (final position and velocity) for each axis.

◆ SetPID()

void valor::WorldAlign::SetPID ( TranslationalPIDF_t x,
TranslationalPIDF_t y,
RotationalPIDF_t rot )

A convenience method to set the PID gains for all three controllers at once.

Parameters
xThe PIDF values for the X-axis controller.
yThe PIDF values for the Y-axis controller.
rotThe PIDF values for the rotation controller.

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