gnea\grbl-Mega  1.0f
Source Code Documentation ( Internal Workings )
planner.h File Reference

Go to the source code of this file.

Data Structures

struct  plan_block_t
 This struct stores a linear movement of a g-code block motion with its critical "nominal" values. More...
 
struct  plan_line_data_t
 Planner data prototype. Must be used when passing new motions to the planner. More...
 

Macros

#define BLOCK_BUFFER_SIZE   36
 The number of linear motions that can be in the plan at any give time. More...
 
#define PLAN_OK   true
 Returned status message from planner. More...
 
#define PLAN_EMPTY_BLOCK   false
 
#define PL_COND_FLAG_RAPID_MOTION   bit(0)
 Define planner data condition flags. Used to denote running conditions of a block. More...
 
#define PL_COND_FLAG_SYSTEM_MOTION   bit(1)
 Single motion. Circumvents planner state. Used by home/park. More...
 
#define PL_COND_FLAG_NO_FEED_OVERRIDE   bit(2)
 Motion does not honor feed override. More...
 
#define PL_COND_FLAG_INVERSE_TIME   bit(3)
 Interprets feed rate value as inverse time when set. More...
 
#define PL_COND_FLAG_SPINDLE_CW   bit(4)
 
#define PL_COND_FLAG_SPINDLE_CCW   bit(5)
 
#define PL_COND_FLAG_COOLANT_FLOOD   bit(6)
 
#define PL_COND_FLAG_COOLANT_MIST   bit(7)
 
#define PL_COND_MOTION_MASK   (PL_COND_FLAG_RAPID_MOTION|PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE)
 
#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)
 

Functions

void plan_reset ()
 Initialize and reset the motion plan subsystem. More...
 
void plan_reset_buffer ()
 Reset buffer only. More...
 
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. More...
 
void plan_discard_current_block ()
 Called when the current block is no longer needed. Discards the block and makes the memory. More...
 
plan_block_tplan_get_system_motion_block ()
 Gets the planner block for the special system motion cases. (Parking/Homing) More...
 
plan_block_tplan_get_current_block ()
 Gets the current block. Returns NULL if buffer empty. More...
 
uint8_t plan_next_block_index (uint8_t block_index)
 Called periodically by step segment buffer. Mostly used internally by planner. More...
 
float plan_get_exec_block_exit_speed_sqr ()
 Called by step segment buffer when computing executing block velocity profile. More...
 
float plan_compute_profile_nominal_speed (plan_block_t *block)
 Called by main program during planner calculations and step segment buffer during initialization. More...
 
void plan_update_velocity_profile_parameters ()
 Re-calculates buffered motions profile parameters upon a motion-based override change. More...
 
void plan_sync_position ()
 Reset the planner position vector (in steps) More...
 
void plan_cycle_reinitialize ()
 Reinitialize plan with a partially completed block. More...
 
uint8_t plan_get_block_buffer_available ()
 Returns the number of available blocks are in the planner buffer. More...
 
uint8_t plan_get_block_buffer_count ()
 Returns the number of active blocks are in the planner buffer. More...
 
uint8_t plan_check_full_buffer ()
 Returns the status of the block ring buffer. True, if buffer is full. More...
 
void plan_get_planner_mpos (float *target)
 

Data Structure Documentation

struct plan_block_t

This struct stores a linear movement of a g-code block motion with its critical "nominal" values.

Definition at line 46 of file planner.h.

Data Fields
float acceleration Axis-limit adjusted line acceleration in (mm/min^2). Does not change.
uint8_t condition Block bitflag variable defining block run conditions. Copied from pl_line_data.
uint8_t direction_bits The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
float entry_speed_sqr The current planned entry speed at block junction in (mm/min)^2.
int32_t line_number Block line number for real-time reporting. Copied from pl_line_data.
float max_entry_speed_sqr Maximum allowable entry speed based on the minimum of junction limit and.
float max_junction_speed_sqr NOTE: This value may be altered by stepper algorithm during execution.

Junction entry speed limit based on direction vectors in (mm/min)^2

float millimeters The remaining distance for this block to be executed in (mm).
float programmed_rate Programmed rate of this block (mm/min).
float rapid_rate Axis-limit adjusted maximum rate for this block direction in (mm/min)
float spindle_speed Block spindle speed. Copied from pl_line_data.
uint32_t step_event_count The maximum step axis count and number of steps required to complete this block.
uint32_t steps[N_AXIS] NOTE: Used by stepper algorithm to execute the block correctly. Do not alter these values.

Step count along each axis

struct plan_line_data_t

Planner data prototype. Must be used when passing new motions to the planner.

Definition at line 78 of file planner.h.

Data Fields
uint8_t condition Bitflag variable to indicate planner conditions. See defines above.
float feed_rate Desired feed rate for line motion. Value is ignored, if rapid motion.
int32_t line_number Desired line number to report when executing.
float spindle_speed Desired spindle speed through line motion.

Macro Definition Documentation

#define BLOCK_BUFFER_SIZE   36

The number of linear motions that can be in the plan at any give time.

Definition at line 27 of file planner.h.

Definition at line 42 of file planner.h.

#define PL_COND_FLAG_COOLANT_FLOOD   bit(6)

Definition at line 39 of file planner.h.

#define PL_COND_FLAG_COOLANT_MIST   bit(7)

Definition at line 40 of file planner.h.

#define PL_COND_FLAG_INVERSE_TIME   bit(3)

Interprets feed rate value as inverse time when set.

Definition at line 36 of file planner.h.

#define PL_COND_FLAG_NO_FEED_OVERRIDE   bit(2)

Motion does not honor feed override.

Definition at line 35 of file planner.h.

#define PL_COND_FLAG_RAPID_MOTION   bit(0)

Define planner data condition flags. Used to denote running conditions of a block.

Definition at line 33 of file planner.h.

#define PL_COND_FLAG_SPINDLE_CCW   bit(5)

Definition at line 38 of file planner.h.

#define PL_COND_FLAG_SPINDLE_CW   bit(4)

Definition at line 37 of file planner.h.

#define PL_COND_FLAG_SYSTEM_MOTION   bit(1)

Single motion. Circumvents planner state. Used by home/park.

Definition at line 34 of file planner.h.

Definition at line 41 of file planner.h.

#define PLAN_EMPTY_BLOCK   false

Definition at line 31 of file planner.h.

#define PLAN_OK   true

Returned status message from planner.

Definition at line 30 of file planner.h.

Function Documentation

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.

Add a new linear movement to the buffer. target[N_AXIS] is the signed, absolute target position.

/ NOTE: Assumes buffer is available. Buffer checks are handled at a higher level by motion_control. In other words, the buffer head is never equal to the buffer tail. Also the feed rate input value is used in three ways: as a normal feed rate if invert_feed_rate is false, as inverse time if invert_feed_rate is true, or as seek/rapids rate if the feed_rate value is negative (and invert_feed_rate always false). The system motion condition tells the planner to plan a motion in the always unused block buffer head. It avoids changing the planner state and preserves the buffer to ensure subsequent gcode motions are still planned correctly, while the stepper module only points to the block buffer head to execute the special system motion.

< Zero all block values.

NOTE: Computes true distance from converted step values.

< Store unit vector numerator

NOTE: This calculation assumes all axes are orthogonal (Cartesian) and works with ABC-axes,

Todo:
Need to check this method handling zero junction speeds when starting from rest.

< Starting from rest. Enforce start from zero velocity.

NOTE: If the junction deviation value is finite, Grbl executes the motions in an exact path

NOTE: The max junction speed is a fixed value, since machine acceleration limits cannot be

NOTE: Computed without any expensive trig, sin() or acos(), by trig half angle identity of cos(theta).

< Trig half angle identity. Always positive.

< pl.previous_unit_vec[] = unit_vec[]

< pl.position[] = target_steps[]

Definition at line 310 of file planner.c.

uint8_t plan_check_full_buffer ( )

Returns the status of the block ring buffer. True, if buffer is full.

Returns the status of the block ring buffer. True, if buffer is full.

Definition at line 246 of file planner.c.

float plan_compute_profile_nominal_speed ( plan_block_t block)

Called by main program during planner calculations and step segment buffer during initialization.

Called by main program during planner calculations and step segment buffer during initialization.

NOTE: All system motion commands, such as homing/parking, are not subject to overrides.

Definition at line 255 of file planner.c.

void plan_cycle_reinitialize ( )

Reinitialize plan with a partially completed block.

Reinitialize plan with a partially completed block.

Definition at line 509 of file planner.c.

void plan_discard_current_block ( )

Called when the current block is no longer needed. Discards the block and makes the memory.

< Discard non-empty buffer.

Definition at line 214 of file planner.c.

uint8_t plan_get_block_buffer_available ( )

Returns the number of available blocks are in the planner buffer.

Definition at line 492 of file planner.c.

uint8_t plan_get_block_buffer_count ( )

Returns the number of active blocks are in the planner buffer.

NOTE: Deprecated. Not used unless classic status reports are enabled in config.h

Definition at line 501 of file planner.c.

plan_block_t* plan_get_current_block ( )

Gets the current block. Returns NULL if buffer empty.

Gets the current block. Returns NULL if buffer empty.

Definition at line 231 of file planner.c.

float plan_get_exec_block_exit_speed_sqr ( )

Called by step segment buffer when computing executing block velocity profile.

Definition at line 238 of file planner.c.

void plan_get_planner_mpos ( float *  target)
plan_block_t* plan_get_system_motion_block ( )

Gets the planner block for the special system motion cases. (Parking/Homing)

Gets the planner block for the special system motion cases. (Parking/Homing)

Definition at line 225 of file planner.c.

uint8_t plan_next_block_index ( uint8_t  block_index)

Called periodically by step segment buffer. Mostly used internally by planner.

Called periodically by step segment buffer. Mostly used internally by planner.

Definition at line 42 of file planner.c.

void plan_reset ( )

Initialize and reset the motion plan subsystem.

Reset all

< Clear planner struct

Definition at line 198 of file planner.c.

void plan_reset_buffer ( )

Reset buffer only.

< Empty = tail

< plan_next_block_index(block_buffer_head)

< = block_buffer_tail;

Definition at line 205 of file planner.c.

void plan_sync_position ( )

Reset the planner position vector (in steps)

Reset the planner position vector (in steps)

Todo:
For motor configurations not in the same coordinate frame as the machine position,

Definition at line 471 of file planner.c.

void plan_update_velocity_profile_parameters ( )

Re-calculates buffered motions profile parameters upon a motion-based override change.

< Set high for first block nominal speed calculation.

< Update prev nominal speed for next incoming block.

Definition at line 278 of file planner.c.