48      units::second_t dt = 20_ms)
 
   49      : kS(kS), kG(kG), 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) + kG + kV * velocity + kA * acceleration;
 
 
   95  [[deprecated(
"Use the current/next velocity overload instead.")]]
 
   98                          units::second_t dt)
 const {
 
  100    auto plant = LinearSystemId::IdentifyVelocitySystem<Distance>(kV, kA);
 
  107           units::volt_t{feedforward.Calculate(r, nextR)(0)};
 
 
  119    return Calculate(currentVelocity, currentVelocity);
 
 
  136    if (kA < 
decltype(kA)(1e-9)) {
 
  137      return kS * 
wpi::sgn(nextVelocity) + kG + kV * nextVelocity;
 
  139      double A = -kV.
value() / kA.value();
 
  140      double B = 1.0 / kA.value();
 
  141      double A_d = 
gcem::exp(A * m_dt.value());
 
  142      double B_d = A > -1e-9 ? B * m_dt.value() : 1.0 / A * (A_d - 1.0) * B;
 
  143      return kG + kS * 
wpi::sgn(currentVelocity) +
 
  146                 (nextVelocity.
value() - A_d * currentVelocity.
value())};
 
 
  167    return (maxVoltage - kS - kG - kA * acceleration) / kV;
 
 
  184    return (-maxVoltage + kS - kG - kA * acceleration) / kV;
 
 
  200    return (maxVoltage - kS * 
wpi::sgn(velocity) - kG - kV * velocity) / kA;
 
 
  216    return MaxAchievableAcceleration(-maxVoltage, velocity);
 
 
  224  constexpr void SetKs(units::volt_t kS) { this->kS = kS; }
 
  231  constexpr void SetKg(units::volt_t kG) { this->kG = kG; }
 
  252  constexpr units::volt_t 
GetKs()
 const { 
return kS; }
 
  259  constexpr units::volt_t 
GetKg()
 const { 
return kG; }
 
  289  units::second_t m_dt;
 
 
A helper class that computes feedforward outputs for a simple elevator (modeled as a motor acting aga...
Definition ElevatorFeedforward.h:22
 
constexpr void SetKs(units::volt_t kS)
Sets the static gain.
Definition ElevatorFeedforward.h:224
 
constexpr void SetKg(units::volt_t kG)
Sets the gravity gain.
Definition ElevatorFeedforward.h:231
 
constexpr units::unit_t< Velocity > MinAchievableVelocity(units::volt_t maxVoltage, units::unit_t< Acceleration > acceleration)
Calculates the minimum achievable velocity given a maximum voltage supply and an acceleration.
Definition ElevatorFeedforward.h:181
 
units::meters Distance
Definition ElevatorFeedforward.h:24
 
constexpr units::unit_t< Acceleration > MaxAchievableAcceleration(units::volt_t maxVoltage, units::unit_t< Velocity > velocity)
Calculates the maximum achievable acceleration given a maximum voltage supply and a velocity.
Definition ElevatorFeedforward.h:198
 
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 ElevatorFeedforward.h:132
 
constexpr units::volt_t GetKs() const
Returns the static gain.
Definition ElevatorFeedforward.h:252
 
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 ElevatorFeedforward.h:80
 
units::compound_unit< Distance, units::inverse< units::seconds > > Velocity
Definition ElevatorFeedforward.h:25
 
constexpr units::unit_t< Velocity > MaxAchievableVelocity(units::volt_t maxVoltage, units::unit_t< Acceleration > acceleration)
Calculates the maximum achievable velocity given a maximum voltage supply and an acceleration.
Definition ElevatorFeedforward.h:164
 
constexpr units::unit_t< Acceleration > MinAchievableAcceleration(units::volt_t maxVoltage, units::unit_t< Velocity > velocity)
Calculates the minimum achievable acceleration given a maximum voltage supply and a velocity.
Definition ElevatorFeedforward.h:214
 
constexpr units::unit_t< kv_unit > GetKv() const
Returns the velocity gain.
Definition ElevatorFeedforward.h:266
 
units::compound_unit< units::volts, units::inverse< Acceleration > > ka_unit
Definition ElevatorFeedforward.h:30
 
constexpr void SetKv(units::unit_t< kv_unit > kV)
Sets the velocity gain.
Definition ElevatorFeedforward.h:238
 
constexpr ElevatorFeedforward(units::volt_t kS, units::volt_t kG, 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 ElevatorFeedforward with the specified gains.
Definition ElevatorFeedforward.h:45
 
constexpr void SetKa(units::unit_t< ka_unit > kA)
Sets the acceleration gain.
Definition ElevatorFeedforward.h:245
 
units::volt_t Calculate(units::unit_t< Velocity > currentVelocity, units::unit_t< Velocity > nextVelocity, units::second_t dt) const
Calculates the feedforward from the gains and setpoints assuming continuous control.
Definition ElevatorFeedforward.h:96
 
constexpr units::volt_t Calculate(units::unit_t< Velocity > currentVelocity) const
Calculates the feedforward from the gains and setpoint assuming discrete control.
Definition ElevatorFeedforward.h:117
 
constexpr units::volt_t GetKg() const
Returns the gravity gain.
Definition ElevatorFeedforward.h:259
 
constexpr units::unit_t< ka_unit > GetKa() const
Returns the acceleration gain.
Definition ElevatorFeedforward.h:273
 
units::compound_unit< units::volts, units::inverse< Velocity > > kv_unit
Definition ElevatorFeedforward.h:29
 
units::compound_unit< Velocity, units::inverse< units::seconds > > Acceleration
Definition ElevatorFeedforward.h:27
 
Constructs a plant inversion model-based feedforward from a LinearSystem.
Definition LinearPlantInversionFeedforward.h:33
 
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
 
Eigen::Vector< double, Size > Vectord
Definition EigenCore.h:12
 
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