Browse Source

Merge pull request #3925 from thinkyhead/rc_statics_planner

Apply static to Planner class
Scott Lahteine 8 years ago
parent
commit
194185539d
2 changed files with 122 additions and 56 deletions
  1. 58
    0
      Marlin/planner.cpp
  2. 64
    56
      Marlin/planner.h

+ 58
- 0
Marlin/planner.cpp View File

@@ -71,6 +71,64 @@
71 71
 
72 72
 Planner planner;
73 73
 
74
+  // public:
75
+
76
+/**
77
+ * A ring buffer of moves described in steps
78
+ */
79
+block_t Planner::block_buffer[BLOCK_BUFFER_SIZE];
80
+volatile uint8_t Planner::block_buffer_head = 0;           // Index of the next block to be pushed
81
+volatile uint8_t Planner::block_buffer_tail = 0;
82
+
83
+float Planner::max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
84
+float Planner::axis_steps_per_unit[NUM_AXIS];
85
+unsigned long Planner::axis_steps_per_sqr_second[NUM_AXIS];
86
+unsigned long Planner::max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
87
+
88
+millis_t Planner::min_segment_time;
89
+float Planner::min_feedrate;
90
+float Planner::acceleration;         // Normal acceleration mm/s^2  DEFAULT ACCELERATION for all printing moves. M204 SXXXX
91
+float Planner::retract_acceleration; // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
92
+float Planner::travel_acceleration;  // Travel acceleration mm/s^2  DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
93
+float Planner::max_xy_jerk;          // The largest speed change requiring no acceleration
94
+float Planner::max_z_jerk;
95
+float Planner::max_e_jerk;
96
+float Planner::min_travel_feedrate;
97
+
98
+#if ENABLED(AUTO_BED_LEVELING_FEATURE)
99
+  matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
100
+#endif
101
+
102
+#if ENABLED(AUTOTEMP)
103
+  float Planner::autotemp_max = 250;
104
+  float Planner::autotemp_min = 210;
105
+  float Planner::autotemp_factor = 0.1;
106
+  bool Planner::autotemp_enabled = false;
107
+#endif
108
+
109
+// private:
110
+
111
+long Planner::position[NUM_AXIS] = { 0 };
112
+
113
+float Planner::previous_speed[NUM_AXIS];
114
+
115
+float Planner::previous_nominal_speed;
116
+
117
+#if ENABLED(DISABLE_INACTIVE_EXTRUDER)
118
+  uint8_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 };
119
+#endif // DISABLE_INACTIVE_EXTRUDER
120
+
121
+#ifdef XY_FREQUENCY_LIMIT
122
+  // Old direction bits. Used for speed calculations
123
+  unsigned char Planner::old_direction_bits = 0;
124
+  // Segment times (in µs). Used for speed calculations
125
+  long Planner::axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
126
+#endif
127
+
128
+/**
129
+ * Class and Instance Methods
130
+ */
131
+
74 132
 Planner::Planner() {
75 133
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
76 134
     bed_level_matrix.set_to_identity();

+ 64
- 56
Marlin/planner.h View File

@@ -108,27 +108,27 @@ class Planner {
108 108
     /**
109 109
      * A ring buffer of moves described in steps
110 110
      */
111
-    block_t block_buffer[BLOCK_BUFFER_SIZE];
112
-    volatile uint8_t block_buffer_head = 0;           // Index of the next block to be pushed
113
-    volatile uint8_t block_buffer_tail = 0;
114
-
115
-    float max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
116
-    float axis_steps_per_unit[NUM_AXIS];
117
-    unsigned long axis_steps_per_sqr_second[NUM_AXIS];
118
-    unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
119
-
120
-    millis_t min_segment_time;
121
-    float min_feedrate;
122
-    float acceleration;         // Normal acceleration mm/s^2  DEFAULT ACCELERATION for all printing moves. M204 SXXXX
123
-    float retract_acceleration; // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
124
-    float travel_acceleration;  // Travel acceleration mm/s^2  DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
125
-    float max_xy_jerk;          // The largest speed change requiring no acceleration
126
-    float max_z_jerk;
127
-    float max_e_jerk;
128
-    float min_travel_feedrate;
111
+    static block_t block_buffer[BLOCK_BUFFER_SIZE];
112
+    static volatile uint8_t block_buffer_head;           // Index of the next block to be pushed
113
+    static volatile uint8_t block_buffer_tail;
114
+
115
+    static float max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
116
+    static float axis_steps_per_unit[NUM_AXIS];
117
+    static unsigned long axis_steps_per_sqr_second[NUM_AXIS];
118
+    static unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
119
+
120
+    static millis_t min_segment_time;
121
+    static float min_feedrate;
122
+    static float acceleration;         // Normal acceleration mm/s^2  DEFAULT ACCELERATION for all printing moves. M204 SXXXX
123
+    static float retract_acceleration; // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
124
+    static float travel_acceleration;  // Travel acceleration mm/s^2  DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
125
+    static float max_xy_jerk;          // The largest speed change requiring no acceleration
126
+    static float max_z_jerk;
127
+    static float max_e_jerk;
128
+    static float min_travel_feedrate;
129 129
 
130 130
     #if ENABLED(AUTO_BED_LEVELING_FEATURE)
131
-      matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
131
+      static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
132 132
     #endif
133 133
 
134 134
   private:
@@ -137,49 +137,57 @@ class Planner {
137 137
      * The current position of the tool in absolute steps
138 138
      * Reclculated if any axis_steps_per_unit are changed by gcode
139 139
      */
140
-    long position[NUM_AXIS] = { 0 };
140
+    static long position[NUM_AXIS];
141 141
 
142 142
     /**
143 143
      * Speed of previous path line segment
144 144
      */
145
-    float previous_speed[NUM_AXIS];
145
+    static float previous_speed[NUM_AXIS];
146 146
 
147 147
     /**
148 148
      * Nominal speed of previous path line segment
149 149
      */
150
-    float previous_nominal_speed;
150
+    static float previous_nominal_speed;
151 151
 
152 152
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
153 153
       /**
154 154
        * Counters to manage disabling inactive extruders
155 155
        */
156
-      uint8_t g_uc_extruder_last_move[EXTRUDERS] = { 0 };
156
+      static uint8_t g_uc_extruder_last_move[EXTRUDERS];
157 157
     #endif // DISABLE_INACTIVE_EXTRUDER
158 158
 
159 159
     #ifdef XY_FREQUENCY_LIMIT
160 160
       // Used for the frequency limit
161
-      #define MAX_FREQ_TIME (1000000.0/XY_FREQUENCY_LIMIT)
161
+      #define MAX_FREQ_TIME long(1000000.0/XY_FREQUENCY_LIMIT)
162 162
       // Old direction bits. Used for speed calculations
163
-      static unsigned char old_direction_bits = 0;
163
+      static unsigned char old_direction_bits;
164 164
       // Segment times (in µs). Used for speed calculations
165
-      static long axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
165
+      static long axis_segment_time[2][3];
166 166
     #endif
167 167
 
168 168
   public:
169 169
 
170
+    /**
171
+     * Instance Methods
172
+     */
173
+
170 174
     Planner();
171 175
 
172 176
     void init();
173 177
 
174
-    void reset_acceleration_rates();
178
+    /**
179
+     * Static (class) Methods
180
+     */
181
+
182
+    static void reset_acceleration_rates();
175 183
 
176 184
     // Manage fans, paste pressure, etc.
177
-    void check_axes_activity();
185
+    static void check_axes_activity();
178 186
 
179 187
     /**
180 188
      * Number of moves currently in the planner
181 189
      */
182
-    FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
190
+    static uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
183 191
 
184 192
     #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
185 193
 
@@ -187,7 +195,7 @@ class Planner {
187 195
         /**
188 196
          * The corrected position, applying the bed level matrix
189 197
          */
190
-        vector_3 adjusted_position();
198
+        static vector_3 adjusted_position();
191 199
       #endif
192 200
 
193 201
       /**
@@ -197,7 +205,7 @@ class Planner {
197 205
        *  feed_rate - (target) speed of the move
198 206
        *  extruder  - target extruder
199 207
        */
200
-      void buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder);
208
+      static void buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder);
201 209
 
202 210
       /**
203 211
        * Set the planner.position and individual stepper positions.
@@ -208,30 +216,30 @@ class Planner {
208 216
        *
209 217
        * Clears previous speed values.
210 218
        */
211
-      void set_position(float x, float y, float z, const float& e);
219
+      static void set_position(float x, float y, float z, const float& e);
212 220
 
213 221
     #else
214 222
 
215
-      void buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder);
216
-      void set_position(const float& x, const float& y, const float& z, const float& e);
223
+      static void buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder);
224
+      static void set_position(const float& x, const float& y, const float& z, const float& e);
217 225
 
218 226
     #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
219 227
 
220 228
     /**
221 229
      * Set the E position (mm) of the planner (and the E stepper)
222 230
      */
223
-    void set_e_position(const float& e);
231
+    static void set_e_position(const float& e);
224 232
 
225 233
     /**
226 234
      * Does the buffer have any blocks queued?
227 235
      */
228
-    FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
236
+    static bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
229 237
 
230 238
     /**
231 239
      * "Discards" the block and "releases" the memory.
232 240
      * Called when the current block is no longer needed.
233 241
      */
234
-    FORCE_INLINE void discard_current_block() {
242
+    static void discard_current_block() {
235 243
       if (blocks_queued())
236 244
         block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
237 245
     }
@@ -240,7 +248,7 @@ class Planner {
240 248
      * The current block. NULL if the buffer is empty.
241 249
      * This also marks the block as busy.
242 250
      */
243
-    FORCE_INLINE block_t* get_current_block() {
251
+    static block_t* get_current_block() {
244 252
       if (blocks_queued()) {
245 253
         block_t* block = &block_buffer[block_buffer_tail];
246 254
         block->busy = true;
@@ -251,12 +259,12 @@ class Planner {
251 259
     }
252 260
 
253 261
     #if ENABLED(AUTOTEMP)
254
-      float autotemp_max = 250;
255
-      float autotemp_min = 210;
256
-      float autotemp_factor = 0.1;
257
-      bool autotemp_enabled = false;
258
-      void getHighESpeed();
259
-      void autotemp_M109();
262
+      static float autotemp_max;
263
+      static float autotemp_min;
264
+      static float autotemp_factor;
265
+      static bool autotemp_enabled;
266
+      static void getHighESpeed();
267
+      static void autotemp_M109();
260 268
     #endif
261 269
 
262 270
   private:
@@ -264,14 +272,14 @@ class Planner {
264 272
     /**
265 273
      * Get the index of the next / previous block in the ring buffer
266 274
      */
267
-    FORCE_INLINE int8_t next_block_index(int8_t block_index) { return BLOCK_MOD(block_index + 1); }
268
-    FORCE_INLINE int8_t prev_block_index(int8_t block_index) { return BLOCK_MOD(block_index - 1); }
275
+    static int8_t next_block_index(int8_t block_index) { return BLOCK_MOD(block_index + 1); }
276
+    static int8_t prev_block_index(int8_t block_index) { return BLOCK_MOD(block_index - 1); }
269 277
 
270 278
     /**
271 279
      * Calculate the distance (not time) it takes to accelerate
272 280
      * from initial_rate to target_rate using the given acceleration:
273 281
      */
274
-    FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration) {
282
+    static float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration) {
275 283
       if (acceleration == 0) return 0; // acceleration was 0, set acceleration distance to 0
276 284
       return (target_rate * target_rate - initial_rate * initial_rate) / (acceleration * 2);
277 285
     }
@@ -284,7 +292,7 @@ class Planner {
284 292
      * This is used to compute the intersection point between acceleration and deceleration
285 293
      * in cases where the "trapezoid" has no plateau (i.e., never reaches maximum speed)
286 294
      */
287
-    FORCE_INLINE float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) {
295
+    static float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) {
288 296
       if (acceleration == 0) return 0; // acceleration was 0, set intersection distance to 0
289 297
       return (acceleration * 2 * distance - initial_rate * initial_rate + final_rate * final_rate) / (acceleration * 4);
290 298
     }
@@ -294,21 +302,21 @@ class Planner {
294 302
      * to reach 'target_velocity' using 'acceleration' within a given
295 303
      * 'distance'.
296 304
      */
297
-    FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity, float distance) {
305
+    static float max_allowable_speed(float acceleration, float target_velocity, float distance) {
298 306
       return sqrt(target_velocity * target_velocity - 2 * acceleration * distance);
299 307
     }
300 308
 
301
-    void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor);
309
+    static void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor);
302 310
 
303
-    void reverse_pass_kernel(block_t* previous, block_t* current, block_t* next);
304
-    void forward_pass_kernel(block_t* previous, block_t* current, block_t* next);
311
+    static void reverse_pass_kernel(block_t* previous, block_t* current, block_t* next);
312
+    static void forward_pass_kernel(block_t* previous, block_t* current, block_t* next);
305 313
 
306
-    void reverse_pass();
307
-    void forward_pass();
314
+    static void reverse_pass();
315
+    static void forward_pass();
308 316
 
309
-    void recalculate_trapezoids();
317
+    static void recalculate_trapezoids();
310 318
 
311
-    void recalculate();
319
+    static void recalculate();
312 320
 
313 321
 };
314 322
 

Loading…
Cancel
Save