3#include <frc/controller/HolonomicDriveController.h>
4#include <frc/controller/PIDController.h>
5#include <frc/controller/ProfiledPIDController.h>
6#include <frc/geometry/Pose2d.h>
7#include <frc/geometry/Rotation2d.h>
8#include <frc/kinematics/ChassisSpeeds.h>
9#include <frc/kinematics/SwerveDriveKinematics.h>
10#include <frc/smartdashboard/Field2d.h>
48 std::function<frc::Pose2d()> poseGetter,
49 std::function<frc::Field2d *()> fieldGetter);
106 double correctionFactor)
override;
114 inline bool AtGoal()
override {
return m_driveController->AtReference(); }
121 return m_targetAngle;
137 double to_min,
double to_max) {
138 return (x - from_min) * (to_max - to_min) / (from_max - from_min) + to_min;
142 TurnToPoseConfig m_config;
143 std::function<frc::Pose2d()> m_poseGetter;
144 std::function<frc::Field2d *()> m_fieldGetter;
145 std::unique_ptr<frc::HolonomicDriveController> m_driveController;
146 frc::Pose2d m_startPose;
147 std::optional<frc::Pose2d> m_targetPose;
148 std::optional<units::degree_t> m_targetAngle;
149 units::degree_t m_targetHeading;
150 frc::ChassisSpeeds m_speeds;
Interface for classes that move towards a target while maintaining driver input.
Allows the robot/an axis to face an arbitrary Pose2d.
bool AtGoal() override
Check if the robot is at the goal angle.
void SetTargetAngleRelative(units::degree_t angle)
Set the angle the robot/axis should be facing relative to its current rotation.
void SetTargetAngleAbsolute(units::degree_t angle)
Set the angle the robot/axis should be facing relative to the field's coordinate system.
std::optional< units::degree_t > GetTargetAngle() const
static units::degree_t GetAngleFromOtherPose(const frc::Pose2d &, const frc::Pose2d &)
Helper to calculate the relative angle between two poses.
std::optional< frc::Pose2d > GetTargetPose() const
void SetTargetPose(frc::Pose2d pose)
Set the pose the robot/axis should be facing.
frc::ChassisSpeeds BlendWithInput(const frc::ChassisSpeeds &other, double correctionFactor) override
Combines two ChassisSpeeds into a single result via a linear regression and coefficient.
units::degree_t GetTargetHeading() const
void Update() override
Call this every loop to get the latest angle relative to the robot's position.
TurnToPose(TurnToPoseConfig config, std::function< frc::Pose2d()> poseGetter, std::function< frc::Field2d *()> fieldGetter)
Construct a new TurnToPose instance.
frc::ChassisSpeeds GetSpeedCorrection() override
Get the Speed Correction object.
static double NormalizeScalar(double x, double from_min, double from_max, double to_min, double to_max)
Helper to normalize a value to a new range.
frc::TrapezoidProfile< units::radians >::Constraints rotationConstraints
frc::Pose2d poseTolerance
A Pose2d within this range will be considered "at-goal".