Keep "astyled" elements in planner.*
This commit is contained in:
@@ -110,7 +110,7 @@ long position[NUM_AXIS]; // Rescaled from extern when axis_steps_p
|
||||
static float previous_speed[NUM_AXIS]; // Speed of previous path line segment
|
||||
static float previous_nominal_speed; // Nominal speed of previous path line segment
|
||||
|
||||
unsigned char g_uc_extruder_last_move[4] = {0,0,0,0};
|
||||
unsigned char g_uc_extruder_last_move[4] = { 0 };
|
||||
|
||||
#ifdef XY_FREQUENCY_LIMIT
|
||||
// Used for the frequency limit
|
||||
@@ -118,7 +118,7 @@ unsigned char g_uc_extruder_last_move[4] = {0,0,0,0};
|
||||
// Old direction bits. Used for speed calculations
|
||||
static unsigned char old_direction_bits = 0;
|
||||
// Segment times (in µs). Used for speed calculations
|
||||
static long axis_segment_time[2][3] = { {MAX_FREQ_TIME+1,0,0}, {MAX_FREQ_TIME+1,0,0} };
|
||||
static long axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
|
||||
#endif
|
||||
|
||||
#if ENABLED(FILAMENT_SENSOR)
|
||||
@@ -153,7 +153,7 @@ FORCE_INLINE float intersection_distance(float initial_rate, float final_rate, f
|
||||
|
||||
// Calculates trapezoid parameters so that the entry- and exit-speed is compensated by the provided factors.
|
||||
|
||||
void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exit_factor) {
|
||||
void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor) {
|
||||
unsigned long initial_rate = ceil(block->nominal_rate * entry_factor); // (step/min)
|
||||
unsigned long final_rate = ceil(block->nominal_rate * exit_factor); // (step/min)
|
||||
|
||||
@@ -178,17 +178,17 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi
|
||||
plateau_steps = 0;
|
||||
}
|
||||
|
||||
#if ENABLED(ADVANCE)
|
||||
volatile long initial_advance = block->advance * entry_factor * entry_factor;
|
||||
volatile long final_advance = block->advance * exit_factor * exit_factor;
|
||||
#endif // ADVANCE
|
||||
#if ENABLED(ADVANCE)
|
||||
volatile long initial_advance = block->advance * entry_factor * entry_factor;
|
||||
volatile long final_advance = block->advance * exit_factor * exit_factor;
|
||||
#endif // ADVANCE
|
||||
|
||||
// block->accelerate_until = accelerate_steps;
|
||||
// block->decelerate_after = accelerate_steps+plateau_steps;
|
||||
CRITICAL_SECTION_START; // Fill variables used by the stepper in a critical section
|
||||
if (!block->busy) { // Don't update variables if block is busy.
|
||||
block->accelerate_until = accelerate_steps;
|
||||
block->decelerate_after = accelerate_steps+plateau_steps;
|
||||
block->decelerate_after = accelerate_steps + plateau_steps;
|
||||
block->initial_rate = initial_rate;
|
||||
block->final_rate = final_rate;
|
||||
#if ENABLED(ADVANCE)
|
||||
@@ -215,7 +215,7 @@ FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity
|
||||
|
||||
|
||||
// The kernel called by planner_recalculate() when scanning the plan from last to first entry.
|
||||
void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) {
|
||||
void planner_reverse_pass_kernel(block_t* previous, block_t* current, block_t* next) {
|
||||
if (!current) return;
|
||||
UNUSED(previous);
|
||||
|
||||
@@ -229,7 +229,7 @@ void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *n
|
||||
// for max allowable speed if block is decelerating and nominal length is false.
|
||||
if (!current->nominal_length_flag && current->max_entry_speed > next->entry_speed) {
|
||||
current->entry_speed = min(current->max_entry_speed,
|
||||
max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
|
||||
max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
|
||||
}
|
||||
else {
|
||||
current->entry_speed = current->max_entry_speed;
|
||||
@@ -252,11 +252,11 @@ void planner_reverse_pass() {
|
||||
|
||||
if (BLOCK_MOD(block_buffer_head - tail + BLOCK_BUFFER_SIZE) > 3) { // moves queued
|
||||
block_index = BLOCK_MOD(block_buffer_head - 3);
|
||||
block_t *block[3] = { NULL, NULL, NULL };
|
||||
block_t* block[3] = { NULL, NULL, NULL };
|
||||
while (block_index != tail) {
|
||||
block_index = prev_block_index(block_index);
|
||||
block[2]= block[1];
|
||||
block[1]= block[0];
|
||||
block[2] = block[1];
|
||||
block[1] = block[0];
|
||||
block[0] = &block_buffer[block_index];
|
||||
planner_reverse_pass_kernel(block[0], block[1], block[2]);
|
||||
}
|
||||
@@ -264,7 +264,7 @@ void planner_reverse_pass() {
|
||||
}
|
||||
|
||||
// The kernel called by planner_recalculate() when scanning the plan from first to last entry.
|
||||
void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *next) {
|
||||
void planner_forward_pass_kernel(block_t* previous, block_t* current, block_t* next) {
|
||||
if (!previous) return;
|
||||
UNUSED(next);
|
||||
|
||||
@@ -275,8 +275,7 @@ void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *n
|
||||
if (!previous->nominal_length_flag) {
|
||||
if (previous->entry_speed < current->entry_speed) {
|
||||
double entry_speed = min(current->entry_speed,
|
||||
max_allowable_speed(-previous->acceleration, previous->entry_speed, previous->millimeters));
|
||||
|
||||
max_allowable_speed(-previous->acceleration, previous->entry_speed, previous->millimeters));
|
||||
// Check for junction speed change
|
||||
if (current->entry_speed != entry_speed) {
|
||||
current->entry_speed = entry_speed;
|
||||
@@ -290,7 +289,7 @@ void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *n
|
||||
// implements the forward pass.
|
||||
void planner_forward_pass() {
|
||||
uint8_t block_index = block_buffer_tail;
|
||||
block_t *block[3] = { NULL, NULL, NULL };
|
||||
block_t* block[3] = { NULL, NULL, NULL };
|
||||
|
||||
while (block_index != block_buffer_head) {
|
||||
block[0] = block[1];
|
||||
@@ -307,8 +306,8 @@ void planner_forward_pass() {
|
||||
// updating the blocks.
|
||||
void planner_recalculate_trapezoids() {
|
||||
int8_t block_index = block_buffer_tail;
|
||||
block_t *current;
|
||||
block_t *next = NULL;
|
||||
block_t* current;
|
||||
block_t* next = NULL;
|
||||
|
||||
while (block_index != block_buffer_head) {
|
||||
current = next;
|
||||
@@ -322,7 +321,7 @@ void planner_recalculate_trapezoids() {
|
||||
current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed
|
||||
}
|
||||
}
|
||||
block_index = next_block_index( block_index );
|
||||
block_index = next_block_index(block_index);
|
||||
}
|
||||
// Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
|
||||
if (next) {
|
||||
@@ -358,7 +357,7 @@ void planner_recalculate() {
|
||||
void plan_init() {
|
||||
block_buffer_head = block_buffer_tail = 0;
|
||||
memset(position, 0, sizeof(position)); // clear position
|
||||
for (int i=0; i<NUM_AXIS; i++) previous_speed[i] = 0.0;
|
||||
for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = 0.0;
|
||||
previous_nominal_speed = 0.0;
|
||||
}
|
||||
|
||||
@@ -374,7 +373,7 @@ void plan_init() {
|
||||
uint8_t block_index = block_buffer_tail;
|
||||
|
||||
while (block_index != block_buffer_head) {
|
||||
block_t *block = &block_buffer[block_index];
|
||||
block_t* block = &block_buffer[block_index];
|
||||
if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS]) {
|
||||
float se = (float)block->steps[E_AXIS] / block->step_event_count * block->nominal_speed; // mm/sec;
|
||||
if (se > high) high = se;
|
||||
@@ -391,7 +390,7 @@ void plan_init() {
|
||||
oldt = t;
|
||||
setTargetHotend0(t);
|
||||
}
|
||||
#endif
|
||||
#endif //AUTOTEMP
|
||||
|
||||
void check_axes_activity() {
|
||||
unsigned char axis_active[NUM_AXIS] = { 0 },
|
||||
@@ -401,7 +400,7 @@ void check_axes_activity() {
|
||||
tail_e_to_p_pressure = EtoPPressure;
|
||||
#endif
|
||||
|
||||
block_t *block;
|
||||
block_t* block;
|
||||
|
||||
if (blocks_queued()) {
|
||||
uint8_t block_index = block_buffer_tail;
|
||||
@@ -413,7 +412,7 @@ void check_axes_activity() {
|
||||
#endif
|
||||
while (block_index != block_buffer_head) {
|
||||
block = &block_buffer[block_index];
|
||||
for (int i=0; i<NUM_AXIS; i++) if (block->steps[i]) axis_active[i]++;
|
||||
for (int i = 0; i < NUM_AXIS; i++) if (block->steps[i]) axis_active[i]++;
|
||||
block_index = next_block_index(block_index);
|
||||
}
|
||||
}
|
||||
@@ -461,10 +460,10 @@ void check_axes_activity() {
|
||||
|
||||
#if ENABLED(BARICUDA)
|
||||
#if HAS_HEATER_1
|
||||
analogWrite(HEATER_1_PIN,tail_valve_pressure);
|
||||
analogWrite(HEATER_1_PIN, tail_valve_pressure);
|
||||
#endif
|
||||
#if HAS_HEATER_2
|
||||
analogWrite(HEATER_2_PIN,tail_e_to_p_pressure);
|
||||
analogWrite(HEATER_2_PIN, tail_e_to_p_pressure);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@@ -475,9 +474,9 @@ float junction_deviation = 0.1;
|
||||
// mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
|
||||
// calculation the caller must also provide the physical length of the line in millimeters.
|
||||
#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
|
||||
void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t extruder)
|
||||
void plan_buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder)
|
||||
#else
|
||||
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_buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder)
|
||||
#endif // AUTO_BED_LEVELING_FEATURE
|
||||
{
|
||||
// Calculate the buffer head after we push this byte
|
||||
@@ -532,7 +531,7 @@ float junction_deviation = 0.1;
|
||||
#endif
|
||||
|
||||
// Prepare to set up new block
|
||||
block_t *block = &block_buffer[block_buffer_head];
|
||||
block_t* block = &block_buffer[block_buffer_head];
|
||||
|
||||
// Mark block as not busy (Not executed by the stepper interrupt)
|
||||
block->busy = false;
|
||||
@@ -622,7 +621,7 @@ float junction_deviation = 0.1;
|
||||
if (block->steps[E_AXIS]) {
|
||||
if (DISABLE_INACTIVE_EXTRUDER) { //enable only selected extruder
|
||||
|
||||
for (int i=0; i<EXTRUDERS; i++)
|
||||
for (int i = 0; i < EXTRUDERS; i++)
|
||||
if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
|
||||
|
||||
switch(extruder) {
|
||||
@@ -873,9 +872,9 @@ float junction_deviation = 0.1;
|
||||
// Compute path unit vector
|
||||
double unit_vec[3];
|
||||
|
||||
unit_vec[X_AXIS] = delta_mm[X_AXIS]*inverse_millimeters;
|
||||
unit_vec[Y_AXIS] = delta_mm[Y_AXIS]*inverse_millimeters;
|
||||
unit_vec[Z_AXIS] = delta_mm[Z_AXIS]*inverse_millimeters;
|
||||
unit_vec[X_AXIS] = delta_mm[X_AXIS] * inverse_millimeters;
|
||||
unit_vec[Y_AXIS] = delta_mm[Y_AXIS] * inverse_millimeters;
|
||||
unit_vec[Z_AXIS] = delta_mm[Z_AXIS] * inverse_millimeters;
|
||||
|
||||
// Compute maximum allowable entry speed at junction by centripetal acceleration approximation.
|
||||
// Let a circle be tangent to both previous and current path line segments, where the junction
|
||||
@@ -893,18 +892,17 @@ float junction_deviation = 0.1;
|
||||
// Compute cosine of angle between previous and current path. (prev_unit_vec is negative)
|
||||
// NOTE: Max junction velocity is computed without sin() or acos() by trig half angle identity.
|
||||
double cos_theta = - previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
|
||||
- previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
|
||||
- previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS] ;
|
||||
|
||||
- previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
|
||||
- previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS] ;
|
||||
// Skip and use default max junction speed for 0 degree acute junction.
|
||||
if (cos_theta < 0.95) {
|
||||
vmax_junction = min(previous_nominal_speed,block->nominal_speed);
|
||||
vmax_junction = min(previous_nominal_speed, block->nominal_speed);
|
||||
// Skip and avoid divide by zero for straight junctions at 180 degrees. Limit to min() of nominal speeds.
|
||||
if (cos_theta > -0.95) {
|
||||
// Compute maximum junction velocity based on maximum acceleration and junction deviation
|
||||
double sin_theta_d2 = sqrt(0.5*(1.0-cos_theta)); // Trig half angle identity. Always positive.
|
||||
double sin_theta_d2 = sqrt(0.5 * (1.0 - cos_theta)); // Trig half angle identity. Always positive.
|
||||
vmax_junction = min(vmax_junction,
|
||||
sqrt(block->acceleration * junction_deviation * sin_theta_d2/(1.0-sin_theta_d2)) );
|
||||
sqrt(block->acceleration * junction_deviation * sin_theta_d2 / (1.0 - sin_theta_d2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1008,9 +1006,9 @@ float junction_deviation = 0.1;
|
||||
#endif // AUTO_BED_LEVELING_FEATURE && !DELTA
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
|
||||
void plan_set_position(float x, float y, float z, const float &e)
|
||||
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_set_position(const float& x, const float& y, const float& z, const float& e)
|
||||
#endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
|
||||
{
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
@@ -1026,10 +1024,10 @@ float junction_deviation = 0.1;
|
||||
st_set_position(nx, ny, nz, ne);
|
||||
previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
|
||||
|
||||
for (int i=0; i<NUM_AXIS; i++) previous_speed[i] = 0.0;
|
||||
for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = 0.0;
|
||||
}
|
||||
|
||||
void plan_set_e_position(const float &e) {
|
||||
void plan_set_e_position(const float& e) {
|
||||
position[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]);
|
||||
st_set_e_position(position[E_AXIS]);
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@
|
||||
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// 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.
|
||||
|
||||
#ifndef PLANNER_H
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "Marlin.h"
|
||||
|
||||
// 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.
|
||||
typedef struct {
|
||||
// Fields used by the bresenham algorithm for tracing the line
|
||||
@@ -46,7 +46,7 @@ typedef struct {
|
||||
|
||||
// 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 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 max_entry_speed; // Maximum allowable junction entry speed in mm/sec
|
||||
float millimeters; // The total travel of this block in mm
|
||||
@@ -55,8 +55,8 @@ typedef struct {
|
||||
unsigned char nominal_length_flag; // Planner flag for nominal speed always reached
|
||||
|
||||
// Settings for the trapezoid generator
|
||||
unsigned long nominal_rate; // The nominal step rate for this block in step_events/sec
|
||||
unsigned long initial_rate; // The jerk-adjusted step rate at start of block
|
||||
unsigned long nominal_rate; // The nominal step rate for this block in step_events/sec
|
||||
unsigned long initial_rate; // The jerk-adjusted step rate at start of block
|
||||
unsigned long final_rate; // The minimal rate at exit
|
||||
unsigned long acceleration_st; // acceleration steps/sec^2
|
||||
unsigned long fan_speed;
|
||||
@@ -69,7 +69,7 @@ typedef struct {
|
||||
|
||||
#define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
|
||||
|
||||
// Initialize the motion plan subsystem
|
||||
// Initialize the motion plan subsystem
|
||||
void plan_init();
|
||||
|
||||
void check_axes_activity();
|
||||
@@ -97,23 +97,23 @@ FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block
|
||||
* Add a new linear movement to the buffer. x, y, z are the signed, absolute target position in
|
||||
* millimeters. Feed rate specifies the (target) speed of the motion.
|
||||
*/
|
||||
void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t extruder);
|
||||
void plan_buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder);
|
||||
|
||||
/**
|
||||
* Set the planner positions. Used for G92 instructions.
|
||||
* Multiplies by axis_steps_per_unit[] to set stepper positions.
|
||||
* Clears previous speed values.
|
||||
*/
|
||||
void plan_set_position(float x, float y, float z, const float &e);
|
||||
void plan_set_position(float x, float y, float z, const float& e);
|
||||
|
||||
#else
|
||||
|
||||
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);
|
||||
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 // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
|
||||
|
||||
void plan_set_e_position(const float &e);
|
||||
void plan_set_e_position(const float& e);
|
||||
|
||||
//===========================================================================
|
||||
//============================= public variables ============================
|
||||
@@ -142,7 +142,7 @@ extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
|
||||
|
||||
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;
|
||||
extern volatile unsigned char block_buffer_tail;
|
||||
|
||||
// Returns true if the buffer has a queued block, false otherwise
|
||||
FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
|
||||
@@ -155,9 +155,9 @@ FORCE_INLINE void plan_discard_current_block() {
|
||||
}
|
||||
|
||||
// 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()) {
|
||||
block_t *block = &block_buffer[block_buffer_tail];
|
||||
block_t* block = &block_buffer[block_buffer_tail];
|
||||
block->busy = true;
|
||||
return block;
|
||||
}
|
||||
|
Reference in New Issue
Block a user