mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Template C++ TrapezoidProfile and ProfiledPIDController on units (#2109)
This commit is contained in:
@@ -23,8 +23,14 @@ namespace frc2 {
|
||||
*
|
||||
* @see TrapezoidProfile
|
||||
*/
|
||||
template <class Distance>
|
||||
class TrapezoidProfileCommand
|
||||
: public CommandHelper<CommandBase, TrapezoidProfileCommand> {
|
||||
: public CommandHelper<CommandBase, TrapezoidProfileCommand<Distance>> {
|
||||
using Distance_t = units::unit_t<Distance>;
|
||||
using Velocity =
|
||||
units::compound_unit<Distance, units::inverse<units::seconds>>;
|
||||
using Velocity_t = units::unit_t<Velocity>;
|
||||
using State = frc::TrapezoidProfile<Distance>::State;
|
||||
public:
|
||||
/**
|
||||
* Creates a new TrapezoidProfileCommand that will execute the given
|
||||
@@ -34,21 +40,31 @@ class TrapezoidProfileCommand
|
||||
* @param output The consumer for the profile output.
|
||||
*/
|
||||
TrapezoidProfileCommand(
|
||||
frc::TrapezoidProfile profile,
|
||||
std::function<void(frc::TrapezoidProfile::State)> output,
|
||||
std::initializer_list<Subsystem*> requirements);
|
||||
frc::TrapezoidProfile<Distance> profile,
|
||||
std::function<void(State)> output,
|
||||
std::initializer_list<Subsystem*> requirements)
|
||||
: m_profile(profile), m_output(output) {
|
||||
AddRequirements(requirements);
|
||||
}
|
||||
|
||||
void Initialize() override;
|
||||
void Initialize() override {
|
||||
m_timer.Reset();
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
void Execute() override;
|
||||
void Execute() override {
|
||||
m_output(m_profile.Calculate(m_timer.Get()));
|
||||
}
|
||||
|
||||
void End(bool interrupted) override;
|
||||
void End(bool interrupted) override { m_timer.Stop(); }
|
||||
|
||||
bool IsFinished() override;
|
||||
bool IsFinished() override {
|
||||
return m_timer.HasPeriodPassed(m_profile.TotalTime());
|
||||
}
|
||||
|
||||
private:
|
||||
frc::TrapezoidProfile m_profile;
|
||||
std::function<void(frc::TrapezoidProfile::State)> m_output;
|
||||
frc::TrapezoidProfile<Distance> m_profile;
|
||||
std::function<void(State)> m_output;
|
||||
|
||||
Timer m_timer;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user