From d3dd8913bdf41e38bbc75b1f5dbe7159650ba80b Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 16 Jan 2021 21:47:38 +0100 Subject: glasslathe: update acceleration curve --- linz/glasslathe/scurve/calc.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'linz/glasslathe/scurve/calc.cpp') 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; int newPotValue; bool timer_enabled = false; -int x = 0; +unsigned long x = 0; bool loop() { const int step_delay = 300; @@ -23,7 +23,7 @@ bool loop() timer_enabled = true; fprintf(stderr, "enable motor\n"); x += step_delay; - printf("[%d, %d],\n", x, 0); + printf("[%lu, %d],\n", x, 0); } /*int step = (current.potValue < 20) ? 1 @@ -32,12 +32,12 @@ bool loop() : (current.potValue < 400) ? 5 : (current.potValue < 500) ? 10 : 20;*/ - int step = (current.frequency > 5000) ? 1 - : (current.frequency > 4500) ? 2 - : (current.frequency > 4000) ? 5 - : (current.frequency > 3000) ? 10 - : (current.frequency > 1000) ? 25 - : 50; + int step = (current.frequency > 5000) ? 100 + : (current.frequency > 4000) ? 100 + : (current.frequency > 3000) ? 150 + : (current.frequency > 2000) ? 150 + : (current.frequency > 1000) ? 120 + : 200; int frequency = (current.direction == target.direction) ? target.frequency : 0; step = std::min(abs(frequency - current.frequency), step); if (frequency < current.frequency) @@ -45,7 +45,7 @@ bool loop() current.frequency += step; x += step_delay; - printf("[%d, %d],\n", x, current.frequency); + printf("[%lu, %d],\n", x, current.frequency); if (current.frequency == 0 && current.direction != target.direction) { @@ -53,7 +53,7 @@ bool loop() current.direction = target.direction; fprintf(stderr, "disable motor. changed direction to %d\n", current.direction); x += step_delay; - printf("[%d, %d],\n", x, 0); + printf("[%lu, %d],\n", x, 0); } } else if (timer_enabled && target.potValue == 0) @@ -61,7 +61,7 @@ bool loop() timer_enabled = false; fprintf(stderr, "disable motor\n"); x += step_delay; - printf("[%d, %d],\n", x, 0); + printf("[%lu, %d],\n", x, 0); } else return false; @@ -74,5 +74,8 @@ int main(int argc, char *argv[]) target.frequency = frequency_max; target.potValue = 1023; while(loop()); + target.frequency = 0; + target.potValue = 0; + while(loop()); return 0; } -- cgit v1.2.3