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

Go to the source code of this file.

Data Structures

struct  planner_t
 Define planner variables. More...
 

Functions

uint8_t plan_next_block_index (uint8_t block_index)
 Returns the index of the next block in the ring buffer. Also called by stepper segment buffer. More...
 
void plan_reset ()
 Initialize and reset the motion plan subsystem. More...
 
void plan_reset_buffer ()
 Reset buffer only. 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 ()
 Returns address of planner buffer block used by system motions. Called by segment generator. More...
 
plan_block_tplan_get_current_block ()
 Returns address of first planner block, if available. Called by various main program functions. More...
 
float plan_get_exec_block_exit_speed_sqr ()
 Called by step segment buffer when computing executing block velocity profile. More...
 
uint8_t plan_check_full_buffer ()
 Returns the availability status of the block ring buffer. True, if full. More...
 
float plan_compute_profile_nominal_speed (plan_block_t *block)
 Computes and returns block nominal speed based on running condition and override values. More...
 
void plan_update_velocity_profile_parameters ()
 Re-calculates buffered motions profile parameters upon a motion-based override change. 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 in millimeters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes. All position data passed to the planner must be in terms of machine position to keep the planner independent of any coordinate system changes and offsets, which are handled by the g-code parser. More...
 
void plan_sync_position ()
 Reset the planner position vectors. Called by the system abort/initialization routine. 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...
 
void plan_cycle_reinitialize ()
 Re-initialize buffer plan with a partially completed block, assumed to exist at the buffer tail. More...
 

Data Structure Documentation

struct planner_t

Define planner variables.

Definition at line 32 of file planner.c.

Data Fields
int32_t position[N_AXIS] The planner position of the tool in absolute steps. Kept separate.
float previous_nominal_speed Nominal speed of previous path line segment.
float previous_unit_vec[N_AXIS] Unit vector of previous path line segment.

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 in millimeters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes. All position data passed to the planner must be in terms of machine position to keep the planner independent of any coordinate system changes and offsets, which are handled by the g-code parser.

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 availability status of the block ring buffer. True, if 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)

Computes and returns block nominal speed based on running condition and override values.

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 ( )

Re-initialize buffer plan with a partially completed block, assumed to exist at the buffer tail.

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 ( )

Returns address of first planner block, if available. Called by various main program functions.

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.

plan_block_t* plan_get_system_motion_block ( )

Returns address of planner buffer block used by system motions. Called by segment generator.

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)

Returns the index of the next block in the ring buffer. Also called by stepper segment buffer.

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 vectors. Called by the system abort/initialization routine.

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.