diff options
| author | manuel <manuel@mausz.at> | 2021-01-16 21:47:38 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2021-01-16 21:47:38 +0100 |
| commit | d3dd8913bdf41e38bbc75b1f5dbe7159650ba80b (patch) | |
| tree | 6f37bbd847f10785cd56eed6ae03ac78447a6330 /linz/glasslathe/scurve/calc.cpp | |
| parent | deb1a919401b89a0da7dcfec9ecb88b17dc30b28 (diff) | |
| download | arduino-d3dd8913bdf41e38bbc75b1f5dbe7159650ba80b.tar.gz arduino-d3dd8913bdf41e38bbc75b1f5dbe7159650ba80b.tar.bz2 arduino-d3dd8913bdf41e38bbc75b1f5dbe7159650ba80b.zip | |
glasslathe: update acceleration curve
Diffstat (limited to 'linz/glasslathe/scurve/calc.cpp')
| -rw-r--r-- | linz/glasslathe/scurve/calc.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/linz/glasslathe/scurve/calc.cpp b/linz/glasslathe/scurve/calc.cpp index 1371577..8797e86 100644 --- a/linz/glasslathe/scurve/calc.cpp +++ b/linz/glasslathe/scurve/calc.cpp | |||
| @@ -12,7 +12,7 @@ const int frequency_max = 6000; | |||
| 12 | int newPotValue; | 12 | int newPotValue; |
| 13 | bool timer_enabled = false; | 13 | bool timer_enabled = false; |
| 14 | 14 | ||
| 15 | int x = 0; | 15 | unsigned long x = 0; |
| 16 | bool loop() | 16 | bool loop() |
| 17 | { | 17 | { |
| 18 | const int step_delay = 300; | 18 | const int step_delay = 300; |
| @@ -23,7 +23,7 @@ bool loop() | |||
| 23 | timer_enabled = true; | 23 | timer_enabled = true; |
| 24 | fprintf(stderr, "enable motor\n"); | 24 | fprintf(stderr, "enable motor\n"); |
| 25 | x += step_delay; | 25 | x += step_delay; |
| 26 | printf("[%d, %d],\n", x, 0); | 26 | printf("[%lu, %d],\n", x, 0); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | /*int step = (current.potValue < 20) ? 1 | 29 | /*int step = (current.potValue < 20) ? 1 |
| @@ -32,12 +32,12 @@ bool loop() | |||
| 32 | : (current.potValue < 400) ? 5 | 32 | : (current.potValue < 400) ? 5 |
| 33 | : (current.potValue < 500) ? 10 | 33 | : (current.potValue < 500) ? 10 |
| 34 | : 20;*/ | 34 | : 20;*/ |
| 35 | int step = (current.frequency > 5000) ? 1 | 35 | int step = (current.frequency > 5000) ? 100 |
| 36 | : (current.frequency > 4500) ? 2 | 36 | : (current.frequency > 4000) ? 100 |
| 37 | : (current.frequency > 4000) ? 5 | 37 | : (current.frequency > 3000) ? 150 |
| 38 | : (current.frequency > 3000) ? 10 | 38 | : (current.frequency > 2000) ? 150 |
| 39 | : (current.frequency > 1000) ? 25 | 39 | : (current.frequency > 1000) ? 120 |
| 40 | : 50; | 40 | : 200; |
| 41 | int frequency = (current.direction == target.direction) ? target.frequency : 0; | 41 | int frequency = (current.direction == target.direction) ? target.frequency : 0; |
| 42 | step = std::min(abs(frequency - current.frequency), step); | 42 | step = std::min(abs(frequency - current.frequency), step); |
| 43 | if (frequency < current.frequency) | 43 | if (frequency < current.frequency) |
| @@ -45,7 +45,7 @@ bool loop() | |||
| 45 | current.frequency += step; | 45 | current.frequency += step; |
| 46 | 46 | ||
| 47 | x += step_delay; | 47 | x += step_delay; |
| 48 | printf("[%d, %d],\n", x, current.frequency); | 48 | printf("[%lu, %d],\n", x, current.frequency); |
| 49 | 49 | ||
| 50 | if (current.frequency == 0 && current.direction != target.direction) | 50 | if (current.frequency == 0 && current.direction != target.direction) |
| 51 | { | 51 | { |
| @@ -53,7 +53,7 @@ bool loop() | |||
| 53 | current.direction = target.direction; | 53 | current.direction = target.direction; |
| 54 | fprintf(stderr, "disable motor. changed direction to %d\n", current.direction); | 54 | fprintf(stderr, "disable motor. changed direction to %d\n", current.direction); |
| 55 | x += step_delay; | 55 | x += step_delay; |
| 56 | printf("[%d, %d],\n", x, 0); | 56 | printf("[%lu, %d],\n", x, 0); |
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| 59 | else if (timer_enabled && target.potValue == 0) | 59 | else if (timer_enabled && target.potValue == 0) |
| @@ -61,7 +61,7 @@ bool loop() | |||
| 61 | timer_enabled = false; | 61 | timer_enabled = false; |
| 62 | fprintf(stderr, "disable motor\n"); | 62 | fprintf(stderr, "disable motor\n"); |
| 63 | x += step_delay; | 63 | x += step_delay; |
| 64 | printf("[%d, %d],\n", x, 0); | 64 | printf("[%lu, %d],\n", x, 0); |
| 65 | } | 65 | } |
| 66 | else | 66 | else |
| 67 | return false; | 67 | return false; |
| @@ -74,5 +74,8 @@ int main(int argc, char *argv[]) | |||
| 74 | target.frequency = frequency_max; | 74 | target.frequency = frequency_max; |
| 75 | target.potValue = 1023; | 75 | target.potValue = 1023; |
| 76 | while(loop()); | 76 | while(loop()); |
| 77 | target.frequency = 0; | ||
| 78 | target.potValue = 0; | ||
| 79 | while(loop()); | ||
| 77 | return 0; | 80 | return 0; |
| 78 | } | 81 | } |
