get rid of #define max and use stl::max
authorJim Morris <morris@wolfman.com>
Fri, 21 Nov 2014 05:54:08 +0000 (21:54 -0800)
committerJim Morris <morris@wolfman.com>
Fri, 21 Nov 2014 05:54:08 +0000 (21:54 -0800)
use ceilf instead of ceil
make minimum step rate settabl ewith M205

src/libs/StepperMotor.cpp
src/libs/StepperMotor.h
src/modules/robot/Block.cpp
src/modules/robot/Planner.cpp
src/modules/robot/Robot.cpp
src/modules/tools/endstops/Endstops.cpp
src/modules/tools/extruder/Extruder.cpp
src/modules/tools/zprobe/ZProbe.cpp
src/modules/utils/currentcontrol/ad5206.h
src/modules/utils/currentcontrol/mcp4451.h

index 48aa55a..e0c0f7b 100644 (file)
@@ -13,7 +13,7 @@
 #include <math.h>
 
 // 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();
index ed00226..079a352 100644 (file)
@@ -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;
index 68b8bee..060919d 100644 (file)
@@ -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;
index 681fb2b..e4a1ac6 100644 (file)
@@ -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;
index b0dab6c..c2283c4 100644 (file)
@@ -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);
         }
     }
 
index 2e31915..4f9131a 100644 (file)
 #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{
index 4c2269c..1e9cc2f 100644 (file)
@@ -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 )
index 2a57eb4..6eab717 100644 (file)
@@ -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)
 {
index ec9cd30..aca5da2 100644 (file)
@@ -8,8 +8,6 @@
 #include <string>
 #include <math.h>
 
-#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);
index c9471a7..499b988 100644 (file)
@@ -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;