-
Notifications
You must be signed in to change notification settings - Fork 1
/
moveTool.ino
59 lines (55 loc) · 1.4 KB
/
moveTool.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
/* E. D'Alessandro - GPL3 licence - @2022 */
////////////////////////////////////////////////////////////
/// moveTool ////
////////////////////////////////////////////////////////////
void moveTool()
{
// imposto il SP al valore attuale di servoEnc
pidSP = servoEnc.read();
moveDist = servoEnc.read() + moveDist * servoEncRes / distOneRev;
if(moveDist > servoEnc.read())
{
do
{
menu();
pidSP = pidSP + 8;
if(pidSP > moveDist){pidSP = moveDist;}
pidVal = servoEnc.read();
pid();
}
while(pidSP < moveDist && menuCheck != 1);
}
else
{
do
{
menu();
pidSP = pidSP - 8;
if(pidSP < moveDist){pidSP = moveDist;}
pidVal = servoEnc.read();
pid();
}
while(pidSP > moveDist && menuCheck != 1);
}
// Mi assicuro che la posizione sia raggiunta almeno come primo passaggio
do
{
menu();
pidSP = moveDist;
pidVal = servoEnc.read();
pid();
}
while(abs(servoEnc.read() - moveDist) > 1 && menuCheck != 1);
// Mi assicuro che la posizione sia raggiunta eseguendo il pid sulla posizione finale per 0.2 secondi
currentMicros = micros();
do
{
pidSP = moveDist;
pidVal = servoEnc.read();
pid();
}
while(micros() <= currentMicros + 200000 && menuCheck != 1);
// Azzero l'uscita in tensione.
digitalWrite(10, 0);
analogWrite (11, 0);
}