|
@@ -21,20 +21,16 @@
|
21
|
21
|
// This module is to be considered a sub-module of stepper.c. Please don't include
|
22
|
22
|
// this file from any other module.
|
23
|
23
|
|
24
|
|
-#ifndef planner_h
|
25
|
|
-#define planner_h
|
|
24
|
+#ifndef PLANNER_H
|
|
25
|
+#define PLANNER_H
|
26
|
26
|
|
27
|
27
|
#include "Marlin.h"
|
28
|
28
|
|
29
|
|
-#ifdef ENABLE_AUTO_BED_LEVELING
|
30
|
|
-#include "vector_3.h"
|
31
|
|
-#endif // ENABLE_AUTO_BED_LEVELING
|
32
|
|
-
|
33
|
29
|
// This struct is used when buffering the setup for each linear movement "nominal" values are as specified in
|
34
|
30
|
// the source g-code and may never actually be reached if acceleration management is active.
|
35
|
31
|
typedef struct {
|
36
|
32
|
// Fields used by the bresenham algorithm for tracing the line
|
37
|
|
- long steps_x, steps_y, steps_z, steps_e; // Step count along each axis
|
|
33
|
+ long steps[NUM_AXIS]; // Step count along each axis
|
38
|
34
|
unsigned long step_event_count; // The number of step events required to complete this block
|
39
|
35
|
long accelerate_until; // The index of the step event on which to stop acceleration
|
40
|
36
|
long decelerate_after; // The index of the step event on which to start decelerating
|
|
@@ -49,7 +45,7 @@ typedef struct {
|
49
|
45
|
#endif
|
50
|
46
|
|
51
|
47
|
// Fields used by the motion planner to manage acceleration
|
52
|
|
-// float speed_x, speed_y, speed_z, speed_e; // Nominal mm/sec for each axis
|
|
48
|
+ // float speed_x, speed_y, speed_z, speed_e; // Nominal mm/sec for each axis
|
53
|
49
|
float nominal_speed; // The nominal speed for this block in mm/sec
|
54
|
50
|
float entry_speed; // Entry speed at previous-current junction in mm/sec
|
55
|
51
|
float max_entry_speed; // Maximum allowable junction entry speed in mm/sec
|
|
@@ -65,48 +61,44 @@ typedef struct {
|
65
|
61
|
unsigned long acceleration_st; // acceleration steps/sec^2
|
66
|
62
|
unsigned long fan_speed;
|
67
|
63
|
#ifdef BARICUDA
|
68
|
|
- unsigned long valve_pressure;
|
69
|
|
- unsigned long e_to_p_pressure;
|
|
64
|
+ unsigned long valve_pressure;
|
|
65
|
+ unsigned long e_to_p_pressure;
|
70
|
66
|
#endif
|
71
|
67
|
volatile char busy;
|
72
|
68
|
} block_t;
|
73
|
69
|
|
74
|
|
-#ifdef ENABLE_AUTO_BED_LEVELING
|
75
|
|
-// this holds the required transform to compensate for bed level
|
76
|
|
-extern matrix_3x3 plan_bed_level_matrix;
|
77
|
|
-#endif // #ifdef ENABLE_AUTO_BED_LEVELING
|
|
70
|
+#define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
|
78
|
71
|
|
79
|
72
|
// Initialize the motion plan subsystem
|
80
|
73
|
void plan_init();
|
81
|
74
|
|
82
|
|
-// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in
|
83
|
|
-// millimaters. Feed rate specifies the speed of the motion.
|
|
75
|
+void check_axes_activity();
|
84
|
76
|
|
85
|
|
-#ifdef ENABLE_AUTO_BED_LEVELING
|
86
|
|
-void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder);
|
|
77
|
+// Get the number of buffered moves
|
|
78
|
+extern volatile unsigned char block_buffer_head;
|
|
79
|
+extern volatile unsigned char block_buffer_tail;
|
|
80
|
+FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
|
87
|
81
|
|
|
82
|
+#ifdef ENABLE_AUTO_BED_LEVELING
|
|
83
|
+ #include "vector_3.h"
|
|
84
|
+ // this holds the required transform to compensate for bed level
|
|
85
|
+ extern matrix_3x3 plan_bed_level_matrix;
|
|
86
|
+ // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in
|
|
87
|
+ // millimaters. Feed rate specifies the speed of the motion.
|
|
88
|
+ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder);
|
|
89
|
+ // Set position. Used for G92 instructions.
|
|
90
|
+ void plan_set_position(float x, float y, float z, const float &e);
|
88
|
91
|
#ifndef DELTA
|
89
|
|
- // Get the position applying the bed level matrix if enabled
|
90
|
|
- vector_3 plan_get_position();
|
|
92
|
+ // Get the position applying the bed level matrix if enabled
|
|
93
|
+ vector_3 plan_get_position();
|
91
|
94
|
#endif
|
92
|
|
-#else
|
93
|
|
-void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder);
|
94
|
|
-#endif // ENABLE_AUTO_BED_LEVELING
|
95
|
|
-
|
96
|
|
-// Set position. Used for G92 instructions.
|
97
|
|
-#ifdef ENABLE_AUTO_BED_LEVELING
|
98
|
|
-void plan_set_position(float x, float y, float z, const float &e);
|
99
|
|
-#else
|
100
|
|
-void plan_set_position(const float &x, const float &y, const float &z, const float &e);
|
101
|
|
-#endif // ENABLE_AUTO_BED_LEVELING
|
|
95
|
+#else //!ENABLE_AUTO_BED_LEVELING
|
|
96
|
+ void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder);
|
|
97
|
+ void plan_set_position(const float &x, const float &y, const float &z, const float &e);
|
|
98
|
+#endif //!ENABLE_AUTO_BED_LEVELING
|
102
|
99
|
|
103
|
100
|
void plan_set_e_position(const float &e);
|
104
|
101
|
|
105
|
|
-
|
106
|
|
-
|
107
|
|
-void check_axes_activity();
|
108
|
|
-uint8_t movesplanned(); //return the nr of buffered moves
|
109
|
|
-
|
110
|
102
|
extern unsigned long minsegmenttime;
|
111
|
103
|
extern float max_feedrate[NUM_AXIS]; // set the max speeds
|
112
|
104
|
extern float axis_steps_per_unit[NUM_AXIS];
|
|
@@ -122,44 +114,41 @@ extern float mintravelfeedrate;
|
122
|
114
|
extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
|
123
|
115
|
|
124
|
116
|
#ifdef AUTOTEMP
|
125
|
|
- extern bool autotemp_enabled;
|
126
|
|
- extern float autotemp_max;
|
127
|
|
- extern float autotemp_min;
|
128
|
|
- extern float autotemp_factor;
|
|
117
|
+ extern bool autotemp_enabled;
|
|
118
|
+ extern float autotemp_max;
|
|
119
|
+ extern float autotemp_min;
|
|
120
|
+ extern float autotemp_factor;
|
129
|
121
|
#endif
|
130
|
122
|
|
131
|
|
-
|
132
|
|
-
|
133
|
|
-
|
134
|
|
-extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instfructions
|
|
123
|
+extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions
|
135
|
124
|
extern volatile unsigned char block_buffer_head; // Index of the next block to be pushed
|
136
|
125
|
extern volatile unsigned char block_buffer_tail;
|
137
|
|
-// Called when the current block is no longer needed. Discards the block and makes the memory
|
138
|
|
-// availible for new blocks.
|
139
|
|
-FORCE_INLINE void plan_discard_current_block()
|
140
|
|
-{
|
141
|
|
- if (block_buffer_head != block_buffer_tail) {
|
142
|
|
- block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1);
|
143
|
|
- }
|
|
126
|
+
|
|
127
|
+// Returns true if the buffer has a queued block, false otherwise
|
|
128
|
+FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
|
|
129
|
+
|
|
130
|
+// Called when the current block is no longer needed. Discards
|
|
131
|
+// the block and makes the memory available for new blocks.
|
|
132
|
+FORCE_INLINE void plan_discard_current_block() {
|
|
133
|
+ if (blocks_queued())
|
|
134
|
+ block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
|
144
|
135
|
}
|
145
|
136
|
|
146
|
137
|
// Gets the current block. Returns NULL if buffer empty
|
147
|
|
-FORCE_INLINE block_t *plan_get_current_block()
|
148
|
|
-{
|
149
|
|
- if (block_buffer_head == block_buffer_tail) {
|
150
|
|
- return(NULL);
|
|
138
|
+FORCE_INLINE block_t *plan_get_current_block() {
|
|
139
|
+ if (blocks_queued()) {
|
|
140
|
+ block_t *block = &block_buffer[block_buffer_tail];
|
|
141
|
+ block->busy = true;
|
|
142
|
+ return block;
|
151
|
143
|
}
|
152
|
|
- block_t *block = &block_buffer[block_buffer_tail];
|
153
|
|
- block->busy = true;
|
154
|
|
- return(block);
|
|
144
|
+ else
|
|
145
|
+ return NULL;
|
155
|
146
|
}
|
156
|
147
|
|
157
|
|
-// Returns true if the buffer has a queued block, false otherwise
|
158
|
|
-FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
|
159
|
|
-
|
160
|
148
|
#ifdef PREVENT_DANGEROUS_EXTRUDE
|
161
|
|
-void set_extrude_min_temp(float temp);
|
|
149
|
+ void set_extrude_min_temp(float temp);
|
162
|
150
|
#endif
|
163
|
151
|
|
164
|
152
|
void reset_acceleration_rates();
|
165
|
|
-#endif
|
|
153
|
+
|
|
154
|
+#endif //PLANNER_H
|