SecondOrderDynamics#

File: samarium/math/SecondOrderDynamics.hpp

namespace sm
template<typename T>
struct SecondOrderDynamics#

Make a value follow an input value using a second order differential equation.

Public Functions

inline explicit SecondOrderDynamics(T initial_input_value = {}, f64 frequency = 4.0, f64 damping = 0.3, f64 response = 0.0)#

Start responding to initial_input_value

Parameters:
  • initial_input_value

  • frequency – Frequency of oscillation. Range: [0, inf)

  • damping – [0, 1.0): with ocscillation. [1.0, inf): asymptotic approach

  • response – at 0, takes time to respond. At 1.0, immediate response. When > 1: overshoots target. < 1 anticipates motion

inline void update_parameters(f64 frequency, f64 damping, f64 response)#

Update the equation parameters.

Parameters:
  • frequency – Frequency of oscillation. Range: [0, inf)

  • damping – [0, 1.0): with ocscillation. [1.0, inf): asymptotic approach

  • response – at 0, takes time to respond. At 1.0, immediate response. When > 1: overshoots target. < 1 anticipates motion

inline void update(f64 dt, T input_value)#

Update value and velocity by integrating.

Parameters:
  • dt – Time step

  • input_value – New input to track

inline void update(f64 dt, T input_value, T input_vel)#

Update value and velocity by integrating.

Parameters:
  • dt – Time step

  • input_value – New input to track

  • input_vel – New velocity

Public Members

T value#
T previous_input#
T vel = {}#
f64 k1#
f64 k2#
f64 k3#