Keep "astyled" elements in planner.*

This commit is contained in:
Scott Lahteine
2015-10-02 23:15:36 -07:00
parent 4c99327329
commit f11586b517
2 changed files with 56 additions and 58 deletions

View File

@@ -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_speed[NUM_AXIS]; // Speed of previous path line segment
static float previous_nominal_speed; // Nominal 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 #ifdef XY_FREQUENCY_LIMIT
// Used for the 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 // Old direction bits. Used for speed calculations
static unsigned char old_direction_bits = 0; static unsigned char old_direction_bits = 0;
// Segment times (in µs). Used for speed calculations // 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 #endif
#if ENABLED(FILAMENT_SENSOR) #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. // 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 initial_rate = ceil(block->nominal_rate * entry_factor); // (step/min)
unsigned long final_rate = ceil(block->nominal_rate * exit_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; plateau_steps = 0;
} }
#if ENABLED(ADVANCE) #if ENABLED(ADVANCE)
volatile long initial_advance = block->advance * entry_factor * entry_factor; volatile long initial_advance = block->advance * entry_factor * entry_factor;
volatile long final_advance = block->advance * exit_factor * exit_factor; volatile long final_advance = block->advance * exit_factor * exit_factor;
#endif // ADVANCE #endif // ADVANCE
// block->accelerate_until = accelerate_steps; // block->accelerate_until = accelerate_steps;
// block->decelerate_after = accelerate_steps+plateau_steps; // block->decelerate_after = accelerate_steps+plateau_steps;
CRITICAL_SECTION_START; // Fill variables used by the stepper in a critical section CRITICAL_SECTION_START; // Fill variables used by the stepper in a critical section
if (!block->busy) { // Don't update variables if block is busy. if (!block->busy) { // Don't update variables if block is busy.
block->accelerate_until = accelerate_steps; 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->initial_rate = initial_rate;
block->final_rate = final_rate; block->final_rate = final_rate;
#if ENABLED(ADVANCE) #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. // 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; if (!current) return;
UNUSED(previous); 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. // 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) { if (!current->nominal_length_flag && current->max_entry_speed > next->entry_speed) {
current->entry_speed = min(current->max_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 { else {
current->entry_speed = current->max_entry_speed; 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 if (BLOCK_MOD(block_buffer_head - tail + BLOCK_BUFFER_SIZE) > 3) { // moves queued
block_index = BLOCK_MOD(block_buffer_head - 3); 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) { while (block_index != tail) {
block_index = prev_block_index(block_index); block_index = prev_block_index(block_index);
block[2]= block[1]; block[2] = block[1];
block[1]= block[0]; block[1] = block[0];
block[0] = &block_buffer[block_index]; block[0] = &block_buffer[block_index];
planner_reverse_pass_kernel(block[0], block[1], block[2]); 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. // 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; if (!previous) return;
UNUSED(next); 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->nominal_length_flag) {
if (previous->entry_speed < current->entry_speed) { if (previous->entry_speed < current->entry_speed) {
double entry_speed = min(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 // Check for junction speed change
if (current->entry_speed != entry_speed) { if (current->entry_speed != entry_speed) {
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. // implements the forward pass.
void planner_forward_pass() { void planner_forward_pass() {
uint8_t block_index = block_buffer_tail; 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) { while (block_index != block_buffer_head) {
block[0] = block[1]; block[0] = block[1];
@@ -307,8 +306,8 @@ void planner_forward_pass() {
// updating the blocks. // updating the blocks.
void planner_recalculate_trapezoids() { void planner_recalculate_trapezoids() {
int8_t block_index = block_buffer_tail; int8_t block_index = block_buffer_tail;
block_t *current; block_t* current;
block_t *next = NULL; block_t* next = NULL;
while (block_index != block_buffer_head) { while (block_index != block_buffer_head) {
current = next; current = next;
@@ -322,7 +321,7 @@ void planner_recalculate_trapezoids() {
current->recalculate_flag = false; // Reset current only to ensure next trapezoid is computed 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. // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
if (next) { if (next) {
@@ -358,7 +357,7 @@ void planner_recalculate() {
void plan_init() { void plan_init() {
block_buffer_head = block_buffer_tail = 0; block_buffer_head = block_buffer_tail = 0;
memset(position, 0, sizeof(position)); // clear position 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; previous_nominal_speed = 0.0;
} }
@@ -374,7 +373,7 @@ void plan_init() {
uint8_t block_index = block_buffer_tail; uint8_t block_index = block_buffer_tail;
while (block_index != block_buffer_head) { 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]) { 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; float se = (float)block->steps[E_AXIS] / block->step_event_count * block->nominal_speed; // mm/sec;
if (se > high) high = se; if (se > high) high = se;
@@ -391,7 +390,7 @@ void plan_init() {
oldt = t; oldt = t;
setTargetHotend0(t); setTargetHotend0(t);
} }
#endif #endif //AUTOTEMP
void check_axes_activity() { void check_axes_activity() {
unsigned char axis_active[NUM_AXIS] = { 0 }, unsigned char axis_active[NUM_AXIS] = { 0 },
@@ -401,7 +400,7 @@ void check_axes_activity() {
tail_e_to_p_pressure = EtoPPressure; tail_e_to_p_pressure = EtoPPressure;
#endif #endif
block_t *block; block_t* block;
if (blocks_queued()) { if (blocks_queued()) {
uint8_t block_index = block_buffer_tail; uint8_t block_index = block_buffer_tail;
@@ -413,7 +412,7 @@ void check_axes_activity() {
#endif #endif
while (block_index != block_buffer_head) { while (block_index != block_buffer_head) {
block = &block_buffer[block_index]; 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); block_index = next_block_index(block_index);
} }
} }
@@ -461,10 +460,10 @@ void check_axes_activity() {
#if ENABLED(BARICUDA) #if ENABLED(BARICUDA)
#if HAS_HEATER_1 #if HAS_HEATER_1
analogWrite(HEATER_1_PIN,tail_valve_pressure); analogWrite(HEATER_1_PIN, tail_valve_pressure);
#endif #endif
#if HAS_HEATER_2 #if HAS_HEATER_2
analogWrite(HEATER_2_PIN,tail_e_to_p_pressure); analogWrite(HEATER_2_PIN, tail_e_to_p_pressure);
#endif #endif
#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 // 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. // calculation the caller must also provide the physical length of the line in millimeters.
#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING) #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 #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 #endif // AUTO_BED_LEVELING_FEATURE
{ {
// Calculate the buffer head after we push this byte // Calculate the buffer head after we push this byte
@@ -532,7 +531,7 @@ float junction_deviation = 0.1;
#endif #endif
// Prepare to set up new block // 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) // Mark block as not busy (Not executed by the stepper interrupt)
block->busy = false; block->busy = false;
@@ -622,7 +621,7 @@ float junction_deviation = 0.1;
if (block->steps[E_AXIS]) { if (block->steps[E_AXIS]) {
if (DISABLE_INACTIVE_EXTRUDER) { //enable only selected extruder 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]--; if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
switch(extruder) { switch(extruder) {
@@ -873,9 +872,9 @@ float junction_deviation = 0.1;
// Compute path unit vector // Compute path unit vector
double unit_vec[3]; double unit_vec[3];
unit_vec[X_AXIS] = delta_mm[X_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[Y_AXIS] = delta_mm[Y_AXIS] * inverse_millimeters;
unit_vec[Z_AXIS] = delta_mm[Z_AXIS]*inverse_millimeters; unit_vec[Z_AXIS] = delta_mm[Z_AXIS] * inverse_millimeters;
// Compute maximum allowable entry speed at junction by centripetal acceleration approximation. // 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 // 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) // 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. // 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] double cos_theta = - previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
- previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS] - previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
- previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS] ; - previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS] ;
// Skip and use default max junction speed for 0 degree acute junction. // Skip and use default max junction speed for 0 degree acute junction.
if (cos_theta < 0.95) { 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. // Skip and avoid divide by zero for straight junctions at 180 degrees. Limit to min() of nominal speeds.
if (cos_theta > -0.95) { if (cos_theta > -0.95) {
// Compute maximum junction velocity based on maximum acceleration and junction deviation // 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, 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 #endif // AUTO_BED_LEVELING_FEATURE && !DELTA
#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING) #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 #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 #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
{ {
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(MESH_BED_LEVELING)
@@ -1026,10 +1024,10 @@ float junction_deviation = 0.1;
st_set_position(nx, ny, nz, ne); st_set_position(nx, ny, nz, ne);
previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest. 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]); position[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]);
st_set_e_position(position[E_AXIS]); st_set_e_position(position[E_AXIS]);
} }

View File

@@ -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 * 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. * 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. * Set the planner positions. Used for G92 instructions.
* Multiplies by axis_steps_per_unit[] to set stepper positions. * Multiplies by axis_steps_per_unit[] to set stepper positions.
* Clears previous speed values. * 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 #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);
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 #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 ============================ //============================= public variables ============================
@@ -155,9 +155,9 @@ FORCE_INLINE void plan_discard_current_block() {
} }
// 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 (blocks_queued()) {
block_t *block = &block_buffer[block_buffer_tail]; block_t* block = &block_buffer[block_buffer_tail];
block->busy = true; block->busy = true;
return block; return block;
} }