From 2be3a6cc61736328b2c04cb4ad2b28ada776740e Mon Sep 17 00:00:00 2001 From: jvangrin Date: Mon, 4 Jul 2011 13:05:20 -0500 Subject: [PATCH 1/4] fixed null pointer dereference in planner_forward_pass_kernel --- planner.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/planner.c b/planner.c index 9dbe363..f21ced6 100644 --- a/planner.c +++ b/planner.c @@ -232,16 +232,18 @@ 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) { if(!current) { return; } - // If the previous block is an acceleration block, but it is not long enough to - // complete the full speed change within the block, we need to adjust out entry - // speed accordingly. Remember current->entry_factor equals the exit factor of - // the previous block. - if(previous->entry_factor < current->entry_factor) { - double max_entry_speed = max_allowable_speed(-settings.acceleration, - current->nominal_speed*previous->entry_factor, previous->millimeters); - double max_entry_factor = max_entry_speed/current->nominal_speed; - if (max_entry_factor < current->entry_factor) { - current->entry_factor = max_entry_factor; + if(previous) { + // If the previous block is an acceleration block, but it is not long enough to + // complete the full speed change within the block, we need to adjust out entry + // speed accordingly. Remember current->entry_factor equals the exit factor of + // the previous block. + if(previous->entry_factor < current->entry_factor) { + double max_entry_speed = max_allowable_speed(-settings.acceleration, + current->nominal_speed*previous->entry_factor, previous->millimeters); + double max_entry_factor = max_entry_speed/current->nominal_speed; + if (max_entry_factor < current->entry_factor) { + current->entry_factor = max_entry_factor; + } } } } From d4f3fdd4bbd99f6d307a4a86f0773597bd287ef7 Mon Sep 17 00:00:00 2001 From: jvangrin Date: Mon, 4 Jul 2011 13:07:32 -0500 Subject: [PATCH 2/4] fix sign of fractional part in printFloat --- wiring_serial.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wiring_serial.c b/wiring_serial.c index 62c4be4..92da993 100644 --- a/wiring_serial.c +++ b/wiring_serial.c @@ -24,6 +24,7 @@ //#include "wiring_private.h" #include +#include #include #include @@ -176,7 +177,7 @@ void printFloat(double n) fractional_part = modf(n, &integer_part); printInteger(integer_part); printByte('.'); - printInteger(round(fractional_part*1000)); + printInteger(labs(round(fractional_part*1000))); } // void printHex(unsigned long n) From 926d74fcb7c93434ce9acf24d08c0dd59908a278 Mon Sep 17 00:00:00 2001 From: jvangrin Date: Tue, 5 Jul 2011 16:50:40 -0500 Subject: [PATCH 3/4] Reset the overflow flag to stop a queued overflow interrupt from resetting the step pulse right after sei() is called --- stepper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stepper.c b/stepper.c index 5b4efcc..3f33c18 100644 --- a/stepper.c +++ b/stepper.c @@ -135,8 +135,10 @@ SIGNAL(TIMER1_COMPA_vect) // Then pulse the stepping pins STEPPING_PORT = (STEPPING_PORT & ~STEP_MASK) | out_bits; // Reset step pulse reset timer so that The Stepper Port Reset Interrupt can reset the signal after - // exactly settings.pulse_microseconds microseconds. + // exactly settings.pulse_microseconds microseconds. Clear the overflow flag to stop a queued + // interrupt from resetting the step pulse too soon. TCNT2 = -(((settings.pulse_microseconds-2)*TICKS_PER_MICROSECOND)/8); + TIFR2 |= (1< Date: Tue, 5 Jul 2011 16:57:03 -0500 Subject: [PATCH 4/4] Make sure we don't accelerate above the nominal_rate --- stepper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stepper.c b/stepper.c index 3f33c18..a017852 100644 --- a/stepper.c +++ b/stepper.c @@ -101,6 +101,9 @@ inline void trapezoid_generator_tick() { if (current_block) { if (step_events_completed < current_block->accelerate_until) { trapezoid_adjusted_rate += current_block->rate_delta; + if (trapezoid_adjusted_rate > current_block->nominal_rate ) { + trapezoid_adjusted_rate = current_block->nominal_rate; + } set_step_events_per_minute(trapezoid_adjusted_rate); } else if (step_events_completed > current_block->decelerate_after) { // NOTE: We will only reduce speed if the result will be > 0. This catches small