|
@ -21,20 +21,16 @@ |
|
|
// This module is to be considered a sub-module of stepper.c. Please don't include
|
|
|
// This module is to be considered a sub-module of stepper.c. Please don't include
|
|
|
// this file from any other module.
|
|
|
// this file from any other module.
|
|
|
|
|
|
|
|
|
#ifndef planner_h |
|
|
#ifndef PLANNER_H |
|
|
#define planner_h |
|
|
#define PLANNER_H |
|
|
|
|
|
|
|
|
#include "Marlin.h" |
|
|
#include "Marlin.h" |
|
|
|
|
|
|
|
|
#ifdef ENABLE_AUTO_BED_LEVELING |
|
|
|
|
|
#include "vector_3.h" |
|
|
|
|
|
#endif // ENABLE_AUTO_BED_LEVELING
|
|
|
|
|
|
|
|
|
|
|
|
// This struct is used when buffering the setup for each linear movement "nominal" values are as specified in
|
|
|
// This struct is used when buffering the setup for each linear movement "nominal" values are as specified in
|
|
|
// the source g-code and may never actually be reached if acceleration management is active.
|
|
|
// the source g-code and may never actually be reached if acceleration management is active.
|
|
|
typedef struct { |
|
|
typedef struct { |
|
|
// Fields used by the bresenham algorithm for tracing the line
|
|
|
// Fields used by the bresenham algorithm for tracing the line
|
|
|
long steps_x, steps_y, steps_z, steps_e; // Step count along each axis
|
|
|
long steps[NUM_AXIS]; // Step count along each axis
|
|
|
unsigned long step_event_count; // The number of step events required to complete this block
|
|
|
unsigned long step_event_count; // The number of step events required to complete this block
|
|
|
long accelerate_until; // The index of the step event on which to stop acceleration
|
|
|
long accelerate_until; // The index of the step event on which to stop acceleration
|
|
|
long decelerate_after; // The index of the step event on which to start decelerating
|
|
|
long decelerate_after; // The index of the step event on which to start decelerating
|
|
@ -49,7 +45,7 @@ typedef struct { |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// Fields used by the motion planner to manage acceleration
|
|
|
// Fields used by the motion planner to manage acceleration
|
|
|
// float speed_x, speed_y, speed_z, speed_e; // Nominal mm/sec for each axis
|
|
|
// float speed_x, speed_y, speed_z, speed_e; // Nominal mm/sec for each axis
|
|
|
float nominal_speed; // The nominal speed for this block in mm/sec
|
|
|
float nominal_speed; // The nominal speed for this block in mm/sec
|
|
|
float entry_speed; // Entry speed at previous-current junction in mm/sec
|
|
|
float entry_speed; // Entry speed at previous-current junction in mm/sec
|
|
|
float max_entry_speed; // Maximum allowable junction entry speed in mm/sec
|
|
|
float max_entry_speed; // Maximum allowable junction entry speed in mm/sec
|
|
@ -65,49 +61,44 @@ typedef struct { |
|
|
unsigned long acceleration_st; // acceleration steps/sec^2
|
|
|
unsigned long acceleration_st; // acceleration steps/sec^2
|
|
|
unsigned long fan_speed; |
|
|
unsigned long fan_speed; |
|
|
#ifdef BARICUDA |
|
|
#ifdef BARICUDA |
|
|
unsigned long valve_pressure; |
|
|
unsigned long valve_pressure; |
|
|
unsigned long e_to_p_pressure; |
|
|
unsigned long e_to_p_pressure; |
|
|
#endif |
|
|
#endif |
|
|
volatile char busy; |
|
|
volatile char busy; |
|
|
} block_t; |
|
|
} block_t; |
|
|
|
|
|
|
|
|
#ifdef ENABLE_AUTO_BED_LEVELING |
|
|
#define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1)) |
|
|
// this holds the required transform to compensate for bed level
|
|
|
|
|
|
extern matrix_3x3 plan_bed_level_matrix; |
|
|
|
|
|
#endif // #ifdef ENABLE_AUTO_BED_LEVELING
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the motion plan subsystem
|
|
|
// Initialize the motion plan subsystem
|
|
|
void plan_init(); |
|
|
void plan_init(); |
|
|
|
|
|
|
|
|
// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in
|
|
|
void check_axes_activity(); |
|
|
// millimaters. Feed rate specifies the speed of the motion.
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING) |
|
|
// Get the number of buffered moves
|
|
|
void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder); |
|
|
extern volatile unsigned char block_buffer_head; |
|
|
#if defined(ENABLE_AUTO_BED_LEVELING) |
|
|
extern volatile unsigned char block_buffer_tail; |
|
|
#ifndef DELTA |
|
|
FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); } |
|
|
// Get the position applying the bed level matrix if enabled
|
|
|
|
|
|
vector_3 plan_get_position(); |
|
|
|
|
|
#endif |
|
|
|
|
|
#endif // ENABLE_AUTO_BED_LEVELING
|
|
|
|
|
|
#else |
|
|
|
|
|
void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder); |
|
|
|
|
|
#endif // ENABLE_AUTO_BED_LEVELING || MESH_BED_LEVELING
|
|
|
|
|
|
|
|
|
|
|
|
// Set position. Used for G92 instructions.
|
|
|
|
|
|
#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING) |
|
|
#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING) |
|
|
void plan_set_position(float x, float y, float z, const float &e); |
|
|
#if defined(ENABLE_AUTO_BED_LEVELING) |
|
|
|
|
|
#include "vector_3.h" |
|
|
|
|
|
// this holds the required transform to compensate for bed level
|
|
|
|
|
|
extern matrix_3x3 plan_bed_level_matrix; |
|
|
|
|
|
// Get the position applying the bed level matrix if enabled
|
|
|
|
|
|
vector_3 plan_get_position(); |
|
|
|
|
|
#endif // ENABLE_AUTO_BED_LEVELING
|
|
|
|
|
|
// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in
|
|
|
|
|
|
// millimeters. Feed rate specifies the speed of the motion.
|
|
|
|
|
|
void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder); |
|
|
|
|
|
// Set position. Used for G92 instructions.
|
|
|
|
|
|
void plan_set_position(float x, float y, float z, const float &e); |
|
|
#else |
|
|
#else |
|
|
void plan_set_position(const float &x, const float &y, const float &z, const float &e); |
|
|
void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder); |
|
|
|
|
|
void plan_set_position(const float &x, const float &y, const float &z, const float &e); |
|
|
#endif // ENABLE_AUTO_BED_LEVELING || MESH_BED_LEVELING
|
|
|
#endif // ENABLE_AUTO_BED_LEVELING || MESH_BED_LEVELING
|
|
|
|
|
|
|
|
|
void plan_set_e_position(const float &e); |
|
|
void plan_set_e_position(const float &e); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void check_axes_activity(); |
|
|
|
|
|
uint8_t movesplanned(); //return the nr of buffered moves
|
|
|
|
|
|
|
|
|
|
|
|
extern unsigned long minsegmenttime; |
|
|
extern unsigned long minsegmenttime; |
|
|
extern float max_feedrate[NUM_AXIS]; // set the max speeds
|
|
|
extern float max_feedrate[NUM_AXIS]; // set the max speeds
|
|
|
extern float axis_steps_per_unit[NUM_AXIS]; |
|
|
extern float axis_steps_per_unit[NUM_AXIS]; |
|
@ -123,44 +114,41 @@ extern float mintravelfeedrate; |
|
|
extern unsigned long axis_steps_per_sqr_second[NUM_AXIS]; |
|
|
extern unsigned long axis_steps_per_sqr_second[NUM_AXIS]; |
|
|
|
|
|
|
|
|
#ifdef AUTOTEMP |
|
|
#ifdef AUTOTEMP |
|
|
extern bool autotemp_enabled; |
|
|
extern bool autotemp_enabled; |
|
|
extern float autotemp_max; |
|
|
extern float autotemp_max; |
|
|
extern float autotemp_min; |
|
|
extern float autotemp_min; |
|
|
extern float autotemp_factor; |
|
|
extern float autotemp_factor; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instfructions
|
|
|
|
|
|
extern volatile unsigned char block_buffer_head; // Index of the next block to be pushed
|
|
|
extern volatile unsigned char block_buffer_head; // Index of the next block to be pushed
|
|
|
extern volatile unsigned char block_buffer_tail; |
|
|
extern volatile unsigned char block_buffer_tail; |
|
|
// Called when the current block is no longer needed. Discards the block and makes the memory
|
|
|
|
|
|
// availible for new blocks.
|
|
|
// Returns true if the buffer has a queued block, false otherwise
|
|
|
FORCE_INLINE void plan_discard_current_block() |
|
|
FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); } |
|
|
{ |
|
|
|
|
|
if (block_buffer_head != block_buffer_tail) { |
|
|
// Called when the current block is no longer needed. Discards
|
|
|
block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1); |
|
|
// the block and makes the memory available for new blocks.
|
|
|
} |
|
|
FORCE_INLINE void plan_discard_current_block() { |
|
|
|
|
|
if (blocks_queued()) |
|
|
|
|
|
block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Gets the current block. Returns NULL if buffer empty
|
|
|
// Gets the current block. Returns NULL if buffer empty
|
|
|
FORCE_INLINE block_t *plan_get_current_block() |
|
|
FORCE_INLINE block_t *plan_get_current_block() { |
|
|
{ |
|
|
if (blocks_queued()) { |
|
|
if (block_buffer_head == block_buffer_tail) { |
|
|
block_t *block = &block_buffer[block_buffer_tail]; |
|
|
return(NULL); |
|
|
block->busy = true; |
|
|
|
|
|
return block; |
|
|
} |
|
|
} |
|
|
block_t *block = &block_buffer[block_buffer_tail]; |
|
|
else |
|
|
block->busy = true; |
|
|
return NULL; |
|
|
return(block); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Returns true if the buffer has a queued block, false otherwise
|
|
|
|
|
|
FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); } |
|
|
|
|
|
|
|
|
|
|
|
#ifdef PREVENT_DANGEROUS_EXTRUDE |
|
|
#ifdef PREVENT_DANGEROUS_EXTRUDE |
|
|
void set_extrude_min_temp(float temp); |
|
|
void set_extrude_min_temp(float temp); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
void reset_acceleration_rates(); |
|
|
void reset_acceleration_rates(); |
|
|
#endif |
|
|
|
|
|
|
|
|
#endif //PLANNER_H
|
|
|