Control Surface stm32
MIDI Control Surface library for Arduino
MovingCoilBallistics.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Settings/SettingsWrapper.hpp>
4
6
8 public:
10 float Ts = 1.0 / MAX_FPS)
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
25
26 if (x >= 1) {
27 x = 1;
28 x_dot = x_dot > 0 ? -1 * x_dot : x_dot;
29 } else if (x < 0) {
30 x = 0;
31 x_dot = x_dot < 0 ? -1 * 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
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
constexpr uint8_t MAX_FPS
The maximum frame rate of the displays.
float operator()(float input)
static MovingCoilBallistics noOvershoot(float Tsfactor=1.0)
static MovingCoilBallistics responsiveVU(float Tsfactor=2.0)
MovingCoilBallistics(float springConstant, float friction, float mass, float Ts=1.0/MAX_FPS)
static MovingCoilBallistics officialVU()
#define DEBUGVAL(...)
Print multiple expressions and their values to the debug output if debugging is enabled.
Definition: Debug.hpp:178