22template <
class Distance>
23 requires units::length_unit<Distance> || units::angle_unit<Distance>
48 units::second_t dt = 20_ms)
49 : kS(kS), kV(kV), kA(kA), m_dt(dt) {
51 wpi::math::MathSharedStore::ReportError(
52 "kV must be a non-negative number, got {}!", kV.value());
53 this->kV = units::unit_t<kv_unit>{0};
57 wpi::math::MathSharedStore::ReportError(
58 "kA must be a non-negative number, got {}!", kA.value());
59 this->kA = units::unit_t<ka_unit>{0};
64 "period must be a positive number, got {}!", dt.value());
79 [[deprecated(
"Use the current/next velocity overload instead.")]]
83 return kS *
wpi::sgn(velocity) + kV * velocity + kA * acceleration;
95 return Calculate(velocity, velocity);
112 if (kA ==
decltype(kA)(0)) {
113 return kS *
wpi::sgn(nextVelocity) + kV * nextVelocity;
115 double A = -kV.
value() / kA.value();
116 double B = 1.0 / kA.value();
117 double A_d =
gcem::exp(A * m_dt.value());
118 double B_d = 1.0 / A * (A_d - 1.0) * B;
119 return kS *
wpi::sgn(currentVelocity) +
122 (nextVelocity.
value() - A_d * currentVelocity.
value())};
141 units::volt_t maxVoltage,
144 return (maxVoltage - kS - kA * acceleration) / kV;
159 units::volt_t maxVoltage,
162 return (-maxVoltage + kS - kA * acceleration) / kV;
178 return (maxVoltage - kS *
wpi::sgn(velocity) - kV * velocity) / kA;
194 return MaxAchievableAcceleration(-maxVoltage, velocity);
202 constexpr units::volt_t
GetKs()
const {
return kS; }
223 constexpr units::second_t
GetDt()
const {
return m_dt; }
236 units::second_t m_dt;
A helper class that computes feedforward voltages for a simple permanent-magnet DC motor.
Definition SimpleMotorFeedforward.h:24
constexpr units::volt_t Calculate(units::unit_t< Velocity > velocity, units::unit_t< Acceleration > acceleration) const
Calculates the feedforward from the gains and setpoints assuming continuous control.
Definition SimpleMotorFeedforward.h:80
constexpr units::unit_t< ka_unit > GetKa() const
Returns the acceleration gain.
Definition SimpleMotorFeedforward.h:216
constexpr units::unit_t< Velocity > MinAchievableVelocity(units::volt_t maxVoltage, units::unit_t< Acceleration > acceleration) const
Calculates the minimum achievable velocity given a maximum voltage supply and an acceleration.
Definition SimpleMotorFeedforward.h:158
units::compound_unit< units::volts, units::inverse< Acceleration > > ka_unit
Definition SimpleMotorFeedforward.h:31
constexpr units::volt_t GetKs() const
Returns the static gain.
Definition SimpleMotorFeedforward.h:202
constexpr units::unit_t< kv_unit > GetKv() const
Returns the velocity gain.
Definition SimpleMotorFeedforward.h:209
constexpr units::unit_t< Acceleration > MaxAchievableAcceleration(units::volt_t maxVoltage, units::unit_t< Velocity > velocity) const
Calculates the maximum achievable acceleration given a maximum voltage supply and a velocity.
Definition SimpleMotorFeedforward.h:176
units::compound_unit< Velocity, units::inverse< units::seconds > > Acceleration
Definition SimpleMotorFeedforward.h:28
constexpr units::volt_t Calculate(units::unit_t< Velocity > currentVelocity, units::unit_t< Velocity > nextVelocity) const
Calculates the feedforward from the gains and setpoints assuming discrete control.
Definition SimpleMotorFeedforward.h:108
constexpr units::volt_t Calculate(units::unit_t< Velocity > velocity) const
Calculates the feedforward from the gains and velocity setpoint assuming discrete control.
Definition SimpleMotorFeedforward.h:94
constexpr SimpleMotorFeedforward(units::volt_t kS, units::unit_t< kv_unit > kV, units::unit_t< ka_unit > kA=units::unit_t< ka_unit >(0), units::second_t dt=20_ms)
Creates a new SimpleMotorFeedforward with the specified gains.
Definition SimpleMotorFeedforward.h:45
constexpr units::unit_t< Acceleration > MinAchievableAcceleration(units::volt_t maxVoltage, units::unit_t< Velocity > velocity) const
Calculates the minimum achievable acceleration given a maximum voltage supply and a velocity.
Definition SimpleMotorFeedforward.h:192
constexpr units::second_t GetDt() const
Returns the period.
Definition SimpleMotorFeedforward.h:223
units::compound_unit< Distance, units::inverse< units::seconds > > Velocity
Definition SimpleMotorFeedforward.h:26
units::compound_unit< units::volts, units::inverse< Velocity > > kv_unit
Definition SimpleMotorFeedforward.h:30
constexpr units::unit_t< Velocity > MaxAchievableVelocity(units::volt_t maxVoltage, units::unit_t< Acceleration > acceleration) const
Calculates the maximum achievable velocity given a maximum voltage supply and an acceleration.
Definition SimpleMotorFeedforward.h:140
Container for values which represent quantities of a given unit.
Definition base.h:1930
constexpr underlying_type value() const noexcept
unit value
Definition base.h:2111
static void ReportError(const S &format, Args &&... args)
Definition MathShared.h:62
static void ReportWarning(const S &format, Args &&... args)
Definition MathShared.h:71
typename units::detail::compound_impl< U, Us... >::type compound_unit
Represents a unit type made up from other units.
Definition base.h:1438
constexpr return_t< T > exp(const T x) noexcept
Compile-time exponential function.
Definition exp.hpp:130
constexpr int sgn(T val)
Definition MathExtras.h:758