Make minimum planner speed configurable
authorJim Morris <morris@wolfman.com>
Sun, 12 Jan 2014 05:54:33 +0000 (21:54 -0800)
committerJim Morris <morris@wolfman.com>
Sun, 12 Jan 2014 05:56:30 +0000 (21:56 -0800)
pop all flushable blocks for queue in one on_idle
Add M205 Sxxx to set minimum planner speed from console and save with M500

ConfigSamples/Smoothieboard/config
src/modules/robot/Block.cpp
src/modules/robot/Conveyor.cpp
src/modules/robot/Planner.cpp
src/modules/robot/Planner.h
src/modules/robot/Robot.cpp

index 7b4c884..c6d87fe 100644 (file)
@@ -15,6 +15,7 @@ acceleration                                 3000             # Acceleration in
 acceleration_ticks_per_second                1000             # Number of times per second the speed is updated
 junction_deviation                           0.05             # Similar to the old "max_jerk", in millimeters, see : https://github.com/grbl/grbl/blob/master/planner.c#L409
                                                               # and https://github.com/grbl/grbl/wiki/Configuring-Grbl-v0.8 . Lower values mean being more careful, higher values means being faster and have more jerk
+#minimum_planner_speed                       0.0              # sets the minimum planner speed in mm/sec
 
 # Stepper module configuration
 microseconds_per_step_pulse                  1                # Duration of step pulses to stepper drivers, in microseconds
index 5aebc7d..dd5ed79 100644 (file)
@@ -54,7 +54,7 @@ void Block::clear()
 
 void Block::debug()
 {
-    THEKERNEL->streams->printf("%p: steps:%4d|%4d|%4d(max:%4d) nominal:r%10d/s%6.1f mm:%9.6f rdelta:%8f acc:%5d dec:%5d rates:%10d>%10d  entry: %10.4f taken:%d ready:%d \r\n", this, this->steps[0], this->steps[1], this->steps[2], this->steps_event_count, this->nominal_rate, this->nominal_speed, this->millimeters, this->rate_delta, this->accelerate_until, this->decelerate_after, this->initial_rate, this->final_rate, this->entry_speed, this->times_taken, this->is_ready );
+    THEKERNEL->streams->printf("%p: steps:%4d|%4d|%4d(max:%4d) nominal:r%10d/s%6.1f mm:%9.6f rdelta:%8f acc:%5d dec:%5d rates:%10d>%10d  entry/max: %10.4f/%10.4f taken:%d ready:%d \r\n", this, this->steps[0], this->steps[1], this->steps[2], this->steps_event_count, this->nominal_rate, this->nominal_speed, this->millimeters, this->rate_delta, this->accelerate_until, this->decelerate_after, this->initial_rate, this->final_rate, this->entry_speed, this->max_entry_speed, this->times_taken, this->is_ready );
 }
 
 
index 0edbc0b..ec7cbcd 100644 (file)
@@ -32,7 +32,7 @@ void Conveyor::on_module_loaded(){
 
 // Delete blocks here, because they can't be deleted in interrupt context ( see Block.cpp:release )
 void Conveyor::on_idle(void* argument){
-    if (flush_blocks){
+    while (flush_blocks > 0){
         // Cleanly delete block
         Block* block = queue.get_tail_ref();
         block->gcodes.clear();
index 3a8a4ae..bf38b95 100644 (file)
@@ -18,6 +18,11 @@ using namespace std;
 #include "Planner.h"
 #include "Conveyor.h"
 
+#define acceleration_checksum          CHECKSUM("acceleration")
+#define max_jerk_checksum              CHECKSUM("max_jerk")
+#define junction_deviation_checksum    CHECKSUM("junction_deviation")
+#define minimum_planner_speed_checksum CHECKSUM("minimum_planner_speed")
+
 // The Planner does the acceleration math for the queue of Blocks ( movements ).
 // It makes sure the speed stays within the configured constraints ( acceleration, junction_deviation, etc )
 // It goes over the list in both direction, every time a block is added, re-doing the math to make sure everything is optimal
@@ -38,6 +43,7 @@ void Planner::on_module_loaded(){
 void Planner::on_config_reload(void* argument){
     this->acceleration =       THEKERNEL->config->value(acceleration_checksum       )->by_default(100  )->as_number() * 60 * 60; // Acceleration is in mm/minute^2, see https://github.com/grbl/grbl/commit/9141ad282540eaa50a41283685f901f29c24ddbd#planner.c
     this->junction_deviation = THEKERNEL->config->value(junction_deviation_checksum )->by_default(0.05f)->as_number();
+    this->minimum_planner_speed = THEKERNEL->config->value(minimum_planner_speed_checksum )->by_default(0.0f)->as_number();
 }
 
 
@@ -101,7 +107,7 @@ void Planner::append_block( int target[], float feed_rate, float distance, float
     // path width or max_jerk in the previous grbl version. This approach does not actually deviate
     // from path, but used as a robust way to compute cornering speeds, as it takes into account the
     // nonlinearities of both the junction angle and junction velocity.
-    float vmax_junction = MINIMUM_PLANNER_SPEED; // Set default max junction speed
+    float vmax_junction = minimum_planner_speed; // Set default max junction speed
 
     if (THEKERNEL->conveyor->queue.size() > 1 && (this->previous_nominal_speed > 0.0F)) {
       // Compute cosine of angle between previous and current path. (prev_unit_vec is negative)
@@ -124,8 +130,8 @@ void Planner::append_block( int target[], float feed_rate, float distance, float
     }
     block->max_entry_speed = vmax_junction;
 
-    // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
-    float v_allowable = this->max_allowable_speed(-this->acceleration,0.0F,block->millimeters); //TODO: Get from config
+    // Initialize block entry speed. Compute based on deceleration to user-defined minimum_planner_speed.
+    float v_allowable = this->max_allowable_speed(-this->acceleration,minimum_planner_speed,block->millimeters); //TODO: Get from config
     block->entry_speed = min(vmax_junction, v_allowable);
 
     // Initialize planner efficiency flags
@@ -152,7 +158,6 @@ void Planner::append_block( int target[], float feed_rate, float distance, float
 
     // The block can now be used
     block->ready();
-
 }
 
 
@@ -228,15 +233,15 @@ void Planner::recalculate() {
         current = &queue->buffer[block_index];
     }
 
-    // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
-    current->calculate_trapezoid( current->entry_speed/current->nominal_speed, MINIMUM_PLANNER_SPEED/current->nominal_speed );
+    // Last/newest block in buffer. Exit speed is set with minimum_planner_speed. Always recalculated.
+    current->calculate_trapezoid( current->entry_speed/current->nominal_speed, minimum_planner_speed/current->nominal_speed );
     current->recalculate_flag = false;
 }
 
 // Debug function
 void Planner::dump_queue(){
     for( int index = 0; index <= THEKERNEL->conveyor->queue.size()-1; index++ ){
-       if( index > 10 && index < THEKERNEL->conveyor->queue.size()-10 ){ continue; }
+       //if( index > 10 && index < THEKERNEL->conveyor->queue.size()-10 ){ continue; }
        THEKERNEL->streams->printf("block %03d > ", index);
        THEKERNEL->conveyor->queue.get_ref(index)->debug();
     }
index 60cbb8b..173f813 100644 (file)
 #include "../communication/utils/Gcode.h"
 #include "Block.h"
 
-#define acceleration_checksum       CHECKSUM("acceleration")
-#define max_jerk_checksum           CHECKSUM("max_jerk")
-#define junction_deviation_checksum CHECKSUM("junction_deviation")
-
-// TODO: Get from config
-#define MINIMUM_PLANNER_SPEED 0.0F
 using namespace std;
 
-
 class Planner : public Module {
     public:
         Planner();
@@ -42,7 +35,7 @@ class Planner : public Module {
 
         float acceleration;          // Setting
         float junction_deviation;    // Setting
-
+        float minimum_planner_speed; // Setting
 };
 
 
index a0e8857..885252b 100644 (file)
@@ -248,16 +248,24 @@ void Robot::on_gcode_received(void * argument){
                 }
                 break;
 
-            case 205: // M205 Xnnn - set junction deviation
+            case 205: // M205 Xnnn - set junction deviation Snnn - Set minimum planner speed
                 gcode->mark_as_taken();
                 if (gcode->has_letter('X'))
                 {
                     float jd= gcode->get_value('X');
                     // enforce minimum
-                    if (jd < 0.0)
-                        jd = 0.0;
+                    if (jd < 0.0F)
+                        jd = 0.0F;
                     THEKERNEL->planner->junction_deviation= jd;
                 }
+                if (gcode->has_letter('S'))
+                {
+                    float mps= gcode->get_value('S');
+                    // enforce minimum
+                    if (mps < 0.0F)
+                        mps = 0.0F;
+                    THEKERNEL->planner->minimum_planner_speed= mps;
+                }
                 break;
 
             case 220: // M220 - speed override percentage
@@ -282,7 +290,7 @@ void Robot::on_gcode_received(void * argument){
                 this->arm_solution->get_steps_per_millimeter(steps);
                 gcode->stream->printf(";Steps per unit:\nM92 X%1.5f Y%1.5f Z%1.5f\n", steps[0], steps[1], steps[2]);
                 gcode->stream->printf(";Acceleration mm/sec^2:\nM204 S%1.5f\n", THEKERNEL->planner->acceleration/3600);
-                gcode->stream->printf(";Junction Deviation:\nM205 X%1.5f\n", THEKERNEL->planner->junction_deviation);
+                gcode->stream->printf(";X- Junction Deviation, S - Minimum Planner speed:\nM205 X%1.5f S%1.5f\n", THEKERNEL->planner->junction_deviation, THEKERNEL->planner->minimum_planner_speed);
                 gcode->mark_as_taken();
                 break;