-
Notifications
You must be signed in to change notification settings - Fork 0
/
GSpindle.cpp
65 lines (54 loc) · 1.24 KB
/
GSpindle.cpp
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
#include "GSpindle.h"
GSpindle::GSpindle(int pin)
{
pinMode(pin, INPUT);
digitalWrite(pin, HIGH);
_spindleUpdateTimePhase = 0;
_spindleDeltaPhase = 0;
_firstRevilution = true;
_spindlePhaseCounter = 0;
_spindleRevolutionsPerSecond = 0;
}
void GSpindle::callbackSpindleUpdate()
{
_spindleDeltaPhase = micros() - _spindleUpdateTimePhase;
//Serial.println(_spindleDeltaPhase);
_spindleUpdateTimePhase = micros();
if (isReady()) {
_spindleRevolutionsPerSecond = calculateSpindleRevolutionsPerSecond();
//Serial.println(_spindleRevolutionsPerSecond);
}
_firstRevilution = false;
}
/*
*/
float GSpindle::calculateSpindleRevolutionsPerSecond()
{
if (!_firstRevilution && _spindleUpdateTimePhase != 0)
{
return 1000000.0 / _spindleDeltaPhase;
}
else
return 0;
}
/*
*/
float GSpindle::calculateMMPerSpindleRevolutionPerSecond(float zAutoFeedSyncSpeed)
{
return _spindleRevolutionsPerSecond * zAutoFeedSyncSpeed;
}
/*
return integer value for the spindle speed: revolutions per minute
*/
float GSpindle::calculateSpindleRevolutionsPerMinute()
{
return _spindleRevolutionsPerSecond * 60.0;
}
boolean GSpindle::isReady()
{
return !_firstRevilution;
}
void GSpindle::reset()
{
_firstRevilution = true;
}