From: Jim Morris Date: Fri, 21 Nov 2014 05:54:08 +0000 (-0800) Subject: get rid of #define max and use stl::max X-Git-Url: https://git.hcoop.net/clinton/Smoothieware.git/commitdiff_plain/9502f9d519c4c8fe56f8cfa0442048c2aa87371f get rid of #define max and use stl::max use ceilf instead of ceil make minimum step rate settabl ewith M205 --- diff --git a/src/libs/StepperMotor.cpp b/src/libs/StepperMotor.cpp index 48aa55a9..e0c0f7b1 100644 --- a/src/libs/StepperMotor.cpp +++ b/src/libs/StepperMotor.cpp @@ -13,7 +13,7 @@ #include // in steps/sec the default minimum speed (was 20steps/sec hardcoded) -#define DEFAULT_MINIMUM_ACTUATOR_RATE 20.0F +float StepperMotor::default_minimum_actuator_rate= 20.0F; // A StepperMotor represents an actual stepper motor. It is used to generate steps that move the actual motor at a given speed // TODO : Abstract this into Actuator @@ -49,7 +49,7 @@ void StepperMotor::init() steps_per_mm = 1.0F; max_rate = 50.0F; - minimum_step_rate = DEFAULT_MINIMUM_ACTUATOR_RATE; + minimum_step_rate = default_minimum_actuator_rate; last_milestone_steps = 0; last_milestone_mm = 0.0F; @@ -99,7 +99,7 @@ void StepperMotor::signal_move_finished() // work is done ! 8t this->moving = false; this->steps_to_move = 0; - this->minimum_step_rate = DEFAULT_MINIMUM_ACTUATOR_RATE; + this->minimum_step_rate = default_minimum_actuator_rate; // signal it to whatever cares 41t 411t this->end_hook->call(); diff --git a/src/libs/StepperMotor.h b/src/libs/StepperMotor.h index ed002264..079a3526 100644 --- a/src/libs/StepperMotor.h +++ b/src/libs/StepperMotor.h @@ -84,6 +84,7 @@ class StepperMotor { float steps_per_mm; float max_rate; // this is not really rate it is in mm/sec, misnamed used in Robot and Extruder float minimum_step_rate; // this is the minimum step_rate in steps/sec for this motor for this block + static float default_minimum_actuator_rate; volatile int32_t current_position_steps; int32_t last_milestone_steps; diff --git a/src/modules/robot/Block.cpp b/src/modules/robot/Block.cpp index 68b8beeb..060919d9 100644 --- a/src/modules/robot/Block.cpp +++ b/src/modules/robot/Block.cpp @@ -103,12 +103,12 @@ void Block::calculate_trapezoid( float entryspeed, float exitspeed ) return; // The planner passes us factors, we need to transform them in rates - this->initial_rate = ceil(this->nominal_rate * entryspeed / this->nominal_speed); // (step/s) - this->final_rate = ceil(this->nominal_rate * exitspeed / this->nominal_speed); // (step/s) + this->initial_rate = ceilf(this->nominal_rate * entryspeed / this->nominal_speed); // (step/s) + this->final_rate = ceilf(this->nominal_rate * exitspeed / this->nominal_speed); // (step/s) // How many steps to accelerate and decelerate float acceleration_per_second = this->rate_delta * THEKERNEL->stepper->get_acceleration_ticks_per_second(); // ( step/s^2) - int accelerate_steps = ceil( this->estimate_acceleration_distance( this->initial_rate, this->nominal_rate, acceleration_per_second ) ); + int accelerate_steps = ceilf( this->estimate_acceleration_distance( this->initial_rate, this->nominal_rate, acceleration_per_second ) ); int decelerate_steps = floor( this->estimate_acceleration_distance( this->nominal_rate, this->final_rate, -acceleration_per_second ) ); // Calculate the size of Plateau of Nominal Rate ( during which we don't accelerate nor decelerate, but just cruise ) @@ -118,7 +118,7 @@ void Block::calculate_trapezoid( float entryspeed, float exitspeed ) // have to use intersection_distance() to calculate when to abort acceleration and start braking // in order to reach the final_rate exactly at the end of this block. if (plateau_steps < 0) { - accelerate_steps = ceil(this->intersection_distance(this->initial_rate, this->final_rate, acceleration_per_second, this->steps_event_count)); + accelerate_steps = ceilf(this->intersection_distance(this->initial_rate, this->final_rate, acceleration_per_second, this->steps_event_count)); accelerate_steps = max( accelerate_steps, 0 ); // Check limits due to numerical round-off accelerate_steps = min( accelerate_steps, int(this->steps_event_count) ); plateau_steps = 0; diff --git a/src/modules/robot/Planner.cpp b/src/modules/robot/Planner.cpp index 681fb2b8..e4a1ac61 100644 --- a/src/modules/robot/Planner.cpp +++ b/src/modules/robot/Planner.cpp @@ -97,7 +97,7 @@ void Planner::append_block( float actuator_pos[], float rate_mm_s, float distanc // NOTE: Minimum stepper speed is limited by MINIMUM_STEPS_PER_MINUTE in stepper.c if( distance > 0.0F ){ block->nominal_speed = rate_mm_s; // (mm/s) Always > 0 - block->nominal_rate = ceil(block->steps_event_count * rate_mm_s / distance); // (step/s) Always > 0 + block->nominal_rate = ceilf(block->steps_event_count * rate_mm_s / distance); // (step/s) Always > 0 }else{ block->nominal_speed = 0.0F; block->nominal_rate = 0; diff --git a/src/modules/robot/Robot.cpp b/src/modules/robot/Robot.cpp index b0dab6cd..c2283c43 100644 --- a/src/modules/robot/Robot.cpp +++ b/src/modules/robot/Robot.cpp @@ -114,7 +114,6 @@ using std::string; // The Robot converts GCodes into actual movements, and then adds them to the Planner, which passes them to the Conveyor so they can be added to the queue // It takes care of cutting arcs into segments, same thing for line that are too long -#define max(a,b) (((a) > (b)) ? (a) : (b)) Robot::Robot() { @@ -434,7 +433,7 @@ void Robot::on_gcode_received(void *argument) } break; - case 205: // M205 Xnnn - set junction deviation, Z - set Z junction deviation, Snnn - Set minimum planner speed + case 205: // M205 Xnnn - set junction deviation, Z - set Z junction deviation, Snnn - Set minimum planner speed, Ynnn - set minimum step rate gcode->mark_as_taken(); if (gcode->has_letter('X')) { float jd = gcode->get_value('X'); @@ -457,6 +456,9 @@ void Robot::on_gcode_received(void *argument) mps = 0.0F; THEKERNEL->planner->minimum_planner_speed = mps; } + if (gcode->has_letter('Y')) { + alpha_stepper_motor->default_minimum_actuator_rate = gcode->get_value('Y'); + } break; case 220: // M220 - speed override percentage @@ -704,14 +706,14 @@ void Robot::append_line(Gcode *gcode, float target[], float rate_mm_s ) // the faster the travel speed the fewer segments needed // NOTE rate is mm/sec and we take into account any speed override float seconds = gcode->millimeters_of_travel / rate_mm_s; - segments = max(1, ceil(this->delta_segments_per_second * seconds)); + segments = max(1.0F, ceilf(this->delta_segments_per_second * seconds)); // TODO if we are only moving in Z on a delta we don't really need to segment at all } else { if(this->mm_per_line_segment == 0.0F) { segments = 1; // don't split it up } else { - segments = ceil( gcode->millimeters_of_travel / this->mm_per_line_segment); + segments = ceilf( gcode->millimeters_of_travel / this->mm_per_line_segment); } } diff --git a/src/modules/tools/endstops/Endstops.cpp b/src/modules/tools/endstops/Endstops.cpp index 2e319156..4f9131a2 100644 --- a/src/modules/tools/endstops/Endstops.cpp +++ b/src/modules/tools/endstops/Endstops.cpp @@ -105,8 +105,6 @@ #define STEPPER THEKERNEL->robot->actuators #define STEPS_PER_MM(a) (STEPPER[a]->get_steps_per_mm()) -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#define min(a,b) (((a) <= (b)) ? (a) : (b)) // Homing States enum{ diff --git a/src/modules/tools/extruder/Extruder.cpp b/src/modules/tools/extruder/Extruder.cpp index 4c2269c8..1e9cc2f0 100644 --- a/src/modules/tools/extruder/Extruder.cpp +++ b/src/modules/tools/extruder/Extruder.cpp @@ -69,7 +69,6 @@ #define PI 3.14159265358979F -#define max(a,b) (((a) > (b)) ? (a) : (b)) /* The extruder module controls a filament extruder for 3D printing: http://en.wikipedia.org/wiki/Fused_deposition_modeling * It can work in two modes : either the head does not move, and the extruder moves the filament at a specified speed ( SOLO mode here ) diff --git a/src/modules/tools/zprobe/ZProbe.cpp b/src/modules/tools/zprobe/ZProbe.cpp index 2a57eb4a..6eab717c 100644 --- a/src/modules/tools/zprobe/ZProbe.cpp +++ b/src/modules/tools/zprobe/ZProbe.cpp @@ -294,7 +294,6 @@ void ZProbe::on_gcode_received(void *argument) } } -#define max(a,b) (((a) > (b)) ? (a) : (b)) // Called periodically to change the speed to match acceleration uint32_t ZProbe::acceleration_tick(uint32_t dummy) { diff --git a/src/modules/utils/currentcontrol/ad5206.h b/src/modules/utils/currentcontrol/ad5206.h index ec9cd300..aca5da2b 100644 --- a/src/modules/utils/currentcontrol/ad5206.h +++ b/src/modules/utils/currentcontrol/ad5206.h @@ -8,8 +8,6 @@ #include #include -#define max(a,b) (((a) > (b)) ? (a) : (b)) - class AD5206 : public DigipotBase { public: AD5206(){ @@ -26,7 +24,7 @@ class AD5206 : public DigipotBase { currents[channel]= -1; return; } - current = min( max( current, 0.0L ), 2.0L ); + current = min( max( current, 0.0F ), 2.0F ); char adresses[6] = { 0x05, 0x03, 0x01, 0x00, 0x02, 0x04 }; currents[channel] = current; cs.set(0); diff --git a/src/modules/utils/currentcontrol/mcp4451.h b/src/modules/utils/currentcontrol/mcp4451.h index c9471a7b..499b9885 100644 --- a/src/modules/utils/currentcontrol/mcp4451.h +++ b/src/modules/utils/currentcontrol/mcp4451.h @@ -60,7 +60,7 @@ class MCP4451 : public DigipotBase { } char current_to_wiper( float current ){ - return char(ceil(float((this->factor*current)))); + return char(ceilf(float((this->factor*current)))); } mbed::I2C* i2c;