-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMotion.h
128 lines (107 loc) · 4.07 KB
/
Motion.h
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
#ifndef _MOTION_H_
#define _MOTION_H_
/* Multiple-Axis motion control. Tightly integrated with GCode class, unfortunaetly.
* (c) 2011, Christopher "ScribbleJ" Jansen
*
*/
#include "config.h"
#include "GCode.h"
#include "Axis.h"
class Motion
{
// Singleton
public:
static Motion& Instance() { static Motion instance; return instance; };
private:
explicit Motion() :AXES((Axis[NUM_AXES])
{
Axis(X_STEP_PIN,X_DIR_PIN,X_ENABLE_PIN,X_MIN_PIN,X_MAX_PIN,X_STEPS_PER_UNIT,X_INVERT_DIR,X_MAX_FEED,X_AVG_FEED,X_START_FEED,X_ACCEL_RATE,X_DISABLE),
Axis(Y_STEP_PIN,Y_DIR_PIN,Y_ENABLE_PIN,Y_MIN_PIN,Y_MAX_PIN,Y_STEPS_PER_UNIT,Y_INVERT_DIR,Y_MAX_FEED,Y_AVG_FEED,Y_START_FEED,Y_ACCEL_RATE,Y_DISABLE),
Axis(Z_STEP_PIN,Z_DIR_PIN,Z_ENABLE_PIN,Z_MIN_PIN,Z_MAX_PIN,Z_STEPS_PER_UNIT,Z_INVERT_DIR,Z_MAX_FEED,Z_AVG_FEED,Z_START_FEED,Z_ACCEL_RATE,Z_DISABLE),
Axis(A_STEP_PIN,A_DIR_PIN,A_ENABLE_PIN,Pin(),Pin(),A_STEPS_PER_UNIT,A_INVERT_DIR,A_MAX_FEED,A_AVG_FEED,A_START_FEED,A_ACCEL_RATE,A_DISABLE)
})
{
setupInterrupt();
interruptOverflow=0;
feed_modifier = 1.0f;
busy = false;
};
Motion(Motion&);
Motion& operator=(Motion&);
Axis AXES[NUM_AXES];
volatile GCode* volatile current_gcode;
volatile unsigned long deltas[NUM_AXES];
volatile long errors[NUM_AXES];
volatile int interruptOverflow;
bool busy;
volatile float feed_modifier;
public:
// Return request Axis
Axis& getAxis(int idx) { return AXES[idx]; }
// Returns current position of all Axes
Point& getCurrentPosition();
// Sets current position; doesn't cause a move, just updates the current position variables.
void setCurrentPosition(GCode &gcode);
// Returns true if machine is in motion
bool axesAreMoving();
// Change stored feedrates/axis data
// WARNING: if you change steps per unit without then changing/resetting all feedrates
// after things will not go well for you!
void setMinimumFeedrate(GCode& gcode);
void setMaximumFeedrate(GCode& gcode);
void setAverageFeedrate(GCode& gcode);
void setStepsPerUnit(GCode& gcode);
void setAccel(GCode& gcode);
void setFeedModifier(float mod);
float getFeedModifier();
void setStepPins(GCode& gcode);
void setDirPins(GCode& gcode);
void setEnablePins(GCode& gcode);
void setMinPins(GCode& gcode);
void setMaxPins(GCode& gcode);
void setMinStopPos(GCode& gcode);
void setMaxStopPos(GCode& gcode);
void setAxisInvert(GCode& gcode);
void setAxisDisable(GCode& gcode);
void setEndstopGlobals(bool inverted, bool pulledup);
void reportConfigStatus(Host& h);
// Motors automatically enabled when used
void disableAllMotors();
void disableAxis(int axis);
void wrapup(GCode& gcode) { checkdisable(gcode); }
void checkdisable(GCode& gcode);
// Uses step data to determine the actual ending position of a move
// (seldom /precisely/ the requested position)
void getActualEndpos(GCode& gcode);
// Run all the math on a G0/G1 movement Gcode to deal with movement later
void gcode_precalc(GCode& gcode, float& feedin, Point* lastend);
// Run extra math to do G1 even better
void gcode_optimize(GCode& gcode, GCode& nextg);
// (re)compute acceleration curve after optimization
void computeAccel(GCode& gcode, GCode* nextg=NULL);
// Actually execute a (precalculated) movement gcode.
void gcode_execute(GCode& gcode);
// Debugging and output to host...
void writePositionToHost(GCode& gcode);
private:
// Calculate the number of steps for each axis in a move.
void getMovesteps(GCode& gcode);
float getSmallestStartFeed(GCode& gcode);
float getSmallestEndFeed(GCode& gcode);
// opt support
void fix_diverge(int32_t *ends, int32_t* starts);
bool join_moves(int32_t *ends, int32_t* starts);
// Functions for handling pulsing motors using a timer interrupt for timing.
public:
void handleInterrupt();
private:
void setupInterrupt();
void enableInterrupt();
void disableInterrupt();
void resetTimer();
void setInterruptCycles(unsigned long cycles);
int ax; // used to avoid allocing loop counter in interrupt.
int accelsteps;
};
extern Motion& MOTION;
#endif // _MOTION_H_