From 8f20562f494de6cbbd0ecc2d84467814624e8bf6 Mon Sep 17 00:00:00 2001 From: daid303 Date: Mon, 12 Nov 2012 15:49:40 +0100 Subject: [PATCH] Fix some of the crowded code style. And fixed the conditional. #300 --- Marlin/planner.cpp | 122 +++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 44 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index bb6f7ebb1..a0e4adcf7 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -435,7 +435,8 @@ void getHighESpeed() } #endif -void check_axes_activity() { +void check_axes_activity() +{ unsigned char x_active = 0; unsigned char y_active = 0; unsigned char z_active = 0; @@ -444,10 +445,12 @@ void check_axes_activity() { unsigned char tail_fan_speed = 0; block_t *block; - if(block_buffer_tail != block_buffer_head) { + if(block_buffer_tail != block_buffer_head) + { uint8_t block_index = block_buffer_tail; tail_fan_speed = block_buffer[block_index].fan_speed; - while(block_index != block_buffer_head) { + while(block_index != block_buffer_head) + { block = &block_buffer[block_index]; if(block->steps_x != 0) x_active++; if(block->steps_y != 0) y_active++; @@ -457,27 +460,31 @@ void check_axes_activity() { block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1); } } - else { -#if FAN_PIN > -1 + else + { + #if FAN_PIN > -1 if (FanSpeed != 0){ analogWrite(FAN_PIN,FanSpeed); // If buffer is empty use current fan speed } -#endif + #endif } if((DISABLE_X) && (x_active == 0)) disable_x(); if((DISABLE_Y) && (y_active == 0)) disable_y(); if((DISABLE_Z) && (z_active == 0)) disable_z(); - if((DISABLE_E) && (e_active == 0)) { + if((DISABLE_E) && (e_active == 0)) + { disable_e0(); disable_e1(); disable_e2(); } #if FAN_PIN > -1 - if((FanSpeed == 0) && (fan_speed ==0)) { + if((FanSpeed == 0) && (fan_speed ==0)) + { analogWrite(FAN_PIN, 0); } - if (FanSpeed != 0 && tail_fan_speed !=0) { + if (FanSpeed != 0 && tail_fan_speed !=0) + { analogWrite(FAN_PIN,tail_fan_speed); } #endif @@ -498,7 +505,8 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa // If the buffer is full: good! That means we are well ahead of the robot. // Rest here until there is room in the buffer. - while(block_buffer_tail == next_buffer_head) { + while(block_buffer_tail == next_buffer_head) + { manage_heater(); manage_inactivity(); LCD_STATUS; @@ -513,23 +521,26 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa target[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]); target[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]); -#ifdef PREVENT_DANGEROUS_EXTRUDE - if(target[E_AXIS]!=position[E_AXIS]) + #ifdef PREVENT_DANGEROUS_EXTRUDE + if(target[E_AXIS]!=position[E_AXIS]) + { if(degHotend(active_extruder)axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH) - { - position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP); + + #ifdef PREVENT_LENGTHY_EXTRUDE + if(labs(target[E_AXIS]-position[E_AXIS])>axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH) + { + position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP); + } + #endif } -#endif -#endif + #endif // Prepare to set up new block block_t *block = &block_buffer[block_buffer_head]; @@ -547,24 +558,29 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e))); // Bail if this is a zero-length block - if (block->step_event_count <= dropsegments) { + if (block->step_event_count <= dropsegments) + { return; - }; + } block->fan_speed = FanSpeed; // Compute direction bits for this block block->direction_bits = 0; - if (target[X_AXIS] < position[X_AXIS]) { + if (target[X_AXIS] < position[X_AXIS]) + { block->direction_bits |= (1<direction_bits |= (1<direction_bits |= (1<direction_bits |= (1<steps_e != 0) { + if(block->steps_e != 0) + { enable_e0(); enable_e1(); enable_e2(); } - if (block->steps_e == 0) { + if (block->steps_e == 0) + { if(feed_ratesteps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments ) { + if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments ) + { block->millimeters = fabs(delta_mm[E_AXIS]); } - else { + else + { block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS])); } float inverse_millimeters = 1.0/block->millimeters; // Inverse millimeters to remove multiple divides @@ -611,14 +632,17 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill #ifdef OLD_SLOWDOWN - if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1) feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); + if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1) + feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); #endif #ifdef SLOWDOWN // segment time im micro seconds unsigned long segment_time = lround(1000000.0/inverse_second); - if ((moves_queued > 1) && (moves_queued < (BLOCK_BUFFER_SIZE * 0.5))) { - if (segment_time < minsegmenttime) { // buffer is draining, add extra time. The amount of time added increases if the buffer is still emptied more. + if ((moves_queued > 1) && (moves_queued < (BLOCK_BUFFER_SIZE * 0.5))) + { + if (segment_time < minsegmenttime) + { // buffer is draining, add extra time. The amount of time added increases if the buffer is still emptied more. inverse_second=1000000.0/(segment_time+lround(2*(minsegmenttime-segment_time)/moves_queued)); } } @@ -632,7 +656,8 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa // Calculate and limit speed in mm/sec for each axis float current_speed[4]; float speed_factor = 1.0; //factor <=1 do decrease speed - for(int i=0; i < 4; i++) { + for(int i=0; i < 4; i++) + { current_speed[i] = delta_mm[i] * inverse_second; if(fabs(current_speed[i]) > max_feedrate[i]) speed_factor = min(speed_factor, max_feedrate[i] / fabs(current_speed[i])); @@ -646,18 +671,22 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa unsigned char direction_change = block->direction_bits ^ old_direction_bits; old_direction_bits = block->direction_bits; - if((direction_change & (1<nominal_speed *= speed_factor; @@ -679,10 +711,12 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa // Compute and limit the acceleration rate for the trapezoid generator. float steps_per_mm = block->step_event_count/block->millimeters; - if(block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0) { + if(block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0) + { block->acceleration_st = ceil(retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 } - else { + else + { block->acceleration_st = ceil(acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 // Limit acceleration per axis if(((float)block->acceleration_st * (float)block->steps_x / (float)block->step_event_count) > axis_steps_per_sqr_second[X_AXIS])