Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
planner.h
00001 /* 00002 planner.h - buffers movement commands and manages the acceleration profile plan 00003 Part of Grbl 00004 00005 Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 00006 Copyright (c) 2009-2011 Simen Svale Skogsrud 00007 00008 Grbl is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation, either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 Grbl is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Grbl. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 #ifndef planner_h 00023 #define planner_h 00024 00025 00026 // The number of linear motions that can be in the plan at any give time 00027 #ifndef BLOCK_BUFFER_SIZE 00028 #ifdef AVRTARGET 00029 #ifdef USE_LINE_NUMBERS 00030 #define BLOCK_BUFFER_SIZE 15 00031 #else 00032 #define BLOCK_BUFFER_SIZE 16 00033 #endif 00034 #else 00035 #define BLOCK_BUFFER_SIZE 36 00036 #endif 00037 #endif 00038 00039 // Returned status message from planner. 00040 #define PLAN_OK true 00041 #define PLAN_EMPTY_BLOCK false 00042 00043 // Define planner data condition flags. Used to denote running conditions of a block. 00044 #define PL_COND_FLAG_RAPID_MOTION bit(0) 00045 #define PL_COND_FLAG_SYSTEM_MOTION bit(1) // Single motion. Circumvents planner state. Used by home/park. 00046 #define PL_COND_FLAG_NO_FEED_OVERRIDE bit(2) // Motion does not honor feed override. 00047 #define PL_COND_FLAG_INVERSE_TIME bit(3) // Interprets feed rate value as inverse time when set. 00048 #define PL_COND_FLAG_SPINDLE_CW bit(4) 00049 #define PL_COND_FLAG_SPINDLE_CCW bit(5) 00050 #define PL_COND_FLAG_COOLANT_FLOOD bit(6) 00051 #define PL_COND_FLAG_COOLANT_MIST bit(7) 00052 #define PL_COND_MOTION_MASK (PL_COND_FLAG_RAPID_MOTION|PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE) 00053 #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) 00054 00055 00056 // This struct stores a linear movement of a g-code block motion with its critical "nominal" values 00057 // are as specified in the source g-code. 00058 typedef struct { 00059 // Fields used by the bresenham algorithm for tracing the line 00060 // NOTE: Used by stepper algorithm to execute the block correctly. Do not alter these values. 00061 uint32_t steps[N_AXIS]; // Step count along each axis 00062 uint32_t step_event_count; // The maximum step axis count and number of steps required to complete this block. 00063 uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) 00064 00065 // Block condition data to ensure correct execution depending on states and overrides. 00066 uint8_t condition; // Block bitflag variable defining block run conditions. Copied from pl_line_data. 00067 #ifdef USE_LINE_NUMBERS 00068 int32_t line_number; // Block line number for real-time reporting. Copied from pl_line_data. 00069 #endif 00070 00071 // Fields used by the motion planner to manage acceleration. Some of these values may be updated 00072 // by the stepper module during execution of special motion cases for replanning purposes. 00073 float entry_speed_sqr; // The current planned entry speed at block junction in (mm/min)^2 00074 float max_entry_speed_sqr; // Maximum allowable entry speed based on the minimum of junction limit and 00075 // neighboring nominal speeds with overrides in (mm/min)^2 00076 float acceleration; // Axis-limit adjusted line acceleration in (mm/min^2). Does not change. 00077 float millimeters; // The remaining distance for this block to be executed in (mm). 00078 // NOTE: This value may be altered by stepper algorithm during execution. 00079 00080 // Stored rate limiting data used by planner when changes occur. 00081 float max_junction_speed_sqr; // Junction entry speed limit based on direction vectors in (mm/min)^2 00082 float rapid_rate; // Axis-limit adjusted maximum rate for this block direction in (mm/min) 00083 float programmed_rate; // Programmed rate of this block (mm/min). 00084 00085 #ifdef VARIABLE_SPINDLE 00086 // Stored spindle speed data used by spindle overrides and resuming methods. 00087 float spindle_speed; // Block spindle speed. Copied from pl_line_data. 00088 #endif 00089 } plan_block_t; 00090 00091 00092 // Planner data prototype. Must be used when passing new motions to the planner. 00093 typedef struct { 00094 float feed_rate; // Desired feed rate for line motion. Value is ignored, if rapid motion. 00095 float spindle_speed; // Desired spindle speed through line motion. 00096 uint8_t condition; // Bitflag variable to indicate planner conditions. See defines above. 00097 #ifdef USE_LINE_NUMBERS 00098 int32_t line_number; // Desired line number to report when executing. 00099 #endif 00100 } plan_line_data_t; 00101 00102 00103 // Initialize and reset the motion plan subsystem 00104 void plan_reset(); // Reset all 00105 void plan_reset_buffer(); // Reset buffer only. 00106 00107 // Add a new linear movement to the buffer. target[N_AXIS] is the signed, absolute target position 00108 // in millimeters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed 00109 // rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes. 00110 uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data); 00111 00112 // Called when the current block is no longer needed. Discards the block and makes the memory 00113 // availible for new blocks. 00114 void plan_discard_current_block(); 00115 00116 // Gets the planner block for the special system motion cases. (Parking/Homing) 00117 plan_block_t *plan_get_system_motion_block(); 00118 00119 // Gets the current block. Returns NULL if buffer empty 00120 plan_block_t *plan_get_current_block(); 00121 00122 // Called periodically by step segment buffer. Mostly used internally by planner. 00123 uint8_t plan_next_block_index(uint8_t block_index); 00124 00125 // Called by step segment buffer when computing executing block velocity profile. 00126 float plan_get_exec_block_exit_speed_sqr(); 00127 00128 // Called by main program during planner calculations and step segment buffer during initialization. 00129 float plan_compute_profile_nominal_speed(plan_block_t *block); 00130 00131 // Re-calculates buffered motions profile parameters upon a motion-based override change. 00132 void plan_update_velocity_profile_parameters(); 00133 00134 // Reset the planner position vector (in steps) 00135 void plan_sync_position(); 00136 00137 // Reinitialize plan with a partially completed block 00138 void plan_cycle_reinitialize(); 00139 00140 // Returns the number of available blocks are in the planner buffer. 00141 uint8_t plan_get_block_buffer_available(); 00142 00143 // Returns the number of active blocks are in the planner buffer. 00144 // NOTE: Deprecated. Not used unless classic status reports are enabled in config.h 00145 uint8_t plan_get_block_buffer_count(); 00146 00147 // Returns the status of the block ring buffer. True, if buffer is full. 00148 uint8_t plan_check_full_buffer(); 00149 00150 void plan_get_planner_mpos(float *target); 00151 00152 00153 #endif
Generated on Tue Jul 12 2022 20:45:31 by
 1.7.2
 1.7.2