|
|
@ -21,20 +21,16 @@ |
|
|
|
// This module is to be considered a sub-module of stepper.c. Please don't include
|
|
|
|
// this file from any other module.
|
|
|
|
|
|
|
|
#ifndef planner_h |
|
|
|
#define planner_h |
|
|
|
#ifndef PLANNER_H |
|
|
|
#define PLANNER_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
|
|
|
|
// the source g-code and may never actually be reached if acceleration management is active.
|
|
|
|
typedef struct { |
|
|
|
// 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
|
|
|
|
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
|
|
|
@ -49,7 +45,7 @@ typedef struct { |
|
|
|
#endif |
|
|
|
|
|
|
|
// 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 entry_speed; // Entry speed at previous-current junction 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 fan_speed; |
|
|
|
#ifdef BARICUDA |
|
|
|
unsigned long valve_pressure; |
|
|
|
unsigned long e_to_p_pressure; |
|
|
|
unsigned long valve_pressure; |
|
|
|
unsigned long e_to_p_pressure; |
|
|
|
#endif |
|
|
|
volatile char busy; |
|
|
|
} block_t; |
|
|
|
|
|
|
|
#ifdef ENABLE_AUTO_BED_LEVELING |
|
|
|
// this holds the required transform to compensate for bed level
|
|
|
|
extern matrix_3x3 plan_bed_level_matrix; |
|
|
|
#endif // #ifdef ENABLE_AUTO_BED_LEVELING
|
|
|
|
#define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1)) |
|
|
|
|
|
|
|
// Initialize the motion plan subsystem
|
|
|
|
void plan_init(); |
|
|
|
|
|
|
|
// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in
|
|
|
|
// millimaters. Feed rate specifies the speed of the motion.
|
|
|
|
void check_axes_activity(); |
|
|
|
|
|
|
|
#if defined(ENABLE_AUTO_BED_LEVELING) || defined(MESH_BED_LEVELING) |
|
|
|
void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder); |
|
|
|
#if defined(ENABLE_AUTO_BED_LEVELING) |
|
|
|
#ifndef DELTA |
|
|
|
// 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
|
|
|
|
// Get the number of buffered moves
|
|
|
|
extern volatile unsigned char block_buffer_head; |
|
|
|
extern volatile unsigned char block_buffer_tail; |
|
|
|
FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); } |
|
|
|
|
|
|
|
// Set position. Used for G92 instructions.
|
|
|
|
#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 |
|
|
|
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
|
|
|
|
|
|
|
|
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 float max_feedrate[NUM_AXIS]; // set the max speeds
|
|
|
|
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]; |
|
|
|
|
|
|
|
#ifdef AUTOTEMP |
|
|
|
extern bool autotemp_enabled; |
|
|
|
extern float autotemp_max; |
|
|
|
extern float autotemp_min; |
|
|
|
extern float autotemp_factor; |
|
|
|
extern bool autotemp_enabled; |
|
|
|
extern float autotemp_max; |
|
|
|
extern float autotemp_min; |
|
|
|
extern float autotemp_factor; |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instfructions
|
|
|
|
extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions
|
|
|
|
extern volatile unsigned char block_buffer_head; // Index of the next block to be pushed
|
|
|
|
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.
|
|
|
|
FORCE_INLINE void plan_discard_current_block() |
|
|
|
{ |
|
|
|
if (block_buffer_head != block_buffer_tail) { |
|
|
|
block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1); |
|
|
|
} |
|
|
|
|
|
|
|
// Returns true if the buffer has a queued block, false otherwise
|
|
|
|
FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); } |
|
|
|
|
|
|
|
// Called when the current block is no longer needed. Discards
|
|
|
|
// 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
|
|
|
|
FORCE_INLINE block_t *plan_get_current_block() |
|
|
|
{ |
|
|
|
if (block_buffer_head == block_buffer_tail) { |
|
|
|
return(NULL); |
|
|
|
FORCE_INLINE block_t *plan_get_current_block() { |
|
|
|
if (blocks_queued()) { |
|
|
|
block_t *block = &block_buffer[block_buffer_tail]; |
|
|
|
block->busy = true; |
|
|
|
return block; |
|
|
|
} |
|
|
|
block_t *block = &block_buffer[block_buffer_tail]; |
|
|
|
block->busy = true; |
|
|
|
return(block); |
|
|
|
else |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
// 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 |
|
|
|
void set_extrude_min_temp(float temp); |
|
|
|
void set_extrude_min_temp(float temp); |
|
|
|
#endif |
|
|
|
|
|
|
|
void reset_acceleration_rates(); |
|
|
|
#endif |
|
|
|
|
|
|
|
#endif //PLANNER_H
|
|
|
|