WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::math::ArmFeedforward Class Reference

A helper class that computes feedforward outputs for a simple arm (modeled as a motor acting against the force of gravity on a beam suspended at an angle). More...

#include <wpi/math/controller/ArmFeedforward.hpp>

Public Types

using Angle = wpi::units::radians
using Velocity = wpi::units::radians_per_second
using Acceleration
using kv_unit
using ka_unit

Public Member Functions

constexpr ArmFeedforward (wpi::units::volt_t kS, wpi::units::volt_t kG, wpi::units::unit_t< kv_unit > kV, wpi::units::unit_t< ka_unit > kA=wpi::units::unit_t< ka_unit >(0), wpi::units::second_t dt=20_ms)
 Creates a new ArmFeedforward with the specified gains.
constexpr wpi::units::volt_t Calculate (wpi::units::unit_t< Angle > angle, wpi::units::unit_t< Velocity > velocity, wpi::units::unit_t< Acceleration > acceleration) const
 Calculates the feedforward from the gains and setpoints assuming continuous control.
wpi::units::volt_t Calculate (wpi::units::unit_t< Angle > currentAngle, wpi::units::unit_t< Velocity > currentVelocity, wpi::units::unit_t< Velocity > nextVelocity, wpi::units::second_t dt) const
 Calculates the feedforward from the gains and setpoints assuming continuous control.
constexpr wpi::units::volt_t Calculate (wpi::units::unit_t< Angle > currentAngle, wpi::units::unit_t< Velocity > currentVelocity) const
 Calculates the feedforward from the gains and setpoint assuming discrete control.
wpi::units::volt_t Calculate (wpi::units::unit_t< Angle > currentAngle, wpi::units::unit_t< Velocity > currentVelocity, wpi::units::unit_t< Velocity > nextVelocity) const
 Calculates the feedforward from the gains and setpoints assuming discrete control.
constexpr wpi::units::unit_t< VelocityMaxAchievableVelocity (wpi::units::volt_t maxVoltage, wpi::units::unit_t< Angle > angle, wpi::units::unit_t< Acceleration > acceleration)
 Calculates the maximum achievable velocity given a maximum voltage supply, a position, and an acceleration.
constexpr wpi::units::unit_t< VelocityMinAchievableVelocity (wpi::units::volt_t maxVoltage, wpi::units::unit_t< Angle > angle, wpi::units::unit_t< Acceleration > acceleration)
 Calculates the minimum achievable velocity given a maximum voltage supply, a position, and an acceleration.
constexpr wpi::units::unit_t< AccelerationMaxAchievableAcceleration (wpi::units::volt_t maxVoltage, wpi::units::unit_t< Angle > angle, wpi::units::unit_t< Velocity > velocity)
 Calculates the maximum achievable acceleration given a maximum voltage supply, a position, and a velocity.
constexpr wpi::units::unit_t< AccelerationMinAchievableAcceleration (wpi::units::volt_t maxVoltage, wpi::units::unit_t< Angle > angle, wpi::units::unit_t< Velocity > velocity)
 Calculates the minimum achievable acceleration given a maximum voltage supply, a position, and a velocity.
constexpr void SetKs (wpi::units::volt_t kS)
 Sets the static gain.
constexpr void SetKg (wpi::units::volt_t kG)
 Sets the gravity gain.
constexpr void SetKv (wpi::units::unit_t< kv_unit > kV)
 Sets the velocity gain.
constexpr void SetKa (wpi::units::unit_t< ka_unit > kA)
 Sets the acceleration gain.
constexpr wpi::units::volt_t GetKs () const
 Returns the static gain.
constexpr wpi::units::volt_t GetKg () const
 Returns the gravity gain.
constexpr wpi::units::unit_t< kv_unitGetKv () const
 Returns the velocity gain.
constexpr wpi::units::unit_t< ka_unitGetKa () const
 Returns the acceleration gain.

Detailed Description

A helper class that computes feedforward outputs for a simple arm (modeled as a motor acting against the force of gravity on a beam suspended at an angle).

Member Typedef Documentation

◆ Acceleration

Initial value:
wpi::units::compound_unit<wpi::units::radians_per_second,
wpi::units::inverse<wpi::units::second>>

◆ Angle

using wpi::math::ArmFeedforward::Angle = wpi::units::radians

◆ ka_unit

Initial value:
wpi::units::compound_unit<wpi::units::volts,
wpi::units::inverse<Acceleration>>

◆ kv_unit

Initial value:
wpi::units::compound_unit<
wpi::units::volts, wpi::units::inverse<wpi::units::radians_per_second>>

◆ Velocity

using wpi::math::ArmFeedforward::Velocity = wpi::units::radians_per_second

Constructor & Destructor Documentation

◆ ArmFeedforward()

wpi::math::ArmFeedforward::ArmFeedforward ( wpi::units::volt_t kS,
wpi::units::volt_t kG,
wpi::units::unit_t< kv_unit > kV,
wpi::units::unit_t< ka_unit > kA = wpi::units::unit_t<ka_unit>(0),
wpi::units::second_t dt = 20_ms )
inlineconstexpr

Creates a new ArmFeedforward with the specified gains.

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

Member Function Documentation

◆ Calculate() [1/4]

wpi::units::volt_t wpi::math::ArmFeedforward::Calculate ( wpi::units::unit_t< Angle > angle,
wpi::units::unit_t< Velocity > velocity,
wpi::units::unit_t< Acceleration > acceleration ) const
inlineconstexpr

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

Parameters
angleThe angle setpoint, in radians. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.
velocityThe velocity setpoint.
accelerationThe acceleration setpoint.
Returns
The computed feedforward, in volts.

◆ Calculate() [2/4]

wpi::units::volt_t wpi::math::ArmFeedforward::Calculate ( wpi::units::unit_t< Angle > currentAngle,
wpi::units::unit_t< Velocity > currentVelocity ) const
inlineconstexpr

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

Use this method when the velocity does not change.

Parameters
currentAngleThe current angle. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.
currentVelocityThe current velocity.
Returns
The computed feedforward in volts.

◆ Calculate() [3/4]

wpi::units::volt_t wpi::math::ArmFeedforward::Calculate ( wpi::units::unit_t< Angle > currentAngle,
wpi::units::unit_t< Velocity > currentVelocity,
wpi::units::unit_t< Velocity > nextVelocity ) const

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

Parameters
currentAngleThe current angle. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.
currentVelocityThe current velocity.
nextVelocityThe next velocity.
Returns
The computed feedforward in volts.

◆ Calculate() [4/4]

wpi::units::volt_t wpi::math::ArmFeedforward::Calculate ( wpi::units::unit_t< Angle > currentAngle,
wpi::units::unit_t< Velocity > currentVelocity,
wpi::units::unit_t< Velocity > nextVelocity,
wpi::units::second_t dt ) const
inline

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

Parameters
currentAngleThe current angle in radians. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.
currentVelocityThe current velocity setpoint.
nextVelocityThe next velocity setpoint.
dtTime between velocity setpoints in seconds.
Returns
The computed feedforward in volts.

◆ GetKa()

wpi::units::unit_t< ka_unit > wpi::math::ArmFeedforward::GetKa ( ) const
inlineconstexpr

Returns the acceleration gain.

Returns
The acceleration gain.

◆ GetKg()

wpi::units::volt_t wpi::math::ArmFeedforward::GetKg ( ) const
inlineconstexpr

Returns the gravity gain.

Returns
The gravity gain.

◆ GetKs()

wpi::units::volt_t wpi::math::ArmFeedforward::GetKs ( ) const
inlineconstexpr

Returns the static gain.

Returns
The static gain.

◆ GetKv()

wpi::units::unit_t< kv_unit > wpi::math::ArmFeedforward::GetKv ( ) const
inlineconstexpr

Returns the velocity gain.

Returns
The velocity gain.

◆ MaxAchievableAcceleration()

wpi::units::unit_t< Acceleration > wpi::math::ArmFeedforward::MaxAchievableAcceleration ( wpi::units::volt_t maxVoltage,
wpi::units::unit_t< Angle > angle,
wpi::units::unit_t< Velocity > velocity )
inlineconstexpr

Calculates the maximum achievable acceleration given a maximum voltage supply, a position, 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 arm.
angleThe angle of the arm. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.
velocityThe velocity of the arm.
Returns
The maximum possible acceleration at the given velocity and angle.

◆ MaxAchievableVelocity()

wpi::units::unit_t< Velocity > wpi::math::ArmFeedforward::MaxAchievableVelocity ( wpi::units::volt_t maxVoltage,
wpi::units::unit_t< Angle > angle,
wpi::units::unit_t< Acceleration > acceleration )
inlineconstexpr

Calculates the maximum achievable velocity given a maximum voltage supply, a position, 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 arm.
angleThe angle of the arm. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.
accelerationThe acceleration of the arm.
Returns
The maximum possible velocity at the given acceleration and angle.

◆ MinAchievableAcceleration()

wpi::units::unit_t< Acceleration > wpi::math::ArmFeedforward::MinAchievableAcceleration ( wpi::units::volt_t maxVoltage,
wpi::units::unit_t< Angle > angle,
wpi::units::unit_t< Velocity > velocity )
inlineconstexpr

Calculates the minimum achievable acceleration given a maximum voltage supply, a position, 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 arm.
angleThe angle of the arm. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.
velocityThe velocity of the arm.
Returns
The minimum possible acceleration at the given velocity and angle.

◆ MinAchievableVelocity()

wpi::units::unit_t< Velocity > wpi::math::ArmFeedforward::MinAchievableVelocity ( wpi::units::volt_t maxVoltage,
wpi::units::unit_t< Angle > angle,
wpi::units::unit_t< Acceleration > acceleration )
inlineconstexpr

Calculates the minimum achievable velocity given a maximum voltage supply, a position, 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 arm.
angleThe angle of the arm. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.
accelerationThe acceleration of the arm.
Returns
The minimum possible velocity at the given acceleration and angle.

◆ SetKa()

void wpi::math::ArmFeedforward::SetKa ( wpi::units::unit_t< ka_unit > kA)
inlineconstexpr

Sets the acceleration gain.

Parameters
kAThe acceleration gain.

◆ SetKg()

void wpi::math::ArmFeedforward::SetKg ( wpi::units::volt_t kG)
inlineconstexpr

Sets the gravity gain.

Parameters
kGThe gravity gain.

◆ SetKs()

void wpi::math::ArmFeedforward::SetKs ( wpi::units::volt_t kS)
inlineconstexpr

Sets the static gain.

Parameters
kSThe static gain.

◆ SetKv()

void wpi::math::ArmFeedforward::SetKv ( wpi::units::unit_t< kv_unit > kV)
inlineconstexpr

Sets the velocity gain.

Parameters
kVThe velocity gain.

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