123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
-
-
-
-
- #ifndef PLANNER_H
- #define PLANNER_H
-
- #include "Marlin.h"
-
- #if ENABLED(AUTO_BED_LEVELING_FEATURE)
- #include "vector_3.h"
- #endif
-
- class Planner;
- extern Planner planner;
-
-
- typedef struct {
-
- unsigned char active_extruder;
-
-
- long steps[NUM_AXIS];
- unsigned long step_event_count;
-
- long accelerate_until;
- long decelerate_after;
- long acceleration_rate;
-
- unsigned char direction_bits;
-
- #if ENABLED(ADVANCE)
- long advance_rate;
- volatile long initial_advance;
- volatile long final_advance;
- float advance;
- #endif
-
-
- float nominal_speed;
- float entry_speed;
- float max_entry_speed;
- float millimeters;
- float acceleration;
- unsigned char recalculate_flag;
- unsigned char nominal_length_flag;
-
-
- unsigned long nominal_rate;
- unsigned long initial_rate;
- unsigned long final_rate;
- unsigned long acceleration_st;
-
- #if FAN_COUNT > 0
- unsigned long fan_speed[FAN_COUNT];
- #endif
-
- #if ENABLED(BARICUDA)
- unsigned long valve_pressure;
- unsigned long e_to_p_pressure;
- #endif
-
- volatile char busy;
-
- } block_t;
-
- #define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
-
- class Planner {
-
- public:
-
-
-
- block_t block_buffer[BLOCK_BUFFER_SIZE];
- volatile uint8_t block_buffer_head = 0;
- volatile uint8_t block_buffer_tail = 0;
-
- float max_feedrate[NUM_AXIS];
- float axis_steps_per_unit[NUM_AXIS];
- unsigned long axis_steps_per_sqr_second[NUM_AXIS];
- unsigned long max_acceleration_units_per_sq_second[NUM_AXIS];
-
- millis_t min_segment_time;
- float min_feedrate;
- float acceleration;
- float retract_acceleration;
- float travel_acceleration;
- float max_xy_jerk;
- float max_z_jerk;
- float max_e_jerk;
- float min_travel_feedrate;
-
- #if ENABLED(AUTO_BED_LEVELING_FEATURE)
- matrix_3x3 bed_level_matrix;
- #endif
-
- private:
-
-
-
- long position[NUM_AXIS] = { 0 };
-
-
-
- float previous_speed[NUM_AXIS];
-
-
-
- float previous_nominal_speed;
-
- #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
-
-
- uint8_t g_uc_extruder_last_move[EXTRUDERS] = { 0 };
- #endif
-
- #ifdef XY_FREQUENCY_LIMIT
-
- #define MAX_FREQ_TIME (1000000.0/XY_FREQUENCY_LIMIT)
-
- static unsigned char old_direction_bits = 0;
-
- static long axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
- #endif
-
- #if ENABLED(DUAL_X_CARRIAGE)
- extern bool extruder_duplication_enabled;
- #endif
-
- public:
-
- Planner();
-
- void init();
-
- void reset_acceleration_rates();
-
-
- void check_axes_activity();
-
-
-
- FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
-
- #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
-
- #if ENABLED(AUTO_BED_LEVELING_FEATURE)
-
-
- vector_3 adjusted_position();
- #endif
-
-
-
- void buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder);
-
-
-
- void set_position(float x, float y, float z, const float& e);
-
- #else
-
- void buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder);
- void set_position(const float& x, const float& y, const float& z, const float& e);
-
- #endif
-
-
-
- void set_e_position(const float& e);
-
-
-
- FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
-
-
-
- FORCE_INLINE void discard_current_block() {
- if (blocks_queued())
- block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
- }
-
-
-
- FORCE_INLINE block_t* get_current_block() {
- if (blocks_queued()) {
- block_t* block = &block_buffer[block_buffer_tail];
- block->busy = true;
- return block;
- }
- else
- return NULL;
- }
-
- #if ENABLED(AUTOTEMP)
- float autotemp_max = 250;
- float autotemp_min = 210;
- float autotemp_factor = 0.1;
- bool autotemp_enabled = false;
- void getHighESpeed();
- void autotemp_M109();
- #endif
-
- private:
-
-
-
- FORCE_INLINE int8_t next_block_index(int8_t block_index) { return BLOCK_MOD(block_index + 1); }
- FORCE_INLINE int8_t prev_block_index(int8_t block_index) { return BLOCK_MOD(block_index - 1); }
-
-
-
- FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration) {
- if (acceleration == 0) return 0;
- return (target_rate * target_rate - initial_rate * initial_rate) / (acceleration * 2);
- }
-
-
-
- FORCE_INLINE float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) {
- if (acceleration == 0) return 0;
- return (acceleration * 2 * distance - initial_rate * initial_rate + final_rate * final_rate) / (acceleration * 4);
- }
-
-
-
- FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity, float distance) {
- return sqrt(target_velocity * target_velocity - 2 * acceleration * distance);
- }
-
- void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor);
-
- void reverse_pass_kernel(block_t* previous, block_t* current, block_t* next);
- void forward_pass_kernel(block_t* previous, block_t* current, block_t* next);
-
- void reverse_pass();
- void forward_pass();
-
- void recalculate_trapezoids();
-
- void recalculate();
-
- };
-
- #endif
|