forked from euphy/polargraph_server_a1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
penlift.ino
97 lines (88 loc) · 2.32 KB
/
penlift.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Polargraph Server. - CORE
* Written by Sandy Noble
* Released under GNU License version 3.
* http://www.polargraph.co.uk
* https://github.com/euphy/polargraph_server_a1
Penlift.
This is one of the core files for the polargraph server program.
This file contains the servo calls that raise or lower the pen from
the page.
The behaviour of the pen lift is this:
If a simple "pen up", or "pen lift" command is received ("C14,END"), then the machine will
not try to lift the pen if it thinks it is already up. It checks the value of the
global boolean variable "isPenUp" to decide this.
If a qualified "pen up" is received, that is one that includes a pen position (eg "C14,150,END"),
then the global "up" position variable is updated, and the servo is moved to that position,
even if it already is "up". Because naturally, if the up position has changed, even if it
is already up, there's a good chance it won't be up enough.
The same goes for the
*/
#ifdef PENLIFT
void penlift_movePen(int start, int end, int delay_ms)
{
penHeight.attach(PEN_HEIGHT_SERVO_PIN);
if(start < end)
{
for (int i=start; i<=end; i++)
{
penHeight.write(i);
delay(delay_ms);
#ifdef DEBUG_PENLIFT
Serial.println(i);
#endif
}
}
else
{
for (int i=start; i>=end; i--)
{
penHeight.write(i);
delay(delay_ms);
#ifdef DEBUG_PENLIFT
Serial.println(i);
#endif
}
}
penHeight.detach();
}
void penlift_penUp()
{
if (inNoOfParams > 1)
{
#ifdef DEBUG_PENLIFT
Serial.print("Penup with params");
#endif
int positionToMoveFrom = isPenUp ? upPosition : downPosition;
upPosition = atoi(inParam1);
penlift_movePen(positionToMoveFrom, upPosition, penLiftSpeed);
}
else
{
if (isPenUp == false)
{
penlift_movePen(downPosition, upPosition, penLiftSpeed);
}
}
isPenUp = true;
}
void penlift_penDown()
{
// check to see if this is a multi-action command (if there's a
// parameter then this sets the "down" motor position too).
if (inNoOfParams > 1)
{
int positionToMoveFrom = isPenUp ? upPosition : downPosition;
downPosition = atoi(inParam1);
penlift_movePen(positionToMoveFrom, downPosition, penLiftSpeed);
}
else
{
if (isPenUp == true)
{
penlift_movePen(upPosition, downPosition, penLiftSpeed);
}
}
isPenUp = false;
}
#endif