Valkyrie 2026
Loading...
Searching...
No Matches
WorldAlign.h
1#pragma once
2#include <utility>
3
4#include <frc/controller/PIDController.h>
5#include <frc/controller/ProfiledPIDController.h>
6#include <frc/geometry/Pose2d.h>
7#include <frc/geometry/Transform2d.h>
8#include <frc/kinematics/ChassisSpeeds.h>
9#include <frc/trajectory/TrapezoidProfile.h>
10#include <networktables/NetworkTableInstance.h>
11#include <networktables/StructTopic.h>
12#include <units/angle.h>
13#include <units/angular_velocity.h>
14#include <units/base.h>
15#include <units/length.h>
16#include <units/time.h>
17#include <units/velocity.h>
18
19#include "valkyrie/Loggable.h"
20#include "valkyrie/controllers/PIDF.h"
21
22namespace valor {
23
42 public:
45
59
60 WorldAlign(TranslationalPIDF_t xPIDF, TranslationalPIDF_t yPIDF, RotationalPIDF_t rotationalPIDF,
61 frc::TrapezoidProfile<units::meter>::Constraints xConstraints, frc::TrapezoidProfile<units::meter>::Constraints yConstraints,
62 frc::TrapezoidProfile<units::radian>::Constraints rotConstraints);
63
71 static frc::Pose2d OffsetGetter(frc::Pose2d, frc::Transform2d);
72
73 template <class Distance, class Velocity = units::compound_unit<Distance, units::inverse<units::seconds>>,
74 class Acceleration = units::compound_unit<Velocity, units::inverse<units::seconds>>>
76 units::unit_t<Distance> distance{0};
77 units::unit_t<Velocity> velocity{0};
78 units::unit_t<Acceleration> acceleration{0};
79 };
80
86
93 void SetPID(TranslationalPIDF_t x, TranslationalPIDF_t y, RotationalPIDF_t rot);
94
99 void SetXPID(TranslationalPIDF_t);
100
105 void SetYPID(TranslationalPIDF_t);
106
111 void SetRotationalPID(RotationalPIDF_t);
112
117 std::tuple<TranslationalPIDF_t, TranslationalPIDF_t, RotationalPIDF_t> GetPID();
118
123 TranslationalPIDF_t GetXPID();
124
129 TranslationalPIDF_t GetYPID();
130
135 RotationalPIDF_t GetRotationalPID();
136
143 void ResetControllers(frc::Pose2d, frc::ChassisSpeeds);
144
150 void ResetXController(units::meter_t, units::meters_per_second_t);
151
157 void ResetYController(units::meter_t, units::meters_per_second_t);
158
164 void ResetRotationalController(frc::Rotation2d, units::radians_per_second_t);
165
172 void SetConstraints(frc::TrapezoidProfile<units::meter>::Constraints x, frc::TrapezoidProfile<units::meter>::Constraints y,
173 frc::TrapezoidProfile<units::radian>::Constraints rot);
174
179 void SetXConstraints(frc::TrapezoidProfile<units::meter>::Constraints);
180
185 void SetYConstraints(frc::TrapezoidProfile<units::meter>::Constraints);
186
191 void SetRotationalConstraints(frc::TrapezoidProfile<units::radian>::Constraints);
192
200 void EnableContinuousRotation(bool enable = true, units::radian_t minimum = units::radian_t{-std::numbers::pi},
201 units::radian_t maximum = units::radian_t{std::numbers::pi});
202
207 frc::TrapezoidProfile<units::meter>::Constraints GetXConstraints();
208
213 frc::TrapezoidProfile<units::meter>::Constraints GetYConstraints();
214
219 frc::TrapezoidProfile<units::radian>::Constraints GetRotationalConstraints();
220
227 void SetGoal(frc::Pose2d goal, StateVector state, bool rotate);
228
233 std::pair<frc::Pose2d, StateVector> GetGoal();
234
242 frc::ChassisSpeeds Calculate(frc::Pose2d pose, frc::ChassisSpeeds currentSpeeds);
243
251 frc::ChassisSpeeds Calculate(frc::Pose2d pose, frc::ChassisSpeeds currentSpeeds, StateVector state);
252
253 void LoggablePeriodic() override;
254
255 private:
256 frc::ProfiledPIDController<units::meter> xController, yController;
257 frc::ProfiledPIDController<units::radian> rotationalController;
258
259 TranslationalPIDF_t xPIDF, yPIDF; // Store PIDF values to access kV
260 RotationalPIDF_t rotationalPIDF; // Store PIDF values to access kV
261
262 frc::Pose2d goalPosition, currPosition;
263 frc::ChassisSpeeds currSpeed;
264 StateVector goalState, setpointState;
265 double calculatedXVal, calculatedYVal;
266};
267
268} // namespace valor
Base helper for publishing and subscribing values to NetworkTables.
Definition Loggable.h:218
void SetRotationalConstraints(frc::TrapezoidProfile< units::radian >::Constraints)
Sets the motion constraints for the rotation controller.
void SetXPID(TranslationalPIDF_t)
Sets the PID gains for the X-axis controller.
void SetYPID(TranslationalPIDF_t)
Sets the PID gains for the Y-axis controller.
void EnableContinuousRotation(bool enable=true, units::radian_t minimum=units::radian_t{-std::numbers::pi}, units::radian_t maximum=units::radian_t{std::numbers::pi})
Enables or disables continuous input for the rotation controller. Continuous input is necessary for r...
void ResetRotationalController(frc::Rotation2d, units::radians_per_second_t)
Resets the rotation controller with a new angle and angular velocity.
WorldAlign(TranslationalPIDF_t xPIDF, TranslationalPIDF_t yPIDF, RotationalPIDF_t rotationalPIDF, frc::TrapezoidProfile< units::meter >::Constraints xConstraints, frc::TrapezoidProfile< units::meter >::Constraints yConstraints, frc::TrapezoidProfile< units::radian >::Constraints rotConstraints)
Constructs a WorldAlign object.
TranslationalPIDF_t GetYPID()
Gets the PID gains for the Y-axis controller.
std::pair< frc::Pose2d, StateVector > GetGoal()
Gets the current goal.
void ResetControllers(frc::Pose2d, frc::ChassisSpeeds)
Resets all controllers with the current robot state. This synchronizes the controller's internal stat...
std::tuple< TranslationalPIDF_t, TranslationalPIDF_t, RotationalPIDF_t > GetPID()
Gets the PID gains for all three controllers.
TranslationalPIDF_t GetXPID()
Gets the PID gains for the X-axis controller.
RotationalPIDF_t GetRotationalPID()
Gets the PID gains for the rotation controller.
frc::TrapezoidProfile< units::meter >::Constraints GetYConstraints()
Gets the motion constraints for the Y-axis controller.
frc::TrapezoidProfile< units::radian >::Constraints GetRotationalConstraints()
Gets the motion constraints for the rotation controller.
void LoggablePeriodic() override
Periodic callback for logging updates.
frc::TrapezoidProfile< units::meter >::Constraints GetXConstraints()
Gets the motion constraints for the X-axis controller.
static frc::Pose2d OffsetGetter(frc::Pose2d, frc::Transform2d)
Calculates a new pose by applying a transformation to a reference pose. This is a static utility func...
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 ...
frc::ChassisSpeeds Calculate(frc::Pose2d pose, frc::ChassisSpeeds currentSpeeds, StateVector state)
Calculates the required chassis speeds to move towards the goal state.
void SetYConstraints(frc::TrapezoidProfile< units::meter >::Constraints)
Sets the motion constraints for the Y-axis controller.
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.
void SetXConstraints(frc::TrapezoidProfile< units::meter >::Constraints)
Sets the motion constraints for the X-axis controller.
void SetConstraints(frc::TrapezoidProfile< units::meter >::Constraints x, frc::TrapezoidProfile< units::meter >::Constraints y, frc::TrapezoidProfile< units::radian >::Constraints rot)
Sets the motion profile constraints for all three controllers.
void ResetYController(units::meter_t, units::meters_per_second_t)
Resets the Y-axis controller with a new position and velocity.
void SetGoal(frc::Pose2d goal, StateVector state, bool rotate)
Sets the desired goal state for the alignment controllers.
void ResetXController(units::meter_t, units::meters_per_second_t)
Resets the X-axis controller with a new position and velocity.
void SetRotationalPID(RotationalPIDF_t)
Sets the PID gains for the rotation controller.
Container to hold PID and feed forward values for the motor controller.
Definition PIDF.h:26
Definition WorldAlign.h:75
Definition WorldAlign.h:81