Replace double with float, optimize calculation
This commit is contained in:
@ -359,7 +359,7 @@ static float auto_tune_h() {
|
||||
float h_fac = 0.0;
|
||||
|
||||
h_fac = r_quot / (2.0 / 3.0);
|
||||
h_fac = 1.0 / h_fac; // (2/3)/CR
|
||||
h_fac = 1.0f / h_fac; // (2/3)/CR
|
||||
return h_fac;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ void GcodeSuite::M48() {
|
||||
|
||||
setup_for_endstop_or_probe_move();
|
||||
|
||||
double mean = 0.0, sigma = 0.0, min = 99999.9, max = -99999.9, sample_set[n_samples];
|
||||
float mean = 0.0, sigma = 0.0, min = 99999.9, max = -99999.9, sample_set[n_samples];
|
||||
|
||||
// Move to the first point, deploy, and probe
|
||||
const float t = probe_pt(X_probe_location, Y_probe_location, raise_after, verbose_level);
|
||||
@ -142,7 +142,7 @@ void GcodeSuite::M48() {
|
||||
}
|
||||
|
||||
for (uint8_t l = 0; l < n_legs - 1; l++) {
|
||||
double delta_angle;
|
||||
float delta_angle;
|
||||
|
||||
if (schizoid_flag)
|
||||
// The points of a 5 point star are 72 degrees apart. We need to
|
||||
@ -199,7 +199,7 @@ void GcodeSuite::M48() {
|
||||
/**
|
||||
* Get the current mean for the data points we have so far
|
||||
*/
|
||||
double sum = 0.0;
|
||||
float sum = 0.0;
|
||||
for (uint8_t j = 0; j <= n; j++) sum += sample_set[j];
|
||||
mean = sum / (n + 1);
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
||||
// setting any extruder filament size disables volumetric on the assumption that
|
||||
// slicers either generate in extruder values as cubic mm or as as filament feeds
|
||||
// for all extruders
|
||||
if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) )
|
||||
if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0)) )
|
||||
planner.set_filament_size(target_extruder, parser.value_linear_units());
|
||||
}
|
||||
planner.calculate_volumetric_multipliers();
|
||||
@ -134,7 +134,7 @@ void GcodeSuite::M205() {
|
||||
#if ENABLED(JUNCTION_DEVIATION)
|
||||
if (parser.seen('J')) {
|
||||
const float junc_dev = parser.value_linear_units();
|
||||
if (WITHIN(junc_dev, 0.01, 0.3)) {
|
||||
if (WITHIN(junc_dev, 0.01f, 0.3f)) {
|
||||
planner.junction_deviation_mm = junc_dev;
|
||||
planner.recalculate_max_e_jerk();
|
||||
}
|
||||
@ -149,7 +149,7 @@ void GcodeSuite::M205() {
|
||||
if (parser.seen('Z')) {
|
||||
planner.max_jerk[Z_AXIS] = parser.value_linear_units();
|
||||
#if HAS_MESH
|
||||
if (planner.max_jerk[Z_AXIS] <= 0.1)
|
||||
if (planner.max_jerk[Z_AXIS] <= 0.1f)
|
||||
SERIAL_ECHOLNPGM("WARNING! Low Z Jerk may lead to unwanted pauses.");
|
||||
#endif
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ void GcodeSuite::M92() {
|
||||
if (parser.seen(axis_codes[i])) {
|
||||
if (i == E_AXIS) {
|
||||
const float value = parser.value_per_axis_unit((AxisEnum)(E_AXIS + TARGET_EXTRUDER));
|
||||
if (value < 20.0) {
|
||||
if (value < 20) {
|
||||
float factor = planner.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] / value; // increase e constants if M92 E14 is given for netfab.
|
||||
#if DISABLED(JUNCTION_DEVIATION)
|
||||
planner.max_jerk[E_AXIS] *= factor;
|
||||
|
@ -107,12 +107,12 @@ void GcodeSuite::M3_M4(bool is_M3) {
|
||||
delay_for_power_down();
|
||||
}
|
||||
else {
|
||||
int16_t ocr_val = (spindle_laser_power - (SPEED_POWER_INTERCEPT)) * (1.0 / (SPEED_POWER_SLOPE)); // convert RPM to PWM duty cycle
|
||||
int16_t ocr_val = (spindle_laser_power - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // convert RPM to PWM duty cycle
|
||||
NOMORE(ocr_val, 255); // limit to max the Atmel PWM will support
|
||||
if (spindle_laser_power <= SPEED_POWER_MIN)
|
||||
ocr_val = (SPEED_POWER_MIN - (SPEED_POWER_INTERCEPT)) * (1.0 / (SPEED_POWER_SLOPE)); // minimum setting
|
||||
ocr_val = (SPEED_POWER_MIN - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // minimum setting
|
||||
if (spindle_laser_power >= SPEED_POWER_MAX)
|
||||
ocr_val = (SPEED_POWER_MAX - (SPEED_POWER_INTERCEPT)) * (1.0 / (SPEED_POWER_SLOPE)); // limit to max RPM
|
||||
ocr_val = (SPEED_POWER_MAX - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // limit to max RPM
|
||||
if (SPINDLE_LASER_PWM_INVERT) ocr_val = 255 - ocr_val;
|
||||
WRITE(SPINDLE_LASER_ENABLE_PIN, SPINDLE_LASER_ENABLE_INVERT); // turn spindle on (active low)
|
||||
analogWrite(SPINDLE_LASER_PWM_PIN, ocr_val & 0xFF); // only write low byte
|
||||
|
@ -103,7 +103,7 @@ void GcodeSuite::get_destination_from_command() {
|
||||
destination[i] = current_position[i];
|
||||
}
|
||||
|
||||
if (parser.linearval('F') > 0.0)
|
||||
if (parser.linearval('F') > 0)
|
||||
feedrate_mm_s = MMM_TO_MMS(parser.value_feedrate());
|
||||
|
||||
#if ENABLED(PRINTCOUNTER)
|
||||
|
@ -92,7 +92,7 @@ void plan_arc(
|
||||
|
||||
const float flat_mm = radius * angular_travel,
|
||||
mm_of_travel = linear_travel ? HYPOT(flat_mm, linear_travel) : ABS(flat_mm);
|
||||
if (mm_of_travel < 0.001) return;
|
||||
if (mm_of_travel < 0.001f) return;
|
||||
|
||||
uint16_t segments = FLOOR(mm_of_travel / (MM_PER_ARC_SEGMENT));
|
||||
if (segments == 0) segments = 1;
|
||||
@ -129,7 +129,7 @@ void plan_arc(
|
||||
linear_per_segment = linear_travel / segments,
|
||||
extruder_per_segment = extruder_travel / segments,
|
||||
sin_T = theta_per_segment,
|
||||
cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
|
||||
cos_T = 1 - 0.5f * sq(theta_per_segment); // Small angle approximation
|
||||
|
||||
// Initialize the linear axis
|
||||
raw[l_axis] = current_position[l_axis];
|
||||
@ -143,7 +143,7 @@ void plan_arc(
|
||||
|
||||
#if HAS_FEEDRATE_SCALING
|
||||
// SCARA needs to scale the feed rate from mm/s to degrees/s
|
||||
const float inv_segment_length = 1.0 / (MM_PER_ARC_SEGMENT),
|
||||
const float inv_segment_length = 1.0f / float(MM_PER_ARC_SEGMENT),
|
||||
inverse_secs = inv_segment_length * fr_mm_s;
|
||||
float oldA = planner.position_float[A_AXIS],
|
||||
oldB = planner.position_float[B_AXIS]
|
||||
@ -289,19 +289,20 @@ void GcodeSuite::G2_G3(const bool clockwise) {
|
||||
relative_mode = relative_mode_backup;
|
||||
#endif
|
||||
|
||||
float arc_offset[2] = { 0.0, 0.0 };
|
||||
float arc_offset[2] = { 0, 0 };
|
||||
if (parser.seenval('R')) {
|
||||
const float r = parser.value_linear_units(),
|
||||
p1 = current_position[X_AXIS], q1 = current_position[Y_AXIS],
|
||||
p2 = destination[X_AXIS], q2 = destination[Y_AXIS];
|
||||
if (r && (p2 != p1 || q2 != q1)) {
|
||||
const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1
|
||||
dx = p2 - p1, dy = q2 - q1, // X and Y differences
|
||||
d = HYPOT(dx, dy), // Linear distance between the points
|
||||
h = SQRT(sq(r) - sq(d * 0.5)), // Distance to the arc pivot-point
|
||||
mx = (p1 + p2) * 0.5, my = (q1 + q2) * 0.5, // Point between the two points
|
||||
sx = -dy / d, sy = dx / d, // Slope of the perpendicular bisector
|
||||
cx = mx + e * h * sx, cy = my + e * h * sy; // Pivot-point of the arc
|
||||
const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1
|
||||
dx = p2 - p1, dy = q2 - q1, // X and Y differences
|
||||
d = HYPOT(dx, dy), // Linear distance between the points
|
||||
dinv = 1/d, // Inverse of d
|
||||
h = SQRT(sq(r) - sq(d * 0.5f)), // Distance to the arc pivot-point
|
||||
mx = (p1 + p2) * 0.5f, my = (q1 + q2) * 0.5f,// Point between the two points
|
||||
sx = -dy * dinv, sy = dx * dinv, // Slope of the perpendicular bisector
|
||||
cx = mx + e * h * sx, cy = my + e * h * sy; // Pivot-point of the arc
|
||||
arc_offset[0] = cx - p1;
|
||||
arc_offset[1] = cy - q1;
|
||||
}
|
||||
|
@ -186,15 +186,15 @@ public:
|
||||
if (c == '\0' || c == ' ') break;
|
||||
if (c == 'E' || c == 'e') {
|
||||
*e = '\0';
|
||||
const float ret = strtod(value_ptr, NULL);
|
||||
const float ret = strtof(value_ptr, NULL);
|
||||
*e = c;
|
||||
return ret;
|
||||
}
|
||||
++e;
|
||||
}
|
||||
return strtod(value_ptr, NULL);
|
||||
return strtof(value_ptr, NULL);
|
||||
}
|
||||
return 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Code value as a long or ulong
|
||||
@ -203,7 +203,7 @@ public:
|
||||
|
||||
// Code value for use as time
|
||||
FORCE_INLINE static millis_t value_millis() { return value_ulong(); }
|
||||
FORCE_INLINE static millis_t value_millis_from_seconds() { return value_float() * 1000UL; }
|
||||
FORCE_INLINE static millis_t value_millis_from_seconds() { return (millis_t)(value_float() * 1000); }
|
||||
|
||||
// Reduce to fewer bits
|
||||
FORCE_INLINE static int16_t value_int() { return (int16_t)value_long(); }
|
||||
@ -220,14 +220,14 @@ public:
|
||||
inline static void set_input_linear_units(const LinearUnit units) {
|
||||
switch (units) {
|
||||
case LINEARUNIT_INCH:
|
||||
linear_unit_factor = 25.4;
|
||||
linear_unit_factor = 25.4f;
|
||||
break;
|
||||
case LINEARUNIT_MM:
|
||||
default:
|
||||
linear_unit_factor = 1.0;
|
||||
linear_unit_factor = 1;
|
||||
break;
|
||||
}
|
||||
volumetric_unit_factor = POW(linear_unit_factor, 3.0);
|
||||
volumetric_unit_factor = POW(linear_unit_factor, 3);
|
||||
}
|
||||
|
||||
inline static float axis_unit_factor(const AxisEnum axis) {
|
||||
@ -261,9 +261,9 @@ public:
|
||||
inline static float to_temp_units(const float &f) {
|
||||
switch (input_temp_units) {
|
||||
case TEMPUNIT_F:
|
||||
return f * 0.5555555556 + 32.0;
|
||||
return f * 0.5555555556f + 32;
|
||||
case TEMPUNIT_K:
|
||||
return f + 273.15;
|
||||
return f + 273.15f;
|
||||
case TEMPUNIT_C:
|
||||
default:
|
||||
return f;
|
||||
@ -276,9 +276,9 @@ public:
|
||||
const float f = value_float();
|
||||
switch (input_temp_units) {
|
||||
case TEMPUNIT_F:
|
||||
return (f - 32.0) * 0.5555555556;
|
||||
return (f - 32) * 0.5555555556f;
|
||||
case TEMPUNIT_K:
|
||||
return f - 273.15;
|
||||
return f - 273.15f;
|
||||
case TEMPUNIT_C:
|
||||
default:
|
||||
return f;
|
||||
@ -288,7 +288,7 @@ public:
|
||||
inline static float value_celsius_diff() {
|
||||
switch (input_temp_units) {
|
||||
case TEMPUNIT_F:
|
||||
return value_float() * 0.5555555556;
|
||||
return value_float() * 0.5555555556f;
|
||||
case TEMPUNIT_C:
|
||||
case TEMPUNIT_K:
|
||||
default:
|
||||
@ -315,8 +315,8 @@ public:
|
||||
FORCE_INLINE static uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; }
|
||||
FORCE_INLINE static int32_t longval(const char c, const int32_t dval=0) { return seenval(c) ? value_long() : dval; }
|
||||
FORCE_INLINE static uint32_t ulongval(const char c, const uint32_t dval=0) { return seenval(c) ? value_ulong() : dval; }
|
||||
FORCE_INLINE static float linearval(const char c, const float dval=0.0) { return seenval(c) ? value_linear_units() : dval; }
|
||||
FORCE_INLINE static float celsiusval(const char c, const float dval=0.0) { return seenval(c) ? value_celsius() : dval; }
|
||||
FORCE_INLINE static float linearval(const char c, const float dval=0) { return seenval(c) ? value_linear_units() : dval; }
|
||||
FORCE_INLINE static float celsiusval(const char c, const float dval=0){ return seenval(c) ? value_celsius() : dval; }
|
||||
|
||||
};
|
||||
|
||||
|
@ -225,7 +225,7 @@ void GcodeSuite::M109() {
|
||||
// break after MIN_COOLING_SLOPE_TIME seconds
|
||||
// if the temperature did not drop at least MIN_COOLING_SLOPE_DEG
|
||||
if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
|
||||
if (old_temp - temp < MIN_COOLING_SLOPE_DEG) break;
|
||||
if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG)) break;
|
||||
next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME;
|
||||
old_temp = temp;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ void GcodeSuite::M190() {
|
||||
#define TEMP_BED_CONDITIONS (wants_to_cool ? thermalManager.isCoolingBed() : thermalManager.isHeatingBed())
|
||||
#endif
|
||||
|
||||
float target_temp = -1.0, old_temp = 9999.0;
|
||||
float target_temp = -1, old_temp = 9999;
|
||||
bool wants_to_cool = false;
|
||||
wait_for_heatup = true;
|
||||
millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
|
||||
@ -163,7 +163,7 @@ void GcodeSuite::M190() {
|
||||
// Break after MIN_COOLING_SLOPE_TIME_BED seconds
|
||||
// if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_BED
|
||||
if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
|
||||
if (old_temp - temp < MIN_COOLING_SLOPE_DEG_BED) break;
|
||||
if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG_BED)) break;
|
||||
next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME_BED;
|
||||
old_temp = temp;
|
||||
}
|
||||
|
Reference in New Issue
Block a user