This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
MovingCoilBallistics.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
6 
8  public:
9  MovingCoilBallistics(float springConstant, float friction, float mass,
10  float Ts = 1.0 / MAX_FPS)
11  : springConstant(springConstant / mass * Ts),
12  friction(friction / mass * Ts), Ts(Ts) {}
13 
16  float operator()(float input) {
17  // float x_dot_new = (1 - friction / mass * Ts) * x_dot -
18  // springConstant / mass * Ts * (x + input);
19  float x_dot_new = (1 - friction) * x_dot + springConstant * (input - x);
20  x = Ts * x_dot + x;
21  x_dot = x_dot_new;
22 
23  DEBUGVAL(x, x_dot);
25 
26  if (x >= 1) {
27  x = 1;
28  x_dot = x_dot > 0 ? -1.0 * x_dot : x_dot;
29  } else if (x < 0) {
30  x = 0;
31  x_dot = x_dot < 0 ? -1.0 * x_dot : x_dot;
32  }
33  return x;
34  }
35 
37  return MovingCoilBallistics(0.16025, 0.0215, 0.001);
38  }
39 
40  static MovingCoilBallistics responsiveVU(float Tsfactor = 2.0) {
41  return MovingCoilBallistics(0.16025, 0.0215, 0.001, Tsfactor / MAX_FPS);
42  }
43 
44  static MovingCoilBallistics noOvershoot(float Tsfactor = 1.0) {
45  return MovingCoilBallistics(1.05, 0.1, 0.002, Tsfactor / MAX_FPS);
46  }
47 
48  private:
49  const float springConstant;
50  const float friction;
51  const float Ts;
52 
53  float x = 0;
54  float x_dot = 0;
55 };
56 
MovingCoilBallistics::springConstant
const float springConstant
Definition: MovingCoilBallistics.hpp:49
MovingCoilBallistics::responsiveVU
static MovingCoilBallistics responsiveVU(float Tsfactor=2.0)
Definition: MovingCoilBallistics.hpp:40
MovingCoilBallistics::noOvershoot
static MovingCoilBallistics noOvershoot(float Tsfactor=1.0)
Definition: MovingCoilBallistics.hpp:44
MovingCoilBallistics::MovingCoilBallistics
MovingCoilBallistics(float springConstant, float friction, float mass, float Ts=1.0/MAX_FPS)
Definition: MovingCoilBallistics.hpp:9
MovingCoilBallistics::x_dot
float x_dot
Definition: MovingCoilBallistics.hpp:54
DEBUGVAL
#define DEBUGVAL(...)
Definition: Debug.hpp:172
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
MovingCoilBallistics::friction
const float friction
Definition: MovingCoilBallistics.hpp:50
MovingCoilBallistics::officialVU
static MovingCoilBallistics officialVU()
Definition: MovingCoilBallistics.hpp:36
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
MAX_FPS
constexpr uint8_t MAX_FPS
The maximum frame rate of the displays.
Definition: Settings.hpp:111
MovingCoilBallistics
Definition: MovingCoilBallistics.hpp:7
MovingCoilBallistics::Ts
const float Ts
Definition: MovingCoilBallistics.hpp:51
SettingsWrapper.hpp
MovingCoilBallistics::x
float x
Definition: MovingCoilBallistics.hpp:53
MovingCoilBallistics::operator()
float operator()(float input)
Definition: MovingCoilBallistics.hpp:16