gnea\grbl-Mega  1.0f
Source Code Documentation ( Internal Workings )
planner.h
Go to the documentation of this file.
1 /*
2  planner.h - buffers movement commands and manages the acceleration profile plan
3  Part of Grbl
4 
5  Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
6  Copyright (c) 2009-2011 Simen Svale Skogsrud
7 
8  Grbl is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  Grbl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Grbl. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #ifndef planner_h
23 #define planner_h
24 
26 #ifndef BLOCK_BUFFER_SIZE
27  #define BLOCK_BUFFER_SIZE 36
28 #endif
29 #define PLAN_OK true
31 #define PLAN_EMPTY_BLOCK false
32 #define PL_COND_FLAG_RAPID_MOTION bit(0)
34 #define PL_COND_FLAG_SYSTEM_MOTION bit(1)
35 #define PL_COND_FLAG_NO_FEED_OVERRIDE bit(2)
36 #define PL_COND_FLAG_INVERSE_TIME bit(3)
37 #define PL_COND_FLAG_SPINDLE_CW bit(4)
38 #define PL_COND_FLAG_SPINDLE_CCW bit(5)
39 #define PL_COND_FLAG_COOLANT_FLOOD bit(6)
40 #define PL_COND_FLAG_COOLANT_MIST bit(7)
41 #define PL_COND_MOTION_MASK (PL_COND_FLAG_RAPID_MOTION|PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE)
42 #define PL_COND_ACCESSORY_MASK (PL_COND_FLAG_SPINDLE_CW|PL_COND_FLAG_SPINDLE_CCW|PL_COND_FLAG_COOLANT_FLOOD|PL_COND_FLAG_COOLANT_MIST)
43 
45 // are as specified in the source g-code.
46 typedef struct {
47 // Fields used by the bresenham algorithm for tracing the line
48 //
50  uint32_t steps[N_AXIS];
51  uint32_t step_event_count;
52  uint8_t direction_bits;
53 
54 // Block condition data to ensure correct execution depending on states and overrides.
55  uint8_t condition;
56  int32_t line_number;
57 
58 // Fields used by the motion planner to manage acceleration. Some of these values may be updated
59 // by the stepper module during execution of special motion cases for replanning purposes.
62 // neighboring nominal speeds with overrides in (mm/min)^2
63  float acceleration;
64  float millimeters;
65 //
67 
68 // Stored rate limiting data used by planner when changes occur.
70  float rapid_rate;
72 
73 // Stored spindle speed data used by spindle overrides and resuming methods.
74  float spindle_speed;
75 } plan_block_t;
76 
78 typedef struct {
79  float feed_rate;
80  float spindle_speed;
81  int32_t line_number;
82  uint8_t condition;
84 
86 void plan_reset();
87 void plan_reset_buffer();
88 // in millimeters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed
90 // rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes.
91 uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data);
93 // availible for new blocks.
100 uint8_t plan_next_block_index(uint8_t block_index);
108 void plan_sync_position();
114 //
118 uint8_t plan_check_full_buffer();
119 
120 void plan_get_planner_mpos(float *target);
121 
122 
123 #endif
int32_t line_number
Block line number for real-time reporting. Copied from pl_line_data.
Definition: planner.h:56
float programmed_rate
Programmed rate of this block (mm/min).
Definition: planner.h:71
#define N_AXIS
Axis array index values. Must start with 0 and be continuous.
Definition: nuts_bolts.h:30
plan_block_t * plan_get_current_block()
Gets the current block. Returns NULL if buffer empty.
Definition: planner.c:231
uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
Add a new linear movement to the buffer. target[N_AXIS] is the signed, absolute target position...
Definition: planner.c:310
void plan_update_velocity_profile_parameters()
Re-calculates buffered motions profile parameters upon a motion-based override change.
Definition: planner.c:278
void plan_get_planner_mpos(float *target)
uint8_t direction_bits
The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
Definition: planner.h:52
Planner data prototype. Must be used when passing new motions to the planner.
Definition: planner.h:78
float spindle_speed
Desired spindle speed through line motion.
Definition: planner.h:80
void plan_discard_current_block()
Called when the current block is no longer needed. Discards the block and makes the memory...
Definition: planner.c:214
float plan_get_exec_block_exit_speed_sqr()
Called by step segment buffer when computing executing block velocity profile.
Definition: planner.c:238
uint8_t condition
Block bitflag variable defining block run conditions. Copied from pl_line_data.
Definition: planner.h:55
float entry_speed_sqr
The current planned entry speed at block junction in (mm/min)^2.
Definition: planner.h:60
float millimeters
The remaining distance for this block to be executed in (mm).
Definition: planner.h:64
float plan_compute_profile_nominal_speed(plan_block_t *block)
Called by main program during planner calculations and step segment buffer during initialization...
Definition: planner.c:255
float acceleration
Axis-limit adjusted line acceleration in (mm/min^2). Does not change.
Definition: planner.h:63
float spindle_speed
Block spindle speed. Copied from pl_line_data.
Definition: planner.h:74
void plan_reset()
Initialize and reset the motion plan subsystem.
Definition: planner.c:198
plan_block_t * plan_get_system_motion_block()
Gets the planner block for the special system motion cases. (Parking/Homing)
Definition: planner.c:225
float rapid_rate
Axis-limit adjusted maximum rate for this block direction in (mm/min)
Definition: planner.h:70
void plan_cycle_reinitialize()
Reinitialize plan with a partially completed block.
Definition: planner.c:509
uint8_t plan_get_block_buffer_count()
Returns the number of active blocks are in the planner buffer.
Definition: planner.c:501
float max_entry_speed_sqr
Maximum allowable entry speed based on the minimum of junction limit and.
Definition: planner.h:61
int32_t line_number
Desired line number to report when executing.
Definition: planner.h:81
float max_junction_speed_sqr
NOTE: This value may be altered by stepper algorithm during execution.
Definition: planner.h:69
uint32_t step_event_count
The maximum step axis count and number of steps required to complete this block.
Definition: planner.h:51
uint8_t plan_get_block_buffer_available()
Returns the number of available blocks are in the planner buffer.
Definition: planner.c:492
void plan_sync_position()
Reset the planner position vector (in steps)
Definition: planner.c:471
uint8_t plan_next_block_index(uint8_t block_index)
Called periodically by step segment buffer. Mostly used internally by planner.
Definition: planner.c:42
uint8_t plan_check_full_buffer()
Returns the status of the block ring buffer. True, if buffer is full.
Definition: planner.c:246
float feed_rate
Desired feed rate for line motion. Value is ignored, if rapid motion.
Definition: planner.h:79
void plan_reset_buffer()
Reset buffer only.
Definition: planner.c:205
uint8_t condition
Bitflag variable to indicate planner conditions. See defines above.
Definition: planner.h:82
This struct stores a linear movement of a g-code block motion with its critical "nominal" values...
Definition: planner.h:46
plan_line_data_t * pl_data
Definition: gcode.c:859