From bb33c76d2b42be87d621d6e7517d449b504905a8 Mon Sep 17 00:00:00 2001 From: FormerLurker Date: Mon, 25 Apr 2022 09:41:35 -0500 Subject: [PATCH] Fix and simplify M214 data types and default config initialization. --- Firmware/ConfigurationStore.cpp | 10 +++++----- Firmware/ConfigurationStore.h | 6 +++--- Firmware/Marlin_main.cpp | 9 +++++---- Firmware/motion_control.cpp | 6 +++--- Firmware/motion_control.h | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index a24bae15..4fdf2bcf 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -283,11 +283,11 @@ bool Config_RetrieveSettings() } } // Initialize arc interpolation settings if they are not already (Not sure about this bit, please review) - if (is_uninitialized(cs.mm_per_arc_segment, sizeof(float))) cs.mm_per_arc_segment = DEFAULT_MM_PER_ARC_SEGMENT; - if (is_uninitialized(cs.min_mm_per_arc_segment, sizeof(float))) cs.min_mm_per_arc_segment = DEFAULT_MIN_MM_PER_ARC_SEGMENT; - if (is_uninitialized(cs.n_arc_correction), sizeof(uint8_t)) cs.n_arc_correction = DEFAULT_N_ARC_CORRECTION; - if (is_uninitialized(cs.min_arc_segments, sizeof(uint16_t))) cs.min_arc_segments = DEFAULT_MIN_ARC_SEGMENTS; - if (is_uninitialized(cs.arc_segments_per_sec, sizeof(uint16_t))) cs.arc_segments_per_sec = DEFAULT_ARC_SEGMENTS_PER_SEC; + if (is_uninitialized(&cs.mm_per_arc_segment, sizeof(cs.mm_per_arc_segment))) cs.mm_per_arc_segment = default_conf.mm_per_arc_segment; + if (is_uninitialized(&cs.min_mm_per_arc_segment, sizeof(cs.min_mm_per_arc_segment))) cs.min_mm_per_arc_segment = default_conf.min_mm_per_arc_segment; + if (is_uninitialized(&cs.n_arc_correction, sizeof(cs.n_arc_correction))) cs.n_arc_correction = default_conf.n_arc_correction; + if (is_uninitialized(&cs.min_arc_segments, sizeof(cs.min_arc_segments))) cs.min_arc_segments = default_conf.min_arc_segments; + if (is_uninitialized(&cs.arc_segments_per_sec, sizeof(cs.arc_segments_per_sec))) cs.arc_segments_per_sec = default_conf.arc_segments_per_sec; #ifdef TMC2130 diff --git a/Firmware/ConfigurationStore.h b/Firmware/ConfigurationStore.h index a5b7b762..ec40ebc0 100644 --- a/Firmware/ConfigurationStore.h +++ b/Firmware/ConfigurationStore.h @@ -42,9 +42,9 @@ typedef struct // Arc Interpolation Settings, configurable via M214 float mm_per_arc_segment; float min_mm_per_arc_segment; - uint8_t n_arc_correction; // If equal to zero, this is disabled - uint16_t min_arc_segments; // If equal to zero, this is disabled - uint16_t arc_segments_per_sec; // If equal to zero, this is disabled + unsigned char n_arc_correction; // If equal to zero, this is disabled + unsigned short min_arc_segments; // If equal to zero, this is disabled + unsigned short arc_segments_per_sec; // If equal to zero, this is disabled } M500_conf; extern M500_conf cs; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index b600a1b2..f6a6731e 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7527,13 +7527,14 @@ Sigma_Exit: // Extract all possible parameters if they appear float p = code_seen('P') ? code_value_float() : cs.mm_per_arc_segment; float s = code_seen('S') ? code_value_float() : cs.min_mm_per_arc_segment; - uint8_t n = code_seen('N') ? code_value() : cs.n_arc_correction; - uint16_t r = code_seen('R') ? code_value() : cs.min_arc_segments; - uint16_t f = code_seen('F') ? code_value() : cs.arc_segments_per_sec; + unsigned char n = code_seen('N') ? code_value() : cs.n_arc_correction; + unsigned short r = code_seen('R') ? code_value() : cs.min_arc_segments; + unsigned short f = code_seen('F') ? code_value() : cs.arc_segments_per_sec; // Ensure mm_per_arc_segment is greater than 0, and that min_mm_per_arc_segment is sero or greater than or equal to mm_per_arc_segment if (p <=0 || s < 0 || p < s) { + // Should we display some error here? break; } @@ -9679,7 +9680,7 @@ void prepare_move() set_current_to_destination(); } -void prepare_arc_move(char isclockwise) { +void prepare_arc_move(bool isclockwise) { float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc // Trace the arc mc_arc(current_position, destination, offset, feedrate * feedmultiply / 60 / 100.0, r, isclockwise, active_extruder); diff --git a/Firmware/motion_control.cpp b/Firmware/motion_control.cpp index 68784300..af7e69a8 100644 --- a/Firmware/motion_control.cpp +++ b/Firmware/motion_control.cpp @@ -26,7 +26,7 @@ // The arc is approximated by generating a huge number of tiny, linear segments. The length of each // segment is configured in settings.mm_per_arc_segment. -void mc_arc(float* position, float* target, float* offset, float feed_rate, float radius, uint8_t isclockwise, uint8_t extruder) +void mc_arc(float* position, float* target, float* offset, float feed_rate, float radius, bool isclockwise, uint8_t extruder) { float r_axis_x = -offset[X_AXIS]; // Radius vector from center to current location float r_axis_y = -offset[Y_AXIS]; @@ -38,7 +38,7 @@ void mc_arc(float* position, float* target, float* offset, float feed_rate, floa // 20200419 - Add a variable that will be used to hold the arc segment length float mm_per_arc_segment = cs.mm_per_arc_segment; // 20210109 - Add a variable to hold the n_arc_correction value - uint8_t n_arc_correction = cs.n_arc_correction; + unsigned char n_arc_correction = cs.n_arc_correction; // CCW angle between position and target from circle center. Only one atan2() trig computation required. float angular_travel_total = atan2(r_axis_x * rt_y - r_axis_y * rt_x, r_axis_x * rt_x + r_axis_y * rt_y); @@ -88,7 +88,7 @@ void mc_arc(float* position, float* target, float* offset, float feed_rate, floa if (millimeters_of_travel_arc < 0.001) { return; } // Calculate the number of arc segments - uint16_t segments = static_cast(ceil(millimeters_of_travel_arc / mm_per_arc_segment)); + unsigned short segments = static_cast(ceil(millimeters_of_travel_arc / mm_per_arc_segment)); /* Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector, and phi is the angle of rotation. Based on the solution approach by Jens Geisler. diff --git a/Firmware/motion_control.h b/Firmware/motion_control.h index 95186cba..4cc16ffa 100644 --- a/Firmware/motion_control.h +++ b/Firmware/motion_control.h @@ -27,6 +27,6 @@ // the direction of helical travel, radius == circle radius, isclockwise boolean. Used // for vector transformation direction. void mc_arc(float *position, float *target, float *offset, float feed_rate, float radius, - unsigned char isclockwise, uint8_t extruder); + bool isclockwise, uint8_t extruder); #endif