Start extruder retract at first acceleration speed instead of 0
authorJim Morris <morris@wolfman.com>
Tue, 25 Nov 2014 07:00:10 +0000 (23:00 -0800)
committerJim Morris <morris@wolfman.com>
Tue, 25 Nov 2014 07:00:10 +0000 (23:00 -0800)
src/libs/Pin.cpp
src/modules/tools/extruder/Extruder.cpp
src/modules/tools/extruder/Extruder.h

index 4136791..97e45ba 100644 (file)
@@ -182,5 +182,5 @@ mbed::PwmOut* Pin::hardware_pwm()
         if (pin == 25) { return new mbed::PwmOut(P3_25); }
         if (pin == 26) { return new mbed::PwmOut(P3_26); }
     }
-    return NULL;
+    return nullptr;
 }
index 9cd5fec..9443b14 100644 (file)
@@ -487,8 +487,7 @@ void Extruder::on_block_begin(void *argument)
             // We take the block, we have to release it or everything gets stuck
             block->take();
             this->current_block = block;
-
-            this->stepper_motor->move( ( this->travel_distance > 0 ), steps_to_step, 0);
+            this->stepper_motor->move( ( this->travel_distance > 0 ), steps_to_step, rate_increase()); // start at first acceleration step
 
         } else {
             this->current_block = NULL;
@@ -534,6 +533,10 @@ void Extruder::on_block_end(void *argument)
     this->current_block = NULL;
 }
 
+uint32_t Extruder::rate_increase() const {
+    return floorf((this->acceleration / THEKERNEL->stepper->get_acceleration_ticks_per_second()) * this->steps_per_millimeter);
+}
+
 // Called periodically to change the speed to match acceleration or to match the speed of the robot
 // Only used in SOLO mode
 uint32_t Extruder::acceleration_tick(uint32_t dummy)
@@ -551,15 +554,10 @@ uint32_t Extruder::acceleration_tick(uint32_t dummy)
     uint32_t target_rate = floorf(this->feed_rate * this->steps_per_millimeter);
 
     if( current_rate < target_rate ) {
-        uint32_t rate_increase = floorf((this->acceleration / THEKERNEL->stepper->get_acceleration_ticks_per_second()) * this->steps_per_millimeter);
-        current_rate = min( target_rate, current_rate + rate_increase );
+        current_rate = min( target_rate, current_rate + rate_increase() );
+        // steps per second
+        this->stepper_motor->set_speed(current_rate);
     }
-    if( current_rate > target_rate ) {
-        current_rate = target_rate;
-    }
-
-    // steps per second
-    this->stepper_motor->set_speed(current_rate);
 
     return 0;
 }
index 9b7830d..58549fe 100644 (file)
@@ -38,6 +38,7 @@ class Extruder : public Tool {
 
     private:
         void on_get_public_data(void* argument);
+        uint32_t rate_increase() const;
 
         StepperMotor*  stepper_motor;
         Pin            step_pin;                     // Step pin for the stepper driver