WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
frc::SimpleMotorFeedforward< Distance > Class Template Reference

A helper class that computes feedforward voltages for a simple permanent-magnet DC motor. More...

#include <frc/controller/SimpleMotorFeedforward.h>

Public Types

using Velocity
 
using Acceleration
 
using kv_unit = units::compound_unit<units::volts, units::inverse<Velocity>>
 
using ka_unit
 

Public Member Functions

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.
 
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.
 
constexpr units::volt_t Calculate (units::unit_t< Velocity > velocity) const
 Calculates the feedforward from the gains and velocity setpoint assuming discrete control.
 
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.
 
constexpr units::unit_t< VelocityMaxAchievableVelocity (units::volt_t maxVoltage, units::unit_t< Acceleration > acceleration) const
 Calculates the maximum achievable velocity given a maximum voltage supply and an acceleration.
 
constexpr units::unit_t< VelocityMinAchievableVelocity (units::volt_t maxVoltage, units::unit_t< Acceleration > acceleration) const
 Calculates the minimum achievable velocity given a maximum voltage supply and an acceleration.
 
constexpr units::unit_t< AccelerationMaxAchievableAcceleration (units::volt_t maxVoltage, units::unit_t< Velocity > velocity) const
 Calculates the maximum achievable acceleration given a maximum voltage supply and a velocity.
 
constexpr units::unit_t< AccelerationMinAchievableAcceleration (units::volt_t maxVoltage, units::unit_t< Velocity > velocity) const
 Calculates the minimum achievable acceleration given a maximum voltage supply and a velocity.
 
constexpr units::volt_t GetKs () const
 Returns the static gain.
 
constexpr units::unit_t< kv_unitGetKv () const
 Returns the velocity gain.
 
constexpr units::unit_t< ka_unitGetKa () const
 Returns the acceleration gain.
 
constexpr units::second_t GetDt () const
 Returns the period.
 

Detailed Description

template<class Distance>
requires units::length_unit<Distance> || units::angle_unit<Distance>
class frc::SimpleMotorFeedforward< Distance >

A helper class that computes feedforward voltages for a simple permanent-magnet DC motor.

Member Typedef Documentation

◆ Acceleration

template<class Distance >
using frc::SimpleMotorFeedforward< Distance >::Acceleration
Initial value:
typename units::detail::compound_impl< U, Us... >::type compound_unit
Represents a unit type made up from other units.
Definition base.h:1438

◆ ka_unit

template<class Distance >
using frc::SimpleMotorFeedforward< Distance >::ka_unit

◆ kv_unit

template<class Distance >
using frc::SimpleMotorFeedforward< Distance >::kv_unit = units::compound_unit<units::volts, units::inverse<Velocity>>

◆ Velocity

template<class Distance >
using frc::SimpleMotorFeedforward< Distance >::Velocity

Constructor & Destructor Documentation

◆ SimpleMotorFeedforward()

template<class Distance >
frc::SimpleMotorFeedforward< Distance >::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 )
inlineconstexpr

Creates a new SimpleMotorFeedforward with the specified gains.

Parameters
kSThe static gain, in volts.
kVThe velocity gain, in volt seconds per distance.
kAThe acceleration gain, in volt secondsĀ² per distance.
dtThe period in seconds.
Throws:
IllegalArgumentException for kv < zero.
Throws:
IllegalArgumentException for ka < zero.
Throws:
IllegalArgumentException for period ≤ zero.

Member Function Documentation

◆ Calculate() [1/3]

template<class Distance >
units::volt_t frc::SimpleMotorFeedforward< Distance >::Calculate ( units::unit_t< Velocity > currentVelocity,
units::unit_t< Velocity > nextVelocity ) const
inlineconstexpr

Calculates the feedforward from the gains and setpoints assuming discrete control.

Note this method is inaccurate when the velocity crosses 0.

Parameters
currentVelocityThe current velocity setpoint.
nextVelocityThe next velocity setpoint.
Returns
The computed feedforward, in volts.

◆ Calculate() [2/3]

template<class Distance >
units::volt_t frc::SimpleMotorFeedforward< Distance >::Calculate ( units::unit_t< Velocity > velocity) const
inlineconstexpr

Calculates the feedforward from the gains and velocity setpoint assuming discrete control.

Use this method when the velocity setpoint does not change.

Parameters
velocityThe velocity setpoint.
Returns
The computed feedforward, in volts.

◆ Calculate() [3/3]

template<class Distance >
units::volt_t frc::SimpleMotorFeedforward< Distance >::Calculate ( units::unit_t< Velocity > velocity,
units::unit_t< Acceleration > acceleration ) const
inlineconstexpr

Calculates the feedforward from the gains and setpoints assuming continuous control.

Parameters
velocityThe velocity setpoint.
accelerationThe acceleration setpoint.
Returns
The computed feedforward, in volts.
Deprecated
Use the current/next velocity overload instead.

◆ GetDt()

template<class Distance >
units::second_t frc::SimpleMotorFeedforward< Distance >::GetDt ( ) const
inlineconstexpr

Returns the period.

Returns
The period.

◆ GetKa()

template<class Distance >
units::unit_t< ka_unit > frc::SimpleMotorFeedforward< Distance >::GetKa ( ) const
inlineconstexpr

Returns the acceleration gain.

Returns
The acceleration gain.

◆ GetKs()

template<class Distance >
units::volt_t frc::SimpleMotorFeedforward< Distance >::GetKs ( ) const
inlineconstexpr

Returns the static gain.

Returns
The static gain.

◆ GetKv()

template<class Distance >
units::unit_t< kv_unit > frc::SimpleMotorFeedforward< Distance >::GetKv ( ) const
inlineconstexpr

Returns the velocity gain.

Returns
The velocity gain.

◆ MaxAchievableAcceleration()

template<class Distance >
units::unit_t< Acceleration > frc::SimpleMotorFeedforward< Distance >::MaxAchievableAcceleration ( units::volt_t maxVoltage,
units::unit_t< Velocity > velocity ) const
inlineconstexpr

Calculates the maximum achievable acceleration given a maximum voltage supply and a velocity.

Useful for ensuring that velocity and acceleration constraints for a trapezoidal profile are simultaneously achievable - enter the velocity constraint, and this will give you a simultaneously-achievable acceleration constraint.

Parameters
maxVoltageThe maximum voltage that can be supplied to the motor.
velocityThe velocity of the motor.
Returns
The maximum possible acceleration at the given velocity.

◆ MaxAchievableVelocity()

template<class Distance >
units::unit_t< Velocity > frc::SimpleMotorFeedforward< Distance >::MaxAchievableVelocity ( units::volt_t maxVoltage,
units::unit_t< Acceleration > acceleration ) const
inlineconstexpr

Calculates the maximum achievable velocity given a maximum voltage supply and an acceleration.

Useful for ensuring that velocity and acceleration constraints for a trapezoidal profile are simultaneously achievable - enter the acceleration constraint, and this will give you a simultaneously-achievable velocity constraint.

Parameters
maxVoltageThe maximum voltage that can be supplied to the motor.
accelerationThe acceleration of the motor.
Returns
The maximum possible velocity at the given acceleration.

◆ MinAchievableAcceleration()

template<class Distance >
units::unit_t< Acceleration > frc::SimpleMotorFeedforward< Distance >::MinAchievableAcceleration ( units::volt_t maxVoltage,
units::unit_t< Velocity > velocity ) const
inlineconstexpr

Calculates the minimum achievable acceleration given a maximum voltage supply and a velocity.

Useful for ensuring that velocity and acceleration constraints for a trapezoidal profile are simultaneously achievable - enter the velocity constraint, and this will give you a simultaneously-achievable acceleration constraint.

Parameters
maxVoltageThe maximum voltage that can be supplied to the motor.
velocityThe velocity of the motor.
Returns
The minimum possible acceleration at the given velocity.

◆ MinAchievableVelocity()

template<class Distance >
units::unit_t< Velocity > frc::SimpleMotorFeedforward< Distance >::MinAchievableVelocity ( units::volt_t maxVoltage,
units::unit_t< Acceleration > acceleration ) const
inlineconstexpr

Calculates the minimum achievable velocity given a maximum voltage supply and an acceleration.

Useful for ensuring that velocity and acceleration constraints for a trapezoidal profile are simultaneously achievable - enter the acceleration constraint, and this will give you a simultaneously-achievable velocity constraint.

Parameters
maxVoltageThe maximum voltage that can be supplied to the motor.
accelerationThe acceleration of the motor.
Returns
The minimum possible velocity at the given acceleration.

The documentation for this class was generated from the following file: