Browse Source

Tweaks to planner.h

Scott Lahteine 7 years ago
parent
commit
77519e9f14
1 changed files with 20 additions and 11 deletions
  1. 20
    11
      Marlin/planner.h

+ 20
- 11
Marlin/planner.h View File

130
 #define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
130
 #define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
131
 
131
 
132
 class Planner {
132
 class Planner {
133
-
134
   public:
133
   public:
135
 
134
 
136
     /**
135
     /**
137
-     * A ring buffer of moves described in steps
136
+     * The move buffer, calculated in stepper steps
137
+     *
138
+     * block_buffer is a ring buffer...
139
+     *
140
+     *             head,tail : indexes for write,read
141
+     *            head==tail : the buffer is empty
142
+     *            head!=tail : blocks are in the buffer
143
+     *   head==(tail-1)%size : the buffer is full
144
+     *
145
+     *  Writer of head is Planner::_buffer_line().
146
+     *  Reader of tail is Stepper::isr(). Always consider tail busy / read-only
138
      */
147
      */
139
     static block_t block_buffer[BLOCK_BUFFER_SIZE];
148
     static block_t block_buffer[BLOCK_BUFFER_SIZE];
140
-    static volatile uint8_t block_buffer_head,  // Index of the next block to be pushed
141
-                            block_buffer_tail;
149
+    static volatile uint8_t block_buffer_head,      // Index of the next block to be pushed
150
+                            block_buffer_tail;      // Index of the busy block, if any
142
 
151
 
143
     #if ENABLED(DISTINCT_E_FACTORS)
152
     #if ENABLED(DISTINCT_E_FACTORS)
144
-      static uint8_t last_extruder;             // Respond to extruder change
153
+      static uint8_t last_extruder;                 // Respond to extruder change
145
     #endif
154
     #endif
146
 
155
 
147
-    static int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
156
+    static int16_t flow_percentage[EXTRUDERS];      // Extrusion factor for each extruder
148
 
157
 
149
     static float e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
158
     static float e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
150
                  filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
159
                  filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
152
                  volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
161
                  volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
153
                                                     // May be auto-adjusted by a filament width sensor
162
                                                     // May be auto-adjusted by a filament width sensor
154
 
163
 
155
-    static float max_feedrate_mm_s[XYZE_N],     // Max speeds in mm per second
164
+    static float max_feedrate_mm_s[XYZE_N],         // Max speeds in mm per second
156
                  axis_steps_per_mm[XYZE_N],
165
                  axis_steps_per_mm[XYZE_N],
157
                  steps_to_mm[XYZE_N];
166
                  steps_to_mm[XYZE_N];
158
     static uint32_t max_acceleration_steps_per_s2[XYZE_N],
167
     static uint32_t max_acceleration_steps_per_s2[XYZE_N],
273
     /**
282
     /**
274
      * Number of moves currently in the planner
283
      * Number of moves currently in the planner
275
      */
284
      */
276
-    static uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
285
+    FORCE_INLINE static uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
277
 
286
 
278
-    static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
287
+    FORCE_INLINE static bool is_full() { return block_buffer_tail == next_block_index(block_buffer_head); }
279
 
288
 
280
     // Update multipliers based on new diameter measurements
289
     // Update multipliers based on new diameter measurements
281
     static void calculate_volumetric_multipliers();
290
     static void calculate_volumetric_multipliers();
529
     /**
538
     /**
530
      * Get the index of the next / previous block in the ring buffer
539
      * Get the index of the next / previous block in the ring buffer
531
      */
540
      */
532
-    static int8_t next_block_index(const int8_t block_index) { return BLOCK_MOD(block_index + 1); }
533
-    static int8_t prev_block_index(const int8_t block_index) { return BLOCK_MOD(block_index - 1); }
541
+    static constexpr int8_t next_block_index(const int8_t block_index) { return BLOCK_MOD(block_index + 1); }
542
+    static constexpr int8_t prev_block_index(const int8_t block_index) { return BLOCK_MOD(block_index - 1); }
534
 
543
 
535
     /**
544
     /**
536
      * Calculate the distance (not time) it takes to accelerate
545
      * Calculate the distance (not time) it takes to accelerate

Loading…
Cancel
Save