Block: remove finish_early flag. Stepper: use Conveyor::flush flag to finish early
authorMichael Moon <triffid.hunter@gmail.com>
Thu, 20 Feb 2014 21:15:42 +0000 (08:15 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Thu, 20 Feb 2014 21:15:42 +0000 (08:15 +1100)
src/modules/robot/Block.cpp
src/modules/robot/Block.h
src/modules/robot/Stepper.cpp

index dc6a1e3..9707c35 100644 (file)
@@ -99,7 +99,6 @@ void Block::clear()
     recalculate_flag    = false;
     nominal_length_flag = false;
     is_ready            = false;
-    finish_early        = false;
 }
 
 void Block::debug()
index eb97aa1..75434cb 100644 (file)
@@ -69,7 +69,6 @@ class Block {
                 bool    recalculate_flag    :1; // Planner flag to recalculate trapezoids on entry junction
                 bool    nominal_length_flag :1; // Planner flag for nominal speed always reached
                 bool    is_ready            :1;
-                bool    finish_early        :1; // assert if we want the block to end NOW rather than finish all steps
             };
         };
 };
index d1e9ce2..bb9be72 100644 (file)
@@ -206,8 +206,30 @@ uint32_t Stepper::trapezoid_generator_tick( uint32_t dummy )
           return 0;
         }
 
+        if (THEKERNEL->conveyor->flush)
+        {
+            if (trapezoid_adjusted_rate > current_block->rate_delta * 1.5F)
+            {
+                trapezoid_adjusted_rate -= current_block->rate_delta;
+            }
+            else if (trapezoid_adjusted_rate == 0.0F)
+            {
+                for (auto i = THEKERNEL->robot->actuators.begin(); i != THEKERNEL->robot->actuators.end(); i++)
+                    (*i)->move(0, 0);
+
+                if (current_block)
+                    current_block->release();
+
+                return 0;
+            }
+            else
+            {
+                trapezoid_adjusted_rate = current_block->rate_delta * 0.5F;
+            }
+            set_step_events_per_second(trapezoid_adjusted_rate);
+        }
         // If we are accelerating
-        if (current_steps_completed <= current_block->accelerate_until + 1)
+        else if (current_steps_completed <= current_block->accelerate_until + 1)
         {
             // Increase speed
             trapezoid_adjusted_rate += current_block->rate_delta;
@@ -217,7 +239,7 @@ uint32_t Stepper::trapezoid_generator_tick( uint32_t dummy )
             set_step_events_per_second(trapezoid_adjusted_rate);
         }
         // If we are decelerating
-        else if (current_block->finish_early || (current_steps_completed > current_block->decelerate_after))
+        else if (current_steps_completed > current_block->decelerate_after)
         {
             // Reduce speed
             // NOTE: We will only reduce speed if the result will be > 0. This catches small