Browse Source

Merge pull request #1658 from thinkyhead/planner_oh_planner

Cleanup of planner code
Scott Lahteine 9 years ago
parent
commit
512a0056a9

+ 2
- 2
Marlin/Marlin.h View File

@@ -178,7 +178,7 @@ void manage_inactivity(bool ignore_stepper_queue=false);
178 178
   #define disable_e3() /* nothing */
179 179
 #endif
180 180
 
181
-enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5}; 
181
+enum AxisEnum {X_AXIS=0, Y_AXIS=1, A_AXIS=0, B_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
182 182
 //X_HEAD and Y_HEAD is used for systems that don't have a 1:1 relationship between X_AXIS and X Head movement, like CoreXY bots.
183 183
 
184 184
 void FlushSerialRequestResend();
@@ -265,7 +265,7 @@ extern int fanSpeed;
265 265
   extern bool filament_sensor;  //indicates that filament sensor readings should control extrusion
266 266
   extern float filament_width_meas; //holds the filament diameter as accurately measured
267 267
   extern signed char measurement_delay[];  //ring buffer to delay measurement
268
-  extern int delay_index1, delay_index2;  //index into ring buffer
268
+  extern int delay_index1, delay_index2;  //ring buffer index. used by planner, temperature, and main code
269 269
   extern float delay_dist; //delay distance counter
270 270
   extern int meas_delay_cm; //delay distance
271 271
 #endif

+ 17
- 0
Marlin/configurator/config/Configuration.h View File

@@ -407,6 +407,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
407 407
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
408 408
 
409 409
 //===========================================================================
410
+//============================ Manual Bed Leveling ==========================
411
+//===========================================================================
412
+
413
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
414
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
415
+
416
+#if defined(MESH_BED_LEVELING)
417
+  #define MESH_MIN_X 10
418
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
419
+  #define MESH_MIN_Y 10
420
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
421
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
422
+  #define MESH_NUM_Y_POINTS 3
423
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
424
+#endif  // MESH_BED_LEVELING
425
+
426
+//===========================================================================
410 427
 //============================= Bed Auto Leveling ===========================
411 428
 //===========================================================================
412 429
 

+ 17
- 0
Marlin/example_configurations/Felix/Configuration.h View File

@@ -355,6 +355,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
355 355
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
356 356
 
357 357
 //===========================================================================
358
+//============================ Manual Bed Leveling ==========================
359
+//===========================================================================
360
+
361
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
362
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
363
+
364
+#if defined(MESH_BED_LEVELING)
365
+  #define MESH_MIN_X 10
366
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
367
+  #define MESH_MIN_Y 10
368
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
369
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
370
+  #define MESH_NUM_Y_POINTS 3
371
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
372
+#endif  // MESH_BED_LEVELING
373
+
374
+//===========================================================================
358 375
 //============================= Bed Auto Leveling ===========================
359 376
 //===========================================================================
360 377
 

+ 17
- 0
Marlin/example_configurations/Felix/Configuration_DUAL.h View File

@@ -355,6 +355,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
355 355
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
356 356
 
357 357
 //===========================================================================
358
+//============================ Manual Bed Leveling ==========================
359
+//===========================================================================
360
+
361
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
362
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
363
+
364
+#if defined(MESH_BED_LEVELING)
365
+  #define MESH_MIN_X 10
366
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
367
+  #define MESH_MIN_Y 10
368
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
369
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
370
+  #define MESH_NUM_Y_POINTS 3
371
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
372
+#endif  // MESH_BED_LEVELING
373
+
374
+//===========================================================================
358 375
 //============================= Bed Auto Leveling ===========================
359 376
 //===========================================================================
360 377
 

+ 17
- 0
Marlin/example_configurations/Hephestos/Configuration.h View File

@@ -381,6 +381,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
381 381
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
382 382
 
383 383
 //===========================================================================
384
+//============================ Manual Bed Leveling ==========================
385
+//===========================================================================
386
+
387
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
388
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
389
+
390
+#if defined(MESH_BED_LEVELING)
391
+  #define MESH_MIN_X 10
392
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
393
+  #define MESH_MIN_Y 10
394
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
395
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
396
+  #define MESH_NUM_Y_POINTS 3
397
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
398
+#endif  // MESH_BED_LEVELING
399
+
400
+//===========================================================================
384 401
 //============================= Bed Auto Leveling ===========================
385 402
 //===========================================================================
386 403
 

+ 17
- 0
Marlin/example_configurations/K8200/Configuration.h View File

@@ -386,6 +386,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
386 386
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
387 387
 
388 388
 //===========================================================================
389
+//============================ Manual Bed Leveling ==========================
390
+//===========================================================================
391
+
392
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
393
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
394
+
395
+#if defined(MESH_BED_LEVELING)
396
+  #define MESH_MIN_X 10
397
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
398
+  #define MESH_MIN_Y 10
399
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
400
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
401
+  #define MESH_NUM_Y_POINTS 3
402
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
403
+#endif  // MESH_BED_LEVELING
404
+
405
+//===========================================================================
389 406
 //============================= Bed Auto Leveling ===========================
390 407
 //===========================================================================
391 408
 

+ 17
- 0
Marlin/example_configurations/SCARA/Configuration.h View File

@@ -410,6 +410,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
410 410
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
411 411
 
412 412
 //===========================================================================
413
+//============================ Manual Bed Leveling ==========================
414
+//===========================================================================
415
+
416
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
417
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
418
+
419
+#if defined(MESH_BED_LEVELING)
420
+  #define MESH_MIN_X 10
421
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
422
+  #define MESH_MIN_Y 10
423
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
424
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
425
+  #define MESH_NUM_Y_POINTS 3
426
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
427
+#endif  // MESH_BED_LEVELING
428
+
429
+//===========================================================================
413 430
 //============================= Bed Auto Leveling ===========================
414 431
 //===========================================================================
415 432
 

+ 17
- 0
Marlin/example_configurations/WITBOX/Configuration.h View File

@@ -380,6 +380,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
380 380
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
381 381
 
382 382
 //===========================================================================
383
+//============================ Manual Bed Leveling ==========================
384
+//===========================================================================
385
+
386
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
387
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
388
+
389
+#if defined(MESH_BED_LEVELING)
390
+  #define MESH_MIN_X 10
391
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
392
+  #define MESH_MIN_Y 10
393
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
394
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
395
+  #define MESH_NUM_Y_POINTS 3
396
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
397
+#endif  // MESH_BED_LEVELING
398
+
399
+//===========================================================================
383 400
 //============================= Bed Auto Leveling ===========================
384 401
 //===========================================================================
385 402
 

+ 17
- 0
Marlin/example_configurations/delta/generic/Configuration.h View File

@@ -410,6 +410,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
410 410
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
411 411
 
412 412
 //===========================================================================
413
+//============================ Manual Bed Leveling ==========================
414
+//===========================================================================
415
+
416
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
417
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
418
+
419
+#if defined(MESH_BED_LEVELING)
420
+  #define MESH_MIN_X 10
421
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
422
+  #define MESH_MIN_Y 10
423
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
424
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
425
+  #define MESH_NUM_Y_POINTS 3
426
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
427
+#endif  // MESH_BED_LEVELING
428
+
429
+//===========================================================================
413 430
 //============================= Bed Auto Leveling ===========================
414 431
 //===========================================================================
415 432
 

+ 17
- 0
Marlin/example_configurations/delta/kossel_mini/Configuration.h View File

@@ -411,6 +411,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o
411 411
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
412 412
 
413 413
 //===========================================================================
414
+//============================ Manual Bed Leveling ==========================
415
+//===========================================================================
416
+
417
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
418
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
419
+
420
+#if defined(MESH_BED_LEVELING)
421
+  #define MESH_MIN_X 10
422
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
423
+  #define MESH_MIN_Y 10
424
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
425
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
426
+  #define MESH_NUM_Y_POINTS 3
427
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
428
+#endif  // MESH_BED_LEVELING
429
+
430
+//===========================================================================
414 431
 //============================= Bed Auto Leveling ===========================
415 432
 //===========================================================================
416 433
 

+ 17
- 0
Marlin/example_configurations/makibox/Configuration.h View File

@@ -378,6 +378,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
378 378
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
379 379
 
380 380
 //===========================================================================
381
+//============================ Manual Bed Leveling ==========================
382
+//===========================================================================
383
+
384
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
385
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
386
+
387
+#if defined(MESH_BED_LEVELING)
388
+  #define MESH_MIN_X 10
389
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
390
+  #define MESH_MIN_Y 10
391
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
392
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
393
+  #define MESH_NUM_Y_POINTS 3
394
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
395
+#endif  // MESH_BED_LEVELING
396
+
397
+//===========================================================================
381 398
 //============================= Bed Auto Leveling ===========================
382 399
 //===========================================================================
383 400
 

+ 17
- 0
Marlin/example_configurations/tvrrug/Round2/Configuration.h View File

@@ -380,6 +380,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
380 380
 //#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
381 381
 
382 382
 //===========================================================================
383
+//============================ Manual Bed Leveling ==========================
384
+//===========================================================================
385
+
386
+// #define MANUAL_BED_LEVELING  // Add display menu option for bed leveling
387
+// #define MESH_BED_LEVELING    // Enable mesh bed leveling
388
+
389
+#if defined(MESH_BED_LEVELING)
390
+  #define MESH_MIN_X 10
391
+  #define MESH_MAX_X (X_MAX_POS - MESH_MIN_X)
392
+  #define MESH_MIN_Y 10
393
+  #define MESH_MAX_Y (Y_MAX_POS - MESH_MIN_Y)
394
+  #define MESH_NUM_X_POINTS 3  // Don't use more than 7 points per axis, implementation limited
395
+  #define MESH_NUM_Y_POINTS 3
396
+  #define MESH_HOME_SEARCH_Z 4  // Z after Home, bed somewhere below but above 0.0
397
+#endif  // MESH_BED_LEVELING
398
+
399
+//===========================================================================
383 400
 //============================= Bed Auto Leveling ===========================
384 401
 //===========================================================================
385 402
 

+ 515
- 648
Marlin/planner.cpp
File diff suppressed because it is too large
View File


+ 50
- 62
Marlin/planner.h View File

@@ -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,49 +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
-#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING)
86
-void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder);
87
-#if defined(ENABLE_AUTO_BED_LEVELING)
88
-  #ifndef DELTA
89
-  // Get the position applying the bed level matrix if enabled
90
-  vector_3 plan_get_position();
91
-  #endif
92
-#endif  // ENABLE_AUTO_BED_LEVELING
93
-#else
94
-void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder);
95
-#endif  // ENABLE_AUTO_BED_LEVELING || MESH_BED_LEVELING
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); }
96 81
 
97
-// Set position. Used for G92 instructions.
98 82
 #if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING)
99
-void plan_set_position(float x, float y, float z, const float &e);
83
+  #if defined(ENABLE_AUTO_BED_LEVELING)
84
+    #include "vector_3.h"
85
+    // this holds the required transform to compensate for bed level
86
+    extern matrix_3x3 plan_bed_level_matrix;
87
+    // Get the position applying the bed level matrix if enabled
88
+    vector_3 plan_get_position();
89
+  #endif  // ENABLE_AUTO_BED_LEVELING
90
+  // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 
91
+  // millimeters. Feed rate specifies the speed of the motion.
92
+  void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder);
93
+  // Set position. Used for G92 instructions.
94
+  void plan_set_position(float x, float y, float z, const float &e);
100 95
 #else
101
-void plan_set_position(const float &x, const float &y, const float &z, const float &e);
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);
102 98
 #endif // ENABLE_AUTO_BED_LEVELING || MESH_BED_LEVELING
103 99
 
104 100
 void plan_set_e_position(const float &e);
105 101
 
106
-
107
-
108
-void check_axes_activity();
109
-uint8_t movesplanned(); //return the nr of buffered moves
110
-
111 102
 extern unsigned long minsegmenttime;
112 103
 extern float max_feedrate[NUM_AXIS]; // set the max speeds
113 104
 extern float axis_steps_per_unit[NUM_AXIS];
@@ -123,44 +114,41 @@ extern float mintravelfeedrate;
123 114
 extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
124 115
 
125 116
 #ifdef AUTOTEMP
126
-    extern bool autotemp_enabled;
127
-    extern float autotemp_max;
128
-    extern float autotemp_min;
129
-    extern float autotemp_factor;
117
+  extern bool autotemp_enabled;
118
+  extern float autotemp_max;
119
+  extern float autotemp_min;
120
+  extern float autotemp_factor;
130 121
 #endif
131 122
 
132
-    
133
-
134
-
135
-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
136 124
 extern volatile unsigned char block_buffer_head;           // Index of the next block to be pushed
137 125
 extern volatile unsigned char block_buffer_tail; 
138
-// Called when the current block is no longer needed. Discards the block and makes the memory
139
-// availible for new blocks.    
140
-FORCE_INLINE void plan_discard_current_block()  
141
-{
142
-  if (block_buffer_head != block_buffer_tail) {
143
-    block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1);  
144
-  }
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);
145 135
 }
146 136
 
147 137
 // Gets the current block. Returns NULL if buffer empty
148
-FORCE_INLINE block_t *plan_get_current_block() 
149
-{
150
-  if (block_buffer_head == block_buffer_tail) { 
151
-    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;
152 143
   }
153
-  block_t *block = &block_buffer[block_buffer_tail];
154
-  block->busy = true;
155
-  return(block);
144
+  else
145
+    return NULL;
156 146
 }
157 147
 
158
-// Returns true if the buffer has a queued block, false otherwise
159
-FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
160
-
161 148
 #ifdef PREVENT_DANGEROUS_EXTRUDE
162
-void set_extrude_min_temp(float temp);
149
+  void set_extrude_min_temp(float temp);
163 150
 #endif
164 151
 
165 152
 void reset_acceleration_rates();
166
-#endif
153
+
154
+#endif //PLANNER_H

+ 53
- 54
Marlin/stepper.cpp View File

@@ -364,7 +364,7 @@ ISR(TIMER1_COMPA_vect) {
364 364
       step_events_completed = 0;
365 365
 
366 366
       #ifdef Z_LATE_ENABLE
367
-        if (current_block->steps_z > 0) {
367
+        if (current_block->steps[Z_AXIS] > 0) {
368 368
           enable_z();
369 369
           OCR1A = 2000; //1ms wait
370 370
           return;
@@ -405,7 +405,7 @@ ISR(TIMER1_COMPA_vect) {
405 405
 
406 406
     #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
407 407
       bool axis ##_## minmax ##_endstop = (READ(AXIS ##_## MINMAX ##_PIN) != AXIS ##_## MINMAX ##_ENDSTOP_INVERTING); \
408
-      if (axis ##_## minmax ##_endstop && old_## axis ##_## minmax ##_endstop && (current_block->steps_## axis > 0)) { \
408
+      if (axis ##_## minmax ##_endstop && old_## axis ##_## minmax ##_endstop && (current_block->steps[AXIS ##_AXIS] > 0)) { \
409 409
         endstops_trigsteps[AXIS ##_AXIS] = count_position[AXIS ##_AXIS]; \
410 410
         endstop_## axis ##_hit = true; \
411 411
         step_events_completed = current_block->step_event_count; \
@@ -414,54 +414,54 @@ ISR(TIMER1_COMPA_vect) {
414 414
 
415 415
     // Check X and Y endstops
416 416
     if (check_endstops) {
417
-      #ifndef COREXY
418
-        if (TEST(out_bits, X_AXIS))   // stepping along -X axis (regular cartesians bot)
419
-      #else
417
+      #ifdef COREXY
420 418
         // Head direction in -X axis for CoreXY bots.
421 419
         // If DeltaX == -DeltaY, the movement is only in Y axis
422
-        if (current_block->steps_x != current_block->steps_y || (TEST(out_bits, X_AXIS) == TEST(out_bits, Y_AXIS)))      
423
-            if (TEST(out_bits, X_HEAD))
424
-      #endif
425
-            { // -direction
426
-              #ifdef DUAL_X_CARRIAGE
427
-                // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
428
-                if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
429
-              #endif          
430
-                {
431
-                  #if defined(X_MIN_PIN) && X_MIN_PIN >= 0
432
-                    UPDATE_ENDSTOP(x, X, min, MIN);
433
-                  #endif
434
-                }
435
-            }
436
-            else { // +direction
437
-              #ifdef DUAL_X_CARRIAGE
438
-                // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
439
-                if ((current_block->active_extruder == 0 && X_HOME_DIR == 1) || (current_block->active_extruder != 0 && X2_HOME_DIR == 1))
440
-              #endif
441
-                {
442
-                  #if defined(X_MAX_PIN) && X_MAX_PIN >= 0
443
-                    UPDATE_ENDSTOP(x, X, max, MAX);
444
-                  #endif
445
-                }
446
-            }
447
-      #ifndef COREXY
448
-        if (TEST(out_bits, Y_AXIS))   // -direction
420
+        if (current_block->steps[A_AXIS] != current_block->steps[B_AXIS] || (TEST(out_bits, A_AXIS) == TEST(out_bits, B_AXIS)))
421
+          if (TEST(out_bits, X_HEAD))
449 422
       #else
423
+          if (TEST(out_bits, X_AXIS))   // stepping along -X axis (regular cartesians bot)
424
+      #endif
425
+          { // -direction
426
+            #ifdef DUAL_X_CARRIAGE
427
+              // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
428
+              if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
429
+            #endif          
430
+              {
431
+                #if defined(X_MIN_PIN) && X_MIN_PIN >= 0
432
+                  UPDATE_ENDSTOP(x, X, min, MIN);
433
+                #endif
434
+              }
435
+          }
436
+          else { // +direction
437
+            #ifdef DUAL_X_CARRIAGE
438
+              // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
439
+              if ((current_block->active_extruder == 0 && X_HOME_DIR == 1) || (current_block->active_extruder != 0 && X2_HOME_DIR == 1))
440
+            #endif
441
+              {
442
+                #if defined(X_MAX_PIN) && X_MAX_PIN >= 0
443
+                  UPDATE_ENDSTOP(x, X, max, MAX);
444
+                #endif
445
+              }
446
+          }
447
+      #ifdef COREXY
450 448
         // Head direction in -Y axis for CoreXY bots.
451 449
         // If DeltaX == DeltaY, the movement is only in X axis
452
-        if (current_block->steps_x != current_block->steps_y || (TEST(out_bits, X_AXIS) != TEST(out_bits, Y_AXIS)))
453
-            if (TEST(out_bits, Y_HEAD))             
450
+        if (current_block->steps[A_AXIS] != current_block->steps[B_AXIS] || (TEST(out_bits, A_AXIS) != TEST(out_bits, B_AXIS)))
451
+          if (TEST(out_bits, Y_HEAD))
452
+      #else
453
+          if (TEST(out_bits, Y_AXIS))   // -direction
454 454
       #endif
455
-            { // -direction
456
-              #if defined(Y_MIN_PIN) && Y_MIN_PIN >= 0
457
-                UPDATE_ENDSTOP(y, Y, min, MIN);
458
-              #endif
459
-            }
460
-            else { // +direction
461
-              #if defined(Y_MAX_PIN) && Y_MAX_PIN >= 0
462
-                UPDATE_ENDSTOP(y, Y, max, MAX);
463
-              #endif
464
-            }
455
+          { // -direction
456
+            #if defined(Y_MIN_PIN) && Y_MIN_PIN >= 0
457
+              UPDATE_ENDSTOP(y, Y, min, MIN);
458
+            #endif
459
+          }
460
+          else { // +direction
461
+            #if defined(Y_MAX_PIN) && Y_MAX_PIN >= 0
462
+              UPDATE_ENDSTOP(y, Y, max, MAX);
463
+            #endif
464
+          }
465 465
     }
466 466
 
467 467
     if (TEST(out_bits, Z_AXIS)) {   // -direction
@@ -509,7 +509,7 @@ ISR(TIMER1_COMPA_vect) {
509 509
       #endif
510 510
 
511 511
       #ifdef ADVANCE
512
-        counter_e += current_block->steps_e;
512
+        counter_e += current_block->steps[E_AXIS];
513 513
         if (counter_e > 0) {
514 514
           counter_e -= current_block->step_event_count;
515 515
           e_steps[current_block->active_extruder] += TEST(out_bits, E_AXIS) ? -1 : 1;
@@ -523,15 +523,14 @@ ISR(TIMER1_COMPA_vect) {
523 523
          * instead of doing each in turn. The extra tests add enough
524 524
          * lag to allow it work with without needing NOPs
525 525
          */
526
-        counter_x += current_block->steps_x;
527
-        if (counter_x > 0) X_STEP_WRITE(HIGH);
528
-        counter_y += current_block->steps_y;
529
-        if (counter_y > 0) Y_STEP_WRITE(HIGH);
530
-        counter_z += current_block->steps_z;
531
-        if (counter_z > 0) Z_STEP_WRITE(HIGH);
526
+        #define STEP_ADD(axis, AXIS) \
527
+         counter_## axis += current_block->steps[AXIS ##_AXIS]; \
528
+         if (counter_## axis > 0) { AXIS ##_STEP_WRITE(HIGH); }
529
+        STEP_ADD(x,X);
530
+        STEP_ADD(y,Y);
531
+        STEP_ADD(z,Z);
532 532
         #ifndef ADVANCE
533
-          counter_e += current_block->steps_e;
534
-          if (counter_e > 0) E_STEP_WRITE(HIGH);
533
+          STEP_ADD(e,E);
535 534
         #endif
536 535
 
537 536
         #define STEP_IF_COUNTER(axis, AXIS) \
@@ -551,7 +550,7 @@ ISR(TIMER1_COMPA_vect) {
551 550
       #else // !CONFIG_STEPPERS_TOSHIBA
552 551
 
553 552
         #define APPLY_MOVEMENT(axis, AXIS) \
554
-          counter_## axis += current_block->steps_## axis; \
553
+          counter_## axis += current_block->steps[AXIS ##_AXIS]; \
555 554
           if (counter_## axis > 0) { \
556 555
             AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN,0); \
557 556
             counter_## axis -= current_block->step_event_count; \

Loading…
Cancel
Save