-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindingMachine.cpp
More file actions
85 lines (63 loc) · 2.09 KB
/
WindingMachine.cpp
File metadata and controls
85 lines (63 loc) · 2.09 KB
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
#include "WindingMachine.h"
WindingMachine::WindingMachine(){
settings_.counterPrescaler = 25;
settings_.pulseDutyCycle = 25;
settings_.stepsPerTurn = 200;
}
void WindingMachine::UpSpeedCorrections(void){
if (state_.speed != target_.speed){
UpdateSpeedOnRun();
}
}
Worder WindingMachine::GetCurrentState(void){
return state_;
}
Worder WindingMachine::GetTargetOrder(void){
return target_;
}
void WindingMachine::AddOneTurnToCurState(void){
++state_.turns;
UpSpeedCorrections();
}
void WindingMachine::SubtracktTurnToCurState(void){
--state_.turns;
UpSpeedCorrections();
}
void WindingMachine::ResetCurrentState(void){
state_.speed = 0;
state_.turns = 0;
}
void WindingMachine::SetTargetOrder( unsigned int turnscount, unsigned int turnspeed, bool cclockwise){
target_.turns = turnscount;
target_.speed = turnspeed;
target_.ccw = cclockwise;
}
void WindingMachine::SetCurrentState( unsigned int turnscount, unsigned int turnspeed, bool cclockwise){
state_.turns = turnscount;
state_.speed = turnspeed;
state_.ccw = cclockwise;
}
void WindingMachine::UpdateSpeedOnRun(void){
uint8_t increment = (state_.speed > 700) ? 1 : 50;
int tempspeed = ((target_.speed - state_.speed) > increment ) ? state_.speed + increment : target_.speed;
MotorsUpdateSpeed(settings_, tempspeed);
state_.speed = tempspeed;
}
void WindingMachine::UpdateTargetSpeed(unsigned int newspeed){
target_.speed = newspeed;
UpdateSpeedOnRun();
}
void WindingMachine::Start(void){
int tempspeed = ((target_.speed - state_.speed) > 100 ) ? state_.speed + 100 : target_.speed;
MotorsStart(settings_, tempspeed, target_.ccw);
state_.speed = tempspeed;
}
void WindingMachine::StopMachine(void){
MotorsStop();
state_.speed = 0;
}
void WindingMachine::UpdateSettings(const int preScaler, const int dutyCycle, const int motorStepsPerTurn){
settings_.counterPrescaler = preScaler;
settings_.pulseDutyCycle = dutyCycle;
settings_.stepsPerTurn = motorStepsPerTurn;
}