-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatrox.cpp
More file actions
234 lines (209 loc) · 7.85 KB
/
atrox.cpp
File metadata and controls
234 lines (209 loc) · 7.85 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// PROJECT ATROX v0.001.1
//***************************************************************************//
// atrox.cpp //
// //
// Description: //
// This is the implementation file for the atrox system class. //
// //
// Written by Antares Husky (antares xavier kiriakov) //
// Distributed under the GNU AGPLv3 license //
// xray77n@gmail.com //
// 04 AUG 2019; Last revision: 05 AUG 2019 //
//***************************************************************************//
#include<AccelStepper.h>
#include "atrox.h"
/* Atrox constructor Atrox(const int[6][6])
> constructs the system by defining default motor settings
arges:
const int[6][6]: an array of motor settings
*/
Atrox::Atrox(const int motorSet[6][6]){
xMotor.stepPerRev = motorSet[0][0];
xMotor.microstepFactor = motorSet[0][1];
xMotor.gboxReductionFactor = motorSet[0][2];
xMotor.gboxIncreaseFactor = motorSet[0][3];
xMotor.speedStep = xMotor.maxSpeedStep = motorSet[0][4];
xMotor.speedStep = xMotor.maxAccelStep = motorSet[0][5];
xMotor.motorhw.setMaxSpeed(xMotor.maxSpeedStep);
xMotor.motorhw.setEnablePin(MOTOR_ENABLE_PIN);
yMotor.stepPerRev = motorSet[1][0];
yMotor.microstepFactor = motorSet[1][1];
yMotor.gboxReductionFactor = motorSet[1][2];
yMotor.gboxIncreaseFactor = motorSet[1][3];
yMotor.speedStep = yMotor.maxSpeedStep = motorSet[1][4];
yMotor.speedStep = yMotor.maxAccelStep = motorSet[1][5];
yMotor.motorhw.setMaxSpeed(yMotor.maxSpeedStep);
yMotor.motorhw.setEnablePin(MOTOR_ENABLE_PIN);
zMotor.stepPerRev = motorSet[2][0];
zMotor.microstepFactor = motorSet[2][1];
zMotor.gboxReductionFactor = motorSet[2][2];
zMotor.gboxIncreaseFactor = motorSet[2][3];
zMotor.speedStep = zMotor.maxSpeedStep = motorSet[2][4];
zMotor.speedStep = zMotor.maxAccelStep = motorSet[2][5];
zMotor.motorhw.setMaxSpeed(zMotor.maxSpeedStep);
zMotor.motorhw.setEnablePin(MOTOR_ENABLE_PIN);
wMotor.stepPerRev = motorSet[3][0];
wMotor.microstepFactor = motorSet[3][1];
wMotor.gboxReductionFactor = motorSet[3][2];
wMotor.gboxIncreaseFactor = motorSet[3][3];
wMotor.speedStep = wMotor.maxSpeedStep = motorSet[3][4];
wMotor.speedStep = wMotor.maxAccelStep = motorSet[3][5];
wMotor.motorhw.setMaxSpeed(wMotor.maxSpeedStep);
wMotor.motorhw.setEnablePin(MOTOR_ENABLE_PIN);
pMotor.stepPerRev = motorSet[4][0];
pMotor.microstepFactor = motorSet[4][1];
pMotor.gboxReductionFactor = motorSet[4][2];
pMotor.gboxIncreaseFactor = motorSet[4][3];
pMotor.speedStep = pMotor.maxSpeedStep = motorSet[5][4];
pMotor.speedStep = pMotor.maxAccelStep = motorSet[5][5];
pMotor.motorhw.setMaxSpeed(pMotor.maxSpeedStep);
pMotor.motorhw.setEnablePin(MOTOR_ENABLE_PIN);
rMotor.stepPerRev = motorSet[5][0];
rMotor.microstepFactor = motorSet[5][1];
rMotor.gboxReductionFactor = motorSet[5][2];
rMotor.gboxIncreaseFactor = motorSet[5][3];
rMotor.speedStep = rMotor.maxSpeedStep = motorSet[6][4];
rMotor.speedStep = rMotor.maxAccelStep = motorSet[6][5];
rMotor.motorhw.setMaxSpeed(rMotor.maxSpeedStep);
rMotor.motorhw.setEnablePin(MOTOR_ENABLE_PIN);
}
/* void Atrox::releaseSteppers()
> disables all stepper motors
no args
returns nothing
*/
void Atrox::releaseSteppers(){
xMotor.motorhw.disableOutputs();
yMotor.motorhw.disableOutputs();
zMotor.motorhw.disableOutputs();
wMotor.motorhw.disableOutputs();
pMotor.motorhw.disableOutputs();
rMotor.motorhw.disableOutputs();
return;
} //end Atrox::releaseSteppers()
/* void Atrox::engageSteppers()
> enables all stepper motors
no args
returns nothing
*/
void Atrox::engageSteppers(){
xMotor.motorhw.enableOutputs();
yMotor.motorhw.enableOutputs();
zMotor.motorhw.enableOutputs();
wMotor.motorhw.enableOutputs();
pMotor.motorhw.enableOutputs();
rMotor.motorhw.enableOutputs();
return;
} //end Atrox::engageSteppers()
/* void Atrox::moveAxis(const Axis axis, const int val, const dynamicsData cmdDynamics)
> moves a single axis by an amount
> will call moveAxisStep() or moveAxisDegree() depending on the unit stored in Atrox::angUnit
args:
const Axis axis: the axis to move
const int val: movement value
const dynamicsData cmdDynamics: the dynamics behaviour of the movement
returns nothing
*/
void Atrox::moveAxis(const Axis axis, const int val, const dynamicsData cmdDynamics){
switch(angUnit){
case STEP:
moveAxisStep(axis, val, cmdDynamics);
break;
case DEGREE:
moveAxisDegree(axis, (float)val, cmdDynamics);
break;
}
return;
} // end Atrox::moveAxis(Axis, int)
/* void Atrox::moveAxis(const Axis axis, const float val, const dynamicsData cmdDynamics)
> overloaded to take float as the movement value
moves a single axis by an amount
will call moveAxisStep() or moveAxisDegree() depending on the unit stored in Atrox::angUnit
args:
const Axis axis: the axis to move
const float val: movement value
const dynamicsData cmdDynamics: the dynamics behaviour of the movement
returns nothing
*/
void Atrox::moveAxis(const Axis axis, const float val, const dynamicsData cmdDynamics){
switch(angUnit){
case STEP:
moveAxisStep(axis, (int)val, cmdDynamics);
break;
case DEGREE:
moveAxisDegree(axis, val, cmdDynamics);
break;
}
return;
} // end Atrox::moveAxis(Axis, float)
/* protected void Atrox::moveAxisStep(const Axis axis, const int step, const dynamicsData cmdDynamics)
> moves a single axis to target position using a step command
this is a blocking function
args:
const Axis axis: the axis to be moved
const int step: the amount to move, in step
const dynamicsData cmdDynamics: the dynamics data of the movement
returns nothing
*/
void Atrox::moveAxisStep(const Axis axis, const int step, const dynamicsData cmdDynamics){
motorData* motorDataPtr;
switch(axis){
case X_AXIS:
motorDataPtr = &xMotor;
break;
case Y_AXIS:
motorDataPtr = &yMotor;
break;
case Z_AXIS:
motorDataPtr = &zMotor;
break;
case W_AXIS:
motorDataPtr = &wMotor;
break;
case P_AXIS:
motorDataPtr = &pMotor;
break;
case R_AXIS:
motorDataPtr = &rMotor;
break;
}
AccelStepper& motor = motorDataPtr->motorhw;
//run motor
bool hasAccl{true};
motor.move(step);
if(abs(cmdDynamics.angAccel) < 1.0){ //arbitrary 1step/s/s minimum
hasAccl = false;
}else{
motor.setAcceleration(cmdDynamics.angAccel);
}
if(abs(cmdDynamics.angSpeed < 0.00027)){ //1step/hr minimum
motor.setSpeed(motorDataPtr->speedStep);
}else{
motor.setSpeed(cmdDynamics.angSpeed);
}
if(hasAccl){
while(motor.distanceToGo() != 0){
motor.run();
}
}else{
while(motor.distanceToGo() != 0){
motor.runSpeedToPosition();
}
}
return;
} // end Atrox::moveAxisStep(const Axis, const int, const dynamicsData)
/* protected void Atrox::moveAxis(const Axis axis, const int degree, const dynamicsData cmdDynamics)
> moves a single axis to target position by a certain degree
will be rounded to the next valid step
this is a blocking function
args:
const Axis axis: the axis to be moved
const float degree: the amount to move, in degrees
const dynamicsData cmdDynamics: the dynamics data of the movement
returns nothing
*/
void Atrox::moveAxisDegree(const Axis axis, const float degree, const dynamicsData cmdDynamics){
//TODO: convert degree to step
//TODO: call function to move axis
return;
} // end Atrox::moveAxis(Axis axis)