summaryrefslogtreecommitdiffstats
path: root/linz/glasslathe/scurve/calc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linz/glasslathe/scurve/calc.cpp')
-rw-r--r--linz/glasslathe/scurve/calc.cpp25
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;
12int newPotValue; 12int newPotValue;
13bool timer_enabled = false; 13bool timer_enabled = false;
14 14
15int x = 0; 15unsigned long x = 0;
16bool loop() 16bool 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}