Replace double with float, optimize calculation
This commit is contained in:
@ -417,12 +417,12 @@ void MarlinSettings::postprocess() {
|
||||
EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
|
||||
|
||||
#if ENABLED(JUNCTION_DEVIATION)
|
||||
const float planner_max_jerk[] = { DEFAULT_XJERK, DEFAULT_YJERK, DEFAULT_ZJERK, DEFAULT_EJERK };
|
||||
const float planner_max_jerk[] = { float(DEFAULT_XJERK), float(DEFAULT_YJERK), float(DEFAULT_ZJERK), float(DEFAULT_EJERK) };
|
||||
EEPROM_WRITE(planner_max_jerk);
|
||||
EEPROM_WRITE(planner.junction_deviation_mm);
|
||||
#else
|
||||
EEPROM_WRITE(planner.max_jerk);
|
||||
dummy = 0.02;
|
||||
dummy = 0.02f;
|
||||
EEPROM_WRITE(dummy);
|
||||
#endif
|
||||
|
||||
@ -488,7 +488,7 @@ void MarlinSettings::postprocess() {
|
||||
#if ABL_PLANAR
|
||||
EEPROM_WRITE(planner.bed_level_matrix);
|
||||
#else
|
||||
dummy = 0.0;
|
||||
dummy = 0.0f;
|
||||
for (uint8_t q = 9; q--;) EEPROM_WRITE(dummy);
|
||||
#endif
|
||||
|
||||
@ -974,7 +974,7 @@ void MarlinSettings::postprocess() {
|
||||
eeprom_error = true;
|
||||
}
|
||||
else {
|
||||
float dummy = 0;
|
||||
float dummy = 0.0f;
|
||||
#if DISABLED(AUTO_BED_LEVELING_UBL) || DISABLED(FWRETRACT) || ENABLED(NO_VOLUMETRICS)
|
||||
bool dummyb;
|
||||
#endif
|
||||
@ -1733,7 +1733,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
|
||||
planner.min_travel_feedrate_mm_s = DEFAULT_MINTRAVELFEEDRATE;
|
||||
|
||||
#if ENABLED(JUNCTION_DEVIATION)
|
||||
planner.junction_deviation_mm = JUNCTION_DEVIATION_MM;
|
||||
planner.junction_deviation_mm = float(JUNCTION_DEVIATION_MM);
|
||||
#else
|
||||
planner.max_jerk[X_AXIS] = DEFAULT_XJERK;
|
||||
planner.max_jerk[Y_AXIS] = DEFAULT_YJERK;
|
||||
@ -1835,7 +1835,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
|
||||
HOTEND_LOOP()
|
||||
#endif
|
||||
{
|
||||
PID_PARAM(Kp, e) = DEFAULT_Kp;
|
||||
PID_PARAM(Kp, e) = float(DEFAULT_Kp);
|
||||
PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
|
||||
PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
|
||||
#if ENABLED(PID_EXTRUSION_SCALING)
|
||||
|
@ -77,7 +77,7 @@ bool relative_mode; // = false;
|
||||
* Used by 'buffer_line_to_current_position' to do a move after changing it.
|
||||
* Used by 'SYNC_PLAN_POSITION_KINEMATIC' to update 'planner.position'.
|
||||
*/
|
||||
float current_position[XYZE] = { 0.0 };
|
||||
float current_position[XYZE] = { 0 };
|
||||
|
||||
/**
|
||||
* Cartesian Destination
|
||||
@ -85,7 +85,7 @@ float current_position[XYZE] = { 0.0 };
|
||||
* and expected by functions like 'prepare_move_to_destination'.
|
||||
* Set with 'get_destination_from_command' or 'set_destination_from_current'.
|
||||
*/
|
||||
float destination[XYZE] = { 0.0 };
|
||||
float destination[XYZE] = { 0 };
|
||||
|
||||
|
||||
// The active extruder (tool). Set with T<extruder> command.
|
||||
@ -100,7 +100,7 @@ uint8_t active_extruder; // = 0;
|
||||
// no other feedrate is specified. Overridden for special moves.
|
||||
// Set by the last G0 through G5 command's "F" parameter.
|
||||
// Functions that override this for custom moves *must always* restore it!
|
||||
float feedrate_mm_s = MMM_TO_MMS(1500.0);
|
||||
float feedrate_mm_s = MMM_TO_MMS(1500.0f);
|
||||
|
||||
int16_t feedrate_percentage = 100;
|
||||
|
||||
@ -509,7 +509,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
|
||||
* but may produce jagged lines. Try 0.5mm, 1.0mm, and 2.0mm
|
||||
* and compare the difference.
|
||||
*/
|
||||
#define SCARA_MIN_SEGMENT_LENGTH 0.5
|
||||
#define SCARA_MIN_SEGMENT_LENGTH 0.5f
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -566,14 +566,14 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
|
||||
|
||||
// For SCARA enforce a minimum segment size
|
||||
#if IS_SCARA
|
||||
NOMORE(segments, cartesian_mm * (1.0 / SCARA_MIN_SEGMENT_LENGTH));
|
||||
NOMORE(segments, cartesian_mm * (1.0f / float(SCARA_MIN_SEGMENT_LENGTH)));
|
||||
#endif
|
||||
|
||||
// At least one segment is required
|
||||
NOLESS(segments, 1U);
|
||||
|
||||
// The approximate length of each segment
|
||||
const float inv_segments = 1.0 / float(segments),
|
||||
const float inv_segments = 1.0f / float(segments),
|
||||
segment_distance[XYZE] = {
|
||||
xdiff * inv_segments,
|
||||
ydiff * inv_segments,
|
||||
@ -599,7 +599,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
|
||||
// SCARA needs to scale the feed rate from mm/s to degrees/s
|
||||
// i.e., Complete the angular vector in the given time.
|
||||
const float segment_length = cartesian_mm * inv_segments,
|
||||
inv_segment_length = 1.0 / segment_length, // 1/mm/segs
|
||||
inv_segment_length = 1.0f / segment_length, // 1/mm/segs
|
||||
inverse_secs = inv_segment_length * _feedrate_mm_s;
|
||||
|
||||
float oldA = planner.position_float[A_AXIS],
|
||||
@ -756,7 +756,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
|
||||
NOLESS(segments, 1U);
|
||||
|
||||
// The approximate length of each segment
|
||||
const float inv_segments = 1.0 / float(segments),
|
||||
const float inv_segments = 1.0f / float(segments),
|
||||
cartesian_segment_mm = cartesian_mm * inv_segments,
|
||||
segment_distance[XYZE] = {
|
||||
xdiff * inv_segments,
|
||||
@ -1335,7 +1335,7 @@ void homeaxis(const AxisEnum axis) {
|
||||
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
||||
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Home 1 Fast:");
|
||||
#endif
|
||||
do_homing_move(axis, 1.5 * max_length(axis) * axis_home_dir);
|
||||
do_homing_move(axis, 1.5f * max_length(axis) * axis_home_dir);
|
||||
|
||||
// When homing Z with probe respect probe clearance
|
||||
const float bump = axis_home_dir * (
|
||||
|
@ -71,7 +71,7 @@ extern float feedrate_mm_s;
|
||||
* Feedrate scaling and conversion
|
||||
*/
|
||||
extern int16_t feedrate_percentage;
|
||||
#define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01)
|
||||
#define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01f)
|
||||
|
||||
extern uint8_t active_extruder;
|
||||
|
||||
@ -141,7 +141,7 @@ void line_to_current_position();
|
||||
void buffer_line_to_destination(const float fr_mm_s);
|
||||
|
||||
#if IS_KINEMATIC
|
||||
void prepare_uninterpolated_move_to_destination(const float fr_mm_s=0.0);
|
||||
void prepare_uninterpolated_move_to_destination(const float fr_mm_s=0);
|
||||
#endif
|
||||
|
||||
void prepare_move_to_destination();
|
||||
@ -149,10 +149,10 @@ void prepare_move_to_destination();
|
||||
/**
|
||||
* Blocking movement and shorthand functions
|
||||
*/
|
||||
void do_blocking_move_to(const float rx, const float ry, const float rz, const float &fr_mm_s=0.0);
|
||||
void do_blocking_move_to_x(const float &rx, const float &fr_mm_s=0.0);
|
||||
void do_blocking_move_to_z(const float &rz, const float &fr_mm_s=0.0);
|
||||
void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s=0.0);
|
||||
void do_blocking_move_to(const float rx, const float ry, const float rz, const float &fr_mm_s=0);
|
||||
void do_blocking_move_to_x(const float &rx, const float &fr_mm_s=0);
|
||||
void do_blocking_move_to_z(const float &rz, const float &fr_mm_s=0);
|
||||
void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s=0);
|
||||
|
||||
void setup_for_endstop_or_probe_move();
|
||||
void clean_up_after_endstop_or_probe_move();
|
||||
@ -268,8 +268,8 @@ void homeaxis(const AxisEnum axis);
|
||||
// Return true if the given position is within the machine bounds.
|
||||
inline bool position_is_reachable(const float &rx, const float &ry) {
|
||||
// Add 0.001 margin to deal with float imprecision
|
||||
return WITHIN(rx, X_MIN_POS - 0.001, X_MAX_POS + 0.001)
|
||||
&& WITHIN(ry, Y_MIN_POS - 0.001, Y_MAX_POS + 0.001);
|
||||
return WITHIN(rx, X_MIN_POS - 0.001f, X_MAX_POS + 0.001f)
|
||||
&& WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f);
|
||||
}
|
||||
|
||||
#if HAS_BED_PROBE
|
||||
@ -282,8 +282,8 @@ void homeaxis(const AxisEnum axis);
|
||||
*/
|
||||
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
|
||||
return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
|
||||
&& WITHIN(rx, MIN_PROBE_X - 0.001, MAX_PROBE_X + 0.001)
|
||||
&& WITHIN(ry, MIN_PROBE_Y - 0.001, MAX_PROBE_Y + 0.001);
|
||||
&& WITHIN(rx, MIN_PROBE_X - 0.001f, MAX_PROBE_X + 0.001f)
|
||||
&& WITHIN(ry, MIN_PROBE_Y - 0.001f, MAX_PROBE_Y + 0.001f);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -150,11 +150,11 @@ float Planner::max_feedrate_mm_s[XYZE_N], // (mm/s) M203 XYZE - Max speeds
|
||||
|
||||
int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
|
||||
|
||||
float Planner::e_factor[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0); // The flow percentage and volumetric multiplier combine to scale E movement
|
||||
float Planner::e_factor[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0f); // The flow percentage and volumetric multiplier combine to scale E movement
|
||||
|
||||
#if DISABLED(NO_VOLUMETRICS)
|
||||
float Planner::filament_size[EXTRUDERS], // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
|
||||
Planner::volumetric_area_nominal = CIRCLE_AREA((DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5), // Nominal cross-sectional area
|
||||
Planner::volumetric_area_nominal = CIRCLE_AREA((float(DEFAULT_NOMINAL_FILAMENT_DIA)) * 0.5f), // Nominal cross-sectional area
|
||||
Planner::volumetric_multiplier[EXTRUDERS]; // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
|
||||
#endif
|
||||
|
||||
@ -188,7 +188,7 @@ float Planner::e_factor[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0); // The flow perce
|
||||
#if ENABLED(AUTOTEMP)
|
||||
float Planner::autotemp_max = 250,
|
||||
Planner::autotemp_min = 210,
|
||||
Planner::autotemp_factor = 0.1;
|
||||
Planner::autotemp_factor = 0.1f;
|
||||
bool Planner::autotemp_enabled = false;
|
||||
#endif
|
||||
|
||||
@ -236,7 +236,7 @@ void Planner::init() {
|
||||
ZERO(position_float);
|
||||
#endif
|
||||
ZERO(previous_speed);
|
||||
previous_nominal_speed_sqr = 0.0;
|
||||
previous_nominal_speed_sqr = 0;
|
||||
#if ABL_PLANAR
|
||||
bed_level_matrix.set_to_identity();
|
||||
#endif
|
||||
@ -859,7 +859,7 @@ void Planner::reverse_pass_kernel(block_t* const current, const block_t * const
|
||||
|
||||
const float new_entry_speed_sqr = TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH)
|
||||
? max_entry_speed_sqr
|
||||
: MIN(max_entry_speed_sqr, max_allowable_speed_sqr(-current->acceleration, next ? next->entry_speed_sqr : sq(MINIMUM_PLANNER_SPEED), current->millimeters));
|
||||
: MIN(max_entry_speed_sqr, max_allowable_speed_sqr(-current->acceleration, next ? next->entry_speed_sqr : sq(float(MINIMUM_PLANNER_SPEED)), current->millimeters));
|
||||
if (current->entry_speed_sqr != new_entry_speed_sqr) {
|
||||
|
||||
// Need to recalculate the block speed - Mark it now, so the stepper
|
||||
@ -1076,7 +1076,7 @@ void Planner::recalculate_trapezoids() {
|
||||
|
||||
// NOTE: Entry and exit factors always > 0 by all previous logic operations.
|
||||
const float current_nominal_speed = SQRT(current->nominal_speed_sqr),
|
||||
nomr = 1.0 / current_nominal_speed;
|
||||
nomr = 1.0f / current_nominal_speed;
|
||||
calculate_trapezoid_for_block(current, current_entry_speed * nomr, next_entry_speed * nomr);
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
if (current->use_advance_lead) {
|
||||
@ -1115,8 +1115,8 @@ void Planner::recalculate_trapezoids() {
|
||||
// Block is not BUSY, we won the race against the Stepper ISR:
|
||||
|
||||
const float next_nominal_speed = SQRT(next->nominal_speed_sqr),
|
||||
nomr = 1.0 / next_nominal_speed;
|
||||
calculate_trapezoid_for_block(next, next_entry_speed * nomr, (MINIMUM_PLANNER_SPEED) * nomr);
|
||||
nomr = 1.0f / next_nominal_speed;
|
||||
calculate_trapezoid_for_block(next, next_entry_speed * nomr, float(MINIMUM_PLANNER_SPEED) * nomr);
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
if (next->use_advance_lead) {
|
||||
const float comp = next->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
|
||||
@ -1162,7 +1162,7 @@ void Planner::recalculate() {
|
||||
|
||||
float t = autotemp_min + high * autotemp_factor;
|
||||
t = constrain(t, autotemp_min, autotemp_max);
|
||||
if (t < oldt) t = t * (1 - (AUTOTEMP_OLDWEIGHT)) + oldt * (AUTOTEMP_OLDWEIGHT);
|
||||
if (t < oldt) t = t * (1 - float(AUTOTEMP_OLDWEIGHT)) + oldt * float(AUTOTEMP_OLDWEIGHT);
|
||||
oldt = t;
|
||||
thermalManager.setTargetHotend(t, 0);
|
||||
}
|
||||
@ -1317,7 +1317,7 @@ void Planner::check_axes_activity() {
|
||||
* Return 1.0 with volumetric off or a diameter of 0.0.
|
||||
*/
|
||||
inline float calculate_volumetric_multiplier(const float &diameter) {
|
||||
return (parser.volumetric_enabled && diameter) ? 1.0 / CIRCLE_AREA(diameter * 0.5) : 1.0;
|
||||
return (parser.volumetric_enabled && diameter) ? RECIPROCAL(CIRCLE_AREA(diameter * 0.5f)) : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1341,11 +1341,11 @@ void Planner::check_axes_activity() {
|
||||
*/
|
||||
void Planner::calculate_volumetric_for_width_sensor(const int8_t encoded_ratio) {
|
||||
// Reconstitute the nominal/measured ratio
|
||||
const float nom_meas_ratio = 1.0 + 0.01 * encoded_ratio,
|
||||
const float nom_meas_ratio = 1 + 0.01f * encoded_ratio,
|
||||
ratio_2 = sq(nom_meas_ratio);
|
||||
|
||||
volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = parser.volumetric_enabled
|
||||
? ratio_2 / CIRCLE_AREA(filament_width_nominal * 0.5) // Volumetric uses a true volumetric multiplier
|
||||
? ratio_2 / CIRCLE_AREA(filament_width_nominal * 0.5f) // Volumetric uses a true volumetric multiplier
|
||||
: ratio_2; // Linear squares the ratio, which scales the volume
|
||||
|
||||
refresh_e_factor(FILAMENT_SENSOR_EXTRUDER_NUM);
|
||||
@ -1690,7 +1690,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
if (de < 0) SBI(dm, E_AXIS);
|
||||
|
||||
const float esteps_float = de * e_factor[extruder];
|
||||
const uint32_t esteps = ABS(esteps_float) + 0.5;
|
||||
const uint32_t esteps = ABS(esteps_float) + 0.5f;
|
||||
|
||||
// Clear all flags, including the "busy" bit
|
||||
block->flag = 0x00;
|
||||
@ -1957,7 +1957,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
// Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill
|
||||
#if ENABLED(SLOWDOWN) || ENABLED(ULTRA_LCD) || defined(XY_FREQUENCY_LIMIT)
|
||||
// Segment time im micro seconds
|
||||
uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs);
|
||||
uint32_t segment_time_us = LROUND(1000000.0f / inverse_secs);
|
||||
#endif
|
||||
|
||||
#if ENABLED(SLOWDOWN)
|
||||
@ -1965,7 +1965,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
if (segment_time_us < min_segment_time_us) {
|
||||
// buffer is draining, add extra time. The amount of time added increases if the buffer is still emptied more.
|
||||
const uint32_t nst = segment_time_us + LROUND(2 * (min_segment_time_us - segment_time_us) / moves_queued);
|
||||
inverse_secs = 1000000.0 / nst;
|
||||
inverse_secs = 1000000.0f / nst;
|
||||
#if defined(XY_FREQUENCY_LIMIT) || ENABLED(ULTRA_LCD)
|
||||
segment_time_us = nst;
|
||||
#endif
|
||||
@ -2005,7 +2005,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
|
||||
|
||||
// Convert into an index into the measurement array
|
||||
filwidth_delay_index[0] = int8_t(filwidth_delay_dist * 0.1);
|
||||
filwidth_delay_index[0] = int8_t(filwidth_delay_dist * 0.1f);
|
||||
|
||||
// If the index has changed (must have gone forward)...
|
||||
if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
|
||||
@ -2021,7 +2021,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
#endif
|
||||
|
||||
// Calculate and limit speed in mm/sec for each axis
|
||||
float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
|
||||
float current_speed[NUM_AXIS], speed_factor = 1.0f; // factor <1 decreases speed
|
||||
LOOP_XYZE(i) {
|
||||
const float cs = ABS((current_speed[i] = delta_mm[i] * inverse_secs));
|
||||
#if ENABLED(DISTINCT_E_FACTORS)
|
||||
@ -2069,7 +2069,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
#endif // XY_FREQUENCY_LIMIT
|
||||
|
||||
// Correct the speed
|
||||
if (speed_factor < 1.0) {
|
||||
if (speed_factor < 1.0f) {
|
||||
LOOP_XYZE(i) current_speed[i] *= speed_factor;
|
||||
block->nominal_rate *= speed_factor;
|
||||
block->nominal_speed_sqr = block->nominal_speed_sqr * sq(speed_factor);
|
||||
@ -2142,7 +2142,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
|
||||
// Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance!
|
||||
// This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament.
|
||||
if (block->e_D_ratio > 3.0)
|
||||
if (block->e_D_ratio > 3.0f)
|
||||
block->use_advance_lead = false;
|
||||
else {
|
||||
const uint32_t max_accel_steps_per_s2 = MAX_E_JERK / (extruder_advance_K * block->e_D_ratio) * steps_per_mm;
|
||||
@ -2177,7 +2177,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
block->acceleration_steps_per_s2 = accel;
|
||||
block->acceleration = accel / steps_per_mm;
|
||||
#if DISABLED(S_CURVE_ACCELERATION)
|
||||
block->acceleration_rate = (uint32_t)(accel * (4096.0 * 4096.0 / (STEPPER_TIMER_RATE)));
|
||||
block->acceleration_rate = (uint32_t)(accel * (4096.0f * 4096.0f / (STEPPER_TIMER_RATE)));
|
||||
#endif
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
if (block->use_advance_lead) {
|
||||
@ -2250,12 +2250,12 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
;
|
||||
|
||||
// NOTE: Computed without any expensive trig, sin() or acos(), by trig half angle identity of cos(theta).
|
||||
if (junction_cos_theta > 0.999999) {
|
||||
if (junction_cos_theta > 0.999999f) {
|
||||
// For a 0 degree acute junction, just set minimum junction speed.
|
||||
vmax_junction_sqr = sq(MINIMUM_PLANNER_SPEED);
|
||||
vmax_junction_sqr = sq(float(MINIMUM_PLANNER_SPEED));
|
||||
}
|
||||
else {
|
||||
NOLESS(junction_cos_theta, -0.999999); // Check for numerical round-off to avoid divide by zero.
|
||||
NOLESS(junction_cos_theta, -0.999999f); // Check for numerical round-off to avoid divide by zero.
|
||||
|
||||
// Convert delta vector to unit vector
|
||||
float junction_unit_vec[XYZE] = {
|
||||
@ -2267,13 +2267,13 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
normalize_junction_vector(junction_unit_vec);
|
||||
|
||||
const float junction_acceleration = limit_value_by_axis_maximum(block->acceleration, junction_unit_vec),
|
||||
sin_theta_d2 = SQRT(0.5 * (1.0 - junction_cos_theta)); // Trig half angle identity. Always positive.
|
||||
sin_theta_d2 = SQRT(0.5f * (1.0f - junction_cos_theta)); // Trig half angle identity. Always positive.
|
||||
|
||||
vmax_junction_sqr = (junction_acceleration * junction_deviation_mm * sin_theta_d2) / (1.0 - sin_theta_d2);
|
||||
if (block->millimeters < 1.0) {
|
||||
vmax_junction_sqr = (junction_acceleration * junction_deviation_mm * sin_theta_d2) / (1.0f - sin_theta_d2);
|
||||
if (block->millimeters < 1) {
|
||||
|
||||
// Fast acos approximation, minus the error bar to be safe
|
||||
const float junction_theta = (RADIANS(-40) * sq(junction_cos_theta) - RADIANS(50)) * junction_cos_theta + RADIANS(90) - 0.18;
|
||||
const float junction_theta = (RADIANS(-40) * sq(junction_cos_theta) - RADIANS(50)) * junction_cos_theta + RADIANS(90) - 0.18f;
|
||||
|
||||
// If angle is greater than 135 degrees (octagon), find speed for approximate arc
|
||||
if (junction_theta > RADIANS(135)) {
|
||||
@ -2287,7 +2287,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
vmax_junction_sqr = MIN3(vmax_junction_sqr, block->nominal_speed_sqr, previous_nominal_speed_sqr);
|
||||
}
|
||||
else // Init entry speed to zero. Assume it starts from rest. Planner will correct this later.
|
||||
vmax_junction_sqr = 0.0;
|
||||
vmax_junction_sqr = 0;
|
||||
|
||||
COPY(previous_unit_vec, unit_vec);
|
||||
|
||||
@ -2378,11 +2378,11 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
|
||||
block->max_entry_speed_sqr = vmax_junction_sqr;
|
||||
|
||||
// Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
|
||||
const float v_allowable_sqr = max_allowable_speed_sqr(-block->acceleration, sq(MINIMUM_PLANNER_SPEED), block->millimeters);
|
||||
const float v_allowable_sqr = max_allowable_speed_sqr(-block->acceleration, sq(float(MINIMUM_PLANNER_SPEED)), block->millimeters);
|
||||
|
||||
// If we are trying to add a split block, start with the
|
||||
// max. allowed speed to avoid an interrupted first move.
|
||||
block->entry_speed_sqr = !split_move ? sq(MINIMUM_PLANNER_SPEED) : MIN(vmax_junction_sqr, v_allowable_sqr);
|
||||
block->entry_speed_sqr = !split_move ? sq(float(MINIMUM_PLANNER_SPEED)) : MIN(vmax_junction_sqr, v_allowable_sqr);
|
||||
|
||||
// Initialize planner efficiency flags
|
||||
// Set flag if block will always reach maximum junction speed regardless of entry/exit speeds.
|
||||
|
@ -324,7 +324,7 @@ class Planner {
|
||||
static void refresh_positioning();
|
||||
|
||||
FORCE_INLINE static void refresh_e_factor(const uint8_t e) {
|
||||
e_factor[e] = (flow_percentage[e] * 0.01
|
||||
e_factor[e] = (flow_percentage[e] * 0.01f
|
||||
#if DISABLED(NO_VOLUMETRICS)
|
||||
* volumetric_multiplier[e]
|
||||
#endif
|
||||
@ -362,19 +362,19 @@ class Planner {
|
||||
* Returns 0.0 if Z is past the specified 'Fade Height'.
|
||||
*/
|
||||
inline static float fade_scaling_factor_for_z(const float &rz) {
|
||||
static float z_fade_factor = 1.0;
|
||||
static float z_fade_factor = 1;
|
||||
if (z_fade_height) {
|
||||
if (rz >= z_fade_height) return 0.0;
|
||||
if (rz >= z_fade_height) return 0;
|
||||
if (last_fade_z != rz) {
|
||||
last_fade_z = rz;
|
||||
z_fade_factor = 1.0 - rz * inverse_z_fade_height;
|
||||
z_fade_factor = 1 - rz * inverse_z_fade_height;
|
||||
}
|
||||
return z_fade_factor;
|
||||
}
|
||||
return 1.0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
FORCE_INLINE static void force_fade_recalc() { last_fade_z = -999.999; }
|
||||
FORCE_INLINE static void force_fade_recalc() { last_fade_z = -999.999f; }
|
||||
|
||||
FORCE_INLINE static void set_z_fade_height(const float &zfh) {
|
||||
z_fade_height = zfh > 0 ? zfh : 0;
|
||||
@ -390,7 +390,7 @@ class Planner {
|
||||
|
||||
FORCE_INLINE static float fade_scaling_factor_for_z(const float &rz) {
|
||||
UNUSED(rz);
|
||||
return 1.0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
FORCE_INLINE static bool leveling_active_at_z(const float &rz) { UNUSED(rz); return true; }
|
||||
@ -831,9 +831,9 @@ class Planner {
|
||||
#if ENABLED(JUNCTION_DEVIATION)
|
||||
|
||||
FORCE_INLINE static void normalize_junction_vector(float (&vector)[XYZE]) {
|
||||
float magnitude_sq = 0.0;
|
||||
float magnitude_sq = 0;
|
||||
LOOP_XYZE(idx) if (vector[idx]) magnitude_sq += sq(vector[idx]);
|
||||
const float inv_magnitude = 1.0 / SQRT(magnitude_sq);
|
||||
const float inv_magnitude = RSQRT(magnitude_sq);
|
||||
LOOP_XYZE(idx) vector[idx] *= inv_magnitude;
|
||||
}
|
||||
|
||||
|
@ -40,12 +40,12 @@
|
||||
#include "../gcode/queue.h"
|
||||
|
||||
// See the meaning in the documentation of cubic_b_spline().
|
||||
#define MIN_STEP 0.002
|
||||
#define MAX_STEP 0.1
|
||||
#define SIGMA 0.1
|
||||
#define MIN_STEP 0.002f
|
||||
#define MAX_STEP 0.1f
|
||||
#define SIGMA 0.1f
|
||||
|
||||
// Compute the linear interpolation between two real numbers.
|
||||
inline static float interp(float a, float b, float t) { return (1.0 - t) * a + t * b; }
|
||||
inline static float interp(float a, float b, float t) { return (1 - t) * a + t * b; }
|
||||
|
||||
/**
|
||||
* Compute a Bézier curve using the De Casteljau's algorithm (see
|
||||
@ -114,7 +114,7 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
|
||||
first1 = position[Y_AXIS] + offset[1],
|
||||
second0 = target[X_AXIS] + offset[2],
|
||||
second1 = target[Y_AXIS] + offset[3];
|
||||
float t = 0.0;
|
||||
float t = 0;
|
||||
|
||||
float bez_target[4];
|
||||
bez_target[X_AXIS] = position[X_AXIS];
|
||||
@ -123,7 +123,7 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
|
||||
|
||||
millis_t next_idle_ms = millis() + 200UL;
|
||||
|
||||
while (t < 1.0) {
|
||||
while (t < 1) {
|
||||
|
||||
thermalManager.manage_heater();
|
||||
millis_t now = millis();
|
||||
@ -136,16 +136,16 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
|
||||
// close to a linear interpolation.
|
||||
bool did_reduce = false;
|
||||
float new_t = t + step;
|
||||
NOMORE(new_t, 1.0);
|
||||
NOMORE(new_t, 1);
|
||||
float new_pos0 = eval_bezier(position[X_AXIS], first0, second0, target[X_AXIS], new_t),
|
||||
new_pos1 = eval_bezier(position[Y_AXIS], first1, second1, target[Y_AXIS], new_t);
|
||||
for (;;) {
|
||||
if (new_t - t < (MIN_STEP)) break;
|
||||
const float candidate_t = 0.5 * (t + new_t),
|
||||
const float candidate_t = 0.5f * (t + new_t),
|
||||
candidate_pos0 = eval_bezier(position[X_AXIS], first0, second0, target[X_AXIS], candidate_t),
|
||||
candidate_pos1 = eval_bezier(position[Y_AXIS], first1, second1, target[Y_AXIS], candidate_t),
|
||||
interp_pos0 = 0.5 * (bez_target[X_AXIS] + new_pos0),
|
||||
interp_pos1 = 0.5 * (bez_target[Y_AXIS] + new_pos1);
|
||||
interp_pos0 = 0.5f * (bez_target[X_AXIS] + new_pos0),
|
||||
interp_pos1 = 0.5f * (bez_target[Y_AXIS] + new_pos1);
|
||||
if (dist1(candidate_pos0, candidate_pos1, interp_pos0, interp_pos1) <= (SIGMA)) break;
|
||||
new_t = candidate_t;
|
||||
new_pos0 = candidate_pos0;
|
||||
@ -156,12 +156,12 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
|
||||
// If we did not reduce the step, maybe we should enlarge it.
|
||||
if (!did_reduce) for (;;) {
|
||||
if (new_t - t > MAX_STEP) break;
|
||||
const float candidate_t = t + 2.0 * (new_t - t);
|
||||
if (candidate_t >= 1.0) break;
|
||||
const float candidate_t = t + 2 * (new_t - t);
|
||||
if (candidate_t >= 1) break;
|
||||
const float candidate_pos0 = eval_bezier(position[X_AXIS], first0, second0, target[X_AXIS], candidate_t),
|
||||
candidate_pos1 = eval_bezier(position[Y_AXIS], first1, second1, target[Y_AXIS], candidate_t),
|
||||
interp_pos0 = 0.5 * (bez_target[X_AXIS] + candidate_pos0),
|
||||
interp_pos1 = 0.5 * (bez_target[Y_AXIS] + candidate_pos1);
|
||||
interp_pos0 = 0.5f * (bez_target[X_AXIS] + candidate_pos0),
|
||||
interp_pos1 = 0.5f * (bez_target[Y_AXIS] + candidate_pos1);
|
||||
if (dist1(new_pos0, new_pos1, interp_pos0, interp_pos1) > (SIGMA)) break;
|
||||
new_t = candidate_t;
|
||||
new_pos0 = candidate_pos0;
|
||||
|
@ -53,7 +53,7 @@ millis_t PrintCounter::deltaDuration() {
|
||||
return lastDuration - tmp;
|
||||
}
|
||||
|
||||
void PrintCounter::incFilamentUsed(double const &amount) {
|
||||
void PrintCounter::incFilamentUsed(float const &amount) {
|
||||
#if ENABLED(DEBUG_PRINTCOUNTER)
|
||||
debug(PSTR("incFilamentUsed"));
|
||||
#endif
|
||||
|
@ -37,13 +37,13 @@
|
||||
#define STATS_EEPROM_ADDRESS 0x32
|
||||
#endif
|
||||
|
||||
struct printStatistics { // 16 bytes (20 with real doubles)
|
||||
struct printStatistics { // 16 bytes
|
||||
//const uint8_t magic; // Magic header, it will always be 0x16
|
||||
uint16_t totalPrints; // Number of prints
|
||||
uint16_t finishedPrints; // Number of complete prints
|
||||
uint32_t printTime; // Accumulated printing time
|
||||
uint32_t longestPrint; // Longest successful print job
|
||||
double filamentUsed; // Accumulated filament consumed in mm
|
||||
float filamentUsed; // Accumulated filament consumed in mm
|
||||
};
|
||||
|
||||
class PrintCounter: public Stopwatch {
|
||||
@ -128,7 +128,7 @@ class PrintCounter: public Stopwatch {
|
||||
*
|
||||
* @param amount The amount of filament used in mm
|
||||
*/
|
||||
static void incFilamentUsed(double const &amount);
|
||||
static void incFilamentUsed(float const &amount);
|
||||
|
||||
/**
|
||||
* @brief Reset the Print Statistics
|
||||
|
@ -625,7 +625,7 @@ static float run_z_probe() {
|
||||
#if MULTIPLE_PROBING > 2
|
||||
|
||||
// Return the average value of all probes
|
||||
const float measured_z = probes_total * (1.0 / (MULTIPLE_PROBING));
|
||||
const float measured_z = probes_total * (1.0f / (MULTIPLE_PROBING));
|
||||
|
||||
#elif MULTIPLE_PROBING == 2
|
||||
|
||||
|
@ -393,13 +393,13 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
||||
SERIAL_PROTOCOLPAIR(MSG_T_MIN, min);
|
||||
SERIAL_PROTOCOLPAIR(MSG_T_MAX, max);
|
||||
if (cycles > 2) {
|
||||
Ku = (4.0 * d) / (M_PI * (max - min) * 0.5);
|
||||
Tu = ((float)(t_low + t_high) * 0.001);
|
||||
Ku = (4.0f * d) / (float(M_PI) * (max - min) * 0.5f);
|
||||
Tu = ((float)(t_low + t_high) * 0.001f);
|
||||
SERIAL_PROTOCOLPAIR(MSG_KU, Ku);
|
||||
SERIAL_PROTOCOLPAIR(MSG_TU, Tu);
|
||||
workKp = 0.6 * Ku;
|
||||
workKp = 0.6f * Ku;
|
||||
workKi = 2 * workKp / Tu;
|
||||
workKd = workKp * Tu * 0.125;
|
||||
workKd = workKp * Tu * 0.125f;
|
||||
SERIAL_PROTOCOLLNPGM("\n" MSG_CLASSIC_PID);
|
||||
SERIAL_PROTOCOLPAIR(MSG_KP, workKp);
|
||||
SERIAL_PROTOCOLPAIR(MSG_KI, workKi);
|
||||
@ -644,7 +644,7 @@ float Temperature::get_pid_output(const int8_t e) {
|
||||
#if ENABLED(PIDTEMP)
|
||||
#if DISABLED(PID_OPENLOOP)
|
||||
pid_error[HOTEND_INDEX] = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX];
|
||||
dTerm[HOTEND_INDEX] = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + PID_K1 * dTerm[HOTEND_INDEX];
|
||||
dTerm[HOTEND_INDEX] = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + float(PID_K1) * dTerm[HOTEND_INDEX];
|
||||
temp_dState[HOTEND_INDEX] = current_temperature[HOTEND_INDEX];
|
||||
#if HEATER_IDLE_HANDLER
|
||||
if (heater_idle_timeout_exceeded[HOTEND_INDEX]) {
|
||||
@ -1098,7 +1098,7 @@ void Temperature::updateTemperaturesFromRawValues() {
|
||||
|
||||
// Convert raw Filament Width to millimeters
|
||||
float Temperature::analog2widthFil() {
|
||||
return current_raw_filwidth * 5.0 * (1.0 / 16383.0);
|
||||
return current_raw_filwidth * 5.0f * (1.0f / 16383.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1111,7 +1111,7 @@ void Temperature::updateTemperaturesFromRawValues() {
|
||||
*/
|
||||
int8_t Temperature::widthFil_to_size_ratio() {
|
||||
if (ABS(filament_width_nominal - filament_width_meas) <= FILWIDTH_ERROR_MARGIN)
|
||||
return int(100.0 * filament_width_nominal / filament_width_meas) - 100;
|
||||
return int(100.0f * filament_width_nominal / filament_width_meas) - 100;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -100,14 +100,14 @@ enum ADCSensorState : char {
|
||||
#define ACTUAL_ADC_SAMPLES MAX(int(MIN_ADC_ISR_LOOPS), int(SensorsReady))
|
||||
|
||||
#if HAS_PID_HEATING
|
||||
#define PID_K2 (1.0-PID_K1)
|
||||
#define PID_K2 (1-float(PID_K1))
|
||||
#define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / TEMP_TIMER_FREQUENCY)
|
||||
|
||||
// Apply the scale factors to the PID values
|
||||
#define scalePID_i(i) ( (i) * PID_dT )
|
||||
#define unscalePID_i(i) ( (i) / PID_dT )
|
||||
#define scalePID_d(d) ( (d) / PID_dT )
|
||||
#define unscalePID_d(d) ( (d) * PID_dT )
|
||||
#define scalePID_i(i) ( float(i) * PID_dT )
|
||||
#define unscalePID_i(i) ( float(i) / PID_dT )
|
||||
#define scalePID_d(d) ( float(d) / PID_dT )
|
||||
#define unscalePID_d(d) ( float(d) * PID_dT )
|
||||
#endif
|
||||
|
||||
class Temperature {
|
||||
|
Reference in New Issue
Block a user