From c5fe1787b941639990663c428f70c9267eb9d3d7 Mon Sep 17 00:00:00 2001 From: Jim Morris Date: Tue, 5 Aug 2014 15:29:08 -0700 Subject: [PATCH] Added z acceleration to configs Endstop/Homing and Zprobe will use Z acceleration for Z if set --- ConfigSamples/AzteegX5Mini/config | 1 + ConfigSamples/Smoothieboard/config | 1 + src/modules/robot/Planner.cpp | 22 ++++++++++++++++++---- src/modules/robot/Planner.h | 2 ++ src/modules/robot/Robot.cpp | 13 +++++++++++-- src/modules/tools/endstops/Endstops.cpp | 4 ++-- src/modules/tools/zprobe/ZProbe.cpp | 5 +++-- 7 files changed, 38 insertions(+), 10 deletions(-) diff --git a/ConfigSamples/AzteegX5Mini/config b/ConfigSamples/AzteegX5Mini/config index 5c4a020f..6ed0bec8 100755 --- a/ConfigSamples/AzteegX5Mini/config +++ b/ConfigSamples/AzteegX5Mini/config @@ -12,6 +12,7 @@ gamma_steps_per_mm 1637.7953 # Steps per mm for # Planner module configuration : Look-ahead and acceleration configuration planner_queue_size 32 # Size of the planning queue, must be a power of 2. 128 seems to be the maximum. acceleration 3000 # Acceleration in mm/second/second. +#z_acceleration 500 # Acceleration for Z only moves in mm/s^2, 0 disables it, disabled by default. DO NOT SET ON A DELTA 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 diff --git a/ConfigSamples/Smoothieboard/config b/ConfigSamples/Smoothieboard/config index b91ddfb4..bc685689 100644 --- a/ConfigSamples/Smoothieboard/config +++ b/ConfigSamples/Smoothieboard/config @@ -16,6 +16,7 @@ gamma_steps_per_mm 1600 # Steps per mm for # Planner module configuration : Look-ahead and acceleration configuration planner_queue_size 32 # DO NOT CHANGE THIS UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING acceleration 3000 # Acceleration in mm/second/second. +#z_acceleration 500 # Acceleration for Z only moves in mm/s^2, 0 disables it, disabled by default. DO NOT SET ON A DELTA 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 diff --git a/src/modules/robot/Planner.cpp b/src/modules/robot/Planner.cpp index 059de15c..b39a352d 100644 --- a/src/modules/robot/Planner.cpp +++ b/src/modules/robot/Planner.cpp @@ -27,6 +27,7 @@ using namespace std; #include #define acceleration_checksum CHECKSUM("acceleration") +#define z_acceleration_checksum CHECKSUM("z_acceleration") #define max_jerk_checksum CHECKSUM("max_jerk") #define junction_deviation_checksum CHECKSUM("junction_deviation") #define minimum_planner_speed_checksum CHECKSUM("minimum_planner_speed") @@ -46,18 +47,23 @@ void Planner::on_module_loaded(){ // Configure acceleration void Planner::on_config_reload(void* argument){ - this->acceleration = THEKERNEL->config->value(acceleration_checksum )->by_default(100.0F )->as_number(); // Acceleration is in mm/s^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(); + this->acceleration = THEKERNEL->config->value(acceleration_checksum)->by_default(100.0F )->as_number(); // Acceleration is in mm/s^2 + this->z_acceleration = THEKERNEL->config->value(z_acceleration_checksum)->by_default(0.0F )->as_number(); // disabled by default + + 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(); } // Append a block to the queue, compute it's speed factors void Planner::append_block( float actuator_pos[], float rate_mm_s, float distance, float unit_vec[] ) { + float acceleration; + // Create ( recycle ) a new block Block* block = THEKERNEL->conveyor->queue.head_ref(); + // Direction bits block->direction_bits = 0; for (int i = 0; i < 3; i++) @@ -74,6 +80,14 @@ void Planner::append_block( float actuator_pos[], float rate_mm_s, float distanc block->steps[i] = labs(steps); } + // use either regular acceleration or a z only move accleration + if(this->z_acceleration > 0.0F && block->steps[ALPHA_STEPPER] == 0 && block->steps[BETA_STEPPER] == 0) { + // z only move + acceleration= this->z_acceleration; + } else{ + acceleration= this->acceleration; + } + // Max number of steps, for all axes block->steps_event_count = max( block->steps[ALPHA_STEPPER], max( block->steps[BETA_STEPPER], block->steps[GAMMA_STEPPER] ) ); @@ -127,7 +141,7 @@ void Planner::append_block( float actuator_pos[], float rate_mm_s, float distanc if (cos_theta > -0.95F) { // Compute maximum junction velocity based on maximum acceleration and junction deviation float sin_theta_d2 = sqrtf(0.5F * (1.0F - cos_theta)); // Trig half angle identity. Always positive. - vmax_junction = min(vmax_junction, sqrtf(this->acceleration * this->junction_deviation * sin_theta_d2 / (1.0F - sin_theta_d2))); + vmax_junction = min(vmax_junction, sqrtf(acceleration * this->junction_deviation * sin_theta_d2 / (1.0F - sin_theta_d2))); } } } diff --git a/src/modules/robot/Planner.h b/src/modules/robot/Planner.h index bce5a801..73127b56 100644 --- a/src/modules/robot/Planner.h +++ b/src/modules/robot/Planner.h @@ -26,6 +26,7 @@ public: void on_module_loaded(); void on_config_reload(void *argument); float get_acceleration() const { return acceleration; } + float get_z_acceleration() const { return z_acceleration > 0.0F ? z_acceleration : acceleration; } friend class Robot; // for acceleration, junction deviation, minimum_planner_speed @@ -35,6 +36,7 @@ private: bool has_deleted_block; // Flag for above value float acceleration; // Setting + float z_acceleration; // Setting float junction_deviation; // Setting float minimum_planner_speed; // Setting }; diff --git a/src/modules/robot/Robot.cpp b/src/modules/robot/Robot.cpp index e688d9cd..6ebea76c 100644 --- a/src/modules/robot/Robot.cpp +++ b/src/modules/robot/Robot.cpp @@ -404,7 +404,7 @@ void Robot::on_gcode_received(void *argument) gcode->mark_as_taken(); break; - case 204: // M204 Snnn - set acceleration to nnn, NB only Snnn is currently supported + case 204: // M204 Snnn - set acceleration to nnn, Znnn sets z acceleration gcode->mark_as_taken(); if (gcode->has_letter('S')) { @@ -416,6 +416,15 @@ void Robot::on_gcode_received(void *argument) acc = 1.0F; THEKERNEL->planner->acceleration = acc; } + if (gcode->has_letter('Z')) { + // TODO for safety so it applies only to following gcodes, maybe a better way to do this? + THEKERNEL->conveyor->wait_for_empty_queue(); + float acc = gcode->get_value('Z'); // mm/s^2 + // enforce positive + if (acc < 0.0F) + acc = 0.0F; + THEKERNEL->planner->z_acceleration = acc; + } break; case 205: // M205 Xnnn - set junction deviation Snnn - Set minimum planner speed @@ -459,7 +468,7 @@ void Robot::on_gcode_received(void *argument) case 500: // M500 saves some volatile settings to config override file case 503: { // M503 just prints the settings gcode->stream->printf(";Steps per unit:\nM92 X%1.5f Y%1.5f Z%1.5f\n", actuators[0]->steps_per_mm, actuators[1]->steps_per_mm, actuators[2]->steps_per_mm); - gcode->stream->printf(";Acceleration mm/sec^2:\nM204 S%1.5f\n", THEKERNEL->planner->acceleration); + gcode->stream->printf(";Acceleration mm/sec^2:\nM204 S%1.5f Z%1.5f\n", THEKERNEL->planner->acceleration, THEKERNEL->planner->z_acceleration); 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->stream->printf(";Max feedrates in mm/sec, XYZ cartesian, ABC actuator:\nM203 X%1.5f Y%1.5f Z%1.5f A%1.5f B%1.5f C%1.5f\n", this->max_speeds[X_AXIS], this->max_speeds[Y_AXIS], this->max_speeds[Z_AXIS], diff --git a/src/modules/tools/endstops/Endstops.cpp b/src/modules/tools/endstops/Endstops.cpp index 8ee22c54..56de5e08 100644 --- a/src/modules/tools/endstops/Endstops.cpp +++ b/src/modules/tools/endstops/Endstops.cpp @@ -678,9 +678,9 @@ uint32_t Endstops::acceleration_tick(uint32_t dummy) uint32_t current_rate = STEPPER[c]->get_steps_per_second(); uint32_t target_rate = int(floor(this->feed_rate[c]*STEPS_PER_MM(c))); - + float acc= (c==Z_AXIS) ? THEKERNEL->planner->get_z_acceleration() : THEKERNEL->planner->get_acceleration(); if( current_rate < target_rate ){ - uint32_t rate_increase = int(floor((THEKERNEL->planner->get_acceleration()/THEKERNEL->stepper->get_acceleration_ticks_per_second())*STEPS_PER_MM(c))); + uint32_t rate_increase = int(floor((acc/THEKERNEL->stepper->get_acceleration_ticks_per_second())*STEPS_PER_MM(c))); current_rate = min( target_rate, current_rate + rate_increase ); } if( current_rate > target_rate ){ current_rate = target_rate; } diff --git a/src/modules/tools/zprobe/ZProbe.cpp b/src/modules/tools/zprobe/ZProbe.cpp index ed78c671..a8800781 100644 --- a/src/modules/tools/zprobe/ZProbe.cpp +++ b/src/modules/tools/zprobe/ZProbe.cpp @@ -317,8 +317,10 @@ void ZProbe::accelerate(int c) { uint32_t current_rate = STEPPER[c]->get_steps_per_second(); uint32_t target_rate = int(floor(this->current_feedrate)); + // Z may have a different acceleration to X and Y + float acc= (c==Z_AXIS) ? THEKERNEL->planner->get_z_acceleration() : THEKERNEL->planner->get_acceleration(); if( current_rate < target_rate ) { - uint32_t rate_increase = int(floor((THEKERNEL->planner->get_acceleration() / THEKERNEL->stepper->get_acceleration_ticks_per_second()) * STEPS_PER_MM(c))); + uint32_t rate_increase = int(floor((acc / THEKERNEL->stepper->get_acceleration_ticks_per_second()) * STEPS_PER_MM(c))); current_rate = min( target_rate, current_rate + rate_increase ); } if( current_rate > target_rate ) { @@ -327,7 +329,6 @@ void ZProbe::accelerate(int c) // steps per second STEPPER[c]->set_speed(max(current_rate, THEKERNEL->stepper->get_minimum_steps_per_second())); -\ } // issue a coordinated move directly to robot, and return when done -- 2.20.1