Browse Source

Apply sq macro throughout

pull/1/head
Scott Lahteine 8 years ago
parent
commit
9f9fe043ba
  1. 17
      Marlin/Marlin_main.cpp
  2. 1
      Marlin/macros.h
  3. 16
      Marlin/planner.cpp
  4. 6
      Marlin/planner.h
  5. 2
      Marlin/ultralcd.cpp

17
Marlin/Marlin_main.cpp

@ -3596,7 +3596,7 @@ inline void gcode_G28() {
* so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z * so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
*/ */
int abl2 = auto_bed_leveling_grid_points * auto_bed_leveling_grid_points; int abl2 = sq(auto_bed_leveling_grid_points);
double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations
eqnBVector[abl2], // "B" vector of Z points eqnBVector[abl2], // "B" vector of Z points
@ -3629,7 +3629,7 @@ inline void gcode_G28() {
#if ENABLED(DELTA) #if ENABLED(DELTA)
// Avoid probing the corners (outside the round or hexagon print surface) on a delta printer. // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
float distance_from_center = sqrt(xProbe * xProbe + yProbe * yProbe); float distance_from_center = HYPOT(xProbe, yProbe);
if (distance_from_center > DELTA_PROBEABLE_RADIUS) continue; if (distance_from_center > DELTA_PROBEABLE_RADIUS) continue;
#endif //DELTA #endif //DELTA
@ -4252,7 +4252,7 @@ inline void gcode_M42() {
return; return;
} }
#else #else
if (sqrt(X_probe_location * X_probe_location + Y_probe_location * Y_probe_location) > DELTA_PROBEABLE_RADIUS) { if (HYPOT(X_probe_location, Y_probe_location) > DELTA_PROBEABLE_RADIUS) {
SERIAL_PROTOCOLLNPGM("? (X,Y) location outside of probeable radius."); SERIAL_PROTOCOLLNPGM("? (X,Y) location outside of probeable radius.");
return; return;
} }
@ -4342,7 +4342,7 @@ inline void gcode_M42() {
#else #else
// If we have gone out too far, we can do a simple fix and scale the numbers // If we have gone out too far, we can do a simple fix and scale the numbers
// back in closer to the origin. // back in closer to the origin.
while (sqrt(X_current * X_current + Y_current * Y_current) > DELTA_PROBEABLE_RADIUS) { while (HYPOT(X_current, Y_current) > DELTA_PROBEABLE_RADIUS) {
X_current /= 1.25; X_current /= 1.25;
Y_current /= 1.25; Y_current /= 1.25;
if (verbose_level > 3) { if (verbose_level > 3) {
@ -4378,10 +4378,9 @@ inline void gcode_M42() {
* data points we have so far * data points we have so far
*/ */
sum = 0.0; sum = 0.0;
for (uint8_t j = 0; j <= n; j++) { for (uint8_t j = 0; j <= n; j++)
float ss = sample_set[j] - mean; sum += sq(sample_set[j] - mean);
sum += ss * ss;
}
sigma = sqrt(sum / (n + 1)); sigma = sqrt(sum / (n + 1));
if (verbose_level > 0) { if (verbose_level > 0) {
if (verbose_level > 1) { if (verbose_level > 1) {
@ -8139,7 +8138,7 @@ void prepare_move_to_destination() {
* This is important when there are successive arc motions. * This is important when there are successive arc motions.
*/ */
// Vector rotation matrix values // Vector rotation matrix values
float cos_T = 1 - 0.5 * theta_per_segment * theta_per_segment; // Small angle approximation float cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
float sin_T = theta_per_segment; float sin_T = theta_per_segment;
float arc_target[NUM_AXIS]; float arc_target[NUM_AXIS];

1
Marlin/macros.h

@ -36,6 +36,7 @@
// Macros for maths shortcuts // Macros for maths shortcuts
#define RADIANS(d) ((d)*M_PI/180.0) #define RADIANS(d) ((d)*M_PI/180.0)
#define DEGREES(r) ((r)*180.0/M_PI) #define DEGREES(r) ((r)*180.0/M_PI)
#define HYPOT(x,y) sqrt(sq(x)+sq(y))
// Macros to contrain values // Macros to contrain values
#define NOLESS(v,n) do{ if (v < n) v = n; }while(0) #define NOLESS(v,n) do{ if (v < n) v = n; }while(0)

16
Marlin/planner.cpp

@ -171,8 +171,8 @@ void Planner::calculate_trapezoid_for_block(block_t* block, float entry_factor,
} }
#if ENABLED(ADVANCE) #if ENABLED(ADVANCE)
volatile long initial_advance = block->advance * entry_factor * entry_factor; volatile long initial_advance = block->advance * sq(entry_factor);
volatile long final_advance = block->advance * exit_factor * exit_factor; volatile long final_advance = block->advance * sq(exit_factor);
#endif // ADVANCE #endif // ADVANCE
// block->accelerate_until = accelerate_steps; // block->accelerate_until = accelerate_steps;
@ -815,13 +815,13 @@ void Planner::check_axes_activity() {
else { else {
block->millimeters = sqrt( block->millimeters = sqrt(
#if ENABLED(COREXY) #if ENABLED(COREXY)
square(delta_mm[X_HEAD]) + square(delta_mm[Y_HEAD]) + square(delta_mm[Z_AXIS]) sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_AXIS])
#elif ENABLED(COREXZ) #elif ENABLED(COREXZ)
square(delta_mm[X_HEAD]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_HEAD]) sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_HEAD])
#elif ENABLED(COREYZ) #elif ENABLED(COREYZ)
square(delta_mm[X_AXIS]) + square(delta_mm[Y_HEAD]) + square(delta_mm[Z_HEAD]) sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_HEAD])
#else #else
square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS]) sq(delta_mm[X_AXIS]) + sq(delta_mm[Y_AXIS]) + sq(delta_mm[Z_AXIS])
#endif #endif
); );
} }
@ -1030,7 +1030,7 @@ void Planner::check_axes_activity() {
dsy = current_speed[Y_AXIS] - previous_speed[Y_AXIS], dsy = current_speed[Y_AXIS] - previous_speed[Y_AXIS],
dsz = fabs(csz - previous_speed[Z_AXIS]), dsz = fabs(csz - previous_speed[Z_AXIS]),
dse = fabs(cse - previous_speed[E_AXIS]), dse = fabs(cse - previous_speed[E_AXIS]),
jerk = sqrt(dsx * dsx + dsy * dsy); jerk = HYPOT(dsx, dsy);
// if ((fabs(previous_speed[X_AXIS]) > 0.0001) || (fabs(previous_speed[Y_AXIS]) > 0.0001)) { // if ((fabs(previous_speed[X_AXIS]) > 0.0001) || (fabs(previous_speed[Y_AXIS]) > 0.0001)) {
vmax_junction = block->nominal_speed; vmax_junction = block->nominal_speed;
@ -1086,7 +1086,7 @@ void Planner::check_axes_activity() {
} }
else { else {
long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_steps_per_s2); long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_steps_per_s2);
float advance = ((STEPS_PER_CUBIC_MM_E) * (EXTRUDER_ADVANCE_K)) * (cse * cse * (EXTRUSION_AREA) * (EXTRUSION_AREA)) * 256; float advance = ((STEPS_PER_CUBIC_MM_E) * (EXTRUDER_ADVANCE_K)) * HYPOT(cse, EXTRUSION_AREA) * 256;
block->advance = advance; block->advance = advance;
block->advance_rate = acc_dist ? advance / (float)acc_dist : 0; block->advance_rate = acc_dist ? advance / (float)acc_dist : 0;
} }

6
Marlin/planner.h

@ -290,7 +290,7 @@ class Planner {
*/ */
static float estimate_acceleration_distance(float initial_rate, float target_rate, float accel) { static float estimate_acceleration_distance(float initial_rate, float target_rate, float accel) {
if (accel == 0) return 0; // accel was 0, set acceleration distance to 0 if (accel == 0) return 0; // accel was 0, set acceleration distance to 0
return (target_rate * target_rate - initial_rate * initial_rate) / (accel * 2); return (sq(target_rate) - sq(initial_rate)) / (accel * 2);
} }
/** /**
@ -303,7 +303,7 @@ class Planner {
*/ */
static float intersection_distance(float initial_rate, float final_rate, float accel, float distance) { static float intersection_distance(float initial_rate, float final_rate, float accel, float distance) {
if (accel == 0) return 0; // accel was 0, set intersection distance to 0 if (accel == 0) return 0; // accel was 0, set intersection distance to 0
return (accel * 2 * distance - initial_rate * initial_rate + final_rate * final_rate) / (accel * 4); return (accel * 2 * distance - sq(initial_rate) + sq(final_rate)) / (accel * 4);
} }
/** /**
@ -312,7 +312,7 @@ class Planner {
* 'distance'. * 'distance'.
*/ */
static float max_allowable_speed(float accel, float target_velocity, float distance) { static float max_allowable_speed(float accel, float target_velocity, float distance) {
return sqrt(target_velocity * target_velocity - 2 * accel * distance); return sqrt(sq(target_velocity) - 2 * accel * distance);
} }
static void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor); static void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor);

2
Marlin/ultralcd.cpp

@ -1356,7 +1356,7 @@ void kill_screen(const char* lcd_msg) {
} }
#if ENABLED(DELTA) #if ENABLED(DELTA)
static float delta_clip_radius_2 = (DELTA_PRINTABLE_RADIUS) * (DELTA_PRINTABLE_RADIUS); static float delta_clip_radius_2 = (DELTA_PRINTABLE_RADIUS) * (DELTA_PRINTABLE_RADIUS);
static int delta_clip( float a ) { return sqrt(delta_clip_radius_2 - a*a); } static int delta_clip( float a ) { return sqrt(delta_clip_radius_2 - sq(a)); }
static void lcd_move_x() { int clip = delta_clip(current_position[Y_AXIS]); _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS, max(sw_endstop_min[X_AXIS], -clip), min(sw_endstop_max[X_AXIS], clip)); } static void lcd_move_x() { int clip = delta_clip(current_position[Y_AXIS]); _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS, max(sw_endstop_min[X_AXIS], -clip), min(sw_endstop_max[X_AXIS], clip)); }
static void lcd_move_y() { int clip = delta_clip(current_position[X_AXIS]); _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS, max(sw_endstop_min[Y_AXIS], -clip), min(sw_endstop_max[Y_AXIS], clip)); } static void lcd_move_y() { int clip = delta_clip(current_position[X_AXIS]); _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS, max(sw_endstop_min[Y_AXIS], -clip), min(sw_endstop_max[Y_AXIS], clip)); }
#else #else

Loading…
Cancel
Save