replace sqrt, hypot, sin, cos with float variants (ie sqrtf, hypotf, sinf, cosf)
authorMichael Moon <triffid.hunter@gmail.com>
Fri, 27 Dec 2013 02:34:42 +0000 (13:34 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Fri, 27 Dec 2013 02:34:42 +0000 (13:34 +1100)
src/modules/robot/Block.cpp
src/modules/robot/Planner.cpp
src/modules/robot/Robot.cpp
src/modules/robot/arm_solutions/RotatableCartesianSolution.cpp

index d231a33..6f442e1 100644 (file)
@@ -100,7 +100,7 @@ float Block::intersection_distance(float initialrate, float finalrate, float acc
 // acceleration within the allotted distance.
 inline float max_allowable_speed(float acceleration, float target_velocity, float distance) {
   return(
-    sqrt(target_velocity*target_velocity-2L*acceleration*distance)  //Was acceleration*60*60*distance, in case this breaks, but here we prefer to use seconds instead of minutes
+    sqrtf(target_velocity*target_velocity-2L*acceleration*distance)  //Was acceleration*60*60*distance, in case this breaks, but here we prefer to use seconds instead of minutes
   );
 }
 
index a88a752..cec10c6 100644 (file)
@@ -117,7 +117,7 @@ void Planner::append_block( int target[], float feed_rate, float distance, float
         // Skip and avoid divide by zero for straight junctions at 180 degrees. Limit to min() of nominal speeds.
         if (cos_theta > -0.95) {
           // Compute maximum junction velocity based on maximum acceleration and junction deviation
-          float sin_theta_d2 = sqrt(0.5*(1.0-cos_theta)); // Trig half angle identity. Always positive.
+          float sin_theta_d2 = sqrtf(0.5*(1.0-cos_theta)); // Trig half angle identity. Always positive.
           vmax_junction = min(vmax_junction,
             sqrtf(this->acceleration * this->junction_deviation * sin_theta_d2/(1.0-sin_theta_d2)) );
         }
@@ -247,7 +247,7 @@ void Planner::dump_queue(){
 // acceleration within the allotted distance.
 float Planner::max_allowable_speed(float acceleration, float target_velocity, float distance) {
   return(
-    sqrt(target_velocity*target_velocity-2L*acceleration*distance)  //Was acceleration*60*60*distance, in case this breaks, but here we prefer to use seconds instead of minutes
+    sqrtf(target_velocity*target_velocity-2L*acceleration*distance)  //Was acceleration*60*60*distance, in case this breaks, but here we prefer to use seconds instead of minutes
   );
 }
 
index 9becadc..4eea717 100644 (file)
@@ -379,7 +379,7 @@ void Robot::append_milestone( float target[], float rate ){
     for(int axis=X_AXIS;axis<=Z_AXIS;axis++){deltas[axis]=target[axis]-this->last_milestone[axis];}
 
     // Compute how long this move moves, so we can attach it to the block for later use
-    float millimeters_of_travel = sqrt( pow( deltas[X_AXIS], 2 ) +  pow( deltas[Y_AXIS], 2 ) +  pow( deltas[Z_AXIS], 2 ) );
+    float millimeters_of_travel = sqrtf( pow( deltas[X_AXIS], 2 ) +  pow( deltas[Y_AXIS], 2 ) +  pow( deltas[Z_AXIS], 2 ) );
 
     // Do not move faster than the configured limits
     for(int axis=X_AXIS;axis<=Z_AXIS;axis++){
@@ -403,7 +403,7 @@ void Robot::append_milestone( float target[], float rate ){
 void Robot::append_line(Gcode* gcode, float target[], float rate ){
 
     // Find out the distance for this gcode
-    gcode->millimeters_of_travel = sqrt( pow( target[X_AXIS]-this->current_position[X_AXIS], 2 ) +  pow( target[Y_AXIS]-this->current_position[Y_AXIS], 2 ) +  pow( target[Z_AXIS]-this->current_position[Z_AXIS], 2 ) );
+    gcode->millimeters_of_travel = sqrtf( pow( target[X_AXIS]-this->current_position[X_AXIS], 2 ) +  pow( target[Y_AXIS]-this->current_position[Y_AXIS], 2 ) +  pow( target[Z_AXIS]-this->current_position[Z_AXIS], 2 ) );
 
     // We ignore non-moves ( for example, extruder moves are not XYZ moves )
     if( gcode->millimeters_of_travel < 0.0001 ){ return; }
@@ -468,7 +468,7 @@ void Robot::append_arc(Gcode* gcode, float target[], float offset[], float radiu
     if (is_clockwise) { angular_travel -= 2*M_PI; }
 
     // Find the distance for this gcode
-    gcode->millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel));
+    gcode->millimeters_of_travel = hypotf(angular_travel*radius, fabs(linear_travel));
 
     // We don't care about non-XYZ moves ( for example the extruder produces some of those )
     if( gcode->millimeters_of_travel < 0.0001 ){ return; }
@@ -530,8 +530,8 @@ void Robot::append_arc(Gcode* gcode, float target[], float offset[], float radiu
         } else {
           // Arc correction to radius vector. Computed only every N_ARC_CORRECTION increments.
           // Compute exact location by applying transformation matrix from initial radius vector(=-offset).
-          cos_Ti = cos(i*theta_per_segment);
-          sin_Ti = sin(i*theta_per_segment);
+          cos_Ti = cosf(i*theta_per_segment);
+          sin_Ti = sinf(i*theta_per_segment);
           r_axis0 = -offset[this->plane_axis_0]*cos_Ti + offset[this->plane_axis_1]*sin_Ti;
           r_axis1 = -offset[this->plane_axis_0]*sin_Ti - offset[this->plane_axis_1]*cos_Ti;
           count = 0;
@@ -555,7 +555,7 @@ void Robot::append_arc(Gcode* gcode, float target[], float offset[], float radiu
 void Robot::compute_arc(Gcode* gcode, float offset[], float target[]){
 
     // Find the radius
-    float radius = hypot(offset[this->plane_axis_0], offset[this->plane_axis_1]);
+    float radius = hypotf(offset[this->plane_axis_0], offset[this->plane_axis_1]);
 
     // Set clockwise/counter-clockwise sign for mc_arc computations
     bool is_clockwise = false;
index 889e4a9..f2a02be 100644 (file)
@@ -9,8 +9,8 @@ RotatableCartesianSolution::RotatableCartesianSolution(Config* passed_config) :
     this->gamma_steps_per_mm = this->config->value(gamma_steps_per_mm_checksum)->as_number();
 
     float alpha_angle  = PIOVER180 * this->config->value(alpha_angle_checksum)->by_default(0.0f)->as_number();
-    this->sin_alpha     = sin(alpha_angle);
-    this->cos_alpha     = cos(alpha_angle);
+    this->sin_alpha     = sinf(alpha_angle);
+    this->cos_alpha     = cosf(alpha_angle);
 }
 
 void RotatableCartesianSolution::millimeters_to_steps( float millimeters[], int steps[] ){